Skip to content

Sample-space-reducing process

Sample-space-reducing processes.

  • Class: SampleSpaceReducingSystem
  • Import: from skcomplex.systems.mathematics.stochastic_processes import SampleSpaceReducingSystem
  • Field: mathematics/stochastic_processes
  • Topics: sample space reduction, agents, zipf, power law
  • References:
    • Corominas-Murtra, Hanel, and Thurner 2015
    • 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 SampleSpaceReducingSystem

trajectory = SampleSpaceReducingSystem().prepare().simulate()

Parameters

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

Parameter Default
n_balls 20
n_states 10
lam 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 SampleSpaceReducingSystem(BaseSystem):
    """Sample-space-reducing processes.

    Their state visits follow Zipf's law `1 / i` for `lam = 1`.

    The system has the group `balls` of state `level`.

    Args:
        n_balls:
            The number of independent balls, all started at the top state.

        n_states:
            The number of states.

        lam:
            The probability of a reducing jump, the exponent of the visiting distribution.

        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 SampleSpaceReducingSystem
        >>> SampleSpaceReducingSystem(4).prepare().system_.elements[0].size
        4
    """

    field = 'mathematics/stochastic_processes'
    topics = ('sample space reduction', 'agents', 'zipf', 'power law')
    references = ('Corominas-Murtra, Hanel, and Thurner 2015', 'Thurner et al. 2018')
    until = 100

    def __init__(
        self,
        n_balls: int = 20,
        *,
        n_states: int = 10,
        lam: float = 1.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_balls = n_balls
        self.n_states = n_states
        self.lam = lam

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the balls at the top state and their jumps."""
        super()._prepare(context)
        jump = ReducingJumpInteraction('jump', target='balls', n_states=self.n_states, lam=self.lam)
        self.system_ = System(
            self.label,
            elements=[BallElement('balls', level=float(self.n_states), size=self.n_balls)],
            interactions=[jump],
        )

Components

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

Elements:

Interactions:

  • ReducingJumpInteraction, from Interaction
class BallElement(Element):
    """Balls of a sample-space-reducing process, each at its state `level`.

    Args:
        label:
            The label of the balls.

        level:
            The initial state, one per ball or shared.

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

    Examples:
        >>> from skcomplex.systems.mathematics.stochastic_processes import BallElement
        >>> BallElement('balls', level=10.0, size=3).level
        10.0
    """

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

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

class ReducingJumpInteraction(Interaction):
    """Jump of a ball of the sample-space-reducing process to a lower state, to any state, or back to the top state.

    A ball at state 1 restarts from the top state `n_states`. Otherwise it jumps with probability `lam` uniformly to a
    state below its own, and else uniformly to any state, so the states are visited with probabilities proportional to
    `i^(-lam)`.

    Args:
        label:
            The label of the interaction.

        target:
            The balls that jump.

        n_states:
            The number of states.

        lam:
            The probability of a reducing jump.

    Examples:
        >>> from skcomplex.systems.mathematics.stochastic_processes import ReducingJumpInteraction
        >>> ReducingJumpInteraction('jump', n_states=20).n_states
        20
    """

    law_classes = (UpdateLaw,)
    draws = True

    def __init__(self, label: str, *, target: Role = 'balls', n_states: int = 10, lam: float = 1.0) -> None:
        super().__init__(label)
        self.target = target
        self.n_states = n_states
        self.lam = lam

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the jump of every ball 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._jump)]

    def _jump(self, agent: BallView, system: SystemView) -> None:
        """Move a ball to its next state."""
        top = round(self.n_states)
        if agent.level <= 1:
            agent.level = float(top)
        elif system.rng.random() < self.lam:
            agent.level = float(system.rng.integers(1, round(agent.level)))
        else:
            agent.level = float(system.rng.integers(1, top + 1))

Equations

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