Modelcore
Lotka-Volterra competition model
Also called competitive Lotka-Volterra equations.
Two species with logistic growth that reduce each other's growth, whose outcome depends on the competition coefficients.
The Lotka-Volterra competition model is a pair of logistic equations in which each species also lowers the growth of the other: and . The outcome depends only on the carrying capacities and the competition coefficients. The two species coexist at a stable equilibrium when each species limits itself more than it limits the other. Otherwise one species wins, or the winner depends on the start. This is the model behind the theorem form of the competitive exclusion principle.
The machine
The state. and are the sizes or densities of two species that use the same resources.
The parameters. All are positive.
- , in 1 per time: the growth rate of species when it is rare and alone.
- , in individuals (or density) of species : its carrying capacity when alone.
- , without unit: the effect of one individual of species 2 on the growth of species 1, measured in individuals of species 1. means that two individuals of species 2 crowd species 1 as much as one individual of species 1 does. is the reverse.
The equations.
The assumptions. Each species alone follows the logistic model. The competition is not explicit: the resources are not in the state, and each species feels the other only through a linear term in the per capita growth rate. The coefficients are constant. The populations are well mixed and large. Some books write or for , or put the coefficients in the form ; this page uses the form above.
The isoclines. The per capita growth of species 1 is zero on the line , and that of species 2 on the line . The relative position of the two lines in the positive quadrant gives the outcome. Two numbers decide it:
- . It is positive if species 1, when rare, can grow in a population of species 2 at its capacity .
- . It is positive if species 2 can invade species 1 at .
LV-COMPETITION-OUTCOME(K1, K2, α12, α21)- 1
Δ1 ← K1 - α12 K2 ▷ can species 1 invade species 2 alone? - 2
Δ2 ← K2 - α21 K1 ▷ can species 2 invade species 1 alone? - 3
if Δ1 > 0 and Δ2 > 0 then return "coexist at (N1*, N2*)" - 4
if Δ1 > 0 and Δ2 < 0 then return "species 1 wins" - 5
if Δ1 < 0 and Δ2 > 0 then return "species 2 wins" - 6
if Δ1 < 0 and Δ2 < 0 then return "bistable: the start decides" - 7
return "degenerate (an isocline passes through an equilibrium)"
The rule costs arithmetic operations. The growth rates and do not enter it: they change how fast the outcome comes, and the path, but not the outcome. The implementation checks the rule against RK4 runs from four start points for 30 random parameter sets.
What it counts
- The four equilibria , , and, when it is positive, the coexistence point
- The stability of each equilibrium, and so the long-run outcome: coexistence, the exclusion of one species, or two outcomes that depend on the start.
- The rate of approach, from the eigenvalues of the Jacobian.
Three examples. All have per unit of time.
| outcome | ||||||
|---|---|---|---|---|---|---|
| 100 | 100 | 0.5 | 0.5 | 50 | 50 | coexistence at , eigenvalues and |
| 100 | 100 | 1.5 | 1.5 | saddle at , eigenvalues and ; the start decides | ||
| 100 | 80 | 0.6 | 1.5 | 52 | species 1 wins and goes to |
In the second case, the start ends at and the start ends at . In the third case, species 1 wins from , although it starts 50 times rarer.
Relation to other models
- Logistic growth. With , species 1 follows the logistic model and goes to .
- Lotka-Volterra predator-prey. The same quadratic terms with opposite signs on the two species. The predator-prey model has neutral cycles; the competition model has no periodic orbits, because it is a competitive system in the plane (each species lowers the growth of the other), and in such a system every bounded solution tends to an equilibrium.
- Resource models. In a model with explicit resources, such as consumers that eat from a pool that is renewed, the coefficients come out of the overlap in the resource use, when the resources are fast and stay near their equilibrium. The Lotka-Volterra form is then a linear approximation near the equilibrium. The competitive exclusion principle page gives a resource model and its theorem.
- More species. The generalized form for species, with , can have cycles and more complex behaviour for . For two species, the outcome is always one of the four cases above.
- Space and patches. In a landscape of patches, a weaker competitor that colonizes faster can persist next to a stronger one. The Levins metapopulation model is the one-species base of these models.
Known results in the model
The boundary equilibria. At the Jacobian is triangular, with the eigenvalues and . So is stable if and a saddle if . By symmetry, has the eigenvalues and . The origin has the eigenvalues and , so it is always unstable.
Proof for . The partial derivatives of at are and . The entry at is . A triangular matrix has its diagonal entries as eigenvalues.
The coexistence point. If , the isoclines meet in one point given above. It is positive if and only if and have the same sign as . The Jacobian there is
with the trace and the determinant .
Proof. At the point, , so the derivative of with respect to is and with respect to is . The second row is the same with the indices swapped. The determinant is .
So a positive coexistence point is a stable node (both eigenvalues are real and negative, because when and the off-diagonal entries have the same sign) when , and a saddle when .
The four cases. Let .
- and : then , because . The coexistence point is positive and every solution with tends to it.
- and : every solution with tends to . Species 1 wins.
- and : species 2 wins, by symmetry.
- and : then . The coexistence point is a positive saddle. Its stable manifold divides the open quadrant into two basins: one of and one of .
The condition of case 1 reads and . The left side of the first inequality is the drop in the per capita growth of species 2 (divided by ) per individual of species 1, and the right side is the drop that one individual of species 1 causes to its own species (divided by ). So coexistence means: each species limits itself more than it limits the other.
Proof of case 1 by a Lyapunov function. Write . Since , the first equation is , and the second is . Let
Then . This quadratic form is positive definite, because its discriminant is . So except at the coexistence point. Each term tends to infinity as or , so the sublevel sets of in the open quadrant are compact, and each solution stays in one of them. By the Lyapunov theorem with LaSalle's principle, each positive solution tends to the only point where .
Proof of case 2. Here the line lies strictly below in the quadrant, because its intercepts and are both smaller. So the quadrant splits into three regions: below , where both species grow; between the lines, where grows and falls; above , where both fall. On the boundary of , the field points into : on (above ), and ; on (below ), and . So a solution that enters stays there. In the solution is monotone in each coordinate and bounded, so it converges, and the limit is an equilibrium in the closure of with . The only one is . A solution in or is also monotone in each coordinate while it stays there. If it stays forever, it converges to an equilibrium in the closure of that region. For the candidates are and , and both are impossible, because is positive and increasing. For the only candidate is . Otherwise the solution enters . With , species 1 follows the logistic model to .
Proof of case 4. The saddle has a one-dimensional stable manifold: two solution curves that tend to . One comes from the region near the origin and one from far away, along the isoclines. Together with the saddle they form a curve that splits the quadrant. On each side, the argument of case 2 applies to the region between the isoclines that touches the axis: the region near where traps solutions and sends them to , and the region near sends them to . A solution that is not on the stable manifold enters one of these two regions, because, as in case 2, it cannot converge to anything else while it is monotone.
Speed of the outcome. The time scale of the final approach is set by the eigenvalue of the stable equilibrium closest to zero. In the coexistence example it is , so a small deviation decays like , three times slower than in a single logistic population with .
Degenerate cases. If or , the coexistence point lies on an axis and merges with a boundary equilibrium. If and , the two isoclines coincide and there is a whole line of equilibria. These cases need exact equalities between parameters, so small changes remove them; they are not robust predictions of coexistence.
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/lotka-volterra-competition/. The authors are listed in prov/8SQFG6.jsonl.
"""The two-species Lotka-Volterra competition model.
dN1/dt = r1 N1 (1 - (N1 + a12 N2) / K1)
dN2/dt = r2 N2 (1 - (N2 + a21 N1) / K2)
All parameters are positive. a12 is the effect of one individual of
species 2 on species 1, in units of individuals of species 1, and a21 is
the reverse. The module classifies the outcome from the parameters,
gives the equilibria and their Jacobians, and integrates the model with
fixed step RK4 so that the tests can compare the two.
"""
import math
def field(n1: float, n2: float, p):
"""The vector field for p = (r1, r2, K1, K2, a12, a21)."""
r1, r2, k1, k2, a12, a21 = p
return r1 * n1 * (1.0 - (n1 + a12 * n2) / k1), r2 * n2 * (1.0 - (n2 + a21 * n1) / k2)
def outcome(p) -> str:
"""'coexist', 'species 1', 'species 2', 'bistable' or 'degenerate' from the invasion tests."""
_, _, k1, k2, a12, a21 = p
inv1 = k1 - a12 * k2 # @line L1
inv2 = k2 - a21 * k1 # @line L2
if inv1 > 0 and inv2 > 0: # @line L3
return "coexist"
if inv1 > 0 and inv2 < 0: # @line L4
return "species 1"
if inv1 < 0 and inv2 > 0: # @line L5
return "species 2"
if inv1 < 0 and inv2 < 0: # @line L6
return "bistable"
return "degenerate" # @line L7
def interior_equilibrium(p):
"""(N1*, N2*) = ((K1 - a12 K2), (K2 - a21 K1)) / (1 - a12 a21), or None if a12 a21 = 1."""
_, _, k1, k2, a12, a21 = p
den = 1.0 - a12 * a21
if den == 0.0:
return None
return (k1 - a12 * k2) / den, (k2 - a21 * k1) / den
def jacobian(n1: float, n2: float, p):
"""The Jacobian matrix of the field at (n1, n2)."""
r1, r2, k1, k2, a12, a21 = p
return (
(r1 * (1.0 - (2.0 * n1 + a12 * n2) / k1), -r1 * a12 * n1 / k1),
(-r2 * a21 * n2 / k2, r2 * (1.0 - (2.0 * n2 + a21 * n1) / k2)),
)
def eigenvalues(m):
"""The two eigenvalues of a real 2 by 2 matrix, as complex numbers."""
(a, b), (c, d) = m
tr, det = a + d, a * d - b * c
disc = complex(tr * tr - 4.0 * det) ** 0.5
return (tr + disc) / 2.0, (tr - disc) / 2.0
def rk4(n1: float, n2: float, dt: float, steps: int, p):
"""The state after `steps` RK4 steps of size dt."""
for _ in range(steps):
k1 = field(n1, n2, p)
k2 = field(n1 + dt * k1[0] / 2, n2 + dt * k1[1] / 2, p)
k3 = field(n1 + dt * k2[0] / 2, n2 + dt * k2[1] / 2, p)
k4 = field(n1 + dt * k3[0], n2 + dt * k3[1], p)
n1 += dt * (k1[0] + 2 * k2[0] + 2 * k3[0] + k4[0]) / 6
n2 += dt * (k1[1] + 2 * k2[1] + 2 * k3[1] + k4[1]) / 6
return n1, n2
def lyapunov(n1: float, n2: float, p) -> float:
"""V = sum of w_i (N_i - N_i* ln N_i), w1 = a21 K1 / r1, w2 = a12 K2 / r2; it decreases when a12 a21 < 1."""
r1, r2, k1, k2, a12, a21 = p
e1, e2 = interior_equilibrium(p)
w1, w2 = a21 * k1 / r1, a12 * k2 / r2
return w1 * (n1 - e1 * math.log(n1)) + w2 * (n2 - e2 * math.log(n2))
test_lotka_volterra_competition.py 93 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lotka-volterra-competition/. The authors are listed in prov/8SQFG6.jsonl.
import random
from lotka_volterra_competition import (
eigenvalues,
field,
interior_equilibrium,
jacobian,
lyapunov,
outcome,
rk4,
)
def test_examples_of_the_page() -> None:
p = (1.0, 1.0, 100.0, 100.0, 0.5, 0.5)
assert outcome(p) == "coexist"
e1, e2 = interior_equilibrium(p)
assert abs(e1 - 200 / 3) < 1e-12 and abs(e2 - 200 / 3) < 1e-12
ev = sorted(z.real for z in eigenvalues(jacobian(e1, e2, p)))
assert abs(ev[0] + 1.0) < 1e-12 and abs(ev[1] + 1 / 3) < 1e-12
n = rk4(5.0, 1.0, 0.05, 4000, p)
assert abs(n[0] - 200 / 3) < 1e-6 and abs(n[1] - 200 / 3) < 1e-6
q = (1.0, 1.0, 100.0, 100.0, 1.5, 1.5)
assert outcome(q) == "bistable"
e1, e2 = interior_equilibrium(q)
assert abs(e1 - 40.0) < 1e-12 and abs(e2 - 40.0) < 1e-12
ev = sorted(z.real for z in eigenvalues(jacobian(e1, e2, q)))
assert abs(ev[0] + 1.0) < 1e-12 and abs(ev[1] - 0.2) < 1e-12
a = rk4(45.0, 35.0, 0.05, 4000, q)
b = rk4(35.0, 45.0, 0.05, 4000, q)
assert abs(a[0] - 100.0) < 1e-6 and a[1] < 1e-6
assert abs(b[1] - 100.0) < 1e-6 and b[0] < 1e-6
s = (1.0, 1.0, 100.0, 80.0, 0.6, 1.5)
assert outcome(s) == "species 1"
c = rk4(1.0, 50.0, 0.05, 4000, s)
assert abs(c[0] - 100.0) < 1e-6 and c[1] < 1e-6
def test_boundary_equilibrium_eigenvalues() -> None:
# At (K1, 0) the eigenvalues are -r1 and r2 (1 - a21 K1 / K2).
p = (0.7, 1.3, 100.0, 80.0, 0.6, 1.5)
ev = sorted(z.real for z in eigenvalues(jacobian(100.0, 0.0, p)))
assert abs(ev[0] - 1.3 * (1 - 1.5 * 100 / 80)) < 1e-12 and abs(ev[1] + 0.7) < 1e-12
def test_classification_matches_simulation() -> None:
# Random parameters with seed 3; the outcome rule against RK4 from several starts.
rng = random.Random(3)
starts = [(1.0, 1.0), (10.0, 90.0), (90.0, 10.0), (150.0, 150.0)]
seen = set()
for _ in range(30):
p = (rng.uniform(0.5, 2.0), rng.uniform(0.5, 2.0), rng.uniform(50, 150),
rng.uniform(50, 150), rng.uniform(0.2, 1.8), rng.uniform(0.2, 1.8))
kind = outcome(p)
seen.add(kind)
ends = [rk4(x, y, 0.05, 6000, p) for x, y in starts]
k1, k2 = p[2], p[3]
if kind == "coexist":
e = interior_equilibrium(p)
assert all(abs(u - e[0]) < 1e-3 and abs(v - e[1]) < 1e-3 for u, v in ends)
elif kind == "species 1":
assert all(abs(u - k1) < 1e-3 and v < 1e-3 for u, v in ends)
elif kind == "species 2":
assert all(abs(v - k2) < 1e-3 and u < 1e-3 for u, v in ends)
elif kind == "bistable":
# Each end is one of the two single-species states.
assert all((abs(u - k1) < 1e-3 and v < 1e-3) or (abs(v - k2) < 1e-3 and u < 1e-3) for u, v in ends)
assert {"coexist", "species 1", "species 2", "bistable"} <= seen
def test_lyapunov_function_decreases_in_coexistence() -> None:
p = (1.0, 0.6, 100.0, 70.0, 0.4, 0.5)
assert outcome(p) == "coexist"
x, y = 3.0, 120.0
v = lyapunov(x, y, p)
for _ in range(300):
x, y = rk4(x, y, 0.05, 2, p)
w = lyapunov(x, y, p)
assert w <= v + 1e-12
v = w
def test_field_vanishes_at_equilibria() -> None:
p = (1.0, 1.0, 100.0, 80.0, 0.6, 0.5)
e = interior_equilibrium(p)
for pt in [(0.0, 0.0), (100.0, 0.0), (0.0, 80.0), e]:
fx, fy = field(pt[0], pt[1], p)
assert abs(fx) < 1e-12 and abs(fy) < 1e-12
References
- Lotka 1925, the equations for species that compete for the same food
- Gause 1934, the competition equations and the experiments with two species of Paramecium and with yeasts
- James D. Murray, Mathematical Biology I, An Introduction, third edition, Springer, 2002, Chapter 3, Models for Interacting Populations (the section on competition models and the principle of competitive exclusion)
Where this leads
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 8SQFG6 Edit this page History Report an error Markdown