General APIs

CellularAutomata.CellularAutomatonType
CellularAutomaton(rule, initial_conditions, generations)

Construct a cellular automaton and retain its complete evolution history. For vector states, evolution_history(automaton) stores time on the first axis. For higher-dimensional states, time is stored on the last axis.

Arguments

  • rule: Cellular-automaton rule defining one transition.
  • initial_conditions: Initial state array.
  • generations: Number of retained generations, including the initial state.

Examples

julia> using CellularAutomata

julia> automaton = CellularAutomaton(DCA(30), [0, 1, 0], 3)
CellularAutomaton with 3 generations
  rule: DCA(30; states=2, radius=1)
  evolution: 3×3 Matrix{Int64}

julia> evolution_history(automaton)
3×3 Matrix{Int64}:
 0  1  0
 1  1  1
 0  0  0
source
CellularAutomata.next_stateFunction
next_state(rule, state; boundary=Periodic(), scheme=Synchronous(), rng=nothing)

Apply one cellular-automaton transition without mutating state. Rule subtypes define their transition by implementing CellularAutomata.__step(rule, state, boundary); this wrapper then applies the selected update scheme.

Arguments

  • rule: Cellular-automaton transition rule.
  • state: Current state array.

Keyword arguments

  • boundary: Boundary condition used outside the state array. Defaults to Periodic().
  • scheme: Update scheme controlling which cells apply the transition. Defaults to Synchronous(); use Stochastic(rate) for a per-cell random mask.
  • rng: Random number generator used by stochastic schemes. It must be supplied explicitly with Stochastic and its state advances when the mask is drawn. It is not consulted by Synchronous.

Examples

julia> using CellularAutomata

julia> next_state(DCA(30), [0, 0, 1, 0, 0])
5-element Vector{Int64}:
 0
 1
 1
 1
 0
source
CellularAutomata.rolloutFunction
rollout(rule, initial_state, steps; boundary=Periodic(), scheme=Synchronous(),
    rng=nothing, save=false)

Apply steps transitions of rule to initial_state. By default only the final state is returned, which is the preferred path inside a loss function. With save=true, return the initial state and every subsequent state stacked with time on the last axis.

Arguments

  • rule: Cellular-automaton transition rule.
  • initial_state: State from which to begin the rollout.
  • steps: Number of transitions to apply.

Keyword arguments

  • boundary: Boundary condition used by each transition. Defaults to Periodic().
  • scheme: Update scheme applied at every step. Defaults to Synchronous().
  • rng: Random number generator passed to every step. It must be supplied explicitly with Stochastic; the same object is reused and its state advances across steps. It is not consulted by Synchronous.
  • save: Retain the initial state and every subsequent state. Defaults to false.

Examples

julia> using CellularAutomata

julia> history = rollout(DCA(30), [0, 0, 1, 0, 0], 2; save=true);

julia> size(history)
(5, 3)

julia> history[:, end]
5-element Vector{Int64}:
 1
 1
 0
 0
 1
source
CellularAutomata.SynchronousType
Synchronous()

Apply the transition to every cell each generation. This is the default update scheme and matches classical (non-stochastic) cellular automata.

source
CellularAutomata.StochasticType
Stochastic(rate)

Apply the transition to each cell independently with probability rate; cells that are not selected keep their previous value. An explicit rng must be passed to next_state or rollout. Drawing the per-cell mask advances the state of that random number generator.

Examples

julia> using CellularAutomata, Random

julia> next_state(DCA(30), [0, 0, 1, 0, 0]; scheme=Stochastic(0.5), rng=Xoshiro(1))
5-element Vector{Int64}:
 0
 1
 1
 0
 0
source
CellularAutomata.PeriodicType
Periodic()

Wrap indices around the opposite edge of the state array.

Examples

julia> using CellularAutomata

julia> next_state(CCA(0 // 1), [0 // 1, 0 // 1, 3 // 10]; boundary=Periodic())
3-element Vector{Rational{Int64}}:
 1//10
 1//10
 1//10
source
CellularAutomata.ReflectingType
Reflecting()

Mirror indices at the edge of the state array.

Examples

julia> using CellularAutomata

julia> next_state(CCA(0 // 1), [0 // 1, 0 // 1, 3 // 10]; boundary=Reflecting())
3-element Vector{Rational{Int64}}:
  0
 1//10
 1//10
source
CellularAutomata.ConstantBoundaryType
ConstantBoundary([value = 0])

Use value for indices outside the state array.

Examples

julia> using CellularAutomata

julia> next_state(CCA(0 // 1), [0 // 1, 0 // 1, 3 // 10]; boundary=ConstantBoundary())
3-element Vector{Rational{Int64}}:
  0
 1//10
 1//10
source
CellularAutomata.AbstractCellularAutomatonRuleType
AbstractCellularAutomatonRule

Supertype for cellular-automaton transition rules. Subtypes must implement CellularAutomata.__step(rule, state, boundary) returning the proposed next state without mutating state. next_state applies validation and the selected update scheme around that transition.

source
CellularAutomata.spatial_dimensionsFunction
spatial_dimensions(rule)

Return the number of spatial dimensions used by a cellular-automaton rule. State arrays may have additional channel or batch dimensions.

Examples

julia> using CellularAutomata

julia> spatial_dimensions(DCA(30))
1

julia> spatial_dimensions(Life(((3,), (2, 3))))
2
source
CellularAutomata.lempel_zivFunction
lempel_ziv(ca::AbstractCellularAutomaton)

Compute the mean Lempel-Ziv complexity across rows of an automaton's retained evolution.

Examples

julia> using CellularAutomata

julia> automaton = CellularAutomaton(DCA(30), [0, 1, 0], 3);

julia> lempel_ziv(automaton)
1.3333333333333333
source