Experiments
An experiment runs a system many times through simulate: over values of its parameters, over random streams, over
scenarios, or over initial states. Experiments are functions of a system that return frozen results, and calibrate
fits the model parameters of a system to observed series and returns the fitted system in its result. An experiment that
repeats a system needs randomness to repeat, and the analyses an experiment applies to its runs check their own tags,
as the analyses page lists. The table lists what every experiment needs of a system.
| Experiment | What it does | What it needs |
|---|---|---|
basin_stability |
Return the fractions of random initial states that end in each attractor. | any system |
calibrate |
Return the fit of the model parameters of a system to observed time series, with SciPy. | any system |
compare_scenarios |
Return the runs of every scenario of a system. | any system |
ensemble |
Return the runs of a system with independent random streams. | the randomness stochastic, or a solver that draws |
orbit_diagram |
Return the values an observable visits after a transient. | any system |
sensitivity |
Return the sensitivity of a scalar output of a system to its inputs, with SALib. | any system |
sweep |
Return the runs of a system over rows of values. | any system |
A compatible experiment
The stochastic SIR epidemic draws its events from random streams, so ensemble runs it once per stream.
from skcomplex.core.experiments import ensemble
from skcomplex.systems.biology.epidemiology import SIRSystem
result = ensemble(SIRSystem(stochastic=True), replicates=3, until=10, random_state=0)
result.column('seed').tolist()
[0, 1, 2]
An incompatible experiment
The deterministic SIR epidemic repeats one run, so ensemble rejects it and names the randomness it needs.
from skcomplex.core.errors import TagError
from skcomplex.core.experiments import ensemble
from skcomplex.systems.biology.epidemiology import SIRSystem
try:
ensemble(SIRSystem(), replicates=3, until=10)
except TagError as error:
message = str(error)
message
assert 'randomness stochastic' in message
ensemble needs the randomness stochastic, but SIRSystem has the randomness deterministic. Its runs repeat one another, so run it once with `simulate`, or give it a part or a solver that draws.
A compatible calibration
calibrate fits the model parameters of a logistic growth to a series it generates.
import numpy as np
from skcomplex.core.experiments import calibrate
from skcomplex.systems.biology.ecology import LogisticGrowthSystem
times = np.arange(0, 21.0)
values = 100 / (1 + 9 * np.exp(-0.5 * times))
bounds = {'r': (0.1, 2.0), 'K': (50, 200)}
fitted = calibrate(LogisticGrowthSystem(), {'population.n': (times, values)}, bounds).system
round(fitted.r, 2), round(fitted.K)
(0.5, 100)
An incompatible calibration
Calibration fits model parameters, which set_params takes. An initial state is a dotted path, not a model
parameter, so calibrate rejects it.
import numpy as np
from skcomplex.core.errors import ValidationError
from skcomplex.core.experiments import calibrate
from skcomplex.systems.biology.ecology import LogisticGrowthSystem
times = np.arange(0, 21.0)
values = 100 / (1 + 9 * np.exp(-0.5 * times))
try:
calibrate(LogisticGrowthSystem(), {'population.n': (times, values)}, {'population.n': (1, 20)})
except ValidationError as error:
message = str(error)
message
assert 'population.n' in message
Calibration fits model parameters of the system, which `set_params` takes, not the dotted paths population.n.