Heisenberg
The majority automaton on a ball of the discrete Heisenberg group.
- Class:
HeisenbergAutomatonSystem - Import:
from skcomplex.systems.computer_science.automata import HeisenbergAutomatonSystem - Field:
computer_science/automata - Topics:
group,cellular automaton,majority,nilpotent - References:
- Ceccherini-Silberstein and Coornaert 2023
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 HeisenbergAutomatonSystem
trajectory = HeisenbergAutomatonSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
radius |
5 |
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 HeisenbergAutomatonSystem(BaseSystem):
"""The majority automaton on a ball of the discrete Heisenberg group.
The group has polynomial growth of degree 4. Every cell reads itself and the cells at `a`, `a^-1`, `b`, and `b^-1`,
on the right, and takes the majority value. The system has the cells `cells.alive`.
Args:
radius:
The radius of the ball.
density:
The probability that a cell starts at 1.
random_state:
The seed or generator of the 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 HeisenbergAutomatonSystem
>>> HeisenbergAutomatonSystem(radius=2).prepare().simulate(until=1).get_values('cells.alive').shape
(2, 17)
"""
field = 'computer_science/automata'
topics = ('group', 'cellular automaton', 'majority', 'nilpotent')
references = ('Ceccherini-Silberstein and Coornaert 2023',)
until = 20
dt = 1
observables = (Observable('density', group='cells', variable='alive'),)
def __init__(
self,
*,
radius: int = 5,
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.radius = radius
self.density = density
self.random_state = random_state
def _get_cells(self, space: BaseSpace) -> Array:
"""Return cells that are 1 with the probability `density`, one per site of a prepared space."""
size = space.prepare().size_
return np.asarray(np.random.default_rng(self.random_state).random(size) < self.density, dtype=float)
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of random cells on a ball of the group and their majority rule."""
super()._prepare(context)
space = CayleySpace(heisenberg(), ball=self.radius)
neighborhood = GeneratorNeighborhood(space.prepare().generators_)
self.system_ = System(
self.label,
elements=[BinaryCellElement('cells', alive=self._get_cells(space), space=space)],
interactions=[MajorityRuleInteraction('majority', target='cells', neighborhood=neighborhood)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BinaryCellElement, fromElement
Interactions:
MajorityRuleInteraction, 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 MajorityRuleInteraction(Interaction):
"""Majority rule of binary cells on the sites of a group.
Every cell takes the value held by more than half of itself and its neighbours, and a tie keeps its value. Only the
neighbours inside the space count, so the cells on the boundary of a ball read fewer neighbours.
Args:
label:
The label of the interaction.
target:
The cells whose state `alive` the rule updates.
neighborhood:
The neighbours of every cell, such as the generators of the group and their inverses.
Examples:
>>> from skcomplex.systems.computer_science.automata import GeneratorNeighborhood, MajorityRuleInteraction
>>> rule = MajorityRuleInteraction('majority', target='cells', neighborhood=GeneratorNeighborhood(['a', 'b']))
>>> rule.neighborhood.generators
['a', 'b']
"""
def __init__(self, label: str, *, target: Role = 'cells', neighborhood: BaseNeighborhood = FREE_GENERATORS) -> None:
super().__init__(label)
self.target = target
self.neighborhood = neighborhood
@staticmethod
def _get_majority(center: Array, *values: Array, degree: Array, **kwargs: object) -> Array:
"""Return the value held by more than half of a cell and its neighbours, keeping it on a tie."""
total = center + np.sum(values, axis=0)
count = degree + 1
return np.where(2 * total > count, 1.0, np.where(2 * total < count, 0.0, center))
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the majority of every cell and its neighbours 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_majority, neighborhood=self.neighborhood, label=self.label),
]