Skip to contents

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 class epiworld_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 by make_saver.

Details

Currently, the following elements can be saved:

  • total_hist History of the model (total numbers per time).

  • virus_info Information about viruses.

  • virus_hist Changes in viruses.

  • tool_info Information about tools.

  • tool_hist Changes in tools.

  • 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    975
#> 5       1    1        1    Infected     24
#> 6       1    1        1   Recovered      1
head(ans$reproductive)
#>   sim_num virus_id    virus source source_exposure_date rt
#> 1       1        0 COVID-19     67                   10  0
#> 2       1        0 COVID-19    981                    9  0
#> 3       1        0 COVID-19    880                    9  0
#> 4       1        0 COVID-19    673                    9  0
#> 5       1        0 COVID-19    452                    9  0
#> 6       1        0 COVID-19    913                    8  0

# Plotting
multi_sir <- run_multiple_get_results(model_sir)$total_hist
multi_sir <- multi_sir[multi_sir$date <= 20,]
plot(multi_sir)