Skip to content

Exponential growth

A population that grows or declines at a constant per-capita rate.

  • Class: ExponentialGrowthSystem
  • Import: from skcomplex.systems.biology.ecology import ExponentialGrowthSystem
  • Field: biology/ecology
  • Topics: population, ode
  • References:
    • Malthus 1798

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 ExponentialGrowthSystem

trajectory = ExponentialGrowthSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
n 10.0
r 0.1
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 ExponentialGrowthSystem(BaseSystem):
    """A population that grows or declines at a constant per-capita rate.

    The system has the population `population`.

    Args:
        n:
            The initial size.

        r:
            The per-capita growth rate.

        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 ExponentialGrowthSystem
        >>> ExponentialGrowthSystem(r=0.2).prepare().system_.interactions[0].r
        0.2
    """

    field = 'biology/ecology'
    topics = ('population', 'ode')
    references = ('Malthus 1798',)
    until = 20.0
    dt = 0.1

    def __init__(
        self,
        n: float = 10.0,
        r: float = 0.1,
        *,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n = n
        self.r = r

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of a population that grows at a constant per-capita rate.

        The population grows or declines.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        self.system_ = System(
            self.label,
            elements=[PopulationElement('population', x=self.n)],
            interactions=[ExponentialGrowthInteraction('growth', target='population', r=self.r)],
        )

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

Interactions:

  • ExponentialGrowthInteraction, from Interaction
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 ExponentialGrowthInteraction(GrowthInteraction):
    """Growth at a constant per capita rate, `dx/dt = r x`.

    It is the exponential form of a growth without harvest.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the element or group whose population grows.

        r:
            The per capita growth rate, negative for decay.

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

    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
    """

    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)

    def _get_rate(self, namespace: SimpleNamespace) -> Expression:
        """Return the growth `r x`, with no harvest.

        Args:
            namespace:
                The namespace of the symbols the rate can use, with the namespace of the target.

        Returns:
            rate:
                The rate of the population.
        """
        return self._get_growth(namespace)

Equations

The equations are those that symbolic returns for the system with its default parameters.

population.x: diff(x_population(t), t) == r_growth*x_population(t)