Nonlinear dynamical systems: chaos and predictability
Quantify the loss of trajectory predictability in chaotic systems with Lyapunov exponents, and examine strange attractors, Poincaré sections, shadowing and ensemble prediction.
After this lesson you can
- Simulate Lorenz-63 and Lorenz-96 and characterize their attractors.
- Calculate the Lyapunov spectrum using Benettin's algorithm and QR reorthogonalization.
- Estimate the predictability horizon from the largest exponent and initial error.
- Construct Poincaré sections and return maps to reduce a flow to a discrete map.
- Explain shadowing and the conditions under which statistics of chaotic simulations are useful.
Before you start
The limit of a trajectory
A weather simulation starts from imperfect observations. Even if the model and integrator were exact, two nearby initial states can separate until they are indistinguishable from two typical states of the system. At that point, interpreting a trajectory as a point prediction is no longer useful. This does not imply that every statistical property is unpredictable: the state distribution and aggregate risks can remain informative after the phase of an individual trajectory is lost.
Linearization describes small perturbations. For and a solution , the tangent vector satisfies . A finite perturbation follows this equation only while sufficiently small; once comparable to the size of the attractor, separation saturates and a line fitted to the entire interval does not estimate initial growth.
Two distinct limits are involved. Reducing the integration step usually brings the numerical solution closer to the exact one over a finite interval, provided the method converges and its assumptions hold. Reducing initial uncertainty brings the prediction closer to the evolution of the actual state. In a sensitive system either difference can be amplified: comparing two integrators at the end of a long interval does not by itself identify which failed. Compare short times first, then check long-term statistics and structural properties.
Lorenz and sensitivity
The 1963 Lorenz system is a reduced model of convection, not an operational forecast:
With , , it shows two lobes and sensitivity to initial conditions. A strange attractor is an invariant set that attracts orbits from a region and has nontrivial geometric structure; “strange” and “chaotic” describe related, not identical, properties. The figure integrates two orbits instead of drawing idealized exponential separation.
If while the perturbation is small and , the predictability horizon for threshold is approximately . Reducing by a factor of one thousand adds rather than multiplying the horizon by one thousand. The finite-time rate fluctuates and the chosen threshold matters. A real atmosphere also has model and observation errors and unresolved variables; no universal number of days follows from this formula.
For example, with , and , the formula gives approximately time units. If initial error is , it gives approximately . Both figures are exponential-model calculations, not measurements from the figure. On the separation curve, first find a region where distance remains small and compare several initial conditions: local oscillations can be as important as the mean trend in a single segment.
Exponents and reorthogonalization
Lyapunov exponents describe asymptotic exponential rates along different tangent directions. Under the integrability and invariance assumptions of Oseledets’ multiplicative ergodic theorem, they exist almost everywhere for the invariant measure considered. The largest measures typical growth of infinitesimal perturbations, not an instantaneous value or a guarantee that every finite perturbation grows monotonically.
To obtain the spectrum, Benettin’s algorithm integrates the state and a matrix of tangent vectors with . Periodically it factors , adds and restarts the vectors with . Dividing the sums by time gives finite-time estimates. Without QR, all generic vectors align with the dominant direction and the rest of the spectrum is lost. State and tangent evolution must use the same integrator stages.
Liouville’s formula for the fundamental matrix gives . If the corresponding limits exist, the time average of divergence is the sum of exponents. For Lorenz-63 it is . In an autonomous flow, the field’s own direction is tangent to a time shift; along a bounded regular nonstationary orbit, under the usual assumptions, it gives a zero exponent. An equilibrium does not automatically satisfy that statement.
Checking the sum detects sign, stage or accumulation errors; it does not identify which individual exponent is wrong. The factorization also has a sign convention: can be negative depending on implementation, so its absolute value is accumulated. The interval between QR steps should avoid both collapse from poor conditioning and unnecessary cost from excessive frequency. Try several intervals and durations, and first test a linear system with known exponents.
Period doubling and return
The logistic map provides a discrete laboratory. As varies, fixed points, cycles and chaotic regions appear, interrupted by periodic windows. Its finite-time exponent is the average of . A positive value indicates average expansion for the observed orbit; transient and duration matter.
For a nonzero fixed point, and the map derivative is . Local stability requires , that is, . Crossing loses this stability and produces a period-two cycle; further doublings appear later. For a periodic orbit of period , the exponent is : it is negative if the derivative product has magnitude less than one. Near a bifurcation, an exponent near zero can make a fixed transient insufficient.
Ratios of distances between successive bifurcations approach the Feigenbaum constant for the appropriate family and limit. A finite-resolution image is insufficient for an accurate measurement: bifurcations must be located, cycle order verified and numerical error controlled.
In this family, each point can be found by solving and for periods . The next cell obtains an initial approximation by iterating slightly before each bifurcation; initial values of select the branch, and the residual is checked. Ratios of successive distances are a reproducible numerical measurement, not values read from pixels.
import numpy as np
from scipy.optimize import root
def cycle(x,r,n):
product=1.
for _ in range(n):
product*=r*(1-2*x)
x=r*x*(1-x)
return x,product
def bifurcation(n,guess):
r=guess-.0001;x=.37
for _ in range(200000): x=r*x*(1-x)
result=root(lambda z:[cycle(z[0],z[1],n)[0]-z[0],cycle(z[0],z[1],n)[1]+1],[x,guess],tol=1e-12)
if np.linalg.norm(result.fun)>1e-8 or abs(result.x[1]-guess)>1e-4: raise RuntimeError('no se localizó la rama')
return result.x[1]
values=np.array([bifurcation(n,g) for n,g in [(1,3.),(2,3.449489743),(4,3.544090359),(8,3.564407266),(16,3.56875942)]])
print('bifurcaciones:',values)
print('razones sucesivas:',np.diff(values)[:-1]/np.diff(values)[1:])A Poincaré section records where a flow crosses a transverse surface in a chosen direction. It reduces a continuous trajectory to a sequence of points; changing direction mixes different crossings. The map of successive maxima of is another reduction, related to but not identical to an arbitrary horizontal section.
Shadowing and statistics
Shadowing states, in versions with hyperbolicity assumptions and sufficiently small local errors, that a pseudoorbit stays close to some exact orbit over the interval considered. That orbit may start from a different initial state: the result does not recover the actual observed trajectory or automatically guarantee validity for every system or integrator.
Ergodic statistics connect time averages and expectations with respect to an invariant measure when the ergodic theorem’s assumptions hold. Discarding a transient does not prove stationarity or ergodicity. To quantify uncertainty of a correlated average, divide a long trajectory into sufficiently long blocks or estimate autocorrelation; comparing replicates and integration steps helps detect bias. An ensemble of initial conditions can estimate distributions and probabilities, provided it reflects initial and model uncertainty.
If the average of correlated values is treated as if they were independent, the estimated standard deviation can be too small. In a stationary process with summable autocorrelations , the variance of the average behaves approximately as , where . In practice the sum must be truncated and sensitivity to truncation checked. Blocks offer an alternative: calculate each block mean, increase block length until estimated uncertainty changes negligibly and check that enough blocks remain. Neither procedure eliminates discretization bias or an incorrect invariant measure.
Lab: Lorenz-96 and the full spectrum
On a ring of variables, , with periodic indices. Its divergence is . The code integrates state and tangents using RK4 and reorthogonalizes by QR. Finite-time estimates are not exact values; repeat with longer times, smaller steps and different transients.
import numpy as np
def lorenz96(x, forcing=8.0):
x=np.asarray(x,dtype=float)
if x.ndim!=1 or len(x)<4: raise ValueError('se requieren al menos cuatro variables')
return (np.roll(x,-1)-np.roll(x,2))*np.roll(x,1)-x+forcing
def jacobian96(x, forcing=8.0):
x=np.asarray(x,dtype=float); n=len(x)
if x.ndim!=1 or n<4: raise ValueError('se requieren al menos cuatro variables')
i=np.arange(n); J=-np.eye(n)
J[i,(i+1)%n]+=x[(i-1)%n]
J[i,(i-2)%n]-=x[(i-1)%n]
J[i,(i-1)%n]+=x[(i+1)%n]-x[(i-2)%n]
return J
def rk4_tangent(f,jac,x,Q,dt):
def rhs(y,V): return f(y),jac(y)@V
a,A=rhs(x,Q); b,B=rhs(x+dt*a/2,Q+dt*A/2)
c,C=rhs(x+dt*b/2,Q+dt*B/2); d,D=rhs(x+dt*c,Q+dt*C)
return x+dt*(a+2*b+2*c+d)/6, Q+dt*(A+2*B+2*C+D)/6
def lyapunov_spectrum(f,jac,x0,dt,n_steps,qr_every=5,burn_steps=0):
x=np.asarray(x0,dtype=float).copy()
if x.ndim!=1 or not np.all(np.isfinite(x)) or dt<=0 or n_steps<=0 or qr_every<1 or burn_steps<0: raise ValueError('parámetros inválidos')
Q=np.eye(len(x))
for _ in range(burn_steps):
x,Q=rk4_tangent(f,jac,x,Q,dt); Q,_=np.linalg.qr(Q)
Q=np.eye(len(x)); sums=np.zeros(len(x))
for i in range(n_steps):
x,Q=rk4_tangent(f,jac,x,Q,dt)
if (i+1)%qr_every==0 or i+1==n_steps:
Q,R=np.linalg.qr(Q); diagonal=np.abs(np.diag(R))
if np.any(diagonal==0): raise FloatingPointError('base tangente singular')
sums+=np.log(diagonal)
return sums/(n_steps*dt)
def kaplan_yorke(exponents):
lam=np.sort(np.asarray(exponents,dtype=float))[::-1]
if not len(lam) or not np.all(np.isfinite(lam)): raise ValueError('espectro inválido')
sums=np.cumsum(lam); positive=np.flatnonzero(sums>=0)
if not len(positive): return 0.0
j=int(positive[-1])+1
return float(j if j==len(lam) else j+sums[j-1]/abs(lam[j]))x0=np.full(8,8.); x0[0]+=.01
exponents=lyapunov_spectrum(lorenz96,jacobian96,x0,.02,1000,5,400)
print('espectro finito:',exponents)
print('suma y divergencia:',sum(exponents),-len(x0))
print('dimensión Kaplan-Yorke estimada:',kaplan_yorke(exponents))The Kaplan-Yorke dimension interpolates between partial sums of ordered exponents. It is an estimate associated with the spectrum, not an exact measurement of geometric dimension for every system. A sum close to checks the volume balance, but does not establish convergence of every exponent.
rng=np.random.default_rng(42)
base=np.full(8,8.);base[0]+=.01
ensemble=base+rng.normal(size=(20,8))*1e-6
initial_rms=np.sqrt(np.mean(np.sum((ensemble-base)**2,axis=1)))
def field_batch(x): return (np.roll(x,-1,axis=1)-np.roll(x,2,axis=1))*np.roll(x,1,axis=1)-x+8
def advance(x,h):
a=field_batch(x);b=field_batch(x+h*a/2);c=field_batch(x+h*b/2);d=field_batch(x+h*c)
return x+h*(a+2*b+2*c+d)/6
reference=base[None,:]
first=None; threshold=1.
for step in range(1000):
ensemble=advance(ensemble,.02);reference=advance(reference,.02)
rms=np.sqrt(np.mean(np.sum((ensemble-reference)**2,axis=1)))
if first is None and rms>=threshold: first=(step+1)*.02
print('primer tiempo RMS >= 1:',first,'error RMS final:',rms)predicted=np.log(1/initial_rms)/exponents[0]
print('RMS inicial:',initial_rms,'predicción exponencial:',predicted,'primer cruce medido:',first)The horizon here is defined by a specific norm threshold and a synthetic ensemble with a fixed seed. The reference starts near the unstable uniform equilibrium, while the spectrum discards a transient: initial local rates and perturbation orientations prevent expecting exact agreement. None would mean that the threshold was not reached in the simulated interval. The result tests the procedure in this model, not atmospheric predictability.
Exercises
Step 1 of 3. What does Liouville's formula state?
import numpy as np
def lyapunov_spectrum(f, jac, x0, dt, n_steps):
pass