run_meanfield {chouca} | R Documentation |
Mean field model
Description
Run the mean field model corresponding to a cellular automaton
Usage
run_meanfield(mod, init, times, ...)
Arguments
mod |
The cellular automaton model (produced by |
init |
The initial landscape, or a vector of covers summing to one, whose length is equal to the number of states in the model. |
times |
The points in time for which output is wanted |
... |
other arguments are passed to |
Details
The mean field approximation to a cellular automaton simply describes the dynamics
of the global covers using differential equations, assumming that both global
and local covers are equal (in chouca
model specifications, this assumes
p = q).
For example, if we consider a model with two states 'a' and 'b' and transitions from and to each other, then the following system of equation is used to describe the variations of the proportions of cells in each state:
\frac{da}{dt} = p_b P(b \to a) - p_a P(a \to b)
\frac{db}{dt} = p_a P(a \to b) - p_b P(b \to a)
Running mean-field approximations is useful to understand general dynamics in the absence of neighborhood interactions between cells, or simply to obtain an fast but approximate simulation of the model.
Note that this function uses directly the expressions of the probabilities, so any
cellular automaton is supported, regardless of whether or not it can be simulated
exactly by run_camodel
.
Value
This function returns the results of the ode
function, which is a matrix with class 'deSolve'
Examples
if ( requireNamespace("deSolve") ) {
# Get the mean-field approximation to the arid vegetation model
arid <- ca_library("aridvege")
mod <- ca_library("aridvege")
init <- generate_initmat(mod, rep(1, 3)/3, nrow = 100, ncol = 100)
times <- seq(0, 128)
out <- run_meanfield(mod, init, times)
# This uses the default plot method in deSolve
plot(out)
# A different model and way to specifiy initial conditions.
coralmod <- ca_library("coralreef")
init <- c(ALGAE = 0.2, CORAL = 0.5, BARE = 0.3)
times <- 10^seq(0, 4, length.out = 64)
out <- run_meanfield(coralmod, init, times, method = "lsoda")
plot(out, ylim = c(0, 1))
}