Skip to content

Populations

Population realizations shared by the biology packages.

They cover populations, structured population densities, growth, mortality, predation, and replicators.

ExponentialGrowthInteraction(label, *, target, r=1.0, state='x')

Bases: GrowthInteraction

Growth at a constant per capita rate, dx/dt = r x.

It is the exponential form of a growth without harvest.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the element or group whose population grows.

required
r float

The per capita growth rate, negative for decay.

1.0
state str

The name of the state of the target that holds the population.

'x'

Examples:

>>> from skcomplex.systems.biology.common.kinetics import CompartmentElement
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.biology.common.populations import ExponentialGrowthInteraction
>>> system = System(
...     elements=[CompartmentElement('rabbits', x=1.0)],
...     interactions=[ExponentialGrowthInteraction('growth', target='rabbits', r=0.5)],
... )
>>> trajectory = system.prepare().simulate(until=2.0, dt=0.01)
>>> round(float(trajectory.get_values('rabbits.x')[-1]), 3)
2.718
Source code in src/skcomplex/systems/biology/common/populations/_exponential_growth.py
48
49
50
51
52
53
54
55
56
def __init__(
    self,
    label: str,
    *,
    target: Role,
    r: float = 1.0,
    state: str = 'x',
) -> None:
    super().__init__(label, target=target, r=r, form='exponential', state=state)

GrowthInteraction(label, *, target, r=1.0, K=1.0, p=1.0, h=0.0, tau=0.0, form='exponential', state='x')

Bases: Interaction

Growth or decay of a population x of a target by a growth law.

The growth comes with a proportional harvest.

The rate of x is the growth of the form minus the harvest h x:

  • 'exponential': r x.
  • 'logistic': r x (1 - (x / K) ** p), the generalized logistic of Richards, with p = 1 for Verhulst's.
  • 'gompertz': r x log(K / x).
  • 'power': r x ** p.
  • 'bertalanffy': r x ** p (1 - (x / K) ** (1 - p)), von Bertalanffy's growth towards K, with p < 1.

With a delay tau above 0, the limiting factor of the logistic and the Gompertz forms reads the population x(t - tau), as in Hutchinson's delayed logistic equation. A negative rate r gives decay.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
target Role

The path of the element or group whose population grows.

required
r float

The growth rate.

1.0
K Annotated[float, open(0, oo)]

The capacity of the logistic, Gompertz, and von Bertalanffy forms.

1.0
p float

The exponent of the logistic, power, and von Bertalanffy forms.

1.0
h Annotated[float, closed_open(0, oo)]

The harvest rate, the fraction of the population removed per unit time.

0.0
tau Annotated[float, closed_open(0, oo)]

The delay of the limiting factor, 0 for none.

0.0
form str

The growth law, 'exponential', 'logistic', 'gompertz', 'power', or 'bertalanffy'.

'exponential'
state str

The name of the state of the target that holds the population.

'x'

Raises:

Type Description
ValidationError

The form is unknown, the state is not a name, a delay is given to a form without a limiting factor, or the von Bertalanffy exponent is 1.

Examples:

>>> from skcomplex.systems.biology.common.kinetics import CompartmentElement
>>> from skcomplex.systems.biology.common.populations import GrowthInteraction
>>> from skcomplex.core.systems import System
>>> system = System(
...     elements=[CompartmentElement('population', x=1.0)],
...     interactions=[GrowthInteraction('growth', target='population', r=1.0, K=100.0, form='logistic')],
... )
>>> trajectory = system.prepare().simulate(until=30, dt=1.0)
>>> round(float(trajectory.get_values('population.x')[-1]), 2)
100.0
Source code in src/skcomplex/systems/biology/common/populations/_growth.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def __init__(
    self,
    label: str,
    *,
    target: Role,
    r: float = 1.0,
    K: Annotated[float, RealSet.open(0, oo)] = 1.0,
    p: float = 1.0,
    h: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    tau: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    form: str = 'exponential',
    state: str = 'x',
) -> None:
    super().__init__(label)
    self.target = target
    self.state = state
    self.r = r
    self.K = K
    self.p = p
    self.h = h
    self.tau = tau
    self.form = form

LogisticGrowthInteraction(label, *, target, r=1.0, K=100.0, tau=0.0, state='x')

Bases: GrowthInteraction

Verhulst's growth limited by a carrying capacity, without harvest.

The population follows dx/dt = r x (1 - x(t - tau) / K).

A delay tau above 0 gives Hutchinson's delayed logistic equation. The generalized logistic of Richards, with an exponent on the crowding, is GrowthInteraction(form='logistic', p=...).

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the element or group whose population grows.

required
r Annotated[float, closed_open(0, oo)]

The per capita growth rate at low density.

1.0
K Annotated[float, open(0, oo)]

The carrying capacity.

100.0
tau Annotated[float, closed_open(0, oo)]

The delay of the limiting factor, 0 for none.

0.0
state str

The name of the state of the target that holds the population.

'x'

Examples:

>>> from skcomplex.systems.biology.common.kinetics import CompartmentElement
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.biology.common.populations import LogisticGrowthInteraction
>>> system = System(
...     elements=[CompartmentElement('rabbits', x=1.0)],
...     interactions=[LogisticGrowthInteraction('growth', target='rabbits', r=1.0, K=50.0)],
... )
>>> trajectory = system.prepare().simulate(until=30.0, dt=0.1)
>>> round(float(trajectory.get_values('rabbits.x')[-1]), 3)
50.0
Source code in src/skcomplex/systems/biology/common/populations/_logistic_growth.py
56
57
58
59
60
61
62
63
64
65
66
def __init__(
    self,
    label: str,
    *,
    target: Role,
    r: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    K: Annotated[float, RealSet.open(0, oo)] = 100.0,
    tau: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    state: str = 'x',
) -> None:
    super().__init__(label, target=target, r=r, K=K, tau=tau, form='logistic', state=state)

MortalityInteraction(label, *, target, d=0.1, state='x')

Bases: Interaction

Death or loss at a constant per capita rate, dx/dt = -d x.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the element or group whose population dies.

required
d Annotated[float, closed_open(0, oo)]

The per capita death rate.

0.1
state str

The name of the state of the target that holds the population.

'x'

Examples:

>>> from skcomplex.systems.biology.common.kinetics import CompartmentElement
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.biology.common.populations import MortalityInteraction
>>> system = System(
...     elements=[CompartmentElement('foxes', x=8.0)],
...     interactions=[MortalityInteraction('death', target='foxes', d=0.5)],
... )
>>> trajectory = system.prepare().simulate(until=2.0, dt=0.01)
>>> round(float(trajectory.get_values('foxes.x')[-1]), 3)
2.943
Source code in src/skcomplex/systems/biology/common/populations/_mortality.py
48
49
50
51
52
53
54
55
56
57
58
59
def __init__(
    self,
    label: str,
    *,
    target: Role,
    d: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
    state: str = 'x',
) -> None:
    super().__init__(label)
    self.target = target
    self.d = d
    self.state = state

NeutralBirthInteraction(label, *, target, b0=1.0, b1=0.9)

Bases: Interaction

Births of single individuals at the rate b0 + b1 x, shared by every species.

The constant part b0 is immigration or speciation, and b1 the birth rate of an individual.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the species or of the group of species.

required
b0 Annotated[float, closed_open(0, oo)]

The rate of immigration or speciation.

1.0
b1 Annotated[float, closed_open(0, oo)]

The birth rate of an individual.

0.9

Examples:

>>> from skcomplex.systems.biology.common.populations import NeutralBirthInteraction
>>> NeutralBirthInteraction('birth', target='trees').b1
0.9
Source code in src/skcomplex/systems/biology/common/populations/_neutral.py
44
45
46
47
48
49
50
51
52
53
54
55
def __init__(
    self,
    label: str,
    *,
    target: Role,
    b0: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    b1: Annotated[float, RealSet.closed_open(0, oo)] = 0.9,
) -> None:
    super().__init__(label)
    self.target = target
    self.b0 = b0
    self.b1 = b1

NeutralDeathInteraction(label, *, target, d0=0.0, d1=1.0)

Bases: Interaction

Deaths of single individuals at the rate d0 + d1 x, shared by every species.

The constant part d0 is emigration or extinction while the species has members, and d1 the death rate of an individual.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the species or of the group of species.

required
d0 Annotated[float, closed_open(0, oo)]

The rate of emigration or extinction while the species has members.

0.0
d1 Annotated[float, closed_open(0, oo)]

The death rate of an individual.

1.0

Examples:

>>> from skcomplex.systems.biology.common.populations import NeutralDeathInteraction
>>> NeutralDeathInteraction('death', target='trees').d1
1.0
Source code in src/skcomplex/systems/biology/common/populations/_neutral.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def __init__(
    self,
    label: str,
    *,
    target: Role,
    d0: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    d1: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
) -> None:
    super().__init__(label)
    self.target = target
    self.d0 = d0
    self.d1 = d1

PopulationDensityElement(label, *, x=0.0, size=None, space=None)

Bases: NonnegativeElement

Value x of the density of a structured population at one class.

A structured population is this element on a lattice of classes, such as sizes or activities, with one value per class, and growth, encounters, and transport change it. The element has no laws of its own.

Parameters:

Name Type Description Default
label str

The label of the element, unique among the components of its system.

required
x Annotated[object, closed_open(0, oo)]

The initial density, a nonnegative number.

0.0
size int | None

The number of members, or None for one.

None
space BaseSpace | None

The space with one member per site, such as a lattice of classes, or None for none.

None

Examples:

>>> from skcomplex.core.components.spaces import LatticeSpace
>>> from skcomplex.systems.biology.common.populations import PopulationDensityElement
>>> classes = LatticeSpace(5, boundary='fixed')
>>> PopulationDensityElement('cells', x=[0.2] * 5, space=classes).x
[0.2, 0.2, 0.2, 0.2, 0.2]
Source code in src/skcomplex/systems/biology/common/populations/_population_density.py
42
43
44
45
46
47
48
49
50
def __init__(
    self,
    label: str,
    *,
    x: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, x=x, size=size, space=space)

PopulationElement(label, *, x=1.0)

Bases: CompartmentElement

Population of one species, a compartment whose state x holds its size.

Parameters:

Name Type Description Default
label str

The label of the population.

required
x Annotated[float, closed_open(0, oo)]

The initial size.

1.0

Examples:

>>> from skcomplex.systems.biology.common.populations import PopulationElement
>>> PopulationElement('rabbits', x=40).x
40
Source code in src/skcomplex/systems/biology/common/populations/_population.py
33
34
35
36
37
38
39
def __init__(
    self,
    label: str,
    *,
    x: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
) -> None:
    super().__init__(label, x=x)

PredationInteraction(label, *, predator, prey, a=0.1, b=0.01)

Bases: Interaction

Lotka-Volterra predation, where encounters remove prey and feed predators.

The prey loses a * predator * prey per unit time and the predator gains b * predator * prey.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
predator Role

The path of the predator population.

required
prey Role

The path of the prey population.

required
a Annotated[float, closed_open(0, oo)]

The attack rate.

0.1
b Annotated[float, closed_open(0, oo)]

The conversion rate of eaten prey into predators.

0.01

Examples:

>>> from skcomplex.systems.biology.ecology import PredationInteraction
>>> PredationInteraction('hunt', predator='foxes', prey='rabbits', a=0.4, b=0.1).prey
'rabbits'
Source code in src/skcomplex/systems/biology/common/populations/_predation.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def __init__(
    self,
    label: str,
    *,
    predator: Role,
    prey: Role,
    a: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
    b: Annotated[float, RealSet.closed_open(0, oo)] = 0.01,
) -> None:
    super().__init__(label)
    self.predator = predator
    self.prey = prey
    self.a = a
    self.b = b

ReplicatorInteraction(label, *, target, fitness=None, state='x')

Bases: Interaction

Replicator equation of the shares of a group, with a fitness f.

The shares follow dx_i/dt = x_i (f_i - sum_j x_j f_j).

Every member of the group holds the share of a type, such as a strategy or a molecule. Its share grows with its fitness above the mean fitness of the group, so the total of the shares stays constant.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the group of types.

required
fitness Callable[[SimpleNamespace], object] | None

The function of the namespace that returns the fitness of a member, such as lambda s: total(s.target.x, weights=payoff) for the payoff of a strategy against the others.

None
state str

The name of the state of the members that holds the share.

'x'

Raises:

Type Description
ValidationError

The fitness is not callable, raised by prepare.

Examples:

>>> from skcomplex.core.components.laws.utils import total
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.biology.evolution import ReplicatorInteraction, StrategyElement
>>> population = StrategyElement('population', x=[0.5, 0.5], size=2)
>>> payoff = ((1.0, 1.0), (0.0, 0.0))
>>> replication = ReplicatorInteraction(
...     'replication', target='population', fitness=lambda s: total(s.target.x, weights=payoff)
... )
>>> system = System(elements=[population], interactions=[replication])
>>> trajectory = system.prepare().simulate(until=20.0, dt=0.1)
>>> [round(float(share), 3) for share in trajectory.get_values('population.x')[-1]]
[1.0, 0.0]
Source code in src/skcomplex/systems/biology/common/populations/_replicator.py
64
65
66
67
68
69
70
71
72
73
74
75
def __init__(
    self,
    label: str,
    *,
    target: Role,
    fitness: Callable[[SimpleNamespace], object] | None = None,
    state: str = 'x',
) -> None:
    super().__init__(label)
    self.target = target
    self.state = state
    self.fitness = fitness