Rosenzweig-MacArthur and rate tipping
Fast prey and slow predators whose carrying capacity shrinks at a rate.
- Class:
RosenzweigMacarthurSystem - Import:
from skcomplex.systems.biology.ecology import RosenzweigMacarthurSystem - Field:
biology/ecology - Topics:
predator-prey,ode,tipping,rate-induced tipping,slow-fast - References:
- Rosenzweig and MacArthur 1963
- Datseris and Parlitz 2022
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 RosenzweigMacarthurSystem
trajectory = RosenzweigMacarthurSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
prey |
None |
predators |
None |
kappa |
0.01 |
eta |
0.8 |
phi |
None |
phi_end |
None |
rate |
0.002 |
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 RosenzweigMacarthurSystem(BaseSystem):
"""Fast prey and slow predators whose carrying capacity shrinks at a rate.
A fast shrinking tips them.
By default the crowding rises from `eta (1 - eta) / (1 + eta)` to `1 - eta`, the range where the coexistence point
at `x = 1 / (1 - eta)` is stable, and the run starts there. A slow rise lets the populations track the point, and a
rise faster than about 0.0004 makes the prey collapse for a while before they return.
In a collapse the prey fall to about `1e-30`, far below any absolute tolerance, and an error of either sign there
decides whether they return or, below zero, run into the pole of the feeding at `x = -1 / eta`. The registered
solver therefore controls the relative error only, with `ScipyODESolver(rtol=1e-8, atol=1e-300)`. The system has the
populations `prey` and `predators`.
Args:
prey:
The initial prey `x`, or `None` for the coexistence point.
predators:
The initial predators `y`, or `None` for the coexistence point.
kappa:
The ratio of the time scales of the prey and the predators.
eta:
The handling time of the predators.
phi:
The initial crowding, or `None` for `eta (1 - eta) / (1 + eta)`.
phi_end:
The final crowding, or `None` for `1 - eta`.
rate:
The rate at which the crowding rises.
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 RosenzweigMacarthurSystem
>>> round(RosenzweigMacarthurSystem().prepare().system_.elements[0].x, 6)
5.0
"""
field = 'biology/ecology'
topics = ('predator-prey', 'ode', 'tipping', 'rate-induced tipping', 'slow-fast')
references = ('Rosenzweig and MacArthur 1963', 'Datseris and Parlitz 2022')
until = 150.0
dt = 0.5
def __init__(
self,
prey: float | None = None,
predators: float | None = None,
*,
kappa: float = 0.01,
eta: float = 0.8,
phi: float | None = None,
phi_end: float | None = None,
rate: float = 0.002,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.prey = prey
self.predators = predators
self.kappa = kappa
self.eta = eta
self.phi = phi
self.phi_end = phi_end
self.rate = rate
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of fast prey and slow predators.
Their carrying capacity shrinks at a rate.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
prey = self.prey
predators = self.predators
phi = self.phi
phi_end = self.phi_end
phi = self.eta * (1 - self.eta) / (1 + self.eta) if phi is None else phi
phi_end = 1 - self.eta if phi_end is None else phi_end
prey = 1 / (1 - self.eta) if prey is None else prey
predators = (1 - phi * prey) * (1 + self.eta * prey) if predators is None else predators
self.system_ = System(
self.label,
elements=[PopulationElement('prey', x=prey), PopulationElement('predators', x=predators)],
interactions=[
RosenzweigMacArthurInteraction(
'predation',
prey='prey',
predators='predators',
kappa=self.kappa,
eta=self.eta,
phi=phi,
phi_end=phi_end,
rate=self.rate,
),
],
solver=ScipyODESolver(rtol=1e-8, atol=1e-300),
)
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:
RosenzweigMacArthurInteraction, 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 RosenzweigMacArthurInteraction(Interaction):
"""Rosenzweig-MacArthur predation of fast prey by slow predators.
The crowding of the prey grows at a constant rate.
In units of the predators' time scale, `kappa dx/dt = x (1 - phi x) - x y / (1 + eta x)` and
`dy/dt = x y / (1 + eta x) - y`. The crowding `phi`, the inverse of the prey's carrying capacity, rises at the rate
`rate` from `phi` to `phi_end` and stays there.
Args:
label:
The label of the interaction.
prey:
The path of the prey population `x`.
predators:
The path of the predator population `y`.
kappa:
The ratio of the time scales of the prey and the predators.
eta:
The handling time of the predators.
phi:
The initial crowding of the prey.
phi_end:
The final crowding of the prey.
rate:
The rate at which the crowding rises.
Examples:
>>> from skcomplex.systems.biology.ecology import RosenzweigMacArthurInteraction
>>> RosenzweigMacArthurInteraction('predation', prey='prey', predators='predators', rate=0.01).rate
0.01
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
prey: Role,
predators: Role,
kappa: Annotated[float, RealSet.open(0, oo)] = 0.01,
eta: Annotated[float, RealSet.closed_open(0, oo)] = 0.8,
phi: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
phi_end: Annotated[float, RealSet.closed_open(0, oo)] = 0.2,
rate: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
) -> None:
super().__init__(label)
self.prey = prey
self.predators = predators
self.kappa = kappa
self.eta = eta
self.phi = phi
self.phi_end = phi_end
self.rate = rate
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rates of the prey and the predators under the ramp of the crowding.
Args:
context:
The namespace of the bound elements, the time `t`, and the parameters.
"""
super()._prepare(context)
s = context
x, y = s.prey.x, s.predators.x
crowding = clip(s.phi + s.rate * s.t, high=s.phi_end)
feeding = x * y / (1 + s.eta * x)
self.laws_ = [RateLaw(x, (x * (1 - crowding * x) - feeding) / s.kappa), RateLaw(y, feeding - y)]
Equations
The equations are those that symbolic returns for the system with its default parameters.
prey.x: diff(x_prey(t), t) == -((where(rate_predation*t + phi_predation > phi_end_predation, phi_end_predation, rate_predation*t + phi_predation)*x_prey(t) - 1)*x_prey(t) + x_predators(t)*x_prey(t)/(eta_predation*x_prey(t) + 1))/kappa_predation
predators.x: diff(x_predators(t), t) == x_predators(t)*x_prey(t)/(eta_predation*x_prey(t) + 1) - x_predators(t)