Cascading sample-space-reducing process
Cascading sample-space-reducing processes.
- Class:
CascadingSampleSpaceReducingSystem - Import:
from skcomplex.systems.mathematics.stochastic_processes import CascadingSampleSpaceReducingSystem - Field:
mathematics/stochastic_processes - Topics:
sample space reduction,agents,cascade,power law - References:
- Corominas-Murtra, Hanel, and Thurner 2017
- 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 CascadingSampleSpaceReducingSystem
trajectory = CascadingSampleSpaceReducingSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_cascades |
100 |
n_states |
100 |
mu |
1.5 |
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 CascadingSampleSpaceReducingSystem(BaseSystem):
"""Cascading sample-space-reducing processes.
Their visits follow the power law `i^(-mu)` for any `mu`.
Every cascade starts with one ball at the top state `n_states`. At every step each ball above state 1 jumps to a
state drawn uniformly below its own and becomes `mu` balls there, `floor(mu)` and one more with the probability of
the rest, and a ball at state 1 leaves the cascade. Every ball stays one step, so the states of the balls of all
frames are the visits, distributed as `i^(-mu)` (Thurner et al. 2018, section 3.3.5.4). For `mu < 1` balls are lost
on the way, `1 - mu` being the probability of a removal. With a conservation law that makes the states of the new
balls sum to the state of their parent, the exponent is 2 whatever `mu`, the case of `FragmentationSystem`. The
system has the group `balls` of state `level`.
Args:
n_cascades:
The number of independent cascades, run together.
n_states:
The number of states.
mu:
The multiplication factor, the mean number of balls a ball becomes at every jump.
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 CascadingSampleSpaceReducingSystem
>>> CascadingSampleSpaceReducingSystem(4).prepare().system_.elements[0].size
4
"""
field = 'mathematics/stochastic_processes'
topics = ('sample space reduction', 'agents', 'cascade', 'power law')
references = ('Corominas-Murtra, Hanel, and Thurner 2017', 'Thurner et al. 2018')
until = 100
def __init__(
self,
n_cascades: int = 100,
*,
n_states: int = 100,
mu: float = 1.5,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.n_cascades = n_cascades
self.n_states = n_states
self.mu = mu
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of one ball at the top state per cascade and their jumps."""
super()._prepare(context)
self.system_ = System(
self.label,
elements=[BallElement('balls', level=float(self.n_states), size=self.n_cascades)],
interactions=[CascadeInteraction('cascade', target='balls', mu=self.mu)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BallElement, fromElement
Interactions:
CascadeInteraction, fromInteraction
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 CascadeInteraction(Interaction):
"""Cascade of balls that multiply by `mu` as they jump to lower states.
At every step a ball at state 1 leaves the cascade, and any other ball becomes `floor(mu)` balls, and one more with
the probability of the rest, each at a state drawn uniformly below its own.
Args:
label:
The label of the interaction.
target:
The balls of the cascade.
mu:
The mean number of balls a ball becomes at every jump, the multiplication factor.
Examples:
>>> from skcomplex.systems.mathematics.stochastic_processes import CascadeInteraction
>>> CascadeInteraction('cascade', mu=2.0).mu
2.0
"""
law_classes = (UpdateLaw,)
draws = True
def __init__(self, label: str, *, target: Role = 'balls', mu: float = 1.5) -> None:
super().__init__(label)
self.target = target
self.mu = mu
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:
"""Replace a ball by its offspring at lower states, or remove it at state 1."""
if agent.level > 1:
whole = math.floor(self.mu)
for _ in range(whole + int(system.rng.random() < self.mu - whole)):
agent.create(level=float(system.rng.integers(1, round(agent.level))))
agent.remove()
Equations
The equations are those that symbolic returns for the system with its default parameters.