implement factory pattern

This commit is contained in:
Niclas
2026-08-14 18:03:39 +02:00
parent 37d9682e27
commit f3c6aac782
6 changed files with 495 additions and 23 deletions
+6 -6
View File
@@ -7,9 +7,9 @@ source(here::here("R", "build_network.R"))
# Helper functions -------------------------------------------------------------
# helper function for wrapping the parameters of the Q_a creation function
# TODO rename this function
make_matrix_creation <- function(seed, n, K, matrix_X, fv, Fv, guard, fX=NULL) {
make_matrix_creation <- function(seed, n, K, matrix_X, Fv, guard, fX=NULL) {
function(a) {
compute_matrix(seed=seed, a, n=n, K=K, matrix_X = matrix_X, fv=fv, Fv=Fv, guard=guard, fX=fX)
compute_matrix(seed=seed, a, n=n, K=K, matrix_X = matrix_X, Fv=Fv, guard=guard, fX=fX)
}
}
@@ -200,7 +200,7 @@ calculate_edge_density <- function(adj_matrix) {
return(rho)
}
# test the estimator routines
seed <- 121L # 121L this seed works exceptionally well
seed <- 141 # 121L this seed works exceptionally well
set.seed(seed)
#X <- matrix(seq(-1, 1, length.out = 5), ncol = 1)
a <- 20
@@ -225,9 +225,9 @@ adj <- compute_adj_matrix(
adj
# Q_a matrix
Qa <- compute_matrix(seed, a=a, n=n, K=K, fv=fv, Fv=Fv, guard=guard, matrix_X=X)
Qa2 <- compute_matrix(seed, a=a, n=n, K=K, fv=fv, Fv=Fv, guard=guard, matrix_X =X, fX= dnorm)
calc_Q_a <- make_matrix_creation(seed, n=n, K=K, matrix_X = X, fv=fv, Fv=Fv, guard=guard, fX=dnorm)
Qa <- compute_matrix(seed, a=a, n=n, K=K, Fv=Fv, guard=guard, matrix_X=X)
Qa2 <- compute_matrix(seed, a=a, n=n, K=K, Fv=Fv, guard=guard, matrix_X =X, fX= dnorm)
calc_Q_a <- make_matrix_creation(seed, n=n, K=K, matrix_X = X, Fv=Fv, guard=guard, fX=dnorm)
loss_func <- function(a) {
Q_a <- calc_Q_a(a)