Experiments
Define experiments, the functions that study a system through many runs.
They are sweeps, ensembles, scenarios, sensitivity, basin stability, orbit diagrams, calibration, posterior coverage,
identifiability, virtual populations, and the calibration of individuals. Each is a function of a system, as the model
selection functions of scikit-learn are, and returns a frozen result. As cross_val_score fits clones of an
estimator, an experiment clones the system, sets parameters with set_params, prepares the clone, and simulates it,
and it prepares once when only initial states or random streams change.
BasinStabilityResult(rows, labels, fractions, errors)
dataclass
A result of basin_stability, the share of initial states per final behaviour.
It holds the random initial states, the final behaviour each one ended in, and the share of the states that reached
each behaviour with its standard error, such as {'capacity': 1.0} when every population grows to its capacity. It
reports how often a power grid stays in step, how often a species survives, and how often a genetic switch ends on.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[Row]
|
The initial states, one mapping from dotted path to value per run. |
required |
labels
|
list[object]
|
The attractor label of every initial state. |
required |
fractions
|
dict[object, float]
|
The fraction of initial states per attractor label. |
required |
errors
|
dict[object, float]
|
The standard error of every fraction. |
required |
See Also
basin_stability: Returns this result.
Examples:
>>> from skcomplex.core.experiments import BasinStabilityResult
>>> BasinStabilityResult([], [], {'capacity': 1.0}, {'capacity': 0.0}).fractions
{'capacity': 1.0}
CalibrationResult(system, estimates, r2, rmse, mae, mape, covariance, simulated, success, samples=None, weights=None, diagnostics=dict(), predictive=None)
dataclass
A result of calibrate, the fitted parameters and system, with measures of fit.
It holds the system with the fitted parameters, the estimates, and how well the runs match the data, such as r2,
the share of the variation of the data the fit explains. A method that samples the likely values also holds the
samples, their weights, its own checks, and a band of simulated series around the data. It reports the fitted rates
of an epidemic, the constants of a reaction, and the growth of a firm.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
AnySystem
|
The system with the fitted model parameters. |
required |
estimates
|
dict[str, float]
|
The fitted value of every parameter, the posterior median for the posterior methods. |
required |
r2
|
float
|
The coefficient of determination over all data points. |
required |
rmse
|
float
|
The root mean squared error. |
required |
mae
|
float
|
The mean absolute error. |
required |
mape
|
float
|
The mean absolute percentage error, over data points that are not zero. |
required |
covariance
|
Array | None
|
The covariance of the estimates, from the Jacobian of the residuals for a point fit and from the weighted
samples for a posterior method, or |
required |
simulated
|
dict[str, Array]
|
The simulated values at the data times, by path. |
required |
success
|
bool
|
Whether the method converged, such as the optimiser of a point fit, the split R-hat of every parameter of MCMC, or a finite loss of variational calibration. |
required |
samples
|
dict[str, Array] | None
|
The samples of every parameter of a posterior method, or |
None
|
weights
|
Array | None
|
The normalised weights of the samples, or |
None
|
diagnostics
|
dict[str, object]
|
The diagnostics of the method, such as the tolerances and acceptance rates of ABC-SMC, the split R-hat and effective sample sizes of MCMC, or the loss history of variational calibration. |
dict()
|
predictive
|
dict[str, object] | None
|
The 5%, 50%, and 95% quantiles of the simulated series of posterior draws at the data times by path, under
|
None
|
See Also
calibrate: Returns this result. IndividualCalibrationResult: Holds one calibration per individual.
Examples:
>>> from skcomplex.core.experiments import calibrate
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> trajectory = LogisticGrowthSystem(r=0.5).prepare().simulate(until=20, dt=1.0)
>>> data = {'population.x': (trajectory.times, trajectory.get_values('population.x'))}
>>> round(calibrate(LogisticGrowthSystem(), data, {'r': (0.1, 2.0)}).r2, 3)
1.0
CoverageResult(levels, coverage, ranks, truths, results)
dataclass
A result of posterior_coverage, how often the intervals hold the true values.
It holds, for every level and parameter, the share of the simulated data sets whose central interval holds the true value, such as 0.9 for a level of 0.9 when the intervals are right. It also holds the rank of every true value among its samples, which is uniform for a sound method. It checks the intervals of the rates of an epidemic, the constants of a reaction, and the parameters of a climate model.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
levels
|
tuple[float, ...]
|
The levels of the central credible intervals. |
required |
coverage
|
dict[float, dict[str, float]]
|
The share of the data sets whose interval holds the true value, by level and parameter. |
required |
ranks
|
dict[str, Array]
|
The weighted share of the samples below the true value, one per data set, by parameter. |
required |
truths
|
dict[str, Array]
|
The true value of every data set, by parameter. |
required |
results
|
tuple[CalibrationResult, ...]
|
The calibration of every data set. |
required |
See Also
posterior_coverage: Returns this result.
Examples:
>>> from skcomplex.core.experiments import CoverageResult
>>> CoverageResult((0.9,), {0.9: {'r': 0.85}}, {}, {}, ()).coverage[0.9]['r']
0.85
ExperimentResult(runs)
dataclass
A result of an experiment, with one row per run and the series it kept.
It holds the runs of sweep, ensemble, and compare_scenarios as a tidy table, one row per run and one column
per parameter, scenario, replicate, seed, and output, which to_frame returns as a data frame. It also reads the
kept series together as an ensemble and a summary across replicates. It holds the runs of an epidemic over its rate
of infection, of a magnet over its temperature, and of a market over its tax.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
tuple[_RunResultSpec, ...]
|
The results of every run, in the experiment's order. |
required |
See Also
sweep: Returns this result for rows of values. ensemble: Returns this result for random streams.
Examples:
>>> from skcomplex.core.experiments import sweep
>>> from skcomplex.systems.biology.epidemiology import SIRSystem
>>> result = sweep(SIRSystem(), {'gamma': [0.1, 0.2]}, until=10)
>>> [row['gamma'] for row in result.rows]
[0.1, 0.2]
rows
property
One row per run with its values and outputs.
A row holds its design values, scenario, replicate, seed, and scalar outputs.
convert_to_frame()
Return the rows as a pandas data frame.
Returns:
| Name | Type | Description |
|---|---|---|
frame |
DataFrame
|
The data frame. |
Source code in src/skcomplex/core/experiments/_results.py
162 163 164 165 166 167 168 169 | |
get_column(name)
Return one column of the rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of a design value, |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[generic]
|
One value per run. |
Source code in src/skcomplex/core/experiments/_results.py
57 58 59 60 61 62 63 64 65 66 67 68 | |
get_ensemble(name)
Return a kept series of every run on common times, with the seeds of the runs.
The series are interpolated on the times of the shortest run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The path of the kept series. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
times |
NDArray[float64]
|
The common times. |
values |
NDArray[float64]
|
One row per run and one column per common time. |
seeds |
NDArray[int64]
|
The seed of the run of every row. |
Examples:
>>> 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)
>>> times, values, seeds = result.get_ensemble('I.x')
>>> values.shape == (3, times.size), seeds.tolist()
(True, [0, 1, 2])
Source code in src/skcomplex/core/experiments/_results.py
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 | |
get_series(name)
Return a kept series of every run.
The series are stacked when all runs have the same number of frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The path of the kept series. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
series |
NDArray[generic]
|
One row per run, or an object array of per-run series of different lengths. |
Source code in src/skcomplex/core/experiments/_results.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
get_summary(quantiles=(0.05, 0.5, 0.95))
Return statistics of every numeric scalar output per row and scenario.
They are the mean, the standard deviation, and the quantiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantiles
|
Sequence[float]
|
The quantiles to report. |
(0.05, 0.5, 0.95)
|
Returns:
| Name | Type | Description |
|---|---|---|
summary |
list[dict[str, object]]
|
One row per design row and scenario, with |
Source code in src/skcomplex/core/experiments/_results.py
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 | |
IdentifiabilityResult(estimates, verdicts, profiles, intervals, errors)
dataclass
A result of identifiability, the best fit and a verdict per parameter.
It holds the best fit and whether the data pin down each parameter, such as {'r': 'strong'}. A profile also holds
the profile and the interval of every parameter, with the verdicts 'identifiable' and 'not identifiable'. Refits
hold the average error of every parameter per level of noise, with the verdicts 'strong', 'weak', and 'none'.
It tells whether case counts fix the rates of an epidemic, counts fix the capacity of a population, and blood
samples fix the clearance of a drug.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimates
|
dict[str, float]
|
The best-fit value of every parameter. |
required |
verdicts
|
dict[str, str]
|
The verdict of every parameter. |
required |
profiles
|
dict[str, tuple[Array, Array]] | None
|
The values of the profiled parameter and the likelihood ratio along its profile, by parameter, or |
required |
intervals
|
dict[str, tuple[float, float]] | None
|
The |
required |
errors
|
dict[str, dict[float, float]] | None
|
The average relative error of every parameter by noise level, or |
required |
See Also
identifiability: Returns this result.
Examples:
>>> from skcomplex.core.experiments import IdentifiabilityResult
>>> IdentifiabilityResult({'r': 0.5}, {'r': 'strong'}, None, None, {'r': {0.01: 0.004}}).verdicts
{'r': 'strong'}
IndividualCalibrationResult(calibrations, estimates)
dataclass
A result of calibrate_individuals, the calibration of every individual.
It holds the calibration of every individual and a table of their estimates, one row per individual and one column
per parameter, such as the growth rate r of the regions 'north' and 'south'. It reports the fitted tumour of
every patient, the rates of an epidemic in every region, and the demand of every firm.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calibrations
|
dict[Hashable, CalibrationResult]
|
The calibration of every individual. |
required |
estimates
|
DataFrame
|
The estimates, with one row per individual and one column per parameter. |
required |
See Also
calibrate_individuals: Returns this result. CalibrationResult: Holds the calibration of one system.
Examples:
>>> import pandas as pd
>>> from skcomplex.core.experiments import IndividualCalibrationResult
>>> table = pd.DataFrame({'r': [0.5, 0.7]}, index=pd.Index(['north', 'south'], name='individual'))
>>> float(IndividualCalibrationResult({}, table).estimates.loc['south', 'r'])
0.7
OrbitDiagramResult(points, periods)
dataclass
A result of orbit_diagram, the values visited for every value of a parameter.
It holds the values a run keeps visiting after it settles, for every value of the parameter, and how many distinct values each run visits, so a period of 2 means a cycle between two values. It shows the period doubling of a population, the route to chaos of a forced pendulum, and the pulses of a laser.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
list[Array]
|
The kept values of the observable for every value of the parameter. |
required |
periods
|
NDArray[int64]
|
The number of distinct kept values for every value of the parameter, the period of periodic orbits. |
required |
See Also
orbit_diagram: Returns this result.
Examples:
>>> from skcomplex.core.experiments import orbit_diagram
>>> from skcomplex.systems.mathematics.dynamical_systems import LogisticMapSystem
>>> orbit_diagram(LogisticMapSystem(), 'r', [2.9, 3.2], 'map.x', transient=1000, keep=20).periods.tolist()
[1, 2]
ScenarioSpec(name='baseline', overrides=None, schedule=(), system=None)
dataclass
Bases: BaseSpec
A spec of a named variant of a system, such as an intervention.
It changes values before the run, changes parameters at given times, or replaces the system, such as
ScenarioSpec('distancing', overrides={'beta': 0.0001}) for a lower rate of infection. Every scenario of an
experiment runs with the same random streams, so scenarios differ only through what they change. An epidemic
compares early and late lockdowns, a climate model compares paths of emissions, and an economy compares tax
policies.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the scenario. |
'baseline'
|
overrides
|
Mapping[str, object] | None
|
A mapping from a name |
None
|
schedule
|
Sequence[tuple[float, str, object]]
|
The changes during the run, as |
()
|
system
|
AnySystem | None
|
A system that replaces the one the factory builds, for structural changes, or |
None
|
See Also
compare_scenarios: Runs the scenarios of a system.
Examples:
>>> from skcomplex.core.experiments import ScenarioSpec
>>> ScenarioSpec('reduced', schedule=[(50.0, 'source.rate', 0.025)]).schedule
[(50.0, 'source.rate', 0.025)]
SensitivityResult(names, inputs, outputs, ranking, effects=None, mu_star=None, mu_star_conf=None, sigma=None, first_order=None, first_order_conf=None, total_order=None, total_order_conf=None)
dataclass
A result of sensitivity, the effect of each input on a scalar output.
It holds the inputs and the output of every run, the effects the method measures, and the inputs ranked from the
most to the least influential, such as 'growth.K' first when the capacity sets the final size. It ranks the rates
of an epidemic by their effect on its peak, the inputs of a climate model by their effect on warming, and the costs
of a supply chain by their effect on profit.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
The inputs, names |
required |
inputs
|
Array
|
The values of the inputs of every run, one column per input. |
required |
outputs
|
Array
|
The output of every run. |
required |
ranking
|
list[str]
|
The inputs from the most to the least influential, by |
required |
effects
|
dict[str, float] | None
|
The one-at-a-time effect of every input, for |
None
|
mu_star
|
dict[str, float] | None
|
The mean absolute elementary effect of every input, for |
None
|
mu_star_conf
|
dict[str, float] | None
|
The confidence interval of |
None
|
sigma
|
dict[str, float] | None
|
The standard deviation of the elementary effects of every input, for |
None
|
first_order
|
dict[str, float] | None
|
The first-order Sobol index of every input, for |
None
|
first_order_conf
|
dict[str, float] | None
|
The confidence interval of |
None
|
total_order
|
dict[str, float] | None
|
The total Sobol index of every input, for |
None
|
total_order_conf
|
dict[str, float] | None
|
The confidence interval of |
None
|
See Also
sensitivity: Returns this result.
Examples:
>>> from skcomplex.core.experiments import sensitivity
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> bounds = {'growth.r': (0.1, 1.0), 'growth.K': (50, 150)}
>>> sensitivity(LogisticGrowthSystem(), bounds, output='population.x', method='oat', until=20).ranking[0]
'growth.K'
VirtualPopulationResult(plausible, acceptance, selected, inclusion)
dataclass
A result of virtual_population, the plausible rows and those selected.
It holds the sampled parameter rows whose runs look plausible, with their outputs, the share of samples that passed, and the rows selected to match observed values with their chance of selection. It holds virtual patients of a trial, plausible economies, and plausible ecosystems.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plausible
|
DataFrame
|
The plausible rows, with one column per parameter and per output. |
required |
acceptance
|
float
|
The share of the sampled rows that are plausible. |
required |
selected
|
DataFrame | None
|
The plausible rows selected to match the target, or |
required |
inclusion
|
Array | None
|
The probability of inclusion of every plausible row, or |
required |
See Also
virtual_population: Returns this result.
Examples:
>>> import pandas as pd
>>> from skcomplex.core.experiments import VirtualPopulationResult
>>> result = VirtualPopulationResult(pd.DataFrame({'r': [0.5], 'size': [2.0]}), 0.25, None, None)
>>> result.acceptance
0.25
basin_stability(system, bounds, classifier, *, n=500, until=None, dt=None, random_state=None, executor='serial', vectorized=False)
Return the share of random initial states that end in each final behaviour.
It draws initial states at random within bounds, runs each one to until, and asks classifier which final
behaviour the run settled into, such as a resting state or a cycle. The share of each behaviour says how well it
withstands large disturbances. With vectorized, every initial state runs as one member of a single simulation. It
measures how often a power grid stays in step after a fault, how often a population survives, and how often a
genetic switch ends on rather than off.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, or a factory of systems, such as a system class. |
required |
bounds
|
Mapping[str, tuple[float, float]]
|
A mapping from dotted state path to the |
required |
classifier
|
Callable[[Trajectory], object]
|
A function of a trajectory that returns the label of the attractor it ends in. |
required |
n
|
int
|
The number of initial states. |
500
|
until
|
float | None
|
The end time of every run, or |
None
|
dt
|
float | None
|
The time between frames, or |
None
|
random_state
|
int | None
|
The seed of the initial states and the runs. |
None
|
executor
|
str | Executor
|
|
'serial'
|
vectorized
|
bool
|
Whether to run every initial state as a member of one simulation of the replicated system. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
BasinStabilityResult
|
The initial states, their attractor labels, and the fraction and its error per attractor. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
No bounds are given, the number of initial states is not a positive integer, or a vectorised run does not compile to a general problem. |
ExperimentError
|
The system is a name. |
See Also
orbit_diagram: Shows the values a run visits over a range of a parameter. ensemble: Runs a system many times with independent random streams.
Examples:
>>> from skcomplex.core.experiments import basin_stability
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> bounds = {'population.x': (0.1, 10)}
>>> basin_stability(LogisticGrowthSystem(), bounds, lambda run: 'capacity', n=5, until=5).fractions
{'capacity': 1.0}
Source code in src/skcomplex/core/experiments/_basin_stability.py
65 66 67 68 69 70 71 72 73 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 175 176 | |
calibrate(system, data, bounds, *, method='local', initial=None, loss='squares', summary=None, n_samples=1000, budget=None, chains=4, replicates=1, dt=None, solver=None, random_state=None)
Return the fit of the model parameters of a system to observed time series.
It searches the parameters within bounds for the run that best matches data, a mapping from a path such as
'population.x' to its observed times and values, and returns a copy of the system with them. Every candidate runs
the system to the last data time and reads its values at the data times, and a random system averages replicates
runs with fixed seeds. A point method returns one estimate, and a method that samples the likely values returns
their median with the samples. It fits the rates of an epidemic to case counts, the constants of a reaction to
measured concentrations, and a predator and prey model to the pelts traded by trappers.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, whose clones take the parameters through |
required |
data
|
Mapping[str, tuple[ArrayLike, ArrayLike]] | Trajectory
|
A mapping from state or observable path to its observed |
required |
bounds
|
Bounds
|
A mapping from a parameter of the system, such as |
required |
method
|
str
|
How to search or sample. |
'local'
|
initial
|
Mapping[str, float] | None
|
The starting values of the parameters of a local fit, or |
None
|
loss
|
str
|
What scores a candidate, as the method allows. |
'squares'
|
summary
|
Summary | None
|
The function from simulated or observed series by path to summary statistics that ABC-SMC compares, or
|
None
|
n_samples
|
int
|
The number of samples of a posterior method, per chain for MCMC. |
1000
|
budget
|
int | None
|
The number of evaluations of a global fit, simulations of ABC-SMC, or steps of variational calibration, or
|
None
|
chains
|
int
|
The number of chains of MCMC. |
4
|
replicates
|
int
|
The number of runs averaged per evaluation. |
1
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
random_state
|
int | None
|
The seed of the runs and of the method. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
CalibrationResult
|
The fitted system, the estimates, and the goodness of fit. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
The system is a system name, the method or the loss is unknown or they do not fit, there is no data, the replicates are bad, or a bound is neither a pair nor a SciPy distribution or has a dotted path. |
See Also
calibrate_individuals: Fits each individual to its own data. identifiability: Tells which parameters the data determine. posterior_coverage: Checks the intervals of a method that samples.
Examples:
>>> from skcomplex.core.experiments import calibrate
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> trajectory = LogisticGrowthSystem(r=0.5).prepare().simulate(until=20, dt=1.0)
>>> data = {'population.x': (trajectory.times, trajectory.get_values('population.x'))}
>>> round(calibrate(LogisticGrowthSystem(), data, {'r': (0.1, 2.0)}).estimates['r'], 2)
0.5
Source code in src/skcomplex/core/experiments/_calibration.py
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | |
calibrate_individuals(system, data, bounds, *, known=None, method='local', loss='squares', initial=None, n_samples=1000, budget=None, chains=4, replicates=1, dt=None, solver=None, random_state=None, executor='serial')
Return the fit of the model parameters of a system to each individual's data.
Each individual has its own data and may have known parameters, such as the dose a patient received. The function
sets the known parameters on a copy of the system and calls calibrate on the data of that individual, so each
fitted copy is the digital twin of one individual. The calibrations run on executor, each with its own seed. It
fits the tumour of every patient of a trial, the rates of an epidemic in every region, and the demand of every firm
of a market.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, whose clones take the parameters through |
required |
data
|
Mapping[Hashable, Data]
|
A mapping from individual to its data, a mapping from state or observable path to |
required |
bounds
|
Bounds
|
A mapping from model parameter to its |
required |
known
|
Mapping[Hashable, Mapping[str, object]] | None
|
A mapping from individual to its known model parameters by name, or |
None
|
method
|
str
|
The method of |
'local'
|
loss
|
str
|
The loss of |
'squares'
|
initial
|
Mapping[str, float] | None
|
The starting values of a local fit, or |
None
|
n_samples
|
int
|
The number of samples of a posterior method. |
1000
|
budget
|
int | None
|
The budget of the method, or |
None
|
chains
|
int
|
The number of chains of MCMC. |
4
|
replicates
|
int
|
The number of runs averaged per evaluation. |
1
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
random_state
|
int | None
|
The seed of the seeds of the individuals. |
None
|
executor
|
str | Executor
|
|
'serial'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
IndividualCalibrationResult
|
The calibration of every individual and the table of their estimates. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
There is no individual, a known parameter is also fitted or belongs to an individual without data, or
|
ExperimentError
|
The system is a name. |
See Also
calibrate: Fits one system to one set of data.
Examples:
>>> from skcomplex.core.experiments import calibrate_individuals
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> runs = {k: LogisticGrowthSystem(r=r).prepare().simulate(until=20) for k, r in [('a', 0.4), ('b', 0.7)]}
>>> data = {k: {'population.x': (run.times, run.get_values('population.x'))} for k, run in runs.items()}
>>> calibrate_individuals(LogisticGrowthSystem(), data, {'r': (0.1, 2.0)}).estimates['r'].round(2).to_dict()
{'a': 0.4, 'b': 0.7}
Source code in src/skcomplex/core/experiments/_individuals.py
64 65 66 67 68 69 70 71 72 73 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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
compare_scenarios(system, scenarios, *, replicates=1, analyses=None, until=None, dt=None, solver=None, outputs=None, warmup=0.0, observables=(), random_state=None, executor='serial')
Return the runs of every scenario of a system.
It runs every ScenarioSpec on a copy of the system, replicates times, and every scenario of a replicate draws
the same random numbers, so the scenarios differ only through what they change. A scenario overrides values before
the run, changes parameters at given times, or replaces the system. It compares early and late lockdowns of an
epidemic, paths of emissions of a climate model, and tax policies of an economy.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, whose clones take parameters through |
required |
scenarios
|
Sequence[ScenarioSpec]
|
The scenarios to compare. |
required |
replicates
|
int
|
The number of runs per scenario. |
1
|
analyses
|
Sequence[Callable[[Trajectory], object]] | None
|
The analyses of every run, functions of a trajectory that return a frozen result, such as analysis
functions bound with |
None
|
until
|
float | None
|
The end time of every run, or |
None
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
outputs
|
Sequence[Output] | None
|
The state and observable paths to keep as series, whose last values are scalar outputs, and functions of
a trajectory that return a scalar or a mapping of scalars. |
None
|
warmup
|
float
|
The simulated time before which kept series are discarded. |
0.0
|
observables
|
Sequence[Observable]
|
The observables of every run, or none for the tuned ones. |
()
|
random_state
|
int | None
|
The seed of the random streams, one per row and replicate. |
None
|
executor
|
str | Executor
|
|
'serial'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ExperimentResult
|
The results of every run, one tidy row per run with the name of its scenario. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
No scenario is given, a scenario is not a |
ExperimentError
|
The system is a name, or the worker processes stop before finishing. |
See Also
ScenarioSpec: Names one variant of a system. sweep: Runs a system over values of its parameters.
Examples:
>>> from skcomplex.core.experiments import ScenarioSpec, compare_scenarios
>>> from skcomplex.systems.biology.epidemiology import SIRSystem
>>> scenarios = [ScenarioSpec(), ScenarioSpec('distancing', overrides={'beta': 0.0001})]
>>> result = compare_scenarios(SIRSystem(), scenarios, until=50, outputs=['I.x'])
>>> [row['scenario'] for row in result.rows]
['baseline', 'distancing']
Source code in src/skcomplex/core/experiments/_scenarios.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 | |
ensemble(system, *, replicates=10, analyses=None, until=None, dt=None, solver=None, outputs=None, warmup=0.0, observables=(), random_state=None, executor='serial')
Return the runs of a system with independent random streams.
It runs a random system replicates times, each with its own random stream spawned from random_state, so the runs
are independent and repeatable, and the result reads them as one row per run. Only the streams change, so the system
is prepared once. A system with no randomness and a solver that draws nothing gives the same run every time and
raises an error. It estimates the spread of the outcomes of an epidemic, of a weather forecast, and of the wealth of
traders in a market.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, whose clones take parameters through |
required |
replicates
|
int
|
The number of runs. |
10
|
analyses
|
Sequence[Callable[[Trajectory], object]] | None
|
The analyses of every run, functions of a trajectory that return a frozen result, such as analysis
functions bound with |
None
|
until
|
float | None
|
The end time of every run, or |
None
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
outputs
|
Sequence[Output] | None
|
The state and observable paths to keep as series, whose last values are scalar outputs, and functions of
a trajectory that return a scalar or a mapping of scalars. |
None
|
warmup
|
float
|
The simulated time before which kept series are discarded. |
0.0
|
observables
|
Sequence[Observable]
|
The observables of every run, or none for the tuned ones. |
()
|
random_state
|
int | None
|
The seed of the random streams, one per row and replicate. |
None
|
executor
|
str | Executor
|
|
'serial'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ExperimentResult
|
The results of every run, one tidy row per run, whose |
Raises:
| Type | Description |
|---|---|
ValidationError
|
The number of runs is not a positive integer, or a setting is not valid. |
ExperimentError
|
The system is a name, or the worker processes stop before finishing. |
TagError
|
The system has the randomness |
See Also
sweep: Runs a system over values of its parameters. compare_scenarios: Runs named variants of a system with shared streams.
Examples:
>>> 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]
Source code in src/skcomplex/core/experiments/_ensemble.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 | |
identifiability(system, data, bounds, *, method='profile', level=0.95, n_starts=5, noise=(0.01,), n=100, dt=None, solver=None, random_state=None, executor='serial')
Return which model parameters of a system the observed time series determine.
A calibration returns estimates even when the data cannot pin them down, and this function tells whether they do. A profile fixes each parameter at values around the best fit and fits the others again, and the parameter is identifiable when the fit worsens enough on both sides within its bounds. Refits add noise to the best run, fit again, and judge each parameter by how far its estimates stray. It tells whether counts fix the growth rate and capacity of a population, whether case counts fix the rates of an epidemic, and whether blood samples fix the clearance of a drug.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, whose clones take the parameters through |
required |
data
|
Data
|
A mapping from state or observable path to its observed |
required |
bounds
|
Bounds
|
A mapping from model parameter to its |
required |
method
|
str
|
|
'profile'
|
level
|
float
|
The confidence level of the likelihood-ratio intervals of a profile, between 0 and 1. |
0.95
|
n_starts
|
int
|
The number of local fits of a profile whose best is the best fit. |
5
|
noise
|
Sequence[float]
|
The relative noise levels of the refits, such as 0.01 for 1% of every value. |
(0.01,)
|
n
|
int
|
The number of noisy copies per level of the refits. |
100
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
random_state
|
int | None
|
The seed of the start points, the runs, and the noise. |
None
|
executor
|
str | Executor
|
|
'serial'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
IdentifiabilityResult
|
The best fit, the verdicts, and the profiles and intervals or the relative errors. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
The method is unknown, the level is not between 0 and 1, a noise level is not positive, a count is not a positive integer, there is no data, or a bound is not valid. |
ExperimentError
|
The system is a name. |
See Also
calibrate: Fits the parameters of a system to data.
Examples:
>>> from skcomplex.core.experiments import identifiability
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> trajectory = LogisticGrowthSystem(r=0.5).prepare().simulate(until=20, dt=1.0)
>>> data = {'population.x': (trajectory.times, trajectory.get_values('population.x'))}
>>> identifiability(LogisticGrowthSystem(), data, {'r': (0.1, 2.0), 'K': (50.0, 500.0)}).verdicts
{'r': 'identifiable', 'K': 'identifiable'}
Source code in src/skcomplex/core/experiments/_identifiability.py
213 214 215 216 217 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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
orbit_diagram(system, parameter, values, observable, *, transient, keep, dt=None, decimals=6, random_state=None, executor='serial', vectorized=False)
Return the values an observable visits after a transient, per parameter value.
It runs the system for every value of parameter to transient + (keep - 1) * dt and keeps the values of
observable from transient on, so a settled cycle shows as the few values it repeats. With vectorized, every
value runs as one member of a single simulation. It shows the period doubling of the logistic map of a population,
the route to chaos of a forced pendulum, and the pulses of a laser.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, or a factory of systems, such as a system class. |
required |
parameter
|
str
|
The parameter to sweep, a name |
required |
values
|
Sequence[float]
|
The values of the parameter. |
required |
observable
|
str
|
The state or observable path whose values are kept. |
required |
transient
|
float
|
The simulated time discarded before keeping values. |
required |
keep
|
int
|
The number of frames kept after the transient. |
required |
dt
|
float | None
|
The time between frames, or |
None
|
decimals
|
int
|
The decimals the kept values are rounded to before counting the period of every orbit. |
6
|
random_state
|
int | None
|
The seed of stochastic runs. |
None
|
executor
|
str | Executor
|
|
'serial'
|
vectorized
|
bool
|
Whether to run every value as a member of one simulation of the replicated system. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
OrbitDiagramResult
|
The kept values and the period of the orbit of every value of the parameter. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
No value is given, or the number of kept frames is not a positive integer. |
ExperimentError
|
The system is a name. |
See Also
basin_stability: Gives the share of initial states per final behaviour. sweep: Runs a system over values of its parameters.
Examples:
>>> from skcomplex.core.experiments import orbit_diagram
>>> from skcomplex.systems.mathematics.dynamical_systems import LogisticMapSystem
>>> diagram = orbit_diagram(LogisticMapSystem(), 'r', [2.9, 3.2], 'map.x', transient=1000, keep=20)
>>> diagram.periods.tolist()
[1, 2]
Source code in src/skcomplex/core/experiments/_orbit_diagram.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 | |
posterior_coverage(system, bounds, times, *, paths=None, method='mcmc', loss='likelihood', n=40, levels=(0.5, 0.9), noise=0.0, summary=None, n_samples=500, budget=None, chains=4, dt=None, solver=None, random_state=None, executor='serial')
Return how often the intervals of a sampling calibration hold the true values.
It draws n sets of true parameters from the priors that bounds give, simulates noisy data from each, calibrates
every data set, and counts how often the central interval of every level holds the true value. A sound method covers
the truth with its 90% interval in 90% of the data sets. It also ranks every true value among its samples, the check
of Talts et al. (2018). It is run before trusting a calibration of an epidemic, a climate model, or a chemical
reaction on real data.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, or a factory of systems. |
required |
bounds
|
Bounds
|
A pair |
required |
times
|
ArrayLike
|
The times of the simulated data. |
required |
paths
|
Sequence[str] | None
|
The state or observable paths of the data, or |
None
|
method
|
str
|
|
'mcmc'
|
loss
|
str
|
The loss of the method. |
'likelihood'
|
n
|
int
|
The number of true parameter vectors. |
40
|
levels
|
Sequence[float]
|
The levels of the central credible intervals, between 0 and 1. |
(0.5, 0.9)
|
noise
|
float
|
The standard deviation of the Gaussian noise added to the simulated data. |
0.0
|
summary
|
Summary | None
|
The summary statistics of ABC-SMC, or |
None
|
n_samples
|
int
|
The number of samples of every calibration, per chain for MCMC. |
500
|
budget
|
int | None
|
The budget of every calibration, or |
None
|
chains
|
int
|
The number of chains of MCMC. |
4
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
random_state
|
int | None
|
The seed of the true values, the noise, and the calibrations. |
None
|
executor
|
str | Executor
|
|
'serial'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
CoverageResult
|
The coverage by level and parameter, the ranks, the true values, and the calibrations. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
The method is not a posterior method, the loss does not fit it, a level is not between 0 and 1, |
See Also
calibrate: Fits the parameters of a system to data.
Examples:
>>> from skcomplex.core.experiments import posterior_coverage
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> settings = dict(method='variational', n=3, levels=(0.9,), noise=5.0, n_samples=100, budget=300)
>>> result = posterior_coverage(LogisticGrowthSystem(n=10.0), {'r': (0.5, 1.0)}, list(range(11)), **settings)
>>> result.ranks['r'].shape
(3,)
Source code in src/skcomplex/core/experiments/_coverage.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
sensitivity(system, bounds, *, output, method='sobol', n=None, until=None, dt=None, solver=None, observables=(), random_state=None, executor='serial')
Return the sensitivity of a scalar output of a system to its inputs, with SALib.
It varies the inputs within bounds, runs the system once per row of the design of the method, as sweep does, and
measures how much each input moves the last value of output. One at a time moves each input alone, Morris averages
many such moves, and Sobol splits the variance of the output among the inputs. It ranks the rates of an epidemic by
their effect on its peak, the inputs of a climate model by their effect on warming, and the costs of a supply chain
by their effect on profit.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, whose clones take parameters through |
required |
bounds
|
Bounds
|
A pair |
required |
output
|
str
|
The state or observable path whose last value is the scalar output. |
required |
method
|
str
|
|
'sobol'
|
n
|
int | None
|
The number of Morris trajectories or of base points of Saltelli's sample, or |
None
|
until
|
float | None
|
The end time of every run, or |
None
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
observables
|
Sequence[Observable]
|
The observables of every run, or none for the tuned ones. |
()
|
random_state
|
int | None
|
The seed of the design, of the runs, and of the bootstrap confidence intervals. |
None
|
executor
|
str | Executor
|
|
'serial'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
SensitivityResult
|
The inputs of every run, the outputs, the indices of the method, and the ranking of the inputs. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The method is unknown or the output is not a name. |
ValidationError
|
A bound is not a pair, or an input is no parameter of the system and no state or parameter of a component. |
See Also
sweep: Runs a system over values of its parameters.
Examples:
>>> from skcomplex.core.experiments import sensitivity
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> bounds = {'growth.r': (0.1, 1.0), 'growth.K': (50, 150)}
>>> result = sensitivity(LogisticGrowthSystem(), bounds, output='population.x', method='oat', until=20)
>>> result.ranking[0]
'growth.K'
Source code in src/skcomplex/core/experiments/_sensitivity.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
sweep(system, parameters, *, design='grid', n=64, replicates=1, analyses=None, until=None, dt=None, solver=None, outputs=None, warmup=0.0, observables=(), random_state=None, executor='serial')
Return the runs of a system over rows of values.
It runs a copy of the system for every row of values, as validation_curve of scikit-learn does, such as
sweep(system, {'r': [0.5, 1.0]}) for two growth rates. A name without a dot, such as r or the nested
growth__r, is set with set_params and the copy is prepared again, and a dotted path, such as population.x,
sets a value of a component on one prepared copy. The rows come from a grid or a random design, and the system
passed in is left unchanged. It maps the change of state of a magnet over temperature, the final size of an epidemic
over its rate of infection, and the clusters of opinions over the confidence of the voters.
Read more in the user guide, under Run experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, whose clones take parameters through |
required |
parameters
|
Bounds | Sequence[Mapping[str, object]]
|
What the design reads by name, or the rows to run. |
required |
design
|
str
|
The design of the rows. |
'grid'
|
n
|
int
|
The number of rows of a sampled design. |
64
|
replicates
|
int
|
The number of runs per row, each with its own random stream. |
1
|
analyses
|
Sequence[Callable[[Trajectory], object]] | None
|
The analyses of every run, functions of a trajectory that return a frozen result, such as analysis
functions bound with |
None
|
until
|
float | None
|
The end time of every run, or |
None
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
outputs
|
Sequence[Output] | None
|
The state and observable paths to keep as series, whose last values are scalar outputs, and functions of
a trajectory that return a scalar or a mapping of scalars. |
None
|
warmup
|
float
|
The simulated time before which kept series are discarded. |
0.0
|
observables
|
Sequence[Observable]
|
The observables of every run, or none for the tuned ones. |
()
|
random_state
|
int | None
|
The seed of the random streams, one per row and replicate. |
None
|
executor
|
str | Executor
|
|
'serial'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ExperimentResult
|
The results of every run, one tidy row per run. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
The design is unknown, the values do not fit it, a name is no parameter of the system and no state or parameter of a component, or a setting is not valid. |
ExperimentError
|
The system is a name, or the worker processes stop before finishing. |
See Also
ensemble: Runs a system many times with independent random streams. sensitivity: Ranks the inputs of a system by their effect on an output.
Examples:
>>> from skcomplex.core.experiments import sweep
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> result = sweep(LogisticGrowthSystem(), {'r': [0.5, 1.0]}, until=5, outputs=['population.x'])
>>> result.get_column('r').tolist()
[0.5, 1.0]
Source code in src/skcomplex/core/experiments/_sweep.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 | |
virtual_population(system, bounds, outputs, constraints, *, n=1000, target=None, design='random', until=None, dt=None, solver=None, random_state=None, executor='serial')
Return plausible parameter sets of a system, and those matching observed values.
It draws n rows of parameters from the priors that bounds give, runs the system once per row with sweep, and
keeps the rows whose outputs all lie in their constraints ranges. With target, the observed values of one
output, it picks among them with the chance of Allen et al. (2016), so the picked outputs follow the observed
spread. It samples virtual patients whose tumours look like those of a trial, economies whose growth lies in
historical ranges, and ecosystems whose populations stay within observed counts.
Read more in the user guide, under Calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemSource
|
The system, whose clones take the parameters through |
required |
bounds
|
Bounds
|
A mapping from model parameter or dotted path to its |
required |
outputs
|
Sequence[Output]
|
The outputs of every run, state and observable paths whose last values are the outputs, and functions of a trajectory that return a scalar, named by the function. |
required |
constraints
|
Mapping[str, Sequence[float]]
|
A mapping from output name to its plausible |
required |
n
|
int
|
The number of sampled rows. |
1000
|
target
|
Mapping[str, ArrayLike] | None
|
A mapping from one output name to its observed values, or |
None
|
design
|
str
|
|
'random'
|
until
|
float | None
|
The end time of every run, or |
None
|
dt
|
float | None
|
The time between frames, or |
None
|
solver
|
BaseSolver | None
|
The solver, or |
None
|
random_state
|
int | None
|
The seed of the rows, the runs, and the selection. |
None
|
executor
|
str | Executor
|
|
'serial'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
VirtualPopulationResult
|
The plausible rows, the acceptance rate, and the selected rows and their probabilities of inclusion. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
The design is not a sampled one, a constraint or the target names no output, a range is not increasing,
the target names more than one output, or |
ExperimentError
|
No row is plausible, or fewer than ten rows are plausible with a target. |
See Also
sweep: Runs a system over rows of values. calibrate: Fits the parameters of a system to data.
Examples:
>>> from skcomplex.core.experiments import virtual_population
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> bounds, ranges, system = {'r': (0.1, 1.0)}, {'population.x': (50.0, 100.0)}, LogisticGrowthSystem()
>>> result = virtual_population(system, bounds, list(ranges), ranges, n=20, until=5.0, random_state=0)
>>> result.acceptance
0.65
Source code in src/skcomplex/core/experiments/_virtual_population.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 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 | |