Skip to content

Random two-branch interval map

Orbits of a random map of [0, 1].

  • Class: RandomBranchMapSystem
  • Import: from skcomplex.systems.mathematics.stochastic_processes import RandomBranchMapSystem
  • Field: mathematics/stochastic_processes
  • Topics: random map, iterated function system, interval map, stationary distribution
  • References:
    • Dilão 2023

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 RandomBranchMapSystem

trajectory = RandomBranchMapSystem().prepare().simulate()

Parameters

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

Parameter Default
n_orbits 200
p1 0.5
mu 1.0
random_state 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 real
Structure fixed

Class

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

class RandomBranchMapSystem(BaseSystem):
    """Orbits of a random map of `[0, 1]`.

    The map has the two branches `(1 + x) / 2` and `mu x²`.

    At every step each orbit applies `(1 + x) / 2` with probability `p1` and `mu x²` otherwise (Dilão 2023, Exercise
    5.10). The first branch pulls towards 1 and the second towards 0, so the orbits settle on a stationary
    distribution whose shape changes with `p1` and `mu`. For `mu = 0` the second branch resets the orbit to 0, and
    the stationary mean is `p1 / (2 - p1)`. For `mu = 1` both branches fix `x = 1`, which attracts the orbits once
    `p1 > 1/2`, since there the first branch halves the distance to 1 and the second doubles it.

    The system has the group `orbits` of state `x`.

    Args:
        n_orbits:
            The number of independent orbits.

        p1:
            The probability of the branch `(1 + x) / 2`.

        mu:
            The coefficient of the branch `mu x²`, between 0 and 1.

        random_state:
            The seed or generator of the initial values, uniform on `[0, 1]`.

        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 RandomBranchMapSystem
        >>> RandomBranchMapSystem(10, p1=0.3).prepare().system_.elements[0].size
        10
    """

    field = 'mathematics/stochastic_processes'
    topics = ('random map', 'iterated function system', 'interval map', 'stationary distribution')
    references = ('Dilão 2023',)
    until = 200
    dt = 1

    def __init__(
        self,
        n_orbits: int = 200,
        *,
        p1: float = 0.5,
        mu: float = 1.0,
        random_state: int | np.random.Generator | None = 0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_orbits = n_orbits
        self.p1 = p1
        self.mu = mu
        self.random_state = random_state

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the orbits and their random map."""
        super()._prepare(context)
        start = np.random.default_rng(self.random_state).uniform(0.0, 1.0, self.n_orbits)
        self.system_ = System(
            self.label,
            elements=[RandomBranchMapElement('orbits', x=start, size=self.n_orbits)],
            interactions=[RandomBranchMapInteraction('map', target='orbits', p1=self.p1, mu=self.mu)],
        )

Components

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

Elements:

  • RandomBranchMapElement, from Element

Interactions:

  • RandomBranchMapInteraction, from Interaction
class RandomBranchMapElement(Element):
    """Values `x` of a random interval map, one per orbit.

    Args:
        label:
            The label of the orbits.

        x:
            The initial value, between 0 and 1, one per orbit or shared.

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

    Examples:
        >>> from skcomplex.systems.mathematics.stochastic_processes import RandomBranchMapElement
        >>> RandomBranchMapElement('map', x=0.3).x
        0.3
    """

    def __init__(
        self,
        label: str,
        *,
        x: Annotated[object, RealSet.closed(0, 1)] = 0.5,
        size: int | None = None,
    ) -> None:
        super().__init__(label, size=size)
        self.x = x

class RandomBranchMapInteraction(Interaction):
    """The random map that applies `(1 + x) / 2` with probability `p1` and `mu x²` otherwise.

    Args:
        label:
            The label of the interaction.

        target:
            The orbits whose values the map moves.

        p1:
            The probability of the branch `(1 + x) / 2`.

        mu:
            The coefficient of the branch `mu x²`, between 0 and 1.

    Examples:
        >>> from skcomplex.systems.mathematics.stochastic_processes import RandomBranchMapInteraction
        >>> RandomBranchMapInteraction('map', target='orbits', p1=0.3).p1
        0.3
    """

    law_classes = (UpdateLaw,)

    draws = True

    def __init__(self, label: str, *, target: Role = 'orbits', p1: float = 0.5, mu: float = 1.0) -> None:
        super().__init__(label)
        self.target = target
        self.p1 = p1
        self.mu = mu

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the update of the value by the branch drawn in the step as the law.

        Args:
            context:
                The namespace of the elements a binding of the roles names.
        """
        super()._prepare(context)
        x = context.target.x
        first = bernoulli('branch', context.p1)
        self.laws_: list[BaseLaw] = [UpdateLaw(x, first * (1 + x) / 2 + (1 - first) * context.mu * x**2)]

Equations

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

orbits.x[i]: x_orbits(t + 1) == -mu_map*(where(bernoulli_branch_map < p1_map, 1, 0) - 1)*x_orbits(t)^2 + 1/2*(x_orbits(t) + 1)*where(bernoulli_branch_map < p1_map, 1, 0)