-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulationsFunctions.R
108 lines (86 loc) · 3.51 KB
/
simulationsFunctions.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
101
102
103
104
105
106
107
108
# Written by Micha³ Makowski
# install.packages("glasso")
# install.packages("huge")
require(glasso)
require(huge)
require(tictoc)
source("measures.R")
createSimulationMatrix <- function(nVec = 150,
pVec = 200,
graphTypeVec = "cluster",
alphaVec = 0.05,
penalizeDiagonalVec = FALSE,
iterationsVec = 1000)
{
output <- expand.grid(nVec, pVec, graphTypeVec, alphaVec, penalizeDiagonalVec, iterationsVec,
KEEP.OUT.ATTRS = FALSE, stringsAsFactors = FALSE)
colnames(output) <- c("n", "p", "graphType", "alpha", "penalizeDiagonal", "iterations")
return(output)
}
simulations <- function(simulationMatrix,
graphParameters = NULL,
additionalMethods = NULL,
verbose = TRUE,
saveEach = FALSE,
saveAll = FALSE,
fileName = "")
{
tic("All")
ticFile <- paste0("./!02 Data/01 Binded/tic", fileName, ".txt")
specificDoCall <- function(x)
doCall("measures",
graphParameters = graphParameters, additionalMethods = additionalMethods, verbose = FALSE,
args = x)
if(verbose)
{
cat("Starting simulations\nnumber of setups = ", NROW(simulationMatrix),
"\nnumber of simulations = ", sum(simulationMatrix$iterations), ".\n")
progressBar <- txtProgressBar(min = 0, max = sum(simulationMatrix$iterations), style = 3)
setTxtProgressBar(progressBar, 0)
}
if(saveAll)
{
filenameAll <- paste0("AllSimulations", fileName, "@", format(Sys.time(), '%y_%m_%d@%H_%M'), "#",
NROW(simulationMatrix)*(3+NROW(additionalMethods)))
}
output <- list()
for(r in seq_len(NROW(simulationMatrix)))
{
ticName <- paste(simulationMatrix[r,], collapse = '_')
tic(ticName)
simResults <- specificDoCall(simulationMatrix[r,])
output[[r]] <- cbind(simResults, simulationMatrix[r,], row.names = NULL)
if(saveEach)
{
filename <- paste0("OneSimulation_",
# format(Sys.time(), '%y_%m_%d_%H_%M'),
paste(simulationMatrix[r,], collapse = '_'))
setup <- simulationMatrix[r,]
save(simResults, setup, additionalMethods, graphParameters,
file = paste0("./!02 Data/", filename, ".RData"))
}
if(saveAll)
{
tempOutput <- do.call("rbind", output)
save(tempOutput, additionalMethods, graphParameters,
file = paste0("./!02 Data/01 Binded/", filenameAll, ".RData"))
}
if(verbose)
setTxtProgressBar(progressBar, sum(simulationMatrix$iterations[1:r]))
toc(quiet = TRUE, log = TRUE)
write(tic.log()[[1]], file = ticFile, append = TRUE)
tic.clearlog()
}
if(verbose)
close(progressBar)
output <- do.call("rbind", output)
if(saveAll)
{
save(output, additionalMethods, graphParameters,
file = paste0("./!02 Data/01 Binded/", filenameAll, ".RData"))
}
toc(quiet = TRUE, log = TRUE)
write(tic.log()[[1]], file = ticFile, append = TRUE)
tic.clearlog()
return(output)
}