Skip to content

Continuous-time random walk

The continuous-time random walk.

  • Class: ContinuousTimeRandomWalkSystem
  • Import: from skcomplex.systems.physics.soft_matter import ContinuousTimeRandomWalkSystem
  • Field: physics/soft_matter
  • Topics: anomalous diffusion, renewal process, subdiffusion, random walk
  • References:
    • Argun et al. 2021
    • Metzler and Klafter 2000
    • Montroll and Weiss 1965
    • Bertin 2021

Use this system

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

from skcomplex.systems.physics.soft_matter import ContinuousTimeRandomWalkSystem

trajectory = ContinuousTimeRandomWalkSystem().prepare().simulate()

Parameters

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

Parameter Default
n_walkers 500
alpha 0.5
tau0 1.0
sigma 1.0
n_dim 2
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time continuous
Space continuous
Laws jump
Randomness stochastic
Domains vector
Structure fixed

Class

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

class ContinuousTimeRandomWalkSystem(BaseSystem):
    """The continuous-time random walk.

    Gaussian jumps follow waiting times with the tail `tau^(-1 - alpha)`.

    For `alpha < 1` the waiting times have no mean, so the number of jumps grows as `t^alpha` and the ensemble mean
    squared displacement grows as `t^alpha`, slower than Brownian motion. The walkers renew on their own clocks. The
    system has the positions `walkers.x` and the jump count `jumps.renewals`.

    Args:
        n_walkers:
            The number of independent walkers.

        alpha:
            The tail exponent of the waiting times.

        tau0:
            The shortest waiting time.

        sigma:
            The standard deviation of the jumps along every axis.

        n_dim:
            The number of dimensions.

        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.physics.soft_matter import ContinuousTimeRandomWalkSystem
        >>> ContinuousTimeRandomWalkSystem(10, alpha=0.7).prepare().system_.interactions[0].alpha
        0.7
    """

    field = 'physics/soft_matter'
    topics = ('anomalous diffusion', 'renewal process', 'subdiffusion', 'random walk')
    references = ('Argun et al. 2021', 'Metzler and Klafter 2000', 'Montroll and Weiss 1965', 'Bertin 2021')
    until = 1000.0
    dt = 5.0

    def __init__(
        self,
        n_walkers: int = 500,
        *,
        alpha: float = 0.5,
        tau0: float = 1.0,
        sigma: float = 1.0,
        n_dim: int = 2,
        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.alpha = alpha
        self.tau0 = tau0
        self.sigma = sigma
        self.n_dim = n_dim

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of walkers that wait power-law times and jump by Gaussian steps.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        walkers = ContinuousTimeWalkerElement('walkers', x=np.zeros((self.n_walkers, self.n_dim)), size=self.n_walkers)
        jumps = WaitingJumpInteraction('jumps', target='walkers', alpha=self.alpha, tau0=self.tau0, sigma=self.sigma)
        self.system_ = System(
            self.label,
            elements=[walkers],
            interactions=[jumps],
            space=ContinuousSpace(n_dim=self.n_dim),
        )

Components

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

Elements:

  • ContinuousTimeWalkerElement, from Element

Interactions:

  • WaitingJumpInteraction, from Interaction
class ContinuousTimeWalkerElement(Element):
    """Walkers at the positions `x` that wait and jump.

    Args:
        label:
            The label of the walkers.

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

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

    Examples:
        >>> from skcomplex.systems.physics.soft_matter import ContinuousTimeWalkerElement
        >>> ContinuousTimeWalkerElement('walkers', x=(1.0, 0.0), size=10).x
        (1.0, 0.0)
    """

    def __init__(self, label: str, *, x: object = (0.0, 0.0), size: int | None = None) -> None:
        super().__init__(label, size=size)
        self.x = x

class WaitingJumpInteraction(Interaction):
    """Jumps by Gaussian steps after power-law waiting times.

    The waiting time is `tau0 r^(-1 / alpha)` for `r` uniform, and every jump adds a normal step of standard deviation
    `sigma` to every coordinate of the position `x`. It is a tracer trapped in a porous rock, a charge carrier in an
    amorphous semiconductor, or a molecule in a crowded cell.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the walkers.

        alpha:
            The tail exponent of the waiting times, below 1 for waiting times without a mean.

        tau0:
            The shortest waiting time.

        sigma:
            The standard deviation of the jumps along every axis.

    Examples:
        >>> from skcomplex.systems.physics.soft_matter import WaitingJumpInteraction
        >>> WaitingJumpInteraction('jumps', target='walkers', alpha=0.7).alpha
        0.7
    """

    law_classes = (JumpLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        alpha: Annotated[float, RealSet.open(0, oo)] = 0.5,
        tau0: Annotated[float, RealSet.open(0, oo)] = 1.0,
        sigma: Annotated[float, RealSet.open(0, oo)] = 1.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.alpha = alpha
        self.tau0 = tau0
        self.sigma = sigma

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the jumps of the positions of the target after the waiting times.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s = context
        waiting = draw('wait', 'pareto', b=s.alpha, scale=s.tau0)
        reset = {item: item + normal(f'jump{index}', 0, s.sigma) for index, item in enumerate(s.target.x)}
        self.laws_ = [JumpLaw(waiting=waiting, reset=reset, label=self.label)]