Noisy automata
An elementary cellular automaton whose outputs are flipped at random.
- Class:
NoisyAutomataSystem - Import:
from skcomplex.systems.computer_science.automata import NoisyAutomataSystem - Field:
computer_science/automata - Topics:
lattice,elementary,noise,stochastic - References:
- Lindgren 2024
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.computer_science.automata import NoisyAutomataSystem
trajectory = NoisyAutomataSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
rule |
18 |
noise |
0.01 |
size |
101 |
density |
0.5 |
random_state |
0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | discrete |
| Space | lattice |
| Laws | update |
| Randomness | unknown |
| Domains | boolean |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class NoisyAutomataSystem(BaseSystem):
"""An elementary cellular automaton whose outputs are flipped at random.
The outputs are flipped with a small probability. The system has the cells `cells.alive`.
Args:
rule:
The Wolfram number from 0 to 255.
noise:
The probability that a cell's output is flipped in a step.
size:
The number of cells of the ring.
density:
The probability that a cell starts alive.
random_state:
The seed or generator of the random initial cells.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.computer_science.automata import NoisyAutomataSystem
>>> NoisyAutomataSystem(184, size=11).prepare().simulate(until=3).get_values('cells.alive').shape
(4, 11)
"""
field = 'computer_science/automata'
topics = ('lattice', 'elementary', 'noise', 'stochastic')
references = ('Lindgren 2024',)
until = 100
dt = 1
def __init__(
self,
rule: int = 18,
*,
noise: float = 0.01,
size: int = 101,
density: float = 0.5,
random_state: int | np.random.Generator | None = 0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.rule = rule
self.noise = noise
self.size = size
self.density = density
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a ring of random cells and their noisy rule."""
super()._prepare(context)
values = (np.random.default_rng(self.random_state).random(self.size) < self.density).astype(float)
self.system_ = System(
self.label,
elements=[BinaryCellElement('cells', alive=values, space=LatticeSpace(self.size))],
interactions=[NoisyRuleInteraction('rule', target='cells', rule=self.rule, noise=self.noise)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BinaryCellElement, fromElement
Interactions:
NoisyRuleInteraction, fromInteraction
class BinaryCellElement(Element):
"""Cell of an automaton whose value `alive` is 0 or 1.
The local rule of an interaction changes the value. With `space`, the element holds one cell on every site.
Args:
label:
The label of the cells.
alive:
The initial value, 0 or 1, or one value per cell.
space:
The space with one cell on every site, such as a lattice, or `None` for one cell.
Examples:
>>> from skcomplex.systems.computer_science.automata import BinaryCellElement
>>> BinaryCellElement('cell', alive=1).alive
1
"""
def __init__(
self,
label: str,
*,
alive: Annotated[float | Array, {0, 1}] = 0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.alive = alive
class NoisyRuleInteraction(Interaction):
"""Elementary rule of a line of cells whose outputs are flipped at random.
Every cell takes the output of the elementary rule of its Wolfram number, and a uniform draw below `noise` flips
it. Without noise it is the elementary automaton, and at noise 1/2 every cell is a fair coin.
Args:
label:
The label of the interaction.
target:
The cells whose state `alive` the rule updates.
rule:
The Wolfram number from 0 to 255.
noise:
The probability that the output of a cell is flipped in a step.
Examples:
>>> from skcomplex.systems.computer_science.automata import NoisyRuleInteraction
>>> NoisyRuleInteraction('rule', target='cells', noise=0.1).noise
0.1
"""
def __init__(self, label: str, *, target: Role = 'cells', rule: int = 18, noise: float = 0.01) -> None:
super().__init__(label)
self.target = target
self.rule = rule
self.noise = noise
def _get_function(self) -> Callable[..., Array]:
"""Return the elementary rule whose output a uniform draw below the noise flips."""
mapping = Wolfram(self.rule).get_table().mapping
outputs = np.array(
[mapping[(left, center, right)] for left, center, right in itertools.product((0, 1), repeat=3)],
)
noise = self.noise
def noisy(left: Array, center: Array, right: Array, *, random: Array, **kwargs: object) -> Array:
output = outputs[(4 * left + 2 * center + right).astype(int)]
return np.where(random < noise, 1 - output, output).astype(float)
return noisy
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the noisy local rule of the cells as the law.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
alive = context.target.alive
self.laws_: list[BaseLaw] = [
UpdateLaw(alive, self._get_function(), neighborhood=ELEMENTARY, label=self.label, stochastic=True),
]