The run_multiple
function allows running multiple simulations at once.
When available, users can take advantage of parallel computing to speed up
the process.
Usage
run_multiple(
m,
ndays,
nsims,
seed = sample.int(10000, 1),
saver = make_saver(),
reset = TRUE,
verbose = TRUE,
nthreads = 1L
)
run_multiple_get_results(m)
make_saver(..., fn = "")
Arguments
- m, ndays, seed
See run.
- nsims
Integer. Number of replicats
- saver
An object of class epiworld_saver.
- reset
When
TRUE
(default,) resets the simulation.- verbose
When
TRUE
(default,) prints a progress bar.- nthreads
Integer. Number of threads (parallel computing.)
- ...
List of strings (characters) specifying what to save (see details).
- fn
A file name pattern.
Value
In the case of
make_saver
, an list of classepiworld_saver
.
The
run_multiple
function runs a specified number of simulations and returns a model object of class epiworld_model.
The
run_multiple_get_results
function returns a named list with the data specified bymake_saver
.
Details
Currently, the following elements can be saved:
total_hist
History of the model (total numbers per time).virus_info
Information aboutviruses
.virus_hist
Changes inviruses
.tool_info
Information abouttools
.tool_hist
Changes intools
.transmission
Transmission events.transition
Transition matrices.reproductive
Reproductive number.generation
Estimation of generation time.
Examples
model_sir <- ModelSIRCONN(
name = "COVID-19",
prevalence = 0.01,
n = 1000,
contact_rate = 2,
transmission_rate = 0.9, recovery_rate = 0.1
)
# Generating a saver
saver <- make_saver("total_hist", "reproductive")
# Running and printing
run_multiple(model_sir, ndays = 100, nsims = 50, saver = saver, nthreads = 2)
#> Starting multiple runs (50) using 2 thread(s)
#> _________________________________________________________________________
#> _________________________________________________________________________
#> ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> done.
# Retrieving the results
ans <- run_multiple_get_results(model_sir)
head(ans$total_hist)
#> sim_num date nviruses state counts
#> 1 1 0 1 Susceptible 990
#> 2 1 0 1 Infected 10
#> 3 1 0 1 Recovered 0
#> 4 1 1 1 Susceptible 981
#> 5 1 1 1 Infected 18
#> 6 1 1 1 Recovered 1
head(ans$reproductive)
#> sim_num virus_id virus source source_exposure_date rt
#> 1 1 0 COVID-19 519 10 0
#> 2 1 0 COVID-19 152 9 0
#> 3 1 0 COVID-19 949 8 0
#> 4 1 0 COVID-19 921 8 0
#> 5 1 0 COVID-19 855 8 0
#> 6 1 0 COVID-19 816 8 0
# Plotting
multi_sir <- run_multiple_get_results(model_sir)$total_hist
multi_sir <- multi_sir[multi_sir$date <= 20, ]
plot(multi_sir)