| update.ca_model {chouca} | R Documentation | 
Update a cellular automaton
Description
Update the definition of a stochastic cellular automaton (SCA), using new parameters, type of wrapping, or any other parameters entering in the definition of the model.
Usage
## S3 method for class 'ca_model'
update(
  object,
  parms = NULL,
  neighbors = NULL,
  wrap = NULL,
  fixed_neighborhood = NULL,
  check_model = "quick",
  verbose = FALSE,
  ...
)
Arguments
| object | The SCA object (returned by  | 
| parms | a named list of parameters, which should be all numeric, single values. If this list contains only a subset of model parameters, the old parameter values will be reused for those not provided. | 
| neighbors | The number of neighbors to use in the cellular automaton ('4' for 4-way or von-Neumann neghborhood, or '8' for an 8-way or Moore neighborhood) | 
| wrap | If  | 
| fixed_neighborhood | When not using wrapping around the edges ( | 
| check_model | A check of the model definition is done to make sure there are no issues with it (e.g. probabilities outside the [1,0] interval, or an unsupported model definition). A quick check that should catch most problems is performed if check_model is "quick", an extensive check that tests all neighborhood configurations is done with "full", and no check is performed with "none". | 
| verbose | whether information should be printed when parsing the model definition. | 
| ... | extra arguments are ignored | 
Details
This function updates some aspects of a pre-defined stochastic celullar automaton, such as parameter values, the type of neighborhood, whether to wrap around the edge of space, etc. It is handy when running multiple simulations, and only a few aspects of the model needs to be changed, such as parameter values. Note that this function cannot add or remove states to a model.
Note that the parms list may only specify a subset of the model parameters
to update. In this case, old parameter values not specified in the call to
update will be re-used.
Value
This function returns a list with class ca_model with the changes applied to 
the original model (see camodel for details about this type of
object).
See Also
camodel, run_camodel...
Examples
# Update the parameters of a model
mussels <- ca_library("musselbed")
mussels[["parms"]] # old parameters
mussels_new <- update(mussels, parms = list(d = 0.2, delta = 0.1, r = 0.8))
mussels_new[["parms"]] # updated parameters
# Update the type of neighborhood, wrapping around the edges, and
# the parameters
mussels_new <- update(mussels,
                      parms = list(d = 0.2, delta = 0.1, r = 0.8),
                      wrap = TRUE,
                      neighbors = 8)
mussels_new
# Run the model for different values of d, the death rate of mussels
ds <- seq(0, 0.25, length.out = 12)
initmat <- generate_initmat(mussels, c(0.5, 0.5, 0), nrow = 64, ncol = 64)
results <- lapply(ds, function(this_dvalue) {
  musselmod <- update(mussels, parms = list(d = this_dvalue))
  run <- run_camodel(musselmod, initmat, times = seq(0, 128))
  data.frame(d = this_dvalue,
             as.data.frame(tail(run[["output"]][["covers"]], 1)))
})
results <- do.call(rbind, results)
plot(results[ ,"d"], results[ ,"MUSSEL"], type = "b",
     xlab = "d", ylab = "Mussel cover")