Skip to content

Fragmentation

The random fragmentation of an object of integer size.

  • Class: FragmentationSystem
  • Import: from skcomplex.systems.mathematics.stochastic_processes import FragmentationSystem
  • Field: mathematics/stochastic_processes
  • Topics: fragmentation, agents, sample space reduction
  • References:
    • 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 FragmentationSystem

trajectory = FragmentationSystem().prepare().simulate()

Parameters

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

Parameter Default
size 1000
rate 0.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 real
Structure variable membership

Class

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

class FragmentationSystem(BaseSystem):
    """The random fragmentation of an object of integer size.

    The fragments keep breaking into smaller ones.

    The total size is conserved, and every fragment ends at size 1. The system has the group `fragments` of state
    `length`.

    Args:
        size:
            The size of the initial object.

        rate:
            The probability that a fragment larger than 1 breaks in a step.

        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 FragmentationSystem
        >>> FragmentationSystem(50).prepare().system_.elements[0].size
        1
    """

    field = 'mathematics/stochastic_processes'
    topics = ('fragmentation', 'agents', 'sample space reduction')
    references = ('Thurner et al. 2018',)
    until = 30

    def __init__(
        self,
        size: int = 1000,
        *,
        rate: float = 0.5,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.size = size
        self.rate = rate

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the initial object and its breaking."""
        super()._prepare(context)
        self.system_ = System(
            self.label,
            elements=[FragmentElement('fragments', length=float(self.size), size=1)],
            interactions=[BreakingInteraction('breaking', target='fragments', rate=self.rate)],
        )

Components

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

Elements:

Interactions:

  • BreakingInteraction, from Interaction
class FragmentElement(Element):
    """Fragments of integer sizes, each with its size `length`.

    Args:
        label:
            The label of the fragments.

        length:
            The initial size, one per fragment or shared.

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

    Examples:
        >>> from skcomplex.systems.mathematics.stochastic_processes import FragmentElement
        >>> FragmentElement('fragments', length=100.0).length
        100.0
    """

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

    def __init__(
        self,
        label: str,
        *,
        length: Annotated[object, RealSet.open(0, oo)] = 1000.0,
        size: int | None = None,
    ) -> None:
        super().__init__(label, size=size)
        self.length = length

class BreakingInteraction(Interaction):
    """Breaking of every fragment larger than 1 with the probability `rate` at a uniformly random whole point.

    The fragment keeps the size left of the cut, and a new fragment takes the rest, so the total size stays the same.

    Args:
        label:
            The label of the interaction.

        target:
            The fragments that break.

        rate:
            The probability that a fragment larger than 1 breaks in a step.

    Examples:
        >>> from skcomplex.systems.mathematics.stochastic_processes import BreakingInteraction
        >>> BreakingInteraction('breaking', rate=0.2).rate
        0.2
    """

    law_classes = (UpdateLaw,)
    draws = True

    def __init__(self, label: str, *, target: Role = 'fragments', rate: float = 0.5) -> None:
        super().__init__(label)
        self.target = target
        self.rate = rate

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

    def _split(self, agent: FragmentView, system: SystemView) -> None:
        """Cut a fragment in two with the probability `rate`, unless it has size 1."""
        length = round(agent.length)
        if length > 1 and system.rng.random() < self.rate:
            kept = int(system.rng.integers(1, length))
            agent.length = float(kept)
            agent.create(length=float(length - kept))

Equations

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