library(finbipartite)
library(igraph)
set.seed(42)
r <- 50
q <- 5
p <- r + q
bipartite <- sample_bipartite(r, q, type="Gnp", p = 1, directed=FALSE)
# randomly assign edge weights to connected nodes
E(bipartite)$weight <- 1
Lw <- as.matrix(laplacian_matrix(bipartite))
B <- -Lw[1:r, (r+1):p]
B[,] <- runif(length(B))
B <- B / rowSums(B)
# utils functions
from_B_to_laplacian <- function(B) {
A <- from_B_to_adjacency(B)
return(diag(rowSums(A)) - A)
}
from_B_to_adjacency <- function(B) {
r <- nrow(B)
q <- ncol(B)
zeros_rxr <- matrix(0, r, r)
zeros_qxq <- matrix(0, q, q)
return(rbind(cbind(zeros_rxr, B), cbind(t(B), zeros_qxq)))
}
Ltrue <- from_B_to_laplacian(B)
X <- MASS::mvrnorm(100*p, rep(0, p), MASS::ginv(Ltrue))
bipartite_graph <- learn_heavy_tail_kcomp_bipartite_graph(X = X,
r = r,
q = q,
k = 1,
nu = 1e2,
verbose=FALSE)
Run the code above in your browser using DataLab