View source: R/learn-gaussian-bipartite-pgd.R
learn_connected_bipartite_graph_pgd | R Documentation |
Laplacian matrix of a connected bipartite graph with Gaussian data
Computes the Laplacian matrix of a bipartite graph on the basis of an observed data matrix.
learn_connected_bipartite_graph_pgd( S, r, q, init = "naive", learning_rate = 1e-04, maxiter = 1000, reltol = 1e-05, verbose = TRUE, record_objective = FALSE, backtrack = TRUE )
S |
a p x p covariance matrix, where p is the number of nodes in the graph. |
r |
number of nodes in the objects set. |
q |
number of nodes in the classes set. |
init |
string denoting how to compute the initial graph. |
learning_rate |
gradient descent parameter. |
maxiter |
maximum number of iterations. |
reltol |
relative tolerance as a convergence criteria. |
verbose |
whether or not to show a progress bar during the iterations. |
record_objective |
whether or not to record the objective function value during iterations. |
backtrack |
whether or not to optimize the learning rate via backtracking. |
A list containing possibly the following elements:
|
estimated Laplacian matrix |
|
estimated adjacency matrix |
|
estimated graph weights matrix |
|
number of iterations taken to reach convergence |
|
boolean flag to indicate whether or not the optimization converged |
|
learning rate value per iteration |
|
objective function value per iteration |
|
time taken per iteration until convergence is reached |
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)) S <- cov(X) bipartite_graph <- learn_connected_bipartite_graph_pgd(S = S, r = r, q = q, verbose=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.