Skip to content

Ageing random walk

Ageing random walks.

  • Class: AgeingRandomWalkSystem
  • Import: from skcomplex.systems.mathematics.stochastic_processes import AgeingRandomWalkSystem
  • Field: mathematics/stochastic_processes
  • Topics: random walk, agents, history dependence, ageing
  • References:
    • Hanel, Thurner, and Gell-Mann 2014
    • Thurner et al. 2018

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.mathematics.stochastic_processes import AgeingRandomWalkSystem

trajectory = AgeingRandomWalkSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
n_walkers 50
p 0.5
nu 1.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 none
Laws update
Randomness stochastic
Domains integer
Structure variable membership

Class

The source of the class shows how it builds its components from its model parameters.

class AgeingRandomWalkSystem(BaseSystem):
    """Ageing random walks.

    The up steps become rarer the more of them a walker has taken.

    After `k` up steps a walker steps up with probability `p / (1 + k)^nu`, so the walk is history dependent and, for
    `nu > 0`, its number of up steps grows as `n^(1 / (1 + nu))` after `n` steps. The system has the group `walkers`.

    Args:
        n_walkers:
            The number of independent walkers, all started at 0.

        p:
            The probability of the first up step.

        nu:
            The exponent of the decay of the up probability.

        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.mathematics.stochastic_processes import AgeingRandomWalkSystem
        >>> AgeingRandomWalkSystem(5).prepare().system_.elements[0].size
        5
    """

    field = 'mathematics/stochastic_processes'
    topics = ('random walk', 'agents', 'history dependence', 'ageing')
    references = ('Hanel, Thurner, and Gell-Mann 2014', 'Thurner et al. 2018')
    until = 100

    def __init__(
        self,
        n_walkers: int = 50,
        *,
        p: float = 0.5,
        nu: float = 1.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_walkers = n_walkers
        self.p = p
        self.nu = nu

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the walkers and the rule of their steps."""
        super()._prepare(context)
        step = AgeingStepInteraction('step', target='walkers', p=self.p, nu=self.nu)
        walkers = AgeingWalkerElement('walkers', size=self.n_walkers)
        self.system_ = System(self.label, elements=[walkers], interactions=[step])

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • AgeingWalkerElement, from Element

Interactions:

  • AgeingStepInteraction, from Interaction
class AgeingWalkerElement(Element):
    """Walkers on the integers, each with its position `x` and its number `ups` of up steps.

    Args:
        label:
            The label of the walkers.

        x:
            The initial position, one per walker or shared.

        ups:
            The initial number of up steps, one per walker or shared.

        size:
            The number of walkers, or `None` for one.

    Examples:
        >>> from skcomplex.systems.mathematics.stochastic_processes import AgeingWalkerElement
        >>> AgeingWalkerElement('walkers', ups=3.0, size=10).ups
        3.0
    """

    visual = VisualSpec('agents', {'color_by': 'x'})

    def __init__(
        self,
        label: str,
        *,
        x: Annotated[object, ZZ] = 0.0,
        ups: Annotated[object, NN] = 0.0,
        size: int | None = None,
    ) -> None:
        super().__init__(label, size=size)
        self.x = x
        self.ups = ups

class AgeingStepInteraction(Interaction):
    """Step of an ageing walker, up with the probability `p / (1 + k)^nu` after `k` up steps and down otherwise.

    Every walker runs the rule once per step.

    Args:
        label:
            The label of the interaction.

        target:
            The walkers whose positions `x` and numbers `ups` of up steps the rule sets.

        p:
            The probability of the first up step.

        nu:
            The exponent of the decay of the up probability with the number of up steps.

    Examples:
        >>> from skcomplex.systems.mathematics.stochastic_processes import AgeingStepInteraction
        >>> AgeingStepInteraction('step', nu=0.5).nu
        0.5
    """

    law_classes = (UpdateLaw,)
    draws = True

    def __init__(self, label: str, *, target: Role = 'walkers', p: float = 0.5, nu: float = 1.0) -> None:
        super().__init__(label)
        self.target = target
        self.p = p
        self.nu = nu

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the step of every walker as the rule.

        Args:
            context:
                The namespace of the elements a binding of the roles names.
        """
        super()._prepare(context)
        self.laws_: list[BaseLaw] = [UpdateLaw(context.target, self._step)]

    def _step(self, agent: AgeingWalkerView, system: SystemView) -> None:
        """Step one walker up or down, counting its up steps."""
        up = float(system.rng.random() < self.p / (1 + agent.ups) ** self.nu)
        agent.ups += up
        agent.x += 2 * up - 1

Equations

The equations are those that symbolic returns for the system with its default parameters.