Time Series as Dynamical Systems: Delay Embedding

Reconstruct a chaotic attractor from a single time series with Takens delay embedding, then forecast it with simplex projection, from scratch in NumPy.

Cover Image for Time Series as Dynamical Systems: Delay Embedding

You record one measurement from a changing system, such as a population count or a sensor reading. The trace looks irregular, but that does not by itself tell you whether the changes come from noise or from deterministic dynamics. Chaotic dynamics can make a deterministic system look noisy. Its recent history may carry information about parts of the system you cannot measure directly.

The recent history can supply missing coordinates, as Takens' 1981 result describes. We reconstruct a Lorenz state from one measured coordinate. Simplex projection gives correlation 0.99 a third of a time unit ahead, against 0.39 for linear forecasting. A Lyapunov exponent near 0.96 per time unit limits how far that improvement extends.

Let's Build It

Click the badge to open the full, runnable notebook in Google Colab:

Open In Colab

Here is the whole trick, animated: we feed in one variable of the Lorenz system, the x(t)x(t) signal, and out comes the butterfly attractor traced in a space built only from delayed copies of xx.

A comet tracing the Lorenz butterfly attractor in a 3-D space whose axes are x(t), x(t-16) and x(t-32), all derived from a single measured signal.

import numpy as np

def lorenz(n, dt=0.01, sigma=10.0, rho=28.0, beta=8.0 / 3.0,
           x0=(1.0, 1.0, 1.0), transient=2000):
    """Integrate the Lorenz system with RK4. Returns (n, 3) after the transient."""
    def f(s):
        x, y, z = s
        return np.array([sigma * (y - x), x * (rho - z) - y, x * y - beta * z])
    traj = np.empty((n + transient, 3))
    s = np.array(x0, float)
    for i in range(n + transient):
        traj[i] = s
        k1 = f(s); k2 = f(s + 0.5 * dt * k1)
        k3 = f(s + 0.5 * dt * k2); k4 = f(s + dt * k3)
        s = s + (dt / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4)
    return traj[transient:]

def time_delay_embed(x, tau, m):
    """Delay vectors [x(t), x(t-tau), ..., x(t-(m-1)tau)]. Returns (N, m)."""
    N = len(x) - (m - 1) * tau
    return np.column_stack([x[i * tau: i * tau + N] for i in range(m)])

traj = lorenz(8000)
x = traj[:, 0]                       # pretend we can only measure this one coordinate
embedded = time_delay_embed(x, tau=16, m=3)
print(embedded.shape)                # (7968, 3): one 3-D point per instant

Three panels: the raw x(t) signal we measure, the true Lorenz attractor in (x, y, z), and the attractor reconstructed from x(t) alone using delay coordinates. The reconstruction is a sheared copy of the original butterfly.

The middle panel is the real attractor, plotted from all three Lorenz coordinates. The right panel uses only x(t)x(t) and two delayed copies of it. The two are not identical, but they have the same shape: two lobes, the same loops, the same holes. We rebuilt the geometry of a three-dimensional system from a single one-dimensional measurement.

What Just Happened?

The idea sounds like it should be impossible. We measured one number over time and recovered a three-dimensional object. How can a delayed copy of xx stand in for the yy and zz we never saw?

The reason is that the variables of a coupled system leak into each other. In the Lorenz equations, x˙=σ(y−x)\dot{x} = \sigma(y - x), so the rate of change of xx carries information about yy. A delayed value x(t−τ)x(t - \tau) is a proxy for that rate of change: the difference x(t)−x(t−τ)x(t) - x(t-\tau) is a crude derivative, and the derivative depends on the unmeasured coordinates. Stack enough delays and you span the same information the full state would.

Takens made this precise. A delay vector

v(t)=[ x(t),  x(t−τ),  x(t−2τ),  …,  x(t−(m−1)τ) ]\mathbf{v}(t) = \big[\,x(t),\; x(t-\tau),\; x(t-2\tau),\; \dots,\; x(t-(m-1)\tau)\,\big]

traces out a shape that is a smooth, invertible deformation (a diffeomorphism) of the true attractor, as long as the dimension mm is large enough. Distances, neighbours, and the branching structure are preserved. That is exactly what we need for forecasting: points that sit near each other on the reconstructed attractor are in similar states, so their near futures are similar too.

A schematic: the left panel reads one signal at three delayed times t-2tau, t-tau and t, marking three dots; the right panel shows those three values becoming a single highlighted point on the reconstructed attractor.

Think of it like recognising a song from a few notes. No single note identifies the tune, but three consecutive notes pin down where you are in the melody. Each delayed sample is a note; the delay vector is the short phrase that locates you on the attractor.

Going Deeper

Delay embedding has two free parameters, the delay τ\tau and the dimension mm, and the data can choose both.

Choosing the delay and the dimension

Pick τ\tau too small and the coordinates x(t)x(t) and x(t−τ)x(t-\tau) are nearly identical, so the attractor collapses onto the diagonal. Pick it too large and, for a chaotic system, the coordinates become effectively unrelated and the shape folds into noise. The standard rule takes the first minimum of the average mutual information between x(t)x(t) and x(t+τ)x(t+\tau): the smallest delay at which the delayed copy adds new information rather than a near-duplicate.

For mm, the false nearest neighbours test asks a simple question. Two points that look like close neighbours in mm dimensions might only be close because the embedding is too cramped, projecting distant parts of the attractor on top of each other. Add one more dimension: if the neighbours fly apart, they were false. Raise mm until the fraction of false neighbours drops to zero.

def mutual_information(x, max_lag=60, bins=32):
    ami = np.empty(max_lag)
    for lag in range(1, max_lag + 1):
        c, _, _ = np.histogram2d(x[:-lag], x[lag:], bins=bins)
        p = c / c.sum()
        pa, pb = p.sum(1), p.sum(0)
        nz = p > 0
        ami[lag - 1] = np.sum(p[nz] * np.log(p[nz] / (pa[:, None] * pb[None, :])[nz]))
    return ami

def first_minimum(curve):
    """First local minimum of a 1-D curve (the delay we want)."""
    for i in range(1, len(curve) - 1):
        if curve[i] < curve[i - 1] and curve[i] < curve[i + 1]:
            return i + 1
    return int(np.argmin(curve)) + 1

tau = first_minimum(mutual_information(x))     # -> 16 samples

Two panels. Left: average mutual information versus delay, with the first minimum marked at tau equals 16 samples. Right: the fraction of false nearest neighbours versus embedding dimension, collapsing from 99 percent at m equals 1 to zero at m equals 3.

The data speaks clearly. Mutual information bottoms out at τ=16\tau = 16 samples, and false nearest neighbours collapse from 99% at m=1m = 1 to 5% at m=2m = 2 and 0% at m=3m = 3. The method recovers the true dimension of the Lorenz system, three, without ever being told the equations.

Forecasting with simplex projection

Once the attractor is reconstructed, forecasting needs no fitted equation. To predict where the system goes next from some current state, find the handful of past states that sat closest to it on the attractor, see where each of them went, and take a distance-weighted average of those outcomes. This is simplex projection, and it is nearest-neighbour forecasting on the reconstructed manifold.

from scipy.spatial import cKDTree

def simplex_forecast(x, tau, m, Tp, lib_frac=0.6):
    emb = time_delay_embed(x, tau, m)
    tip = (m - 1) * tau
    split = int(len(emb) * lib_frac)
    lib = np.arange(split); lib = lib[tip + lib + Tp < len(x)]
    pred = np.arange(split, len(emb)); pred = pred[tip + pred + Tp < len(x)]
    tree = cKDTree(emb[lib])
    dist, nbr = tree.query(emb[pred], k=m + 1)         # m+1 nearest neighbours
    w = np.exp(-dist / np.maximum(dist[:, [0]], 1e-12))
    w /= w.sum(1, keepdims=True)
    predicted = np.sum(w * x[tip + lib[nbr] + Tp], axis=1)   # weighted future
    actual = x[tip + pred + Tp]
    return predicted, actual

The payoff is the difference between a nonlinear and a linear view of the same data. We compare simplex projection against a linear autoregression fitted on the identical delay coordinates, forecasting further and further ahead.

Forecast skill (correlation between predicted and actual) versus horizon. Simplex projection stays above 0.9 out to more than a full time unit and only slowly declines, while the linear model collapses through zero and goes negative by a horizon of one time unit.

One step ahead, both methods score a near-perfect correlation of 1.0: over a tiny interval even chaos looks linear. As the horizon grows they separate sharply. At a third of a time unit the simplex forecast still scores 0.99 while the linear model has fallen to 0.39. Push further and the linear model's skill drops through zero and turns negative, worse than guessing the mean, while simplex projection holds above 0.8. The nonlinear method captures the deterministic rule that the linear model cannot see.

The predictability horizon

Simplex projection does not hold forever, and that is not a flaw in the method. It is chaos. Two states that start imperceptibly close drift apart at an exponential rate, the defining property of a chaotic system, and the rate is the largest Lyapunov exponent λ\lambda. Follow pairs of nearby points on the reconstructed attractor, watch how their separation grows, and the slope of the log-separation gives λ\lambda directly (the Rosenstein method).

Mean log separation of initially close trajectories versus time. After a short transient the curve is linear, and a fitted line over that region gives a Lyapunov exponent of about 0.96 per time unit, implying a predictability horizon near one time unit.

The fitted slope is λ≈0.96\lambda \approx 0.96 per time unit, close to the textbook Lorenz value of 0.906. Its reciprocal, 1/λ≈11/\lambda \approx 1 time unit, is the predictability horizon: the timescale over which a small error grows by a factor of ee. That is why the simplex skill curve decays where it does. No model, however clever, forecasts a chaotic system far past its Lyapunov horizon, because the information you started with has been amplified beyond recognition.

When this works and when it does not

The method shines on the Lorenz system because that system is exactly what the theory assumes: low-dimensional, deterministic, densely sampled, almost noise-free. Real data rarely obliges on all four counts.

Two panels. Left: yearly sunspot counts from 1700 to 2008, showing the roughly 11-year solar cycle. Right: the attractor reconstructed from the sunspot series with a 4-year delay, a noisy loop rather than a clean butterfly.

The sunspot record is a favourite test case: a strong roughly 11-year cycle with real nonlinearity in its amplitude. Reconstructed with a 4-year delay, it shows a clear cyclic core, evidence of deterministic structure, but the loop is fuzzy. The series is short (about 300 yearly points), observational noise is large, and the underlying dynamics are higher-dimensional than Lorenz. Delay embedding still adds a genuine nonlinear lens the statistical models lack, but the clean attractor and the long predictability horizon of the textbook example do not survive contact with messy data. Reach for these methods when you suspect low-dimensional determinism and have a long, clean series; keep a statistical model like ARIMA or a changepoint detector when the series is short, dominated by noise, or stochastic rather than deterministic.

Where This Comes From

The chain of ideas runs from a topology theorem to a working forecasting toolkit.

A timeline from Takens (1981, delay embedding rebuilds the attractor) to Sugihara and May (1990, simplex projection, chaos versus noise) to Kennel et al. (1992, false nearest neighbours for the dimension m) to Rosenstein (1993, Lyapunov from a single series) to Sugihara et al. (2012, convergent cross mapping for causality).

Floris Takens (1981), "Detecting Strange Attractors in Turbulence", proved the embedding theorem. His result guarantees that for a generic observation function and an embedding dimension m>2dm > 2d (where dd is the attractor's dimension), the delay map is an embedding: the reconstructed and true attractors are diffeomorphic. The two-lobed shape we recovered is that theorem made visible.

George Sugihara and Robert May (1990), "Nonlinear forecasting as a way of distinguishing chaos from measurement error", turned the theorem into a test. Their insight is that the shape of the skill-versus-horizon curve is diagnostic:

"For chaotic time series, the accuracy of nonlinear forecasts falls off with increasing prediction interval; for uncorrelated noise, forecasting accuracy is independent of the prediction interval."

A skill curve that decays with horizon, exactly the simplex curve we plotted, is a fingerprint of deterministic chaos rather than random noise. Kennel, Brown and Abarbanel (1992) contributed the false-nearest-neighbours criterion for mm, and Rosenstein, Collins and De Luca (1993) gave the practical algorithm for estimating λ\lambda from a single series that we used. Two decades later, Sugihara et al. (2012), "Detecting Causality in Complex Ecosystems", extended the same reconstruction idea into convergent cross mapping, a way to infer which variable drives which from observational time series alone. The humble delay vector turns out to be a tool for forecasting, for telling chaos from noise, and for causality.

Interactive Tools

  • Markov Chain Simulator: Watch a state evolve under fixed transition rules; a dynamical system is the deterministic, continuous cousin of a Markov chain.
  • Regression Playground: Fit the linear models that simplex projection outperforms once the dynamics turn nonlinear.
  • Gaussian Process Playground: Another model-free forecaster: a GP predicts from similarity in input space the way simplex predicts from proximity on the attractor.

Stay in the loop

Get notified when new tutorials and deep-dives are published. No spam, unsubscribe anytime.

Related Posts

Frequently Asked Questions