forked from epiforecasts/ringbp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameter_sweep.Rd
83 lines (68 loc) · 2.52 KB
/
parameter_sweep.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/parameter_sweep.R
\name{parameter_sweep}
\alias{parameter_sweep}
\title{Sweep across parameters}
\usage{
parameter_sweep(scenarios = NULL, samples = 1, sim_fn = NULL)
}
\arguments{
\item{scenarios}{A dataframe containing all gridded scenarios - see the examples for the required structure.
Defaults to NULL.}
\item{samples}{Numeric, defaults to 1. The number of samples to take.}
\item{sim_fn}{Function, defaults to NULL. The vectorised model simulation function - see the examples
for usage.}
}
\value{
A nested \code{data.table} containing the parameters for each scenario and a nested list of output
from \code{wuhan_sim}.
}
\description{
Explore scenarios using gridding with sampling for parameters not in the grid. Parameters that
are included in the grid are currently hard coded. Use the \code{future} package to control parallisation
outside of the function.
}
\examples{
\dontrun{
library(data.table)
scenarios <- data.table(expand.grid(
delay_group = list(data.table(
delay = c("SARS","Wuhan"),
delay_shape = c(1.651524,2.305172),
delay_scale = c(4.287786,9.483875)
)),
k_group = list(data.table(
theta = c("<1\%","15\%","30\%"),
k = c(1,0.88,0.47)
)),
index_R0 = c(1.5,2.5,3.5),
prop.asym = c(0, 0.1),
control_effectiveness = seq(0,1,0.2),
num.initial.cases = c(5,20,40))
list_cols <- grep("_group", colnames(scenarios), value = TRUE)
non_list_cols <- setdiff(colnames(scenarios), list_cols)
expanded_groups <- scenarios[, rbindlist(delay_group), by = c(non_list_cols)]
expanded_k <- scenarios[, rbindlist(k_group), by = c(non_list_cols)]
scenarios <- merge(
expanded_groups, expanded_k, by = non_list_cols, allow.cartesian = TRUE
)
scenarios[, scenario := 1:.N]
## Parameterise fixed paramters
sim_with_params <- purrr::partial(ringbp::scenario_sim,
cap_max_days = 365,
cap_cases = 5000,
r0isolated = 0,
disp.iso= 1,
disp.subclin = 0.16,
disp.com = 0.16,
quarantine = FALSE)
## Default is to run sequntially on a single core
future::plan("sequential")
## Set up multicore if using see ?future::plan for details
## Use the workers argument to control the number of cores used.
future::plan("multiprocess")
## Run paramter sweep
sweep_results <- ringbp::parameter_sweep(scenarios, sim_fn = sim_with_params, samples = 1)
sweep_results
}
}