CA: Stochastic Cellular Automaton

Description Usage Format Details See Also Examples

Description

simecol example: This model simulates a stochastic cellular automaton.

Usage

1

Format

An S4 object according to the gridModel specification. The object contains the following slots:

main

functions with the state transition rules of Coway's Game of Life.

parms

a list with two vector elements:

pbirth

probability of birth,

pdeath

death probability, dependend on neighbors.

times

number of time steps to be simulated.

init

a matrix, giving the initial state of the cellular grid (default: rectangle in the middle of the grid).

Details

To see all details, please have a look into the implementation below.

See Also

sim, parms, init, times.

Examples

 1
 2
 3
 4
 5
 6
 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
##============================================
## Basic Usage:
##   work with the example
##============================================
data(CA)
times(CA)["to"] <- 10
plot(sim(CA))

set.seed(345)
times(CA)["to"] <- 50
CA <- sim(CA)

library(lattice)
tcol <- (terrain.colors(13))[-13]
x <- out(CA, last=TRUE)
x <- ifelse(x == 0, NA, x)
levelplot(x,
  cuts = 11,
  col.regions = tcol,
  colorkey = list(at = seq(0, 55, 5))
)

##============================================
## Implementation:
##   The code of the CA model
##============================================
CA <- new("gridModel",
  main = function(time, init, parms) {
    z     <- init
    nb    <- eightneighbors(z)
    pgen  <- 1 - (1 - parms$pbirth)^nb
    zgen  <- ifelse(z == 0 &
               runif(z) < pgen, 1, 0)
    zsurv <- ifelse(z >= 1 &
               runif(z) < (1 - parms$pdeath),
               z + 1, 0)
    zgen + zsurv
  },
  parms = list(pbirth = 0.02, pdeath = 0.01),
  times = c(from = 1, to = 50, by = 1),
  init = matrix(0, nrow = 40, ncol = 40),
  solver = "iteration"
)
init(CA)[18:22,18:22] <- 1
##============================================

Example output

Loading required package: deSolve

simecol documentation built on Oct. 7, 2021, 9:20 a.m.