Subshifts
A Markov chain on the golden mean shift.
- Class:
SubshiftsSystem - Import:
from skcomplex.systems.computer_science.automata import SubshiftsSystem - Field:
computer_science/automata - Topics:
group,subshift,golden mean,Markov chain - References:
- Ceccherini-Silberstein and Coornaert 2023
- Lind and Marcus 1995
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 SubshiftsSystem
trajectory = SubshiftsSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
size |
200 |
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 SubshiftsSystem(BaseSystem):
"""A Markov chain on the golden mean shift.
The shift holds the configurations of a ring that never hold two adjacent ones.
The ring is the cyclic group of order `size`, a periodic lattice. It starts empty, and every step proposes to flip
every cell in a random order, rejecting the flips that would put two ones side by side. The chain samples the
admissible configurations, whose number grows as the power of the golden ratio. The system has the cells
`cells.alive`.
Args:
size:
The number of cells of the ring, the order of the cyclic group.
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 SubshiftsSystem
>>> SubshiftsSystem(10).prepare().simulate(until=1).get_values('cells.alive').shape
(2, 10)
"""
field = 'computer_science/automata'
topics = ('group', 'subshift', 'golden mean', 'Markov chain')
references = ('Ceccherini-Silberstein and Coornaert 2023', 'Lind and Marcus 1995')
until = 50
dt = 1
observables = (Observable('density', group='cells', variable='alive'),)
def __init__(
self,
size: int = 200,
*,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.size = size
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of an empty ring of the golden mean shift and its random flips."""
super()._prepare(context)
self.system_ = System(
self.label,
elements=[GoldenCellElement('cells', space=LatticeSpace(self.size))],
interactions=[GoldenMeanMoveInteraction('flips', target='cells')],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
GoldenCellElement, fromElement
Interactions:
GoldenMeanMoveInteraction, fromInteraction
class GoldenCellElement(Element):
"""Cell of the golden mean shift, whose state `alive` is 0 or 1.
Its configurations hold no two adjacent ones. 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 GoldenCellElement
>>> GoldenCellElement('cell', alive=1).alive
1
"""
def __init__(
self,
label: str,
*,
alive: Annotated[float | Array, GOLDEN_MEAN] = 0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.alive = alive
class GoldenMeanMoveInteraction(Interaction):
"""Random flips of binary cells that never put two ones side by side.
Every step proposes to flip every cell, in a random order, with probability one half, and rejects the flips that
would put a one next to another one.
Args:
label:
The label of the interaction.
target:
The cells whose state `alive` the flips change.
Examples:
>>> from skcomplex.systems.computer_science.automata import GoldenMeanMoveInteraction
>>> GoldenMeanMoveInteraction('flips', target='cells').target
'cells'
"""
def __init__(self, label: str, *, target: Role = 'cells') -> None:
super().__init__(label)
self.target = target
@staticmethod
def _get_move(left: Array, center: Array, right: Array, *, random: Array, **kwargs: object) -> Array:
"""Return the cell flipped with probability one half, unless a 1 would sit next to another 1."""
flipped = np.where(random < FLIP_PROBABILITY, 1.0 - center, center)
blocked = (flipped == 1) & ((left == 1) | (right == 1))
return np.where(blocked, center, flipped)
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the flips, one cell after the other, 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_move,
neighborhood=THREE_CELLS,
schedule='random-sequential',
label=self.label,
stochastic=True,
),
]