nb_kernel | R Documentation |
This function builds standard neighborhood kernels for use in a cellular automaton
nb_kernel(type, distance)
type |
The type of neighborhood kernel, either "von_neumann", "moore", or "circular" |
distance |
The distance (sometimes called "order") that the neighborhood should span. A value of 1 for example will only consider neighbors directly adjacent to a focal cell, and a value of 3 will consider neighbors that are up to three cells away from a focal cell. |
A key concept in a stochastic cellular automaton is the neighborhood, which defines
which cells are used to compute q_i
, the proportion of cells around a focal
cell in state i
.
Typical neighborhoods include the Moore and Von Neumann neighborhoods of order 1,
which means that q
will be computed using the 8 cells all around a focal cell,
or only its 4 nearest neighbors, respectively. These types of neighborhoods can be
extended to larger distances, i.e. considering neighbors that are not only adjacent
to a cell, but at a given integer distance distance
. See Examples section to
visualize different types of neighborhoods.
# Classic moore and von_neumann neighborhoods
print( nb_kernel("moore", 1) )
print( nb_kernel("von_neumann", 1) )
# Moore kernel of order 2
ker <- nb_kernel("moore", 2)
image(ker)
# Different kernel types and distances
opar <- par(no.readonly = TRUE)
par(mfcol = c(3, 5))
lapply(c(1, 3, 6, 9, 12), function(distance) {
image( nb_kernel("von_neumann", distance) )
title(sprintf("Von Neumann kernel, distance %s", distance))
image( nb_kernel("moore", distance) )
title(sprintf("Moore kernel, distance %s", distance))
image( nb_kernel("circular", distance) )
title(sprintf("Circular kernel, distance %s", distance))
})
par(opar)
# Circular kernel with a given distance
opar <- par(no.readonly = TRUE)
par(mfrow = c(3, 3))
lapply(seq(1, 9*2, by = 2), function(distance) {
image( nb_kernel("circular", distance) )
title(sprintf("Circular kernel, distance %s", distance))
})
par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.