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. 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 share of random initial states that end in each final behaviour. | any system |
calibrate |
Return the fit of the model parameters of a system to observed time series. | any system |
calibrate_individuals |
Return the fit of the model parameters of a system to each individual's data. | 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 |
identifiability |
Return which model parameters of a system the observed time series determine. | any system |
orbit_diagram |
Return the values an observable visits after a transient, per parameter value. | any system |
posterior_coverage |
Return how often the intervals of a sampling calibration hold the true values. | 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 |
virtual_population |
Return plausible parameter sets of a system, and those matching observed 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.get_column('seed').tolist()
[0, 1, 2]
The result holds one run for each of the seeds 0, 1, and 2.
An incompatible experiment
The deterministic SIR epidemic repeats one run, so ensemble raises a TagError that 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 component or a solver that draws.
The message says that ensemble needs the randomness stochastic, and advises one run with simulate, or a component or
a solver that draws.
A compatible calibration
calibrate fits the model parameters of a logistic growth to a series computed from its closed form with r = 0.5
and K = 100.
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.x': (times, values)}, bounds).system
round(fitted.r, 2), round(fitted.K)
(0.5, 100)
The fit recovers r = 0.5 and K = 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 raises a ValidationError.
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.x': (times, values)}, {'population.x': (1, 20)})
except ValidationError as error:
message = str(error)
message
assert 'population.x' in message
Calibration fits parameters of the system, which `set_params` takes, not the dotted paths population.x.
The message says that calibration fits model parameters, which set_params takes, and not the dotted path
population.x.