Class Experiment
java.lang.Object
com.eco.bio7.simulation.Experiment
Runs a model several times without a display (batch runs): a sweep of the
parameters (all combinations of the given values), repetitions with other
seeds and a number of steps. The runs are computed in parallel threads (one
model for each run). The result is a table with a row for each recorded step
of each run: the run, the seed, the values of the swept parameters, the step,
the values of the line charts in this step (chart(...): the first chart by the
name of the series, other charts as "chart: series") and the values of
record(name, value).
Experiment.Table t = new Experiment(SheepWolvesField.class)
.param("growth", 0.02, 0.04, 0.06)
.param("wolves", 4, 8, 12)
.steps(500).repetitions(5).every(10)
.run();
t.save("experiment.csv"); // a file of the project (relative path) or an absolute path
t.toR("experiment"); // a data frame in R (if R runs)
The seed of repetition k is seed + k (the same seeds for all parameter
values: common random numbers). A run ends early if the model calls stop(). A model which sets its own seed in init()
(seed(...)) gets the same numbers in all repetitions. Models with static
fields which change should run in one thread (threads(1)).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe result of an experiment: a row for each recorded step of each run. -
Constructor Summary
ConstructorsConstructorDescriptionExperiment(Simulation model) An experiment with the class of a model: the parameters (Param fields) of this model are the start values of each run (e.g., the settings of the model in Bio7).Experiment(Class<? extends Simulation> model) An experiment with a model class (the parameters: the defaults of its fields). -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Stops the experiment (the runs which have started end after their current step).Given parameter sets instead of (or combined with) the sweep, e.g.every(int n) A row every n steps (default 1: each step; the step 0 and the last step are always recorded).The values of a parameter (a Param field or another field of the model) in the sweep.paramValues(String name, Object... values) The values of a parameter of any type (e.g., booleans or the options of a String).progress(BiConsumer<Integer, Integer> progress) Called after each run with the number of finished runs and of all runs (from the threads of the runs).repetitions(int repetitions) The number of runs for each combination of the parameters (default 1).run()Runs the experiment (blocks until all runs are finished) and returns the table.intruns()The number of runs (the combinations of the values times the repetitions).seed(int seed) The seed of the first repetition (default 42, the seed of the model in Bio7).steps(int steps) The number of steps of each run (default 100).threads(int n) The number of parallel threads (default: the processors - 1).static Object[]The values of a parameter from a text (e.g., of a dialog): "0.1, 0.2, 0.5", a range "0.1:0.5:0.1" (from:to:step) or "true, false".
-
Constructor Details
-
Experiment
An experiment with a model class (the parameters: the defaults of its fields). -
Experiment
An experiment with the class of a model: the parameters (Param fields) of this model are the start values of each run (e.g., the settings of the model in Bio7).
-
-
Method Details
-
param
The values of a parameter (a Param field or another field of the model) in the sweep. -
paramValues
The values of a parameter of any type (e.g., booleans or the options of a String). -
design
Given parameter sets instead of (or combined with) the sweep, e.g. a Latin hypercube or the samples of a sensitivity analysis (created in R or Python): the names of the parameters and a row of values for each set. Each row is run with the repetitions; the column "point" of the table is the row of the design (0, 1, ...). Values of int fields are rounded.new Experiment(NetworkEpidemic.class).design(new String[] { "infection", "recovery" }, new double[][] { { 0.02, 0.04 }, { 0.05, 0.03 }, { 0.08, 0.06 } }).repetitions(5).run(); -
steps
The number of steps of each run (default 100). -
repetitions
The number of runs for each combination of the parameters (default 1). -
seed
The seed of the first repetition (default 42, the seed of the model in Bio7). -
every
A row every n steps (default 1: each step; the step 0 and the last step are always recorded). -
threads
The number of parallel threads (default: the processors - 1). -
progress
Called after each run with the number of finished runs and of all runs (from the threads of the runs). -
cancel
public void cancel()Stops the experiment (the runs which have started end after their current step). -
runs
public int runs()The number of runs (the combinations of the values times the repetitions). -
run
Runs the experiment (blocks until all runs are finished) and returns the table.- Throws:
Exception
-
values
-