ntsa.tools.lyapunov
At a glance
| Function | One-liner |
|---|---|
get_rhs(model) |
RHS callable f(u) from model.time_derivative (continuous models only). |
fd_jacobian(f, u, eps=1e-6) |
Finite-difference Jacobian. |
get_jacobian(model, f=None) |
Analytic Jacobian for Lorenz63/96, finite-difference otherwise. |
lyapunov_spectrum(model, ...) |
Full spectrum via tangent-space QR (Benettin / Gram-Schmidt), sorted descending; runs until the running exponents converge (halving test), full_output=True returns the convergence history. |
leading_lyapunov(model, n_pert=8, ...) |
\(\lambda_1 \pm\) std from perturbation-growth fit; works for any Model. |
rosenstein_lyapunov(x, dt, ...) |
Data-only \(\lambda_1\) from a scalar series (Rosenstein et al. 1993): Theiler-windowed nearest-neighbour divergence, fitted with fit_log_growth — no model equations needed. |
fit_log_growth(t, log_seps) |
Linear-region fit of log separation; nan if \(R^2 < 0.5\). |
kaplan_yorke(exponents) |
Kaplan–Yorke dimension from a spectrum (shown as a box on the delay-portrait panel). |
covariant_lyapunov_vectors(...) |
TODO stub (Ginelli et al. 2007) — raises NotImplementedError. |
Full reference
ntsa.tools.lyapunov
Lyapunov exponent tools for continuous-time dynamical-system models.
Benettin QR spectrum (joint RK4 state+tangent integration), leading-exponent estimation from perturbation growth, analytic/finite-difference Jacobians, and a data-only Rosenstein estimator for measured series (no equations needed). Reference: Kantz & Schreiber, "Nonlinear Time Series Analysis", Ch. 11.
get_rhs(model)
Return f(u) -> du/dt for a continuous-time model.
Parameters read once from {**model.alpha0, **model.governing_eqns_params}.
Raises AttributeError for discrete-map models (no time_derivative).
Source code in ntsa/tools/lyapunov.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
fd_jacobian(f, u, eps=1e-06)
Central-difference Jacobian of f at u, per-column step h = eps*max(1, |u_j|).
Source code in ntsa/tools/lyapunov.py
73 74 75 76 77 78 79 80 81 82 83 84 | |
get_jacobian(model, f=None)
Return jac(u) -> (N, N): analytic for Lorenz63/Lorenz96, else finite differences.
Source code in ntsa/tools/lyapunov.py
87 88 89 90 91 92 93 | |
lyapunov_spectrum(model, n_exp=None, dt=None, t_transient=None, t_run=None, t_max=None, atol=0.002, rtol=0.05, N_gs=4, u0=None, seed=0, verbose=True, full_output=False)
Lyapunov spectrum via Gram-Schmidt reorthonormalisation (Benettin et al.).
Integrates state + tangent space with a fixed-step joint RK4, so dt
defaults to min(model.dt, 0.01) to keep the tangent propagation accurate.
Times default to multiples of t_lyap (t_CR fallback): warmup 10x, run 200x.
t_run is a floor, not the horizon: integration continues (up to t_max,
default 20t_run) until every running exponent satisfies the halving test
|lam_j(T) - lam_j(T/2)| < max(atol, rtol|lam_j(T)|) at two consecutive
checks (one pass can be a phase coincidence on a periodic orbit). This
catches both the O(1/T) drift of neutral exponents on limit cycles — atol
is effectively how close to zero they must land — and the slow statistical
convergence of chaotic ones. Warns if t_max is hit unconverged.
Returns:
| Type | Description |
|---|---|
np.ndarray, shape (n_exp,), sorted descending. With ``full_output=True``,
|
|
returns ``(exponents, info)`` where info has T, converged, t_hist and
|
|
lam_hist (running estimates, one row per QR step, unsorted).
|
|
Source code in ntsa/tools/lyapunov.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
fit_log_growth(t, log_seps)
Fit the exponential-growth window of mean log-separation curves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
(Nt,) times; log_seps : (Nt, n_pert) per-member log separations.
|
|
required |
Returns:
| Type | Description |
|---|---|
(lam1, lam1_std, i1, i2, r2); lam1 is nan when r2 < 0.5 or window too short.
|
|
Source code in ntsa/tools/lyapunov.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
leading_lyapunov(model, n_pert=8, eps=1e-06, t_run=None, seed=0)
Leading Lyapunov exponent from the growth of small random perturbations.
Integrates one reference and n_pert perturbed trajectories SERIALLY
(m=1 each) and fits the linear window of the mean log separation.
Returns:
| Type | Description |
|---|---|
(lam1, lam1_std, res) with res holding t, log_sep, mean_log_sep, i1, i2,
|
|
r2, lam1, lam1_std, sat, diam. lam1 is nan when the fit is rejected —
|
|
R^2 < 0.5, no real growth range, or saturation far below the attractor
|
|
diameter (non-normal transient amplification, not chaos).
|
|
Source code in ntsa/tools/lyapunov.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
rosenstein_lyapunov(x, dt, zeta=None, dim=None, theiler=None, k_max=None, n_ref=1000)
Data-only leading Lyapunov exponent from a scalar series (Rosenstein et al. 1993).
Delay-embeds x, pairs each reference point with its nearest neighbour at
least a Theiler window away in time, tracks the pairwise divergence, and fits
the linear window of the mean log divergence with fit_log_growth — so the
same rejection guards apply as in leading_lyapunov (R^2 >= 0.5 and a real
exponential-growth range): periodic or noise-floor-bound data returns nan
rather than a spurious slope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Scalar series, shape (Nt,). |
required |
dt
|
float
|
Sampling time. |
required |
zeta
|
int
|
Embedding delay/dimension; default |
None
|
dim
|
int
|
Embedding delay/dimension; default |
None
|
theiler
|
int
|
Temporal exclusion window (samples) for the neighbour search; default the
mean inter-maximum spacing (the signal's mean period), floored at |
None
|
k_max
|
int
|
Divergence-tracking horizon (samples); default 10 Theiler windows, capped so every pair can be tracked to the end of the record. |
None
|
n_ref
|
int
|
Maximum number of reference points, strided over the record. |
1000
|
Returns:
| Type | Description |
|---|---|
(lam1, lam1_std, res) mirroring `leading_lyapunov`; `res` plugs into
|
|
`characterize.plot_lyapunov_fit` and adds zeta, dim, theiler, n_pairs.
|
|
`lam1_std` is the slope spread across 8 blocks of pairs (pseudo-members),
|
|
not the raw pair-to-pair scatter. Raises ValueError when the record is too
|
|
short to form a divergence horizon or enough neighbour pairs.
|
|
Source code in ntsa/tools/lyapunov.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
kaplan_yorke(exponents, tol=0.002)
Kaplan-Yorke dimension from a sorted-descending Lyapunov spectrum.
D_KY = j + sum_{i<=j} lam_i / |lam_{j+1}| with j the largest index keeping the cumulative sum >= -tol (tol absorbs the finite-time jitter of neutral exponents, so a limit cycle reads ~1 instead of 0). Returns 0.0 for an all-contracting spectrum (fixed point) and Nphi if the sum never turns negative within the resolved exponents.
Source code in ntsa/tools/lyapunov.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
covariant_lyapunov_vectors(*args, **kwargs)
Covariant Lyapunov vectors — not implemented.
Source code in ntsa/tools/lyapunov.py
451 452 453 454 | |