-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulate.R
100 lines (72 loc) · 2.92 KB
/
simulate.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#### Generate networks ####
# parallelise
cl <- makeCluster(18)
registerDoParallel(cl)
# make the networks
# 20, 50, 100, 200 nodes
# 2,4,6,8 dimensions
# unif, normal distribution and groups of 2,3,4
# use mle
# repeat 5 times each
rep <- 5
nodes_vec <- c(20, 50, 100, 200)
dim_vec <- c(2, 4, 6, 8)
set.seed(09101999)
start_time <- Sys.time()
simulation_unif <- foreach(i = 1:rep,
.packages = c("latentnet", "tidyverse",
"mvtnorm")) %dopar%
gen_fit_all(n = nodes_vec, dim = dim_vec,
distribution = "unif")
save(simulation_unif, file = "./simulations/simulation_unif.RData") # save
end_time <- Sys.time()
time_diff_unif <- end_time-start_time
set.seed(09101999)
start_time <- Sys.time()
simulation_normal <- foreach(i = 1:rep,
.packages = c("latentnet", "tidyverse",
"mvtnorm")) %dopar% gen_fit_all(
n = nodes_vec, dim = dim_vec,
distribution = "normal")
save(simulation_normal, file = "./simulations/simulation_normal.RData")
end_time <- Sys.time()
time_diff_normal <- end_time-start_time
set.seed(09101999)
start_time <- Sys.time()
simulation_groups2 <- foreach(i = 1:rep,
.packages = c("latentnet", "tidyverse",
"mvtnorm")) %dopar% gen_fit_all(
n = nodes_vec,
dim = dim_vec,
distribution = "groups",
n_groups = 2)
save(simulation_groups2, file = "./simulations/simulation_groups2.RData")
end_time <- Sys.time()
time_diff_groups2 <- end_time-start_time
set.seed(09101999)
start_time <- Sys.time()
simulation_groups3 <- foreach(i = 1:rep,
.packages = c("latentnet", "tidyverse",
"mvtnorm")) %dopar%
gen_fit_all(n = nodes_vec,
dim = dim_vec,
distribution = "groups", n_groups = 3)
save(simulation_groups3, file = "./simulations/simulation_groups3.RData")
end_time <- Sys.time()
time_diff_groups3 <- end_time-start_time
set.seed(09101999)
start_time <- Sys.time()
simulation_groups4 <- foreach(i = 1:rep,
.packages = c("latentnet", "tidyverse",
"mvtnorm")) %dopar% gen_fit_all(
n = nodes_vec, dim = dim_vec,
distribution = "groups", n_groups = 4)
save(simulation_groups4, file = "./simulations/simulation_groups4.RData")
end_time <- Sys.time()
time_diff_groups4 <- end_time-start_time
time_diff_unif
time_diff_normal
time_diff_groups2
time_diff_groups3
time_diff_groups4
stopCluster(cl)