Criticality
Criticality systems.
The package covers sandpiles, forest fires, absorbing-state transitions, learners at the edge, and avalanches.
ActiveFieldElement(label, *, rho=0.5, nu=1.0, space=None)
Bases: Element
Sites of the Langevin equation of directed percolation with a conserved field.
Every site has an activity rho and a field nu. ActivePercolationInteraction grows, saturates, spreads, and
shakes the activity, and feeds and drains the field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the site or the field. |
required |
rho
|
object
|
The initial activity, or one value per site. |
0.5
|
nu
|
object
|
The initial field, or one value per site. |
1.0
|
space
|
BaseSpace | None
|
The lattice of the sites, or |
None
|
Examples:
>>> from skcomplex.systems.physics.criticality import ActiveFieldElement
>>> ActiveFieldElement('site').nu
1.0
Source code in src/skcomplex/systems/physics/criticality/_absorbing.py
52 53 54 55 56 57 58 59 60 61 62 | |
ActivePercolationInteraction(label, *, target, a=-1.0, b=1.0, c=1.0, d=1.0, e=0.2, f=0.0, g=0.0)
Bases: Interaction
Directed percolation of an activity fed by a conserved field.
The activity follows rho_t = (a + b nu) rho - c rho^2 + d laplacian(rho) + e sqrt(rho) eta, and the field
follows nu_t = laplacian(nu) + f - g rho. Both stay nonnegative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the sites, whose values are |
required |
a
|
float
|
The linear growth rate of the activity. |
-1.0
|
b
|
float
|
The growth of the activity per unit of the field. |
1.0
|
c
|
float
|
The saturation of the activity. |
1.0
|
d
|
float
|
The diffusion coefficient of the activity. |
1.0
|
e
|
float
|
The amplitude of the noise. |
0.2
|
f
|
float
|
The input of the field. |
0.0
|
g
|
float
|
The consumption of the field by the activity. |
0.0
|
Examples:
>>> from skcomplex.systems.physics.criticality import ActivePercolationInteraction
>>> ActivePercolationInteraction('percolation', target='neurons').e
0.2
Source code in src/skcomplex/systems/physics/criticality/_absorbing.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
AvalancheInteraction(label, *, target, state='height', threshold=4, mode='redistribute')
Bases: TopplingInteraction
Slowly driven sandpile.
Every step drops one grain on a random site, and the full sites topple in avalanches.
A site that holds threshold grains topples. In the mode 'redistribute' it sends one grain to each of its
neighbours, as in the Bak-Tang-Wiesenfeld sandpile, and in the mode 'random' every grain goes to a neighbour drawn
at random, as in the Manna sandpile. Grains that topple over a fixed edge leave the pile, and every avalanche is
recorded as an event under the label of the interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction and of its avalanche events. |
required |
target
|
Role
|
The path of the lattice group of sites. |
required |
state
|
str
|
The name of the state that holds the grains. |
'height'
|
threshold
|
int
|
The number of grains at which a site topples. |
4
|
mode
|
str
|
|
'redistribute'
|
Examples:
>>> from skcomplex.systems.physics.criticality import AvalancheInteraction
>>> AvalancheInteraction('avalanche', target='pile', threshold=2, mode='random').share
1
Source code in src/skcomplex/systems/physics/criticality/_criticality.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
BranchingInteraction(label, *, target, generations=10)
Bases: Interaction
Branching of an avalanche down a binary tree, with the branching probability tuned by the dissipation.
Every step, each of the z active sites of generation g makes two active sites of the next generation with the
probability p. The avalanche ends at the last generation or with no active site. Then the z sites of the last
generation leave, p changes by (1 - z) / N with N = 2^(generations + 1) - 1 sites, and a new avalanche starts
from one site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the tree, whose values are the probability |
required |
generations
|
int
|
The number of generations of the tree, at least 1. |
10
|
Examples:
>>> from skcomplex.systems.physics.criticality import BranchingInteraction
>>> BranchingInteraction('branching', target='tree').generations
10
Source code in src/skcomplex/systems/physics/criticality/_sandpiles.py
345 346 347 348 | |
CracklingNoiseResult(times, values, labels, sizes, durations, shapes, exponent, predicted, mean_shapes, shape_spread)
dataclass
Crackling-noise scaling of avalanches.
The avalanches are those of an activity series or the relaxations of a lattice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
Array | None
|
The time of every value, or |
required |
values
|
Array | None
|
The series, as one column, or |
required |
labels
|
list[str]
|
The label of the series. |
required |
sizes
|
Array
|
The sum of the values of every avalanche. |
required |
durations
|
Array
|
The number of samples of every avalanche. |
required |
shapes
|
list[Array]
|
The profile of every avalanche of a series, empty for records. |
required |
exponent
|
float
|
The exponent |
required |
predicted
|
float
|
The exponent |
required |
mean_shapes
|
dict[int, Array]
|
The mean shape of every chosen duration, scaled to unit mean height, on a grid of 0 to 1. |
required |
shape_spread
|
float
|
The mean over the inner 80 percent of the scaled time of the relative difference between the largest and
the smallest mean shape of the chosen durations, |
required |
DirectedPercolationLangevinSystem(shape=(64, 64), *, a=-1.0, b=1.0, c=1.0, d=1.0, e=0.2, f=0.0, g=0.0, energy=1.2, density=0.5, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Langevin field theory of an absorbing-state transition.
An active density is fed by an energy field.
The active density rho grows at the local rate a + b nu, saturates through -c rho^2, spreads with the
diffusivity d, and fluctuates with the multiplicative noise e sqrt(rho), which vanishes in the absorbing state
rho = 0. The energy field nu diffuses, gains the drive f, and loses the dissipation g rho, so rho_t = (a +
b nu) rho - c rho^2 + d laplacian(rho) + e sqrt(rho) xi and nu_t = laplacian(nu) + f - g rho (Tian et al., Eqs.
3-4). Both fields stay nonnegative. Without drive and dissipation the energy is a fixed control parameter: below the
threshold nu_c = -a / b activity dies out, and above it the density settles near (a + b nu) / c. The system has
the activity neurons.rho and the energy neurons.nu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The number of sites along every axis of the periodic lattice. |
(64, 64)
|
a
|
float
|
The bare growth rate of the activity. |
-1.0
|
b
|
float
|
The gain of the growth rate per unit of energy. |
1.0
|
c
|
float
|
The saturation of the activity. |
1.0
|
d
|
float
|
The diffusivity of the activity. |
1.0
|
e
|
float
|
The amplitude of the multiplicative noise. |
0.2
|
f
|
float
|
The drive of the energy. |
0.0
|
g
|
float
|
The dissipation of the energy per unit of activity. |
0.0
|
energy
|
float
|
The initial energy at every site. |
1.2
|
density
|
float
|
The mean initial activity, drawn uniformly between 0 and twice this value. |
0.5
|
random_state
|
int | Generator | None
|
The seed or generator of the initial activity. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import DirectedPercolationLangevinSystem
>>> system = DirectedPercolationLangevinSystem((8, 8), energy=0.5).prepare().system_
>>> float(system.elements[0].nu.mean())
0.5
Source code in src/skcomplex/systems/physics/criticality/_absorbing.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
EnergySiteElement(label, *, energy=0.0, space=None)
Bases: Element
Sites of the Zhang sandpile.
Every site stores a continuous energy.
A cascade loads the energy in random packets and resets the sites above the threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the site or the lattice of sites. |
required |
energy
|
object
|
The initial energy, or one value per site. |
0.0
|
space
|
BaseSpace | None
|
The lattice of the sites, or |
None
|
Examples:
>>> from skcomplex.systems.physics.criticality import EnergySiteElement
>>> EnergySiteElement('site').energy
0.0
Source code in src/skcomplex/systems/physics/criticality/_sandpiles.py
54 55 56 | |
EvolutionarySKGameSystem(n_agents=256, *, memory=0.75, temperature=None, max_temperature=2.0, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The evolutionary Sherrington-Kirkpatrick game.
The game self-organises to the edge of ergodicity breaking.
After Lesmana et al. (2026, arXiv 2604.15669), N agents play ±1 on a Sherrington-Kirkpatrick landscape with
symmetric Gaussian couplings of variance 1 / N. Each learns the incentive of its actions with memory alpha and
plays by a softmax policy at its own temperature, and the least fit agent is replaced, as in the Bak-Sneppen system,
by a newcomer whose temperature is drawn uniformly on [0, max_temperature]. The temperatures evolve to the edge
between ergodic and frozen learning, the replacement cascades have sizes distributed as S^(-3/2), and the mean
reward exceeds that of the game at any fixed temperature. With a fixed temperature, no agent is replaced and the
system is the Sherrington-Kirkpatrick game of Galla and Farmer. The system has the group agents of states
incentive, spin, temperature, fitness, and reward, and the observables mean_reward, mean_temperature,
and least_fitness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_agents
|
int
|
The number of agents |
256
|
memory
|
float
|
The weight |
0.75
|
temperature
|
ArrayLike | None
|
The temperature of every agent, or one per agent, of the game without replacement, or |
None
|
max_temperature
|
float
|
The largest temperature of a newcomer, and of the initial temperatures drawn uniformly. |
2.0
|
random_state
|
int | Generator | None
|
The seed or generator of the couplings, the initial actions, and the initial temperatures. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import EvolutionarySKGameSystem
>>> system = EvolutionarySKGameSystem(16).prepare().system_
>>> couplings = system.interactions[0].couplings
>>> system.elements[0].size, bool((couplings == couplings.T).all()), float(couplings.trace())
(16, True, 0.0)
Source code in src/skcomplex/systems/physics/criticality/_evolutionary_learning.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
FireInteraction(label, *, target, neighborhood=NEAREST)
Bases: Interaction
Stochastic rule of the Drossel-Schwabl forest fire.
The cover is 0 for empty, 1 for a tree, and 2 for burning.
Every step a tree catches fire from a burning neighbour or from lightning with the probability lightning of the
site, a burning site becomes empty, and a tree grows on an empty site with the probability growth of the site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction, unique among the components of its system. |
required |
target
|
Role
|
The path of the lattice or network of sites. |
required |
neighborhood
|
BaseNeighborhood
|
The neighbours a fire spreads to, the von Neumann neighbourhood of a square lattice, the six neighbours of a triangular lattice, or the neighbours of a node, each with the site itself. |
NEAREST
|
Examples:
>>> from skcomplex.systems.physics.criticality import FireInteraction
>>> FireInteraction('fire', target='forest').neighborhood.metric
'manhattan'
Source code in src/skcomplex/systems/physics/criticality/_criticality.py
176 177 178 179 | |
FixedEnergySandpileSystem(shape=(32, 32), *, density=2.3, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The fixed-energy sandpile.
It is a Bak-Tang-Wiesenfeld pile with no drive and no loss on a periodic lattice.
Every step, every site with at least four grains gives one grain to each of its four neighbours, all at once. The
lattice is periodic, so the density of grains density is conserved, and it controls an absorbing phase transition.
Below the critical density, about 2.125 on the square lattice, the topplings stop in an absorbing configuration, and
above it the pile stays active forever. The density of active sites, the observable activity, is the order
parameter. The grains start scattered uniformly at random over the sites. The system has the heights pile.height
and the observable activity, the density of active sites.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The number of rows and columns. |
(32, 32)
|
density
|
float
|
The mean number of grains per site. |
2.3
|
random_state
|
int | Generator | None
|
The seed or generator of the initial grains. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import FixedEnergySandpileSystem
>>> trajectory = FixedEnergySandpileSystem((8, 8), density=2.0).prepare().simulate(until=2)
>>> trajectory.get_values('pile.height').shape
(3, 64)
Source code in src/skcomplex/systems/physics/criticality/_sandpiles.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
ForestElement(label, *, cover=0.0, growth=0.05, lightning=0.0001, space=None)
Bases: Element
Sites of the Drossel-Schwabl forest fire.
Every site is empty at 0, a tree at 1, or burning at 2.
A FireInteraction grows trees on empty sites with probability growth, sets them on fire from a burning
neighbour or from lightning with probability lightning, and empties burning sites.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the site or the lattice of sites. |
required |
cover
|
object
|
The initial cover, 0, 1, or 2, or one cover per site. |
0.0
|
growth
|
Annotated[float, closed_open(0, oo)]
|
The probability that a tree grows on an empty site per step. |
0.05
|
lightning
|
Annotated[float, closed_open(0, oo)]
|
The probability that lightning strikes a tree per step. |
0.0001
|
space
|
BaseSpace | None
|
The lattice or network of the sites, or |
None
|
Examples:
>>> from skcomplex.systems.physics.criticality import ForestElement
>>> ForestElement('site').growth
0.05
Source code in src/skcomplex/systems/physics/criticality/_criticality.py
75 76 77 78 79 80 81 82 83 84 85 86 87 | |
ForestFireSystem(shape=(100, 100), *, growth=0.05, lightning=0.0001, density=0.5, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Drossel-Schwabl forest fire.
Slow growth and rare lightning give fires of every size.
The system has the covers forest.cover.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The number of rows and columns. |
(100, 100)
|
growth
|
float
|
The probability that a tree grows on an empty site per step. |
0.05
|
lightning
|
float
|
The probability that lightning strikes a tree per step. |
0.0001
|
density
|
float
|
The initial fraction of sites with a tree. |
0.5
|
random_state
|
int | Generator | None
|
The seed or generator of the initial forest. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import ForestFireSystem
>>> ForestFireSystem((10, 10)).prepare().system_.elements[0].growth
0.05
Source code in src/skcomplex/systems/physics/criticality/_criticality.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
GrainSiteElement(label, *, height=0.0, space=None)
Bases: Element
Sites of a sandpile.
Every site holds a number of grains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the site or the lattice of sites. |
required |
height
|
object
|
The initial number of grains, or one number per site. |
0.0
|
space
|
BaseSpace | None
|
The lattice of the sites, or |
None
|
Examples:
>>> from skcomplex.systems.physics.criticality import GrainSiteElement
>>> GrainSiteElement('site').height
0.0
Source code in src/skcomplex/systems/physics/criticality/_sandpiles.py
80 81 82 | |
HexagonalForestFireSystem(shape=(80, 80), *, graph=None, growth=0.02, lightning=1e-05, density=0.5, cover=None, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Drossel-Schwabl forest fire on a hexagonal lattice or on a graph.
The hexagonal cells form a triangular lattice, and on a graph the sites are its nodes.
Every site of the periodic triangular lattice has six neighbours, and every node of a graph has the neighbours along
its edges. Slow growth and rare lightning give fires of every size. The system has the covers forest.cover.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The number of rows and columns of the triangular lattice, unused on a graph. |
(80, 80)
|
graph
|
Graph | None
|
The graph whose nodes are the sites, or |
None
|
growth
|
float
|
The probability that a tree grows on an empty site per step. |
0.02
|
lightning
|
float
|
The probability that lightning strikes a tree per step. |
1e-05
|
density
|
float
|
The initial fraction of sites with a tree. |
0.5
|
cover
|
Sequence[float] | None
|
The initial cover of every site, 0 for empty, 1 for a tree, and 2 for burning, in lattice shape or node
order, or |
None
|
random_state
|
int | Generator | None
|
The seed or generator of the initial forest. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> import networkx as nx
>>> from skcomplex.systems.physics.criticality import HexagonalForestFireSystem
>>> HexagonalForestFireSystem((10, 10)).prepare().system_.elements[0].space.prepare().size_
100
>>> HexagonalForestFireSystem(graph=nx.cycle_graph(12)).prepare().system_.elements[0].space.prepare().size_
12
Source code in src/skcomplex/systems/physics/criticality/_criticality.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
LearnerElement(label, *, incentive=0.0, spin=1.0, temperature=1.0, fitness=0.0, reward=0.0, size=None)
Bases: Element
Agents of the evolutionary Sherrington-Kirkpatrick game.
Every agent keeps an incentive Q, the value of action +1, an action s = ±1, a temperature T, a fitness s Q,
and the reward s h of its last action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or the group. |
required |
incentive
|
object
|
The initial incentive |
0.0
|
spin
|
object
|
The initial action, -1 or 1, or one per agent. |
1.0
|
temperature
|
object
|
The initial temperature |
1.0
|
fitness
|
object
|
The initial fitness |
0.0
|
reward
|
object
|
The initial reward |
0.0
|
size
|
int | None
|
The number of agents, or |
None
|
Examples:
>>> from skcomplex.systems.physics.criticality import LearnerElement
>>> LearnerElement('agent').temperature
1.0
Source code in src/skcomplex/systems/physics/criticality/_evolutionary_learning.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
LearningAgentElement(label, *, sigma=1.0, Q=0.0, alpha=0.5, temperature=0.5, size=None)
Bases: Element
Agents of the SK game, each playing an action of ±1 from a softmax policy over its incentive to play +1.
SKReinforcementInteraction updates the incentive Q with the memory alpha and draws the action sigma at the
temperature T.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or the group. |
required |
sigma
|
object
|
The initial action, -1 or 1, or one action per agent. |
1.0
|
Q
|
object
|
The initial incentive. |
0.0
|
alpha
|
Annotated[float, open(0, oo)]
|
The memory parameter, the weight of the latest reward. |
0.5
|
temperature
|
Annotated[float, open(0, oo)]
|
The exploration temperature |
0.5
|
size
|
int | None
|
The number of agents, or |
None
|
Examples:
>>> from skcomplex.systems.physics.criticality import LearningAgentElement
>>> LearningAgentElement('agent').alpha
0.5
Source code in src/skcomplex/systems/physics/criticality/_learning.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
MannaSandpileSystem(shape=(32, 32), *, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Manna sandpile.
It is a stochastic sandpile of another universality class than Bak-Tang-Wiesenfeld.
The pile starts from random stable heights of 0 or 1 grain, and its avalanches are recorded as avalanche events
with their sizes, durations, and areas. The system has the heights pile.height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The number of rows and columns. |
(32, 32)
|
random_state
|
int | Generator | None
|
The seed or generator of the initial heights. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import MannaSandpileSystem
>>> trajectory = MannaSandpileSystem((10, 10)).prepare().simulate(until=2, dt=1, random_state=0)
>>> trajectory.get_values('pile.height').shape
(3, 100)
Source code in src/skcomplex/systems/physics/criticality/_criticality.py
312 313 314 315 316 317 318 319 320 321 322 323 | |
SKGameSystem(n_agents=256, *, alpha=0.5, temperature=0.5, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The SK game of reinforcement learners.
The rewards come from quenched Sherrington-Kirkpatrick couplings.
Every agent plays sigma_i = ±1 and earns sigma_i sum_j J_ij sigma_j, with symmetric Gaussian couplings of mean
0, variance 1 / N, and zero diagonal. It discounts its rewards with the memory alpha into the incentive Q_i
and plays from a softmax policy at the temperature T (Lesmana et al., Eqs. 1-3). All agents start with zero
incentives, so their first actions are random, and update in parallel. At low temperature the agents freeze into one
of many ordered states with a high collective reward, and at high temperature they explore noisily with a low one.
The system has the actions agents.sigma, the incentives agents.Q, and the coupling matrix couplings of its
interaction learning. Its standard observable reward is the mean reward per agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_agents
|
int
|
The number of agents |
256
|
alpha
|
float
|
The memory parameter. |
0.5
|
temperature
|
float
|
The exploration temperature of every agent. |
0.5
|
random_state
|
int | Generator | None
|
The seed or generator of the couplings and of the initial actions. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import SKGameSystem
>>> couplings = SKGameSystem(10).prepare().system_.interactions[0].couplings
>>> bool((couplings == couplings.T).all())
True
Source code in src/skcomplex/systems/physics/criticality/_learning.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
SKLearningInteraction(label, *, target, memory=0.75, max_temperature=2.0, couplings=None, evolving=True, settling=2)
Bases: Interaction
Learning of the agents of the Sherrington-Kirkpatrick game, with the replacement of the least fit.
Every step the incentive of an agent becomes (1 - alpha) Q + alpha h for the local field h = Σ_j J_ij s_j, the
agent plays the action s = ±1 by the softmax policy at its temperature T, and its fitness is s Q. When the
agents evolve, the least fit one is replaced by a newcomer with no incentive and a temperature drawn uniformly up to
max_temperature, who learns from the field at once. The reward s h of the last actions is kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the agents. |
required |
memory
|
Annotated[float, closed_open(0, oo)]
|
The weight |
0.75
|
max_temperature
|
Annotated[float, open(0, oo)]
|
The largest temperature of a newcomer. |
2.0
|
couplings
|
ArrayLike | None
|
The coupling matrix |
None
|
evolving
|
bool
|
Whether the least fit agent is replaced. |
True
|
settling
|
int
|
The number of steps of learning alone after every replacement, so replacements happen when |
2
|
Examples:
>>> from skcomplex.systems.physics.criticality import SKLearningInteraction
>>> SKLearningInteraction('learning', target='agents').memory
0.75
Source code in src/skcomplex/systems/physics/criticality/_evolutionary_learning.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
SKReinforcementInteraction(label, *, target, couplings=None)
Bases: Interaction
Reinforcement learning of the agents of the SK game.
Every step the incentive of an agent becomes (1 - alpha) Q + alpha sum_j J_ij sigma_j, with its memory alpha
and the quenched couplings J, and the agent plays sigma = 1 with the softmax probability 1 / (1 + exp(-2 Q /
T)) at its temperature T, and -1 otherwise. Both run in parallel. It is a market of traders who follow their
past gains, players of a repeated game, or neurons that learn from their inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the agents, whose values are |
required |
couplings
|
ArrayLike | None
|
The coupling matrix |
None
|
Examples:
>>> from skcomplex.systems.physics.criticality import SKReinforcementInteraction
>>> SKReinforcementInteraction('learning', target='agents').target
'agents'
Source code in src/skcomplex/systems/physics/criticality/_learning.py
104 105 106 107 | |
SandpileSystem(shape=(50, 50), *, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Bak-Tang-Wiesenfeld sandpile on a lattice with open edges.
The pile starts from random stable heights.
Its avalanches are recorded as avalanche events with their sizes, the number of topplings, their durations, and
their areas. The system has the heights pile.height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The number of rows and columns. |
(50, 50)
|
random_state
|
int | Generator | None
|
The seed or generator of the initial heights. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import SandpileSystem
>>> trajectory = SandpileSystem((10, 10)).prepare().simulate(until=2, dt=1, random_state=0)
>>> trajectory.get_values('pile.height').shape
(3, 100)
Source code in src/skcomplex/systems/physics/criticality/_criticality.py
245 246 247 248 249 250 251 252 253 254 255 256 | |
SelfOrganizedBranchingSystem(p=0.3, *, generations=10, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The self-organized branching process of Zapperi, Lauritsen, and Stanley.
It is a mean-field sandpile.
An avalanche starts from one active site at the top of a binary tree of generations generations. Every active site
relaxes with the probability p into two active sites of the next generation, and stays still otherwise, so every
generation has 2 Binomial(z, p) active sites. The sigma active sites that reach the last generation leave the
system as dissipation. After every avalanche one unit of energy has entered and sigma have left, so the
probability changes by (1 - sigma) / N with N = 2^(generations + 1) - 1 sites. A supercritical p makes large
dissipating avalanches that lower it, and a subcritical one lets energy accumulate, so p organizes itself to the
critical value p_c = 1 / 2, where the branching ratio 2 p is 1. The process advances one generation per step, so
a step is a time of the avalanche and avalanches follow each other without pause. The system has the probability
tree.p, the active sites tree.z, and the generation tree.g.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
The initial branching probability. |
0.3
|
generations
|
int
|
The number of generations of the tree, at least 1. |
10
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import SelfOrganizedBranchingSystem
>>> SelfOrganizedBranchingSystem(0.4).prepare().system_.elements[0].values['p']
0.4
Source code in src/skcomplex/systems/physics/criticality/_sandpiles.py
419 420 421 422 423 424 425 426 427 428 429 430 | |
ToppleInteraction(label, *, target, threshold=4)
Bases: Interaction
Parallel toppling of a sandpile without drive.
Every site at or above the threshold topples once a step.
Every step, every site that holds at least threshold grains loses threshold grains, and every site gains one
grain from each toppling neighbour, all at once. On a periodic lattice no grain is lost, so the number of grains is
conserved, and the activity either dies out in an absorbing configuration or lasts forever.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction, unique among the components of its system. |
required |
target
|
Role
|
The path of the lattice group of sites. |
required |
threshold
|
int
|
The number of grains at which a site topples, the number of its neighbours. |
4
|
Examples:
>>> from skcomplex.systems.physics.criticality import ToppleInteraction
>>> ToppleInteraction('topple', target='pile').threshold
4
Source code in src/skcomplex/systems/physics/criticality/_sandpiles.py
112 113 114 115 | |
ZhangSandpileSystem(shape=(32, 32), *, threshold=1.0, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Zhang sandpile.
It is a continuous sandpile whose unstable sites give away all their energy.
Every step loads a site chosen at random with a packet of energy of uniform size in [0, threshold]. A site whose
energy reaches the threshold relaxes: its energy falls to 0 and each of its four neighbours gains a quarter of it,
all at once, until no site is unstable. Energy that would go beyond the open edges is lost. The pile organizes
itself into a critical state with avalanches of every size, recorded as avalanche events with their sizes,
durations, and areas, and the energies of the sites cluster near a few values. The energies start uniformly at
random below the threshold. The system has the energies pile.energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The number of rows and columns. |
(32, 32)
|
threshold
|
float
|
The energy at which a site relaxes, which is also the largest packet. |
1.0
|
random_state
|
int | Generator | None
|
The seed or generator of the initial energies. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.physics.criticality import ZhangSandpileSystem
>>> ZhangSandpileSystem((8, 8)).prepare().system_.interactions[0].mode
'reset'
Source code in src/skcomplex/systems/physics/criticality/_sandpiles.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
crackling_noise(source, *, variables=None, threshold=0.0, durations=(), min_count=10, min_duration=1, size_exponent=None, duration_exponent=None)
Return the crackling-noise scaling of avalanches.
The avalanches are those of an activity series or the relaxations of a lattice.
It finds the avalanches as the events of kind 'excursions', then fits the exponent gamma of the mean size
against the duration, <S>(T) ~ T^gamma, predicts it as (tau_T - 1) / (tau_S - 1) from the exponents of the
size and duration laws, such as those fit_law(..., law='power') fits, and collapses the mean shapes of the chosen
durations, which agree after scaling at a critical point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array that holds the activity series, or records of avalanches. |
required |
variables
|
Sequence[str] | None
|
The one variable of a trajectory to read, or |
None
|
threshold
|
float
|
The activity an avalanche exceeds at every step, subtracted from its profile. |
0.0
|
durations
|
Sequence[int]
|
The durations whose mean shapes are compared. |
()
|
min_count
|
int
|
The fewest avalanches of a duration used in the fit of the mean size. |
10
|
min_duration
|
int
|
The shortest duration used in the fit of the mean size. |
1
|
size_exponent
|
float | None
|
The exponent |
None
|
duration_exponent
|
float | None
|
The exponent |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
CracklingNoiseResult
|
The avalanches, the exponent of the mean size and its prediction, and the mean shapes. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The fewest avalanches of a duration is not positive, or fewer than 2 durations have that many avalanches. |
Examples:
>>> from skcomplex.systems.physics.criticality import crackling_noise
>>> activity = [0, 1, 0, 1, 2, 1, 0, 1, 0, 2, 3, 2, 0]
>>> round(crackling_noise(activity, min_count=1).exponent, 2)
1.55
Source code in src/skcomplex/systems/physics/criticality/_crackling_noise.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |