-
Notifications
You must be signed in to change notification settings - Fork 4
/
benchmark.R
113 lines (89 loc) · 3.39 KB
/
benchmark.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
109
110
111
112
113
#' -----------------------------------------------------------------------------
#' Benchmarks individual inference methods with respect to runtime
#'
#' @author Johann Hawe <[email protected]>
#'
#' @date Thu Apr 8 07:43:53 2021
#' -----------------------------------------------------------------------------
log <- file(snakemake@log[[1]], open = "wt")
sink(log)
sink(log, type = "message")
# ------------------------------------------------------------------------------
print("Load libraries and source scripts")
# ------------------------------------------------------------------------------
library(microbenchmark)
# needed to simulate data
library(BDgraph)
source("scripts/lib.R")
source("scripts/reg_net.R")
source("scripts/reg_net_utils.R")
source("scripts/benchmark_methods.R")
threads <- snakemake@threads
RhpcBLASctl::omp_set_num_threads(1)
RhpcBLASctl::blas_set_num_threads(1)
simulation_number_of_nodes <-
as.numeric(snakemake@wildcards$number_nodes)
simulation_sample_size <-
as.numeric(snakemake@wildcards$sample_size)
benchmark_number_iterations <-
snakemake@params$benchmark_number_iterations
model <- snakemake@wildcards$model
# ------------------------------------------------------------------------------
print("Preparing benchmark input functions.")
# ------------------------------------------------------------------------------
benchmark_input <- list()
is_model_with_prior <-
ifelse(model %in% c("glasso", "bdgraph"),
TRUE, FALSE)
# only one where we can use priors but without 'no prior' version
if (model == "irafnet") {
benchmark_input[[model]] <-
quote(reg_net(s$data, s$priors, model,
threads = threads))
} else {
if (is_model_with_prior) {
benchmark_input[[paste0(model, "_priors")]] <-
quote(reg_net(s$data, s$priors, model,
threads = threads))
benchmark_input[[model]] <-
# we set 'use_gstart' in case it is bdgraph
quote(reg_net(
s$data,
NULL,
model,
use_gstart = F,
threads = threads
))
} else {
benchmark_input[[model]] <-
quote(reg_net(s$data, NULL, model,
threads = threads))
}
}
# ------------------------------------------------------------------------------
print("Performing benchmark.")
# ------------------------------------------------------------------------------
benchmark_results <- microbenchmark(
list = benchmark_input,
times = benchmark_number_iterations,
unit = "s",
setup = {
s <-
simulate_data(simulation_number_of_nodes,
simulation_sample_size)
}
)
# ------------------------------------------------------------------------------
print("Benchmark done. Finishing up.")
# ------------------------------------------------------------------------------
benchmark_results$sample_size <- simulation_sample_size
benchmark_results$number_of_nodes <- simulation_number_of_nodes
saveRDS(benchmark_results, file = snakemake@output$result_table)
# ------------------------------------------------------------------------------
print("Report warnings:")
# ------------------------------------------------------------------------------
warnings()
# ------------------------------------------------------------------------------
print("SessionInfo:")
# ------------------------------------------------------------------------------
devtools::session_info()