Modeladvanced
Fisher-KPP equation
Also called Fisher's equation, Kolmogorov-Petrovsky-Piskunov equation.
The equation u_t = D u_xx + r u (1 - u) has fronts for every speed c >= 2 sqrt(r D), and a start of bounded extent spreads at the minimal speed 2 sqrt(r D).
The Fisher-KPP equation joins logistic growth to random movement, modelled by the heat equation. It describes a species, or an advantageous gene, that invades empty space. Its main objects are travelling fronts that move the state into the state at a constant speed . Fronts exist for every speed and for no smaller speed. A population that starts in a bounded region spreads at the smallest of these speeds, , which depends only on the growth of small populations and on their diffusion.
The machine
The state. is a density relative to the carrying capacity, at the place and the time . In Fisher's reading, is the frequency of a new gene that gives a small advantage.
The parameters.
- , in length squared per time: the diffusion coefficient. An individual that moves at random spreads with a mean square distance of after the time .
- , in 1 per time: the growth rate of a small population.
The equation.
The assumptions. Each place grows logistically, and individuals move by diffusion with no direction. The habitat is uniform and has one dimension; the same equation with holds in more dimensions. The density is a continuous quantity, so the model is a large population limit, and very small densities in the far tail still grow.
Scaling. With and , the equation becomes , with no parameters. A speed in the scaled units is the speed in the original units. So the minimal speed is the minimal speed of the scaled equation.
The KPP class. The results below hold for every growth term with , on , and , with in place of . The logistic term is the standard case.
A numerical solution. The implementation uses the method of lines: second differences on a grid of step , and explicit Euler in time with step . The two ends mirror their neighbours, which is a no-flux boundary. Let .
FISHER-KPP-FRONT(u, Δx, Δt, T) ▷ u: grid values; mirror ends- 1
μ ← D Δt / Δx² - 2
repeat T / Δt times - 3
for each grid point i - 4
v_i ← u_i + μ (u_{i-1} - 2 u_i + u_{i+1}) + Δt r u_i (1 - u_i) - 5
u ← v - 6
x_f ← the first point where u falls through 1/2 (linear interpolation) - 7
return x_f
Each step costs for grid points, so a run to the time costs . The scheme keeps when (proof below), which also makes it stable in the sense of von Neumann. The front position at two times gives a measured speed.
What it counts
- The travelling fronts with and , and the set of speeds for which they exist.
- The minimal speed .
- The speed at which a population that starts in a bounded region spreads.
- The shape of the front: its width is of order .
An example. Take , so . On with and , so that , start from for and after it. The front crosses at these points:
| 10 | 20 | 30 | 40 | |
|---|---|---|---|---|
| front position | 24.27 | 42.95 | 62.17 | 81.60 |
| speed over the last 10 time units | 1.868 | 1.922 | 1.942 |
The speed rises toward its limit from below and slowly. The limit for this grid is not exactly : the linearized scheme spreads at (see below). With and that value is , so the grid matters at the level of a few percent.
A front with a known formula. For , the function
is a front with the speed . Started from this profile, the scheme above moves the front at between and , close to and above .
Relation to other models
- Logistic growth. With , every point grows on its own logistically. Diffusion couples the points and turns the growth into a moving front.
- The heat equation. With , a density spreads but does not grow, and the spread is like , not like . The combination gives a linear spread in time.
- Exponential growth with diffusion. The linear equation has the solution times a solution of the heat equation. It spreads at the same speed . For the Fisher-KPP equation, the front is pulled by its leading edge, where is small and the equation is close to this linear one.
- The bistable equation. With an Allee effect, and , small densities decline, and fails. Then there is only one front speed: for it is , with the front . This front is pushed by the region behind it, not pulled by its edge.
- Epidemic waves. The SIR model with diffusion of the infected, , has the same linearization at the front edge, with in place of . So an epidemic wave into a population of density moves at , and no wave forms if .
- Turing instability. A system of two reaction-diffusion equations can form stationary patterns. The scalar Fisher-KPP equation cannot: it has fronts, but no stable pattern.
- Gene frequencies. In Fisher's reading, is the frequency of a gene with a small selective advantage in a population spread along a line. The Wright-Fisher model is the model of the same frequency in one well-mixed population with random drift.
Known results in the model
The front equation. is a solution if and only if solves the ordinary equation
with and . This follows from and .
No front is slower than . If is a front with , then .
Proof. Write the front equation as the system , in the plane. Near its linearization has the characteristic equation , with the roots . If , the roots are complex with a negative real part, so is a stable focus, and every solution that tends to it turns around it. Then changes sign infinitely often, which a density cannot do.
A front exists for every . For each such , there is a decreasing front with and .
Proof. Let and let be the triangle , . On its three sides the field points into :
- on with : ;
- on with : ;
- on : .
So no solution leaves once it is inside. The point is a saddle: with , the linearization has the roots of , one positive and one negative. The branch of its unstable manifold with leaves along the direction and so enters . In , , so decreases and is bounded below by ; the solution converges, and its limit is an equilibrium in other than , which is . This solution is the front.
For each speed the front is unique up to a shift in . For it decays like with the smaller root ; for it decays like .
The exact front. For , with solves the front equation with .
Proof. Let , so and . Then and , and . Multiply the front equation by . The coefficient of is and that of is . Both are zero if and only if and , so and .
Its tail is , with , and indeed .
The speed from the leading edge. A tail solves the linear equation if and only if
The minimum of over is at , with the value . A start with a tail that is less steep than moves at the speed ; this is why the exact front above keeps its speed . A start with bounded support has no tail at all, and it takes the minimal speed.
A start of bounded extent spreads at . Let be zero outside a bounded interval and not zero everywhere. Then for each , , and for each , as (Aronson and Weinberger 1978, who prove it in any number of dimensions).
Proof of the first half. Since , the comparison principle for parabolic equations gives , where with the same start. Let the start vanish outside . Then
At with , the exponent is at most , which tends to when .
The second half needs a lower bound that grows, and Aronson and Weinberger build it from the fronts above. Kolmogorov, Petrovsky and Piskunov proved that the solution from a step start converges in shape to the front of minimal speed.
The scheme keeps in . If and for all , then .
Proof. Write with . For the lower bound, , since . For the upper bound, and , so .
The speed of the scheme. The grid has its own spreading speed. A mode grows per step by the factor , so the linearized scheme spreads at . This is for and for , both below , and it tends to as both steps go to zero. The test checks that the measured speed from the step lies between and this value.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fisher-kpp-equation/. The authors are listed in prov/2NM058.jsonl.
"""The Fisher-KPP equation u_t = D u_xx + r u (1 - u) on [0, L].
The solver is the method of lines with second differences in space and
explicit Euler in time, with mirror (no-flux) ends. It reports where the
front crosses u = 1/2, so that the tests can measure the front speed and
compare it with the minimal speed 2 sqrt(r D), with the speed of the
scheme itself, and with the exact wave of speed 5 / sqrt(6).
"""
import math
def minimal_speed(d: float, r: float) -> float:
"""The minimal front speed 2 sqrt(r D)."""
return 2.0 * math.sqrt(r * d)
def linear_speed(lam: float, d: float, r: float) -> float:
"""The speed D lam + r / lam of the decay exp(-lam (x - c t)) in the linearized equation."""
return d * lam + r / lam
def exact_wave(z: float) -> float:
"""The exact wave U(z) = (1 + exp(z / sqrt 6))^-2 for D = r = 1, with speed 5 / sqrt 6."""
return (1.0 + math.exp(z / math.sqrt(6.0))) ** -2
EXACT_SPEED = 5.0 / math.sqrt(6.0)
def front_position(u, dx: float):
"""The first x where u falls through 1/2, by linear interpolation, or None."""
for i in range(len(u) - 1):
if u[i] >= 0.5 > u[i + 1]:
return (i + (u[i] - 0.5) / (u[i] - u[i + 1])) * dx
return None
def step(u, mu: float, rdt: float):
"""One explicit step; mu = D dt / dx^2 and rdt = r dt. The ends mirror their neighbours."""
n = len(u)
v = [0.0] * n
for i in range(n): # @line L3
left = u[i - 1] if i > 0 else u[1]
right = u[i + 1] if i < n - 1 else u[n - 2]
ui = u[i]
v[i] = ui + mu * (left - 2.0 * ui + right) + rdt * ui * (1.0 - ui) # @line L4
return v
def simulate(u0, dx: float, dt: float, t_end: float, d: float = 1.0, r: float = 1.0, marks=()):
"""Run to t_end; return the final grid values and the front position at each time in marks."""
mu = d * dt / dx ** 2 # @line L1
rdt = r * dt
at = {int(round(m / dt)): m for m in marks}
fronts = {}
u = list(u0)
for s in range(1, int(round(t_end / dt)) + 1): # @line L2
u = step(u, mu, rdt) # @line L5
if s in at:
fronts[at[s]] = front_position(u, dx) # @line L6
return u, fronts # @line L7
def step_start(length: float, dx: float, x0: float = 10.0):
"""u = 1 for x < x0 and u = 0 after it, on the grid 0, dx, ..., length."""
n = int(round(length / dx)) + 1
return [1.0 if i * dx < x0 else 0.0 for i in range(n)]
def wave_start(length: float, dx: float, x0: float = 20.0):
"""The exact wave placed with its centre region near x0."""
n = int(round(length / dx)) + 1
return [exact_wave(i * dx - x0) for i in range(n)]
def discrete_linear_speed(dx: float, dt: float, d: float = 1.0, r: float = 1.0) -> float:
"""The spreading speed of the linearized scheme: the minimum over lam of ln(g(lam)) / (dt lam).
A mode exp(-lam x) grows per step by g = 1 + r dt + 2 mu (cosh(lam dx) - 1).
"""
mu = d * dt / dx ** 2
best = math.inf
for i in range(1, 6001):
lam = i * 0.001
g = 1.0 + r * dt + 2.0 * mu * (math.cosh(lam * dx) - 1.0)
best = min(best, math.log(g) / (dt * lam))
return best
test_fisher_kpp_equation.py 62 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fisher-kpp-equation/. The authors are listed in prov/2NM058.jsonl.
import math
from fisher_kpp_equation import (
EXACT_SPEED,
discrete_linear_speed,
exact_wave,
linear_speed,
minimal_speed,
simulate,
step_start,
wave_start,
)
def test_minimal_speed_is_the_minimum_of_the_linear_speeds() -> None:
for d, r in [(1.0, 1.0), (0.5, 2.0), (3.0, 0.1)]:
lam_star = math.sqrt(r / d)
assert abs(linear_speed(lam_star, d, r) - minimal_speed(d, r)) < 1e-12
for lam in (0.3 * lam_star, 0.9 * lam_star, 1.1 * lam_star, 4.0 * lam_star):
assert linear_speed(lam, d, r) > minimal_speed(d, r)
assert minimal_speed(1.0, 1.0) == 2.0
def test_exact_wave_solves_the_wave_equation() -> None:
# D U'' + c U' + r U (1 - U) = 0 with D = r = 1 and c = 5 / sqrt 6.
assert abs(EXACT_SPEED - 2.041241) < 1e-6 and EXACT_SPEED > 2.0
h = 1e-3
worst = 0.0
for i in range(-200, 201):
z = i * 0.05
u = exact_wave(z)
up = (exact_wave(z + h) - exact_wave(z - h)) / (2 * h)
upp = (exact_wave(z + h) - 2 * u + exact_wave(z - h)) / h ** 2
worst = max(worst, abs(upp + EXACT_SPEED * up + u * (1 - u)))
assert worst < 1e-6
assert abs(exact_wave(-40.0) - 1.0) < 1e-6 and exact_wave(40.0) < 1e-6
def test_step_start_spreads_just_below_the_minimal_speed() -> None:
dx, dt = 0.25, 0.01
u, fronts = simulate(step_start(100.0, dx), dx, dt, 40.0, marks=(10.0, 20.0, 30.0, 40.0))
# The scheme keeps u in [0, 1] because 2 D dt / dx^2 + r dt <= 1.
assert 2 * dt / dx ** 2 + dt <= 1 and min(u) >= 0.0 and max(u) <= 1.0
assert abs(fronts[10.0] - 24.27) < 0.01 and abs(fronts[40.0] - 81.60) < 0.01
speed = (fronts[40.0] - fronts[30.0]) / 10.0
cap = discrete_linear_speed(dx, dt)
assert abs(cap - 1.9854) < 1e-3
# The front from compact data approaches the linear speed of the scheme from below.
assert 1.9 < speed < cap < 2.0
assert (fronts[20.0] - fronts[10.0]) / 10 < (fronts[40.0] - fronts[30.0]) / 10
def test_steep_and_shallow_starts() -> None:
# The exact wave decays like exp(-2 z / sqrt 6), a tail less steep than exp(-z), and keeps its own speed 5 / sqrt 6.
dx, dt = 0.25, 0.01
_, fronts = simulate(wave_start(80.0, dx), dx, dt, 20.0, marks=(5.0, 20.0))
speed = (fronts[20.0] - fronts[5.0]) / 15.0
assert abs(speed - EXACT_SPEED) < 0.03
assert speed > 2.0
References
- Ronald A. Fisher, The wave of advance of advantageous genes, Annals of Eugenics 7(4), 1937, the equation for the frequency of an advantageous gene in a population spread along a line, and the speed of its wave of advance
- Kolmogorov, Petrovsky and Piskunov 1937, the existence of travelling fronts for each speed from the minimal one, and the convergence of the solution from a step to the front of minimal speed
- Donald G. Aronson and Hans F. Weinberger, Multidimensional nonlinear diffusion arising in population genetics, Advances in Mathematics 30(1), 1978, pages 33 to 76 (the asymptotic speed of spread for initial data of bounded support)
- James D. Murray, Mathematical Biology I, An Introduction, third edition, Springer, 2002, Chapter 13, Biological Waves, Single-Species Models (the Fisher-KPP equation, its travelling waves and the exact solution)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 2NM058 Edit this page History Report an error Markdown