PredatorPreyPlant
— Predator-Prey Dynamics including Vegetation#
This is an expansion of the Predator-Prey model in which plants (the resource the prey feeds on) are modelled explicitly. The main additions/changes are the following:
The movement mechanism is different, and the movement rule now involves a movement radius so that each entity can move further than one cell per turn.
The presence of plants which can grow, based on different growth models
Implementation Details#
Movement#
In contrast to the PredatorPrey
model, the movement rule is no longer called once per cell each turn.
Instead, it is called for num_moves
random cells each turn.
This makes it possible for one cell to be selected multiple times to carry out the movement rule and other cells might not be selected at all within that time step.
The internal num_moves
parameter can be set in the configuration via the num_moves_fraction
key, which allows specifying it in units of the total number of grid cells.
Three possible actions take place on a selected cell:
In case both a predator and a prey are on a cell, the prey will flee in the same fashion as in the standard Predator-Prey model.
If there is a predator but no prey on the cell, the predator will move until it finds a prey or until it reaches the
move_limit
.If there is only a prey but no resource, the prey will move to find resources until it reaches it or arrives at the
move_limit
. In this phase the prey will move to a cell even if there is a predator on it.
Vegetation Growth Model#
There are three options for the growth models of the vegatation:
none
: deactivates explicit modelling of vegetation. Grass regrows every turn, thus prey can also eat every turn.deterministic
: vegetation will regrow after a specific number of time-steps.stochastic
: vegetation will regrow with a certain probability, evaluated each time step.
Default configuration parameters#
Below are the default configuration parameters for the PredatorPreyPlant
model:
# --- Space -------------------------------------------------------------------
space:
periodic: true
# --- CellManager -------------------------------------------------------------
cell_manager:
grid:
structure: square
resolution: 64
neighborhood:
mode: Moore
cell_params:
# Initial prey and predator resources are drawn from a uniform integer (!)
# distribution with the limits specified below.
predator:
min_init_resources: !is-positive-or-zero 2
max_init_resources: !is-positive-or-zero 8
prey:
min_init_resources: !is-positive-or-zero 2
max_init_resources: !is-positive-or-zero 8
# The probabilities to have a predator, plant, and/or prey on a cell.
# These probabilities are evaluated independently and for each cell.
p_predator: !is-probability 0.2
p_prey: !is-probability 0.3
p_plant: !is-probability 1.
# 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`, `prey`, and `plant`.
# 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 # TODO Set this in your run.yml
load_predator: !is-bool false
load_prey: !is-bool false
load_plant: !is-bool false
# --- Model dynamics ----------------------------------------------------------
# How many cells to randomly select each time step and apply the movement rule
# to (in units of the number of available cells). Can also be > 1.
num_moves_fraction: !is-positive-or-zero 1.
# Species-specific parameters; the model dynamics arise from these
predator:
# Resource intake from eating and maximum resource value
resource_intake: !is-positive-or-zero 15.
resource_max: !is-positive-or-zero 30.
# Cost of living (per time step)
cost_of_living: !is-positive-or-zero 3.5
# Movement limit; how many single steps a predator can make when moving.
move_limit: !is-positive-int 2
# Reproduction parameters: minimum resources required, probability for
# the reproduction taking place, and cost of reproduction.
repro_resource_requ: !is-positive-or-zero 2.
repro_prob: !is-probability 0.2
repro_cost: !is-positive-or-zero 1.
prey:
resource_intake: !is-positive-or-zero 3.
resource_max: !is-positive-or-zero 8.
cost_of_living: !is-positive-or-zero 1.
move_limit: !is-positive-int 1
# Fleeing probability when on the same cell together with a predator
p_flee: !is-probability 0.3
repro_resource_requ: !is-positive-or-zero 1.5
repro_prob: !is-probability 0.4
repro_cost: !is-positive-or-zero 1.2
plant:
# Plants' growth model
growth_model: !param
dtype: str
default: stochastic
is_any_of: [none, deterministic, stochastic]
# Available models:
# - none: As in the standard Predator-Prey model, the presence of
# plants is ignored. Thus, available resources for prey
# are unlimited.
#
# - deterministic The system will regrow plants deterministically after a
# constant regeneration time given by ``regen_time``.
#
# - stochastic The system will regrow plants with a probability
# given by parameter ``regen_prob``, evaluated each time
# step for each cell without a plant on it.
# The deterministic regeneration time
regen_time: !is-unsigned 7
# The regeneration probability (for stochastic regrowth)
regen_prob: !is-probability 0.25
Available plots#
The following plot configurations are available for the PredatorPreyPlant
model:
Default Plot Configuration#
phase_space/predator_prey:
based_on: phase_space
x: predator_density
y: prey_density
hue: time
helpers:
set_labels:
x: Predator Density $[1/A]$
y: Prey Density $[1/A]$
phase_space/prey_plant:
based_on: phase_space
x: prey_density
y: plant_density
hue: time
helpers:
set_labels:
x: Prey Density $[1/A]$
y: Plant Density $[1/A]$
# --- Time series of mean values ----------------------------------------------
species_densities:
based_on: species_densities
mean_resources:
based_on: mean_resources
# --- Animation of the spatial resource development of prey and predators -----
ca/resources:
based_on: resources
# --- Animation of the spatial development of prey and predator populations ---
ca/population:
based_on: population
# --- More detailed animation: prey only, combined, predator only -------------
ca/population_detailed:
based_on: population_detailed
Base Plot Configuration#
.variables:
model_name: &model_name PredatorPreyPlant
base_path: &base_path data/PredatorPreyPlant
# Colors used throughout these plots
cmap: &cmap
empty: &color_empty white
predator: &color_predator '#FFCC66'
prey: &color_prey '#006666'
plant: &color_plant '#339999'
both: &color_both '#CC3333'
# =============================================================================
# ╔╦╗╔═╗╔╦╗╔═╗╦ ╔═╗╔╦╗╔═╗╔═╗
# ║ ║╣ ║║║╠═╝║ ╠═╣ ║ ║╣ ╚═╗
# ╩ ╚═╝╩ ╩╩ ╩═╝╩ ╩ ╩ ╚═╝╚═╝
# =============================================================================
# -- Overloads ----------------------------------------------------------------
# Overload some configs to insert model-specific settings
# Model-specific defaults
.defaults:
based_on: .defaults
# Can define something here ...
# .. Creators .................................................................
.creator.universe:
based_on:
- .creator.universe
- .defaults
dag_options:
select_path_prefix: *base_path
.creator.multiverse:
based_on:
- .creator.multiverse
- .defaults
select_and_combine:
base_path: *base_path
# =============================================================================
# ╔═╗╦ ╔═╗╔╦╗╔═╗
# ╠═╝║ ║ ║ ║ ╚═╗
# ╩ ╩═╝╚═╝ ╩ ╚═╝
# =============================================================================
# -- Phase space plots --------------------------------------------------------
phase_space:
based_on:
- .creator.universe
- .plot.facet_grid.scatter
select: &pred_prey_plant_density
predator_density:
path: predator
transform:
- .mean: [ !dag_prev , [ 'x', 'y' ] ]
prey_density:
path: prey
transform:
- .mean: [ !dag_prev , [ 'x', 'y' ] ]
plant_density:
path: plant
transform:
- .mean: [ !dag_prev , [ 'x', 'y' ] ]
transform:
- operation: xr.Dataset
kwargs:
data_vars:
predator_density: !dag_tag predator_density
prey_density: !dag_tag prey_density
plant_density: !dag_tag plant_density
tag: data
# 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:
- .creator.universe
- .plot.facet_grid.line
- .hlpr.kind.time_series
select:
<<: *pred_prey_plant_density
transform:
- xr.Dataset:
data_vars:
predator: !dag_tag predator_density
prey: !dag_tag prey_density
- .to_array: [!dag_prev ]
kwargs:
dim: kind
tag: data
hue: kind
helpers:
set_labels:
y: Density $[1/A]$
set_title:
title: Predator and Prey Densities
set_legend:
title: Species
style: &color_cycler
axes.prop_cycle: !format
fstr: "cycler('color', ['{cmap[predator]:}', '{cmap[prey]:}'])"
cmap: *cmap
# -- Time series of the predator and prey resources ---------------------------
mean_resources:
based_on:
- .creator.universe
- .plot.facet_grid.line
- .hlpr.kind.time_series
select:
resource_predator:
path: resource_predator
transform:
- .where: [ !dag_prev ge 1, !dag_prev , 0] # TODO Syntax ok???
- .mean: [!dag_prev , ['x', 'y']]
resource_prey:
path: resource_prey
transform:
- .where: [ !dag_prev ge 1, !dag_prev , 0]
- .mean: [!dag_prev , ['x', 'y']]
transform:
- operation: xr.Dataset
kwargs:
data_vars:
predator: !dag_tag resource_predator
prey: !dag_tag resource_prey
- .to_array: [ !dag_prev ]
kwargs:
dim: kind
tag: data
x: time
hue: kind
helpers:
set_limits:
y: [0, ~]
set_labels:
y: Resource Density $[1/A]$
set_title:
title: Mean Total Resources
set_legend:
title: Species
style:
<<: *color_cycler
# --- Animation of the spatial resource development of prey and predators -----
resources:
based_on:
- .creator.universe
- .plot.ca
select:
resource_predator: resource_predator
resource_prey: resource_prey
resource_max_predator:
path: "../../cfg"
with_previous_result: true
transform:
- recursive_getitem: [[*model_name, predator, resource_max]]
resource_max_prey:
path: "../../cfg"
with_previous_result: true
transform:
- recursive_getitem: [[*model_name, prey, resource_max]]
# Select the properties to plot
to_plot:
resource_predator:
title: Predator resources
vmin: 0
vmax: !dag_result resource_max_predator
cmap: YlGn
resource_prey:
title: Prey resources
vmin: 0
vmax: !dag_result resource_max_prey
cmap: YlGn
# --- Animation of the spatial development of prey and predator populations ---
population:
based_on:
- .creator.universe
- .plot.ca
select:
predator:
path: predator
transform: [.data] # resolve GridDC to have an xr-native object
prey:
path: prey
transform: [.data] # resolve GridDC to have an xr-native object
transform:
# Use base-2 encoding to denote whether a cell is empty, contains only a
# prey, only a predator or both:
- mul: [!dag_tag predator, 2]
- add: [!dag_prev , !dag_tag prey]
tag: combined
to_plot:
combined:
title: Predator & Prey positions
cmap:
empty: *color_empty # 0
prey: *color_prey # 1
predator: *color_predator # 2
both: *color_both # 3
# --- More detailed animation: prey only, combined, predator only -------------
population_detailed:
based_on:
- .creator.universe
- .plot.ca
select:
predator:
path: predator
transform: [.data] # resolve GridDC to have an xr-native object
prey:
path: prey
transform: [.data] # resolve GridDC to have an xr-native object
plant:
path: plant
transform: [ .data ] # resolve GridDC to have an xr-native object
transform:
# Use base-2 encoding to denote whether a cell is empty or contains both
- mul: [ !dag_tag predator, !dag_tag prey ]
- .assign_attrs: [!dag_prev , {'grid_structure': 'square'}]
tag: combined
to_plot:
predator:
title: Predator
cmap:
empty: *color_empty
predator: *color_predator
add_colorbar: false
prey:
title: Prey
cmap:
empty: *color_empty
prey: *color_prey
add_colorbar: false
combined:
title: Predator & Prey
cmap:
empty: *color_empty
both: *color_both
add_colorbar: false
plant:
title: Plant
cmap:
empty: *color_empty
both: *color_plant
add_colorbar: false
For available base plots, see Base Plot Configuration Pool.
References#
Kurt Roth: Chaotic, Complex, and Evolving Environmental Systems, unpublished lecture notes, University of Heidelberg, 2019.