From 9b702d154aec116d28cc516304b51bf5decf6bb3 Mon Sep 17 00:00:00 2001 From: Niclas Date: Wed, 1 Apr 2026 14:35:51 +0200 Subject: [PATCH] first version of building the network --- R/build_network.R | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 R/build_network.R diff --git a/R/build_network.R b/R/build_network.R new file mode 100644 index 0000000..772c7a1 --- /dev/null +++ b/R/build_network.R @@ -0,0 +1,31 @@ +source(here::here("R", "graphon_distribution.R")) + +compute_adj_matrix <- function( + X_matrix, + v, + a, + phi, + rho_n, + Fv = pnorm +) { + xi <- vapply(v, FUN = function(x){pgraphon(x, a, Fv, X_matrix)}, numeric(1)) + print(xi) + dim_adj <- length(v) + + rand_mat <- matrix(runif(dim_adj^2), dim_adj, dim_adj) + upper_mask <- upper.tri(rand_mat, diag=FALSE) + rand_mat[!upper_mask] <- 0 + rand_mat <- rand_mat + t(rand_mat) + diag(nrow=dim_adj) + graphon_function <- function(x,y) { rho_n * phi(x,y)} + probabilities <- outer(xi, xi, FUN=graphon_function) + + adj_mat <- (rand_mat < probabilities) * 1L +} + +set.seed(1) +X <- matrix(rnorm(4), nrow = 4, ncol=1) +a <- 0.5 +v <- rnorm(4) + +adj <- compute_adj_matrix(X, v, a, phi = function(x,y) {x * y}, 0.5) +adj