General APIs
CellularAutomata.CellularAutomaton — Type
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 0CellularAutomata.next_state — Function
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 toPeriodic().scheme: Update scheme controlling which cells apply the transition. Defaults toSynchronous(); useStochastic(rate)for a per-cell random mask.rng: Random number generator used by stochastic schemes. It must be supplied explicitly withStochasticand its state advances when the mask is drawn. It is not consulted bySynchronous.
Examples
julia> using CellularAutomata
julia> next_state(DCA(30), [0, 0, 1, 0, 0])
5-element Vector{Int64}:
0
1
1
1
0CellularAutomata.rollout — Function
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 toPeriodic().scheme: Update scheme applied at every step. Defaults toSynchronous().rng: Random number generator passed to every step. It must be supplied explicitly withStochastic; the same object is reused and its state advances across steps. It is not consulted bySynchronous.save: Retain the initial state and every subsequent state. Defaults tofalse.
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
1CellularAutomata.AbstractUpdateScheme — Type
AbstractUpdateSchemeSupertype for cellular-automaton update schemes, controlling which cells apply a transition each generation.
CellularAutomata.Synchronous — Type
Synchronous()Apply the transition to every cell each generation. This is the default update scheme and matches classical (non-stochastic) cellular automata.
CellularAutomata.Stochastic — Type
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
0CellularAutomata.cellular_automaton_rule — Function
cellular_automaton_rule(automaton::AbstractCellularAutomaton)Return the transition rule used by automaton.
CellularAutomata.evolution_history — Function
evolution_history(automaton::AbstractCellularAutomaton)Return the retained cellular-automaton evolution.
CellularAutomata.generation_count — Function
generation_count(automaton::AbstractCellularAutomaton) -> IntReturn the number of generations retained by automaton.
CellularAutomata.neighborhood_radius — Function
neighborhood_radius(neighborhood::AbstractNeighborhood)
neighborhood_radius(rule::AbstractCellularAutomatonRule)Return the spatial radius or extent used by neighborhood or rule.
Custom AbstractNeighborhood subtypes must implement this method.
CellularAutomata.rule_lookup_table — Function
rule_lookup_table(rule::AbstractDiscreteCellularAutomatonRule)Return the neighborhood lookup table used by rule.
CellularAutomata.cell_state_count — Function
cell_state_count(rule::AbstractDiscreteCellularAutomatonRule) -> IntReturn the number of possible cell states supported by rule.
CellularAutomata.Periodic — Type
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//10CellularAutomata.Reflecting — Type
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//10CellularAutomata.ConstantBoundary — Type
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//10CellularAutomata.AbstractCellularAutomaton — Type
AbstractCellularAutomatonSupertype for cellular automata that retain an evolution history.
CellularAutomata.AbstractCellularAutomatonRule — Type
AbstractCellularAutomatonRuleSupertype 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.
CellularAutomata.AbstractBoundaryCondition — Type
AbstractBoundaryConditionSupertype for boundary conditions used when neighborhoods cross state-array edges.
CellularAutomata.AbstractDiscreteCellularAutomatonRule — Type
AbstractDiscreteCellularAutomatonRuleSupertype for cellular-automaton rules based on discrete neighborhood lookup tables.
CellularAutomata.AbstractContinuousCellularAutomatonRule — Type
AbstractContinuousCellularAutomatonRuleSupertype for cellular-automaton rules with continuous cell states.
CellularAutomata.AbstractTotalisticCellularAutomatonRule — Type
AbstractTotalisticCellularAutomatonRuleSupertype for rules whose transitions depend on the total neighborhood state.
CellularAutomata.AbstractLifeLikeCellularAutomatonRule — Type
AbstractLifeLikeCellularAutomatonRuleSupertype for Life-like cellular-automaton rules.
CellularAutomata.spatial_dimensions — Function
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))))
2CellularAutomata.lempel_ziv — Function
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