-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_scenario.R
71 lines (63 loc) · 3.16 KB
/
run_scenario.R
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
# function to run any scenario/model in parallel
run_scenario <- function(resolution,
model_type=c("structured", "unstructured", "unstructuredcov", "joint", "jointcov", "jointtwo"),
plotting=FALSE,
summary_results=FALSE,
nsamp = NULL,
seed = NULL,
dim = NULL,
lambda = NULL,
env.beta = NULL,
kappa = NULL,
sigma2x = NULL,
strata = NULL,
rows = NULL,
cols = NULL,
probs = NULL,
plot = FALSE,
plotdat = FALSE,
qsize = qsize,
rho = rho,
correlation = FALSE,
n_runs = NULL,
scenario_name = NULL,
parameter = NULL){
# run the model in a parallel loop
# create a cluster
cl = makeCluster(4)
registerDoParallel(cl)
strt = Sys.time() # record system time
model_output = foreach(i=1:n_runs,
.combine=c,
.multicombine = TRUE,
.packages=c("rgeos", "INLA", "reshape2", "fields"),
.errorhandling = 'pass') %dopar% {
source("run_function_multiple.R")
run_function_multiple(resolution=resolution,
model_type=model_type,
plotting=FALSE,
summary_results=TRUE,
nsamp = nsamp,
seed = seed[i],
dim = dim,
lambda = lambda,
env.beta = env.beta,
kappa = kappa,
sigma2x = sigma2x,
strata = strata,
rows = rows,
cols = cols,
probs = probs,
plot = FALSE,
plotdat = FALSE,
qsize = qsize,
rho = rho,
parameter = parameter,
correlation = correlation
)
}
# want to save the output named by the scenario and value
stopCluster(cl)
print(Sys.time()-strt)
save(model_output, file = paste(scenario_name, model_type, parameter, ".RData", sep=""))
}