Skip to content

Logistic growth with a varying capacity

Logistic growth under a seasonal carrying capacity.

  • Class: VaryingCapacityLogisticSystem
  • Import: from skcomplex.systems.biology.ecology import VaryingCapacityLogisticSystem
  • Field: biology/ecology
  • Topics: population, ode, forcing, periodic
  • References:
    • Coleman 1979
    • Trzaska 2023

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 VaryingCapacityLogisticSystem

trajectory = VaryingCapacityLogisticSystem().prepare().simulate()

Parameters

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

Parameter Default
n 10.0
r 2.0
K 100.0
amplitude 0.5
period 1.0
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 VaryingCapacityLogisticSystem(BaseSystem):
    """Logistic growth under a seasonal carrying capacity.

    It settles on a cycle of the season's period.

    Whatever its initial size, the population tends to a unique periodic solution, which lags behind the capacity and
    varies less than it. The system has the population `population`.

    Args:
        n:
            The initial size.

        r:
            The intrinsic growth rate.

        K:
            The mean carrying capacity.

        amplitude:
            The relative amplitude of the seasonal variation of the capacity, below 1.

        period:
            The period of the seasons.

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

    field = 'biology/ecology'
    topics = ('population', 'ode', 'forcing', 'periodic')
    references = ('Coleman 1979', 'Trzaska 2023')
    until = 20.0
    dt = 0.05

    def __init__(
        self,
        n: float = 10.0,
        *,
        r: float = 2.0,
        K: float = 100.0,
        amplitude: float = 0.5,
        period: float = 1.0,
        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
        self.K = K
        self.amplitude = amplitude
        self.period = period

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of logistic growth under a seasonal carrying capacity.

        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=[
                SeasonalLogisticGrowthInteraction(
                    'growth',
                    target='population',
                    r=self.r,
                    K=self.K,
                    amplitude=self.amplitude,
                    period=self.period,
                ),
            ],
        )

Components

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

Elements:

Interactions:

  • SeasonalLogisticGrowthInteraction, 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 SeasonalLogisticGrowthInteraction(LogisticGrowthInteraction):
    """Logistic growth under a carrying capacity that varies periodically.

    The capacity is `K(t) = K (1 + amplitude sin(2 pi t / T))`.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the population.

        r:
            The per capita growth rate at low density.

        K:
            The mean carrying capacity.

        amplitude:
            The relative amplitude of the variation of the capacity, below 1.

        period:
            The period `T` of the variation.

    Examples:
        >>> from skcomplex.systems.biology.ecology import SeasonalLogisticGrowthInteraction
        >>> SeasonalLogisticGrowthInteraction('growth', target='rabbits', period=12.0).period
        12.0
    """

    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,
        amplitude: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
        period: Annotated[float, RealSet.open(0, oo)] = 1.0,
    ) -> None:
        super().__init__(label, target=target, r=r, K=K)
        self.amplitude = amplitude
        self.period = period

    def _get_capacity(self, namespace: SimpleNamespace) -> Expression:
        """Return the capacity at the time of the namespace.

        It is `K (1 + amplitude sin(2 pi t / T))`.

        Args:
            namespace:
                The namespace of the symbols the rate can use.

        Returns:
            capacity:
                The carrying capacity at the time `t`.
        """
        s = namespace
        capacity: Expression = s.K * (1 + s.amplitude * sin(2 * pi * s.t / s.period))
        return capacity

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)/((amplitude_growth*sin(2*pi*t/period_growth) + 1)*K_growth) - 1)*x_population(t)