Competition
Two species that compete for the same resources.
- Class:
CompetitionSystem - Import:
from skcomplex.systems.biology.ecology import CompetitionSystem - Field:
biology/ecology - Topics:
competition,ode,exclusion - References:
- Lotka 1925
- Volterra 1926
- Argun et al. 2021
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.biology.ecology import CompetitionSystem
trajectory = CompetitionSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
first |
10.0 |
second |
10.0 |
r1 |
1.0 |
r2 |
0.8 |
K1 |
100.0 |
K2 |
80.0 |
alpha12 |
0.5 |
alpha21 |
0.6 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | none |
| Laws | rate |
| Randomness | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class CompetitionSystem(BaseSystem):
"""Two species that compete for the same resources.
They coexist or exclude each other.
The species coexist at `n1 = (K1 - alpha12 K2) / (1 - alpha12 alpha21)` and `n2 = (K2 - alpha21 K1) / (1 - alpha12
alpha21)` when both are positive and `alpha12 alpha21 < 1`. Otherwise one species excludes the other. The system has
the populations `first` and `second`.
Args:
first:
The initial size of the first population.
second:
The initial size of the second population.
r1:
The growth rate of the first population.
r2:
The growth rate of the second population.
K1:
The carrying capacity of the first population.
K2:
The carrying capacity of the second population.
alpha12:
The effect of one member of the second population on the first, relative to one of its own.
alpha21:
The effect of one member of the first population on the second, relative to one of its own.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.biology.ecology import CompetitionSystem
>>> CompetitionSystem(alpha12=0.2).prepare().system_.interactions[0].alpha12
0.2
"""
field = 'biology/ecology'
topics = ('competition', 'ode', 'exclusion')
references = ('Lotka 1925', 'Volterra 1926', 'Argun et al. 2021')
until = 50.0
dt = 0.1
def __init__(
self,
first: float = 10.0,
second: float = 10.0,
*,
r1: float = 1.0,
r2: float = 0.8,
K1: float = 100.0,
K2: float = 80.0,
alpha12: float = 0.5,
alpha21: float = 0.6,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.first = first
self.second = second
self.r1 = r1
self.r2 = r2
self.K1 = K1
self.K2 = K2
self.alpha12 = alpha12
self.alpha21 = alpha21
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of two species that compete for the same resources.
They coexist or exclude each other.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
self.system_ = System(
self.label,
elements=[PopulationElement('first', x=self.first), PopulationElement('second', x=self.second)],
interactions=[
CompetitionInteraction(
'competition',
first='first',
second='second',
r1=self.r1,
r2=self.r2,
K1=self.K1,
K2=self.K2,
alpha12=self.alpha12,
alpha21=self.alpha21,
),
],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
PopulationElement, fromElement, through the shared recipeNonnegativeElement
Interactions:
CompetitionInteraction, fromInteraction
class PopulationElement(CompartmentElement):
"""Population of one species, a compartment whose state `x` holds its size.
Args:
label:
The label of the population.
x:
The initial size.
Examples:
>>> from skcomplex.systems.biology.common.populations import PopulationElement
>>> PopulationElement('rabbits', x=40).x
40
"""
def __init__(
self,
label: str,
*,
x: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
) -> None:
super().__init__(label, x=x)
class CompetitionInteraction(Interaction):
"""Lotka-Volterra competition of two species for the same resources.
Each species grows logistically, and the other species fills its carrying capacity in proportion to a competition
coefficient, `dn1/dt = r1 n1 (1 - (n1 + alpha12 n2) / K1)` and `dn2/dt = r2 n2 (1 - (n2 + alpha21 n1) / K2)`.
Args:
label:
The label of the interaction.
first:
The path of the first population.
second:
The path of the second population.
r1:
The growth rate of the first population.
r2:
The growth rate of the second population.
K1:
The carrying capacity of the first population.
K2:
The carrying capacity of the second population.
alpha12:
The effect of one member of the second population on the first, relative to one of its own.
alpha21:
The effect of one member of the first population on the second, relative to one of its own.
Examples:
>>> from skcomplex.systems.biology.ecology import CompetitionInteraction
>>> CompetitionInteraction('competition', first='deer', second='elk', alpha12=0.5).alpha12
0.5
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
first: Role,
second: Role,
r1: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
r2: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
K1: Annotated[float, RealSet.open(0, oo)] = 100.0,
K2: Annotated[float, RealSet.open(0, oo)] = 100.0,
alpha12: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
alpha21: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
) -> None:
super().__init__(label)
self.first = first
self.second = second
self.r1 = r1
self.r2 = r2
self.K1 = K1
self.K2 = K2
self.alpha12 = alpha12
self.alpha21 = alpha21
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the logistic rates with the competitor in the crowding term.
Args:
context:
The namespace of the bound elements, the time `t`, and the parameters.
"""
super()._prepare(context)
s = context
first, second = s.first.x, s.second.x
self.laws_ = [
RateLaw(first, s.r1 * first * (1 - (first + s.alpha12 * second) / s.K1)),
RateLaw(second, s.r2 * second * (1 - (second + s.alpha21 * first) / s.K2)),
]
Equations
The equations are those that symbolic returns for the system with its default parameters.
first.x: diff(x_first(t), t) == -r1_competition*((alpha12_competition*x_second(t) + x_first(t))/K1_competition - 1)*x_first(t)
second.x: diff(x_second(t), t) == -r2_competition*((alpha21_competition*x_first(t) + x_second(t))/K2_competition - 1)*x_second(t)