-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbenchmark_methods.R
64 lines (50 loc) · 1.92 KB
/
benchmark_methods.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
#' -----------------------------------------------------------------------------
#' Methods script for the benchmarking.
#'
#' @author Johann Hawe <[email protected]>
#'
#' @date Thu Apr 8 07:46:06 2021
#' -----------------------------------------------------------------------------
# ------------------------------------------------------------------------------
#' Creates a simulated data and prior matrix to be used for the benchmarking
#'
#' @param number_of_nodes The number of nodes to simulate
#' @param number_of_samples The number of samples to simulate
#'
#' @author Johann Hawe
#'
# ------------------------------------------------------------------------------
simulate_data <- function(number_of_nodes, number_of_samples) {
require(BDgraph)
node_names <- paste0("N", 1:number_of_nodes)
data <- BDgraph::bdgraph.sim(p=number_of_nodes,
n = number_of_samples,
graph = "scale-free")$data
colnames(data) <- node_names
priors <- create_random_prior_matrix(data)
colnames(priors) <- rownames(priors) <- node_names
return(list(data = data, priors = priors))
}
# ------------------------------------------------------------------------------
#' Method DESC
#'
#' @param
#' @param
#' @param
#' @param
#'
#' @author Johann Hawe
#'
# ------------------------------------------------------------------------------
create_random_prior_matrix <- function(data) {
number_of_nodes <- ncol(data)
PSEUDO_PRIOR <- 1e-7
priors <- matrix(PSEUDO_PRIOR, nrow=number_of_nodes, ncol=number_of_nodes)
# set random prior values
number_of_priors <- floor(runif(1) * number_of_nodes)
prior_indices <- sample(which(upper.tri(priors)), number_of_priors)
priors[prior_indices] <- runif(number_of_priors, PSEUDO_PRIOR, 1 - PSEUDO_PRIOR)
# make symmetric
priors[lower.tri(priors)] <- t(priors)[lower.tri(priors)]
return(priors)
}