The logistic map and the road to chaos

The logistic map and the road to chaos
Page content

Take a number between 0 and 1. Multiply it by one minus itself, then by a constant $r$. Feed the result back in and repeat:

$$ x_{n+1} = r x_n (1 - x_n) $$

For some values of $r$ the sequence settles on one number. For others it bounces between 2, 4 or 8 values, and for others it never repeats and looks like noise. It is one multiplication away from a linear recurrence, and most of the vocabulary of chaos can be read off it.

This is the first post in a series on dynamical systems and chaos. I start here because everything can be computed in a few lines and checked by eye.

Where the map comes from

The map became famous through a 1976 review by the ecologist Robert May, Simple mathematical models with very complicated dynamics. He starts from a population that breeds once a season, with generations that do not overlap. If $N_t$ is the size of generation $t$, the simplest model with growth and crowding is $N_{t+1} = N_t (a - b N_t)$. Rescale with $x = bN/a$ and you get the equation above with $r = a$. For $r$ between 0 and 4 the interval from 0 to 1 maps into itself.

May ends the review asking for this equation to be taught early, because “we would all be better off if more people realised that simple nonlinear systems do not necessarily possess simple dynamical properties”.

The continuous version of the same idea is the logistic equation $\dot{x} = x (1 - x)$, and it is boring: every positive start moves monotonically to $x = 1$ and stays there. It has to. A flow on a line cannot jump over a fixed point, so it can never overshoot.

A map can, and for a programmer there is a neat way to connect the two. Integrate the logistic equation with forward Euler and a step $h$: $y_{n+1} = y_n + h y_n (1 - y_n)$. Substitute $x = h y / (1 + h)$ and this is exactly the logistic map with $r = 1 + h$. So everything below is what explicit Euler does to a perfectly tame equation when the time step is too big. If you have ever watched a physics integrator blow up, you have seen the first act :).

Fixed points and the first doubling

Write $f(x) = r x (1 - x)$. Solving $f(x) = x$ gives two fixed points, $x = 0$ and $x^\ast = 1 - 1/r$. A small error $e$ near a fixed point becomes $f^{\prime}(x^\ast) e$ after one step, so the point is stable when $\left| f^{\prime}(x^\ast) \right| \lt 1$. Here $f^{\prime}(x) = r (1 - 2x)$, which gives $f^{\prime}(0) = r$ and $f^{\prime}(x^\ast) = 2 - r$.

The origin is stable for $r \lt 1$ (the population dies out) and $x^\ast$ is stable for $1 \lt r \lt 3$. Above $r = 2$ the slope is negative, so the orbit closes in while jumping from one side to the other. At $r = 3$ the slope is exactly $-1$. In Euler terms that is $h = 2$, the textbook stability limit of the method for a decay rate of 1.

What comes next is not an explosion, because the map is bounded. Look for points that return after two steps, $f(f(x)) = x$. That is a quartic, but two of its roots are the fixed points. Dividing them out leaves $r^2 x^2 - r (r + 1) x + (r + 1) = 0$, so

$$ x_\pm = \frac{r + 1 \pm \sqrt{(r - 3)(r + 1)}}{2r} $$

The square root is real exactly when $r \ge 3$. A pair of points that swap with each other is born at $r = 3$, on the very spot where the fixed point loses its stability. By the chain rule this 2-cycle is stable while $\left| f^{\prime}(x_+) f^{\prime}(x_-) \right| \lt 1$, and using the sum and the product of the roots the product of slopes comes out as $4 + 2r - r^2$. It equals $+1$ at $r = 3$ and reaches $-1$ at $r = 1 + \sqrt{6} \approx 3.449$, where the same thing happens to the 2-cycle.

A cobweb diagram is the graphical way to iterate: go up to the curve, across to the diagonal, and repeat.

Tick "Show f(f(x))" and move r slowly through 3. Then skip the first 200 steps and keep going up.

Below 3 the coral curve crosses the diagonal once away from zero, at the fixed point. At 3 it is tangent there, and above 3 it crosses three times: the old fixed point, now unstable, with the two new points $x_\pm$ on either side. The cobweb turns from a spiral into a box and the time series becomes a zigzag that stops shrinking. Notice how slow the convergence is close to $r = 3$: the slope is almost $-1$, so each step removes almost nothing from the error.

The cascade and Feigenbaum’s number

The 2-cycle doubles into a 4-cycle at $1 + \sqrt{6}$, that one into an 8-cycle near 3.544, and so on, each cycle surviving over a shorter stretch of $r$ than the one before. The doublings pile up at $r_\infty \approx 3.569946$. This picture shows where the orbit ends up for every $r$:

Drag a box on the diagram to zoom in. Try the upper branch after the first split, then zoom again inside what you find.

A stable cycle shows up as a few sharp lines and a chaotic value of $r$ as a smeared band. Zoom on one branch after a split and you find a smaller copy of the whole picture, and inside it another one. The “A copy inside it” button jumps to one that sits in the widest gap of the chaotic region, with its own cascade and its own gaps. The strip at the bottom is the Lyapunov exponent, I will come back to it.

The self-similarity has a number attached. Call $r_n$ the value where the cycle of period $2^n$ appears. The gaps between them shrink geometrically:

$$ \delta = \lim_{n \to \infty} \frac{r_n - r_{n-1}}{r_{n+1} - r_n} = 4.669201609\ldots $$

It is easier to measure with the superstable values, where the cycle of period $2^n$ passes through the top of the parabola at $x = 1/2$. Those are roots of a smooth function of $r$, so Newton’s method finds them:

// r for which x = 1/2 lies on a cycle of period 2^n
function superstable(n, r) {
	for (var it = 0; it < 30; it++) {
		var x = 0.5, dx = 0;            // dx = derivative of x in r
		for (var i = 0; i < (1 << n); i++) {
			dx = x * (1 - x) + r * (1 - 2 * x) * dx;
			x = r * x * (1 - x);
		}
		r -= (x - 0.5) / dx;
	}
	return r;
}

Starting each search one predicted gap after the previous root, the ratios of consecutive gaps come out as 4.7089, 4.6808, 4.6630, 4.6684, 4.6690, 4.6692.

Now the strange part. Replace the parabola with $r \sin(\pi x)$, which has completely different bifurcation values, and run the same code. I get 4.0457, 4.5559, 4.6452, 4.6641, 4.6681, 4.6690. Same limit.

Mitchell Feigenbaum published this in 1978 as Quantitative universality for a class of nonlinear transformations. The constant does not belong to the map. It depends only on the map having a single hump with a quadratic top (for tops of another order he gets other numbers).

The explanation is a renormalisation argument. Look at $f(f(x))$ near $x = 1/2$ just after a doubling: it has a small hump of its own, upside down. Flip it, magnify it by a factor $\alpha$, and it looks like $f$ did one doubling earlier. So “iterate twice and rescale” is an operation on functions, and the cascade is that operation applied over and over. It has a fixed point, a universal function $g$ that satisfies (with $x$ measured from the top of the hump)

$$ g(x) = -\alpha g\left(g\left(\frac{x}{\alpha}\right)\right), \quad \alpha = 2.5029\ldots $$

Any one-hump map with a quadratic top is pulled towards $g$ as you go down its cascade, and forgets its own details on the way. The fixed point is unstable in exactly one direction, and $\delta$ is the rate of escape along it. That is why a parabola and a sine give the same number.

Chaos, measured

What does “chaotic” mean here, concretely? Take two orbits a tiny distance $d_0$ apart. After one step the distance is about $\left| f^{\prime}(x_0) \right| d_0$, and after $N$ steps it is $d_0$ times the product of all the slopes met on the way. Take the logarithm and average:

$$ \lambda = \lim_{N \to \infty} \frac{1}{N} \sum_{n=0}^{N-1} \ln \left| f^{\prime}(x_n) \right| $$

This is the Lyapunov exponent, and nearby orbits separate like $e^{\lambda n}$. On a stable cycle it is negative. At a bifurcation it touches zero. When it is positive, small differences grow exponentially, which is what sensitive dependence on initial conditions means. In code it is a running sum of Math.log(Math.abs(r * (1 - 2 * x))), and that is the strip under the bifurcation diagram. Go back and look at it: the spikes going down are the superstable points (an orbit through $x = 1/2$ puts a zero in the product), and every dive below zero inside the chaotic region lines up with a gap in the picture above.

The second orbit starts 0.000000001 away from the first. Compare the gap with the dashed line at 3.9 and 4, then press 3.83.

At $r = 3.9$ you cannot tell the two orbits apart for about 30 steps, and after that they have nothing to do with each other. All that time the gap was growing along the dashed line, by a factor of about 1.6 per step.

At $r = 4$ the exponent is exactly $\ln 2$ (the substitution $x = \sin^2 \theta$ turns the map into doubling the angle), so you lose one bit per step. A double has 53 bits of mantissa. After about 53 iterations the orbit you compute at $r = 4$ shares no digits with the exact orbit of the number you started from, however carefully you write the loop.

Period three

Now 3.83. The exponent is negative and the dashed line points down, yet the gap climbs for 40 steps exactly as before. Then both orbits fall onto a cycle of period 3, and with the default starting point they land on it out of step, so the gap never closes. Something chaotic is still in there.

This is the widest gap in the bifurcation diagram, the period-3 window. It opens at $r = 1 + \sqrt{8} \approx 3.8284$, where $f(f(f(x)))$ becomes tangent to the diagonal and a stable 3-cycle appears together with an unstable twin. The 3-cycle then goes through its own doublings, 6, 12, 24, and that cascade is the small copy you zoomed into.

Period three is special. In 1975 Tien-Yien Li and James Yorke proved, in a paper called Period three implies chaos, that a continuous map of an interval with a point of period 3 has points of every other period too, plus an uncountable set of points whose orbits never settle on any cycle. This is where the word got its technical use.

There is a subtlety here that popular accounts skip. Inside the window almost every starting point ends up on the stable 3-cycle, the Lyapunov exponent is negative, and the diagram shows three clean lines. The cycles of all other periods and the uncountable set of aperiodic orbits do exist, but they are all unstable and together they have measure zero. You only see them as the long irregular transient in the widget above. So chaos in the sense of Li and Yorke and chaos in the sense of $\lambda \gt 0$ are two different statements, and at $r = 3.83$ only the first one is true.

Do real populations do this?

May’s point was about ecology: if a model this simple produces fluctuations that look random, an irregular census does not have to mean a noisy environment. Finding this in existing field data turned out to be hard, and the search stayed inconclusive.

The cleanest evidence I know of comes from a laboratory. Costantino, Desharnais, Cushing and Dennis worked with the flour beetle Tribolium castaneum and in 1997 published Chaotic dynamics in an insect population in Science. The details matter here.

Their model is not the logistic map. It has three variables, the numbers of larvae, pupae and adults counted every two weeks, and the nonlinearity is cannibalism: larvae and adults eat eggs, adults eat pupae. The model predicted that with a very high adult death rate, changing how many pupae survive to become adults would take the population through quasiperiodic oscillations and then chaos, with a strong cycle of period three at the far end. So they imposed those conditions by hand. They removed or added adults so that the adult death rate was 0.96 per two weeks, and so that recruitment followed the model’s formula with a cannibalism coefficient of their choice: seven values from 0 to 1, plus an untouched control.

The result, in the words of the abstract, is that “the dynamics of animal abundance changed from equilibrium to quasiperiodic cycles to chaos”, following the model from one treatment to the next. So it is a real nonlinear feedback (the cannibalism is the beetles’ own doing) producing a predicted sequence of bifurcations in real animals. It is not a wild population, the route goes through quasiperiodic cycles and not through period doubling, and two of the parameters were set by the experimenters. The claim rests on the whole sequence of treatments matching the model, not on one wiggly time series.

A later review by the same group adds a twist I like. Beetles come in whole numbers, and a bounded deterministic system with finitely many states can only cycle. What the long record of the chaotic treatment shows is a population that follows one of the cycles the models predict for a while, then another: they pick out episodes close to periods 11, 8, 6 and 3. Chaos in a real population looks less like the smeared bands above and more like an orbit that keeps changing its mind :).

Further reading