Skip to content

Predator Prey

dissmodel.models.sysdyn.predatorprey.PredatorPrey

Bases: Model

Lotka-Volterra predator-prey model.

Models the dynamic interaction between a prey population and a predator population. Prey grow exponentially in the absence of predators; predators decline without prey. Their interaction drives cyclic oscillations in both populations.

Parameters:

Name Type Description Default
predator float

Initial predator population, by default 40.

required
prey float

Initial prey population, by default 1000.

required
prey_growth float

Intrinsic prey growth rate, by default 0.08.

required
prey_death_pred float

Rate at which predators kill prey per encounter, by default 0.001.

required
pred_death float

Intrinsic predator death rate, by default 0.02.

required
pred_growth_kills float

Rate at which predators reproduce per kill, by default 0.00002.

required
Notes

The @track_plot decorators register prey and predator for automatic live plotting. Any :class:~dissmodel.visualization.Chart connected to the same environment will plot both variables at every step without any extra configuration.

The update equations follow the discrete Lotka-Volterra model:

.. math::

P_{t+1} = P_t + r_P \cdot P_t - d_{PP} \cdot P_t \cdot Q_t

Q_{t+1} = Q_t - d_Q \cdot Q_t + g_Q \cdot P_t \cdot Q_t

Where :math:P is prey, :math:Q is predator.

Examples:

>>> from dissmodel.core import Environment
>>> env = Environment(end_time=100)
>>> model = PredatorPrey()
>>> env.run()
Source code in dissmodel/models/sysdyn/predatorprey.py
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@track_plot("Prey", "green")
@track_plot("Predator", "red")
class PredatorPrey(Model):
    """
    Lotka-Volterra predator-prey model.

    Models the dynamic interaction between a prey population and a
    predator population. Prey grow exponentially in the absence of
    predators; predators decline without prey. Their interaction drives
    cyclic oscillations in both populations.

    Parameters
    ----------
    predator : float, optional
        Initial predator population, by default 40.
    prey : float, optional
        Initial prey population, by default 1000.
    prey_growth : float, optional
        Intrinsic prey growth rate, by default 0.08.
    prey_death_pred : float, optional
        Rate at which predators kill prey per encounter, by default 0.001.
    pred_death : float, optional
        Intrinsic predator death rate, by default 0.02.
    pred_growth_kills : float, optional
        Rate at which predators reproduce per kill, by default 0.00002.

    Notes
    -----
    The ``@track_plot`` decorators register ``prey`` and ``predator``
    for automatic live plotting. Any :class:`~dissmodel.visualization.Chart`
    connected to the same environment will plot both variables at every
    step without any extra configuration.

    The update equations follow the discrete Lotka-Volterra model:

    .. math::

        P_{t+1} = P_t + r_P \\cdot P_t - d_{PP} \\cdot P_t \\cdot Q_t

        Q_{t+1} = Q_t - d_Q \\cdot Q_t + g_Q \\cdot P_t \\cdot Q_t

    Where :math:`P` is prey, :math:`Q` is predator.

    Examples
    --------
    >>> from dissmodel.core import Environment
    >>> env = Environment(end_time=100)
    >>> model = PredatorPrey()
    >>> env.run()
    """

    #: Current predator population.
    predator: float

    #: Current prey population.
    prey: float

    #: Intrinsic prey growth rate.
    prey_growth: float

    #: Rate at which predators kill prey per encounter.
    prey_death_pred: float

    #: Intrinsic predator death rate.
    pred_death: float

    #: Rate at which predators reproduce per kill.
    pred_growth_kills: float

    def setup(
        self,
        predator: float = 40.0,
        prey: float = 1000.0,
        prey_growth: float = 0.08,
        prey_death_pred: float = 0.001,
        pred_death: float = 0.02,
        pred_growth_kills: float = 0.00002,
    ) -> None:
        """
        Configure the model parameters.

        Parameters
        ----------
        predator : float, optional
            Initial predator population, by default 40.
        prey : float, optional
            Initial prey population, by default 1000.
        prey_growth : float, optional
            Intrinsic prey growth rate, by default 0.08.
        prey_death_pred : float, optional
            Rate at which predators kill prey per encounter,
            by default 0.001.
        pred_death : float, optional
            Intrinsic predator death rate, by default 0.02.
        pred_growth_kills : float, optional
            Rate at which predators reproduce per kill,
            by default 0.00002.
        """
        self.predator       = predator
        self.prey           = prey
        self.prey_growth    = prey_growth
        self.prey_death_pred = prey_death_pred
        self.pred_death     = pred_death
        self.pred_growth_kills = pred_growth_kills

    def execute(self) -> None:
        """
        Advance the model by one time step.

        Updates prey and predator populations according to the
        discrete Lotka-Volterra equations.
        """
        self.prey += (
            self.prey_growth * self.prey
            - self.prey_death_pred * self.prey * self.predator
        )
        self.predator += (
            -self.pred_death * self.predator
            + self.pred_growth_kills * self.prey * self.predator
        )

execute()

Advance the model by one time step.

Updates prey and predator populations according to the discrete Lotka-Volterra equations.

Source code in dissmodel/models/sysdyn/predatorprey.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
def execute(self) -> None:
    """
    Advance the model by one time step.

    Updates prey and predator populations according to the
    discrete Lotka-Volterra equations.
    """
    self.prey += (
        self.prey_growth * self.prey
        - self.prey_death_pred * self.prey * self.predator
    )
    self.predator += (
        -self.pred_death * self.predator
        + self.pred_growth_kills * self.prey * self.predator
    )

setup(predator=40.0, prey=1000.0, prey_growth=0.08, prey_death_pred=0.001, pred_death=0.02, pred_growth_kills=2e-05)

Configure the model parameters.

Parameters:

Name Type Description Default
predator float

Initial predator population, by default 40.

40.0
prey float

Initial prey population, by default 1000.

1000.0
prey_growth float

Intrinsic prey growth rate, by default 0.08.

0.08
prey_death_pred float

Rate at which predators kill prey per encounter, by default 0.001.

0.001
pred_death float

Intrinsic predator death rate, by default 0.02.

0.02
pred_growth_kills float

Rate at which predators reproduce per kill, by default 0.00002.

2e-05
Source code in dissmodel/models/sysdyn/predatorprey.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def setup(
    self,
    predator: float = 40.0,
    prey: float = 1000.0,
    prey_growth: float = 0.08,
    prey_death_pred: float = 0.001,
    pred_death: float = 0.02,
    pred_growth_kills: float = 0.00002,
) -> None:
    """
    Configure the model parameters.

    Parameters
    ----------
    predator : float, optional
        Initial predator population, by default 40.
    prey : float, optional
        Initial prey population, by default 1000.
    prey_growth : float, optional
        Intrinsic prey growth rate, by default 0.08.
    prey_death_pred : float, optional
        Rate at which predators kill prey per encounter,
        by default 0.001.
    pred_death : float, optional
        Intrinsic predator death rate, by default 0.02.
    pred_growth_kills : float, optional
        Rate at which predators reproduce per kill,
        by default 0.00002.
    """
    self.predator       = predator
    self.prey           = prey
    self.prey_growth    = prey_growth
    self.prey_death_pred = prey_death_pred
    self.pred_death     = pred_death
    self.pred_growth_kills = pred_growth_kills