Superdiffusive Levy flight
The Lévy flight.
- Class:
LevyFlightSystem - Import:
from skcomplex.systems.physics.soft_matter import LevyFlightSystem - Field:
physics/soft_matter - Topics:
anomalous diffusion,superdiffusion,random walk,stochastic map - References:
- Bertin 2021
- Shlesinger, Zaslavsky, and Frisch 1995
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 LevyFlightSystem
trajectory = LevyFlightSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_walkers |
500 |
mu |
1.2 |
l0 |
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 | discrete |
| Space | continuous |
| Laws | update |
| Randomness | stochastic |
| Domains | vector |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class LevyFlightSystem(BaseSystem):
"""The Lévy flight.
The walk jumps in random directions by lengths with the tail `l^(-1 - mu)`.
For `mu < 2` the jump lengths have no variance, so the walk is dominated by its longest jumps and the typical
distance travelled after `n` steps grows as `n^(1 / mu)`, faster than the `n^(1/2)` of a random walk. The system has
the positions `walkers.x`.
Args:
n_walkers:
The number of independent walkers.
mu:
The tail exponent of the jump lengths.
l0:
The shortest jump length.
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 LevyFlightSystem
>>> LevyFlightSystem(10, mu=1.5).prepare().system_.interactions[0].mu
1.5
"""
draws = True
field = 'physics/soft_matter'
topics = ('anomalous diffusion', 'superdiffusion', 'random walk', 'stochastic map')
references = ('Bertin 2021', 'Shlesinger, Zaslavsky, and Frisch 1995')
until = 200.0
dt = 1.0
def __init__(
self,
n_walkers: int = 500,
*,
mu: float = 1.2,
l0: 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.mu = mu
self.l0 = l0
self.n_dim = n_dim
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of walkers that jump with power-law lengths in random directions.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
walkers = LevyFlierElement('walkers', x=np.zeros((self.n_walkers, self.n_dim)), size=self.n_walkers)
self.system_ = System(
self.label,
elements=[walkers],
interactions=[LevyJumpInteraction('flights', target='walkers', mu=self.mu, l0=self.l0)],
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:
LevyFlierElement, fromElement
Interactions:
LevyJumpInteraction, fromInteraction
class LevyFlierElement(Element):
"""Walkers at the positions `x` that jump at every step.
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 LevyFlierElement
>>> LevyFlierElement('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 LevyJumpInteraction(Interaction):
"""Jumps at every step in a random direction, with lengths of the power-law tail `l^(-1 - mu)`.
The length of a jump is `l0 r^(-1 / mu)` for `r` uniform, and its direction is uniform. It is an albatross that
forages, a photon in a hot gas, or a bank note passed between towns.
Args:
label:
The label of the interaction.
target:
The path of the walkers.
mu:
The tail exponent of the jump lengths, below 2 for jumps of infinite variance.
l0:
The shortest jump length.
Examples:
>>> from skcomplex.systems.physics.soft_matter import LevyJumpInteraction
>>> LevyJumpInteraction('flights', target='walkers', mu=1.5).mu
1.5
"""
law_classes = (UpdateLaw,)
draws = True
def __init__(
self,
label: str,
*,
target: Role,
mu: Annotated[float, RealSet.open(0, oo)] = 1.2,
l0: Annotated[float, RealSet.open(0, oo)] = 1.0,
) -> None:
super().__init__(label)
self.target = target
self.mu = mu
self.l0 = l0
def _get_direction(self, size: int) -> list[Expression]:
"""Return a unit vector of uniformly random direction, drawn from standard normal components."""
components = [normal(f'direction{index}') for index in range(size)]
length = sqrt(sum(component**2 for component in components))
return [component / length for component in components]
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the position after a jump in a random direction.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
x = context.target.x
length = draw('length', 'pareto', b=context.mu, scale=context.l0)
steps = self._get_direction(len(list(x)))
self.laws_ = [UpdateLaw(x, vector(SR, [item + length * step for item, step in zip(x, steps, strict=True)]))]