Definition of a Hamiltonian Lorenz model - cchandre/HamLorenz GitHub Wiki
Custom Hamiltonian Lorenz Models
A custom Hamiltonian Lorenz model can be defined by specifying either f
, phi
, or both (if they are mathematically compatible, i.e., $f(x)\phi\prime(x)=1$) when creating an instance of the class. For example:
hl = HamLorenz(100, phi=sp.sinh(x))
If provided, f
and phi
must be SymPy expressions. The model requires computing the inverse of the function $\phi$. This is done in two steps:
-
Symbolic inversion:
SymPy first attempts to compute the inverse usingsympy.solve
.- If multiple branches are found, the user is prompted to choose which one to use.
-
Numerical fallback:
If symbolic inversion fails, the inverse is computed numerically using SciPy’sroot_scalar
with Newton’s method.- Note: This numerical method is significantly slower than symbolic inversion.
Notes
- The default model uses a cubic nonlinearity: $\phi(x) = x + \frac{x^3}{3}$.
- If only
f
is specified, the code symbolically computes the correspondingphi
using SymPy before converting it to a NumPy function. - Likewise, if only
phi
is specified,f
is derived symbolically. - If both are provided, the code checks their consistency, ensuring that $f(x)\phi\prime(x) = 1$.
Correlation in the Model
Correlation is introduced through a correlation length $K$ and a coefficient vector ($\xi_1$,..., $\xi_{K}$).
By default:
- $K = 1$
- $\xi = 1$
Notes
- If
xi
has fewer thanK
elements, it is automatically expanded to lengthK
by repeating $\xi_1$. AUserWarning
is issued. - If
xi
has more thanK
elements, it is truncated to the firstK
entries. AUserWarning
is also issued in this case.