Provides methods for initializing the synthetic population, parallel simulation, calibration and monitoring.
new()Create a new Simulator object.
Simulator$new( initializer = NULL, acc_events = list(), man_events = list(), seeds = 123, keep_init = FALSE, ... )
initializerA function that generates the initial population.
acc_eventsA list of AccumulationEvent objects.
man_eventsA list of ManipulationEvent objects.
seedsSeed values for random number generation.
keep_initA logical value indicating whether the initial status should be stored.
If TRUE the initial population can be retrieved with the method get_init.
...Additional arguments to initializer,
A new Simulator object.
start_cluster()Start a parallel computation cluster.
Simulator$start_cluster( cl, nc, export, packages, interface = c("doParallel", "doMPI") )
clA cluster object.
ncSize of the cluster (available computing cores).
exportA character vector giving the names of objects from the global environment that should be exported to the workers.
packagesA character vector giving the names of packages that should be loaded on the workers.
interfaceInterface to "foreach", must match the cluster type ("doParallel" and "doMPI" are currently supported).
stop_cluster()Stop a parallel computation cluster.
Simulator$stop_cluster()
run()Progress the simulation.
Simulator$run(N, show_progress = TRUE)
NAn integer indicating the length of the simulation.
show_progressA logical value.
If TRUE shows a progress bar that tracks the completion of the simulation
(for non-parallel computations only)
unitA character string giving the time unit that t_sim corresponds to.
run_scenarios()Run various scenarios with the same initial population using different interventions with replications.
Simulator$run_scenarios( interventions, replications, N, seeds_override = NULL, output, ... )
interventionsA list of interventions corresponding to the scenarios to run, see 'details'.
replicationsAn integer describing how many times each scenario should be replicated.
NA single integer or an integer vector describing the simulation runtime for each scenario.
seeds_overrideIf NULL, a different seed is automatically used for each scenario.
If provided, should be an integer matrix with replications rows and length(interventions) columns.
outputA function to apply to the population after each scenario.
...Additional arguments passed to output.
Each element of interventions should be a named list with the following elements:
acc_events, acc_pars, man_events, man_pars and pars.
The element acc_events should be a list of objects of class AccumulationEvent and
acc_pars should be a list of the same length of numeric vectors giving the parameter values for these events.
Similarly, man_events should be a list of object of class ManipulationEvent with man_pars
being a list of the same length of numeric vectors giving the parameter values.
Finally, pars should be a list of parameter values (see configure).
For additional details, see intervene.
reconfigure()Configure the parameters of Event objects.
Simulator$reconfigure(pars)
parsA named list of parameters, see 'details'.
The parameter list pars should be structured as follows:
Each element should have a name of an Event object and each
element should be a named list where the names correspond
to the names of the parameters of whose values are to be configured.
configure()Configure events, run a simulation and compute a summary statistic for calibration. The original status is restored after completion.
Simulator$configure(N, pars, output, seeds = 123, ...)
NA numeric value indicating the length of the simulation
parsA list of parameter values, see 'details'.
outputA function that computes a summary statistic from the simulation.
seedsSeed values for random number generation.
...Additional arguments passed to output.
The parameter list pars should be structured as follows:
Each element should have a name of an Event object and each
element should be a named list where the names correspond
to the names of the parameters of whose values are to be configured.
The output of output_function evaluated for the resulting population.
intervene()Carry out an intervention that applies a set of accumulation events and manipulation events, and changes the values of specific parameters. By default, the events are applied first, then the parameters are changed.
acc_eventsA list of accumulation events to apply.
man_eventsA list of manipulation events to apply.
parsA list of parameter values to set, see 'details'.
events_firstA logical value. If TRUE (the default) then the events are applied before any changes to the parameters. If FALSE the parameter values are changed first.
The parameter list pars should be structured as follows:
Each element should have a name of an Event object and each
element should be a named list where the names correspond
to the names of the parameters of whose values are to be configured.
get_status()Get the status of the current population.
Simulator$get_status()
A data.table of the current status.
get_init()Get the initial status of the population, if available.
Simulator$get_init()
A data.table of the initial status if it was recorded, otherwise NULL.
get_sample(). Get a sample of the current population
Simulator$get_sample(sampler, ...)
samplerA function that constructs the output sample.
...Additional arguments passed to sampler.
The sample generated by sampler.
get_history()Get the simulation history as recorded by the monitor.
Simulator$get_history()
If the monitor is enabled, A list with an element for each evaluation of the monitor aggregators at their specified intervals These elements are lists as well, where the first element is the time index, and the remaining elements correspond to the values returned by the evaluated aggregators of the monitor. If no monitor is specified, returns NULL (invisibly).
initialize_monitor()Initialize monitors to track specific status variables throughout the simulation at certain intervals.
Simulator$initialize_monitor(aggregators, intervals, combiners = NULL)
aggregatorsA list of functions to compute aggregate summary statistics from the simulated population.
intervalsA numeric vector giving the time interval after which each aggregator should be evaluated.
combinersIf parallel computation is used, this is a list of functions that combine the aggregator results from each parallel worker.
reset()Reset the simulated population to the initial state (if initial status was kept). Note that any changes to event parameters are kept as is and have to be configured manually, if so desired.
Simulator$reset(force = FALSE, seeds = NULL)
forceIf TRUE, reset the simulator even if the initial status is not available.
seedsAn integer vector. If given, sets the pseudo-RNG seeds. This will then reset the seed numbers, and the simulation time.
clone()The objects of this class are cloneable with this method.
Simulator$clone(deep = FALSE)
deepWhether to make a deep clone.