Title: | The Sparse Latent Position Model for Nonnegative Interaction Data |
---|---|
Description: | Models the nonnegative entries of a rectangular adjacency matrix using a sparse latent position model, as illustrated in Rastelli, R. (2018) "The Sparse Latent Position Model for nonnegative weighted networks" <arXiv:1808.09262>. |
Authors: | Riccardo Rastelli [aut, cre] |
Maintainer: | Riccardo Rastelli <[email protected]> |
License: | GPL-3 |
Version: | 1.0 |
Built: | 2025-02-09 03:59:41 UTC |
Source: | https://github.com/cran/SparseLPM |
Models the nonnegative entries of a rectangular adjacency matrix using a sparse latent position model, as illustrated in Rastelli, R. (2018) "The Sparse Latent Position Model for nonnegative weighted networks" <arXiv:1808.09262>.
Riccardo Rastelli
Mantainer: Riccardo Rastelli <[email protected]>
Rastelli, R. (2018) "The Sparse Latent Position Model for nonnegative weighted networks", https://arxiv.org/abs/1808.09262
Evaluates the evidence lower bound for a given configuration of variational parameters.
slpm_elbo(X, var_pars, hyper_pars, verbose = F)
slpm_elbo(X, var_pars, hyper_pars, verbose = F)
X |
Rectangular adjacency matrix with non-negative entries. |
var_pars |
A list defining the variational parameters of the model. See Details for more specific indications. |
hyper_pars |
A list defining the hyperparameters of the model. The list should contain three vectors of length |
verbose |
|
The list var_pars
must contain:
M*K
matrix denoting the Gaussian means for senders.
N*K
matrix denoting the Gaussian means for receivers.
M*K
matrix denoting the Gaussian variances for senders.
N*K
matrix denoting the Gaussian variances for receivers.
M*N*K
array representing the soft clustering for the edges. This may be interpreted as the posterior probability that edge ij
is determined by the k
-th latent dimension.
K
dimensional vector containing the variational parameters for the mixing proportions. This may be interpreted as the importance of each latent dimension.
K
dimensional vector containing the shapes of the variational Gamma distributions associated to the precisions.
K
dimensional vector containing the rates of the variational Gamma distributions associated to the precisions.
computing_time |
Number of seconds required for the evaluation. |
elbo |
Value of the ELBO for the given variational parameters. |
set.seed(12345) M <- N <- 10 K <- 2 network <- slpm_gen(M = M, N = N, K = K) var_pars <- slpm_init(X = network$adj, K = K) hyper_pars <- list(delta = rep(1,K), a_gamma = rep(1,K), b_gamma = rep(1,K)) slpm_elbo(X = network$adj, var_pars = var_pars, hyper_pars = hyper_pars, verbose = FALSE)
set.seed(12345) M <- N <- 10 K <- 2 network <- slpm_gen(M = M, N = N, K = K) var_pars <- slpm_init(X = network$adj, K = K) hyper_pars <- list(delta = rep(1,K), a_gamma = rep(1,K), b_gamma = rep(1,K)) slpm_elbo(X = network$adj, var_pars = var_pars, hyper_pars = hyper_pars, verbose = FALSE)
Generates the adjacency matrix adj
of a SparseLPM by sampling both the data and model parameters from the posterior distribution.
slpm_gen(M, N, K, hyper_pars = NULL)
slpm_gen(M, N, K, hyper_pars = NULL)
M |
Number of rows of |
N |
Number of cols of |
K |
Number of latent dimensions of the SparseLPM. |
hyper_pars |
A list defining the hyperparameters of the model. If left as |
A list with components:
adj |
Generated adjacency matrix. |
U |
Generated latent positions for senders. |
V |
Generated latent positions for receivers. |
lambda |
Latent variables attached to each of the edges, selecting which dimension determines the edge probability. |
gamma |
Vector of the Gaussian precisions associated to the latent dimensions. |
set.seed(12345) network <- slpm_gen(M = 10, N = 8, K = 2)
set.seed(12345) network <- slpm_gen(M = 10, N = 8, K = 2)
Evaluates the expected adjacency matrix for a fitted SparseLPM.
slpm_gof(var_pars)
slpm_gof(var_pars)
var_pars |
A list defining the variational parameters of the model. See Details for more specific indications. |
The list var_pars
must contain:
M*K
matrix denoting the Gaussian means for senders.
N*K
matrix denoting the Gaussian means for receivers.
M*K
matrix denoting the Gaussian variances for senders.
N*K
matrix denoting the Gaussian variances for receivers.
M*N*K
array representing the soft clustering for the edges. This may be interpreted as the posterior probability that edge ij
is determined by the k
-th latent dimension.
K
dimensional vector containing the variational parameters for the mixing proportions. This may be interpreted as the importance of each of the latent dimensions.
K
dimensional vector containing the shapes of the variational Gamma distributions associated to the precisions.
K
dimensional vector containing the rates of the variational Gamma distributions associated to the precisions.
Note that this function only uses the alphas and the lambdas. Also, to avoid numerical instability, the lambdas are automatically pre-transformed into a hard partitioning using a Maximum A Posterior method.
An adjacency matrix with non-negative entries.
set.seed(12345) M <- N <- 10 K <- 2 fitted_var_pars <- list() fitted_var_pars$alpha_u_tilde = matrix(rnorm(M*K),M,K) fitted_var_pars$alpha_v_tilde = matrix(rnorm(N*K),N,K) fitted_var_pars$lambda_tilde = array(NA,c(M,N,K)) fitted_var_pars$lambda_tilde[,,1] = matrix(runif(M*N),M,N) fitted_var_pars$lambda_tilde[,,2] = 1-fitted_var_pars$lambda_tilde[,,1] expected_adj <- slpm_gof(fitted_var_pars)
set.seed(12345) M <- N <- 10 K <- 2 fitted_var_pars <- list() fitted_var_pars$alpha_u_tilde = matrix(rnorm(M*K),M,K) fitted_var_pars$alpha_v_tilde = matrix(rnorm(N*K),N,K) fitted_var_pars$lambda_tilde = array(NA,c(M,N,K)) fitted_var_pars$lambda_tilde[,,1] = matrix(runif(M*N),M,N) fitted_var_pars$lambda_tilde[,,2] = 1-fitted_var_pars$lambda_tilde[,,1] expected_adj <- slpm_gof(fitted_var_pars)
Initialises the variational parameters of a SparseLPM.
slpm_init(X, K, method = "random", threshold = 0.1, stdev = NULL)
slpm_init(X, K, method = "random", threshold = 0.1, stdev = NULL)
X |
Rectangular adjacency matrix with non-negative entries. |
K |
Number of latent dimensions of the SparseLPM. |
method |
The variational parameters are initialised at random. However, if |
threshold |
A small number added to each of the entries of |
stdev |
Standard deviation of the Gaussian used to generate the random latent positions. |
Returns a list of variational parameters that can be used as input for slpm_nga or slpm_elbo.
set.seed(12345) M <- N <- 10 K <- 2 network <- slpm_gen(M = M, N = N, K = K) var_pars_init <- slpm_init(X = network$adj, K = K)
set.seed(12345) M <- N <- 10 K <- 2 network <- slpm_gen(M = M, N = N, K = K) var_pars_init <- slpm_init(X = network$adj, K = K)
Runs a Natural Gradient Ascent algorithm to maximise the variational objective for a Sparse LPM.
slpm_nga(X, K, var_pars_init, hyper_pars = NULL, tol = 0.01, n_iter_max = 100000, natural_gradient = T, learning_rate_factor_up = 2, learning_rate_factor_down = 2, verbose = F)
slpm_nga(X, K, var_pars_init, hyper_pars = NULL, tol = 0.01, n_iter_max = 100000, natural_gradient = T, learning_rate_factor_up = 2, learning_rate_factor_down = 2, verbose = F)
X |
Rectangular adjacency matrix with non-negative entries. |
K |
The number of latent dimension of the model. |
var_pars_init |
List of variational parameters to be used as starting point for the optimisation. See Details for more specific indications. |
hyper_pars |
List defining the hyperparameters of the model. The list should contain three vectors of |
tol |
Positive number setting the stop condition: the algorithm stops if one entire iteration yields an increase in the objective function smaller than this value. |
n_iter_max |
Maximum number of iterations the algorithm should be run for. |
natural_gradient |
|
learning_rate_factor_up |
Before any natural gradient ascent update, the current step size is multiplied by this number to ensure that the algorithms tries new solutions which are relatively far from the current one. |
learning_rate_factor_down |
During any natural gradient ascent update, if a certain step size leads to a decrease in the objective function, then the step is divided by this number repeatedly until an increase is ensured. |
verbose |
|
var_pars
and var_pars_init
are lists with components:
M*K
matrix representing the Gaussian means for the latent positions of senders.
N*K
matrix representing the Gaussian means for the latent positions of receivers.
M*K
matrix representing the Gaussian variances for the latent positions of senders.
N*K
matrix representing the Gaussian variances for the latent positions of receivers.
M*N*K
array with entries corresponding to the posterior probabilities of assigning each edge to each latent dimension.
Vector of K
positive values representing the Dirichlet parameters generating the mixing proportions.
Vector of K
positive values corresponding to the shapes of the variational Gamma distribution on the precisions.
Vector of K
positive values corresponding to the rates of the variational Gamma distribution on the precisions.
A list with components:
computing_time |
Number of seconds required for the optimisation process. |
var_pars |
List containing the optimal values for the variational parameters. |
learning_rates_u |
Current step-size for the update of the variational parameters of each Gaussian distribution on the latent positions of senders. |
learning_rates_v |
Current step-size for the update of the variational parameters of each Gaussian distribution on the latent positions of receivers. |
elbo_values |
Values of the variational objective at the end of each of the iterations. |
elbo_init |
Value of the variational objective for the initial configuration. |
elbo_final |
Value of the variational objective for the optimal solution found. |
Rastelli, R. (2018) "The Sparse Latent Position Model for nonnegative weighted networks", https://arxiv.org/abs/1808.09262
set.seed(12345) network <- slpm_gen(M = 15, N = 10, K = 2) K <- 6 var_pars_init <- slpm_init(X = network$adj, K = K) res <- slpm_nga(X = network$adj, K = K, var_pars_init = var_pars_init)
set.seed(12345) network <- slpm_gen(M = 15, N = 10, K = 2) K <- 6 var_pars_init <- slpm_init(X = network$adj, K = K) res <- slpm_nga(X = network$adj, K = K, var_pars_init = var_pars_init)