PredatorPrey Dynamics
Contents
PredatorPrey
Dynamics#
This model is implemented as a cellular automaton (CA) with the cells arranged on a two-dimensional grid and represents a simple case of spatially resolved population dynamics.
Note
Currently, the execution order of rules is different from the code referred to in the script.
There, cells are called randomly and the sequence of rules is applied to an individual cell before proceeding to the next one.
In the Utopia PredatorPrey
model, a rule is applied to all cells before the proceeding to the next rule.
Due to that, results from the script can not be replicated exactly with this code.
Scenario#
As the name suggests, there are two different species present in this model: prey and predator. The prey species has a steady inflow of resources (e.g. by eating plants, whose population dynamics are not represented in this model). The predator species feeds on the prey. Both species expend resources to uphold their structure (“living costs”) and to reproduce, which happens in an asexual manner (i.e. individuals can reproduce without a mate).
The interaction consists of the predator moving on the grid and looking for prey in its neighborhood. Upon making contact, it consumes the prey. The prey may flee with a certain probability.
Implementation#
This is modelled using a cellular automaton (CA). Each cell of the CA has four possible states:
Empty
Inhabited by a prey
Inhabited by a predator
Inhabited by both a prey and a predator
No two individuals of the same species can be on the same cell at the same time. Consequently, each cell contains a variable for each species, in which the resource level of the respective individual is stored. The interaction is calculated for each timestep and consists of four sequentially applied rules:
Cost: resources of each individual are depleted by the cost of living. Individuals with negative or zero resources die and are hence removed.
Movement: predators move to a cell populated by prey in their neighborhood, or to an empty cell if there is no prey. Prey that are on a cell together with a predator flee to an empty cell in their neighborhood with a certain probability. If there are several cells in the neigborhood that meet the above condition, one is chosen at random.
Eating:: prey consume resources and predators eat prey if they are on the same cell.
Reproduction: if an individual’s resources exceed a certain value and if there is a cell in its neighborhood that is not already populated by an individual of the same species, it reproduces and an individual of the same species is created on the empty cell. 2 resource units are transferred to the offspring.
All cells are updated asynchronously. The order for the cell update is random for rules 2 and 4, to avoid introducing any ordering artefacts. For rules 1 and 3, this is not required.
Initialization#
Cells are initialized in a random fashion: depending on the probabilities configured by the user, each is initialized in one of the four states. The parameters controlling this are given in the model configuration, listed below.
Default configuration parameters#
Below are the default configuration parameters for the PredatorPrey
model:
# --- Space -------------------------------------------------------------------
space:
periodic: true
# --- CellManager -------------------------------------------------------------
cell_manager:
grid:
structure: square
resolution: 64 # in cells per unit length of physical space
neighborhood:
mode: Moore
# Initial species parameters
cell_params:
# Resource reservoir for predator and prey
predator:
init_resources: !is-unsigned 2
prey:
init_resources: !is-unsigned 2
# The probabilities to have a cell initialized with prey and/or predator
# on it. Need be non-negative and sum up to a value <= 1.0
p_predator: !is-probability 0.1
p_prey: !is-probability 0.2
# Load species positions from datasets of a HDF5 file.
# If enabled, the presence of an entity is set using data from the respective
# dataset, i.e. `predator` and `prey`.
# Values can only be 0 or 1, specifying whether the respective entity is
# present on the corresponding cell.
cell_states_from_file:
hdf5_file: !is-string /abs/path/to/data.hdf5
load_predator: !is-bool false
load_prey: !is-bool false
# --- Model dynamics ----------------------------------------------------------
# Species-specific parameters; the model dynamics arise from these
predator:
# Resource intake from eating and maximum resource value
resource_intake: !param
default: 3.
dtype: float
limits: [0.,~]
resource_max: !param
default: 8.
dtype: float
limits: [0.,~]
# Cost of living (per time step)
cost_of_living: !param
default: 1.
dtype: float
limits: [0.,~]
# Reproduction parameters: minimum resources required, probability for
# the reproduction taking place, and cost of reproduction.
repro_resource_requ: !param
default: 4.
dtype: float
limits: [0.,~]
repro_prob: !is-probability 0.2
repro_cost: !param
default: 2.
dtype: float
limits: [0.,~]
prey:
resource_intake: !param
default: 3.
dtype: float
limits: [0.,~]
resource_max: !param
default: 8.
dtype: float
limits: [0.,~]
# Cost of living (per time step)
cost_of_living: !param
default: 1.
dtype: float
limits: [0.,~]
# Fleeing probability when on the same cell together with a predator
p_flee: !is-probability 0.5
repro_resource_requ: !param
default: 4.
dtype: float
limits: [0.,~]
repro_prob: !is-probability 0.2
repro_cost: !param
default: 2.
dtype: float
limits: [0.,~]
Available plots#
The following plot configurations are available for the PredatorPrey
model:
Default Plot Configuration#
# --- Plot of the predator density against the prey density -------------------
phase_space:
based_on: phase_space
# --- Time series of the predator and prey spatial densities and resources ----
species_densities:
based_on: species_densities
mean_resources:
based_on: mean_resources
# --- Animation of the spatial resource development of prey and predators -----
resources:
based_on: .ca.state.anim_ffmpeg # update to *_frames to save frames
model_name: PredatorPrey
# Select the properties to plot
to_plot:
resource_predator:
title: Predator
limits: [0, 8] # Should be adapted to the resource_max model parameter
resource_prey:
title: Prey
limits: [0, 8] # Should be adapted to the resource_max model parameter
# Adjust plot aesthetics
helpers:
set_suptitle:
title: Resources
fontsize: xx-large
# --- Animation of the spatial development of prey and predator populations ---
population:
based_on: combined_grid_animation_ffmpeg # update to *_frames to save frames
to_plot:
# Combined by model_plots.PredatorPrey.ca.combine_pred_and_prey function
combined: &population_combined
title: Predator and Prey
limits: [0, 3]
cmap:
empty: white
prey: orange
predator: blue
both: red
# --- More detailed animation: prey only, combined, predator only -------------
population_detailed:
based_on: combined_grid_animation_ffmpeg # update to *_frames to save frames
enabled: false
to_plot:
predator:
title: Predator
limits: [0, 1]
cmap:
empty: white
predator: blue
combined:
<<: *population_combined
prey:
title: Prey
limits: [0, 1]
cmap:
empty: white
prey: orange
Base Plot Configuration#
# -- Plot of the predator density against the prey density --------------------
phase_space:
based_on: .time_series.phase_space
model_name: PredatorPrey
# Select the data
x: predator
y: prey
# Set helpers accordingly
helpers:
set_labels:
x: Predator Density $[1/A]$
y: Prey Density $[1/A]$
# How to color-code the time axis
cmap: viridis_r
# All below: passed on to plt.scatter
s: 3.5
# -- Time series of the predator and prey densities ---------------------------
species_densities:
based_on: .time_series.densities
helpers:
set_limits:
x: [0, max]
set_labels:
y: Density $[1/A]$
set_title:
title: Predator and Prey Densities
model_name: PredatorPrey
# Which data to calculate the densities from
to_plot:
predator:
mean_of: [x, y]
preprocess:
- create_mask: [==, 1]
label: Predator
prey:
mean_of: [x, y]
preprocess:
- create_mask: [==, 1]
label: Prey
# -- Time series of the predator and prey resources ---------------------------
mean_resources:
based_on: .basic_uni.lineplots
helpers:
set_limits:
x: [0, max]
y: [0, ~]
set_labels:
y: Resource Density $[1/A]$
set_title:
title: Mean Total Resources
model_name: PredatorPrey
# Take average only of cells with resources >= 1
to_plot:
resource_predator:
path_to_data: resource_predator
transform_data:
- where: [ge, 1]
- mean: [x, y]
label: Predator
resource_prey:
path_to_data: resource_prey
transform_data:
- where: [ge, 1]
- mean: [x, y]
label: Prey
# -- A grid animation that shows combined predator and prey positions ---------
combined_grid_animation_frames: &combined_grid_anim
based_on: .ca.state.anim_frames
model_name: PredatorPrey
# Use the custom plotting function
module: model_plots.PredatorPrey
plot_func: combine_pred_and_prey
combined_grid_animation_ffmpeg:
<<: *combined_grid_anim
based_on: .ca.state.anim_ffmpeg
For the utopya base plots, see Multiverse Base Configuration.
References#
Kurt Roth: Chaotic, Complex, and Evolving Environmental Systems, unpublished lecture notes, University of Heidelberg, 2019.