Skip to content

Commit a814b67

Browse files
committed
maint: updates in preparation for submission to CRAN
1 parent c9f1e0c commit a814b67

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: spectralGraphTopology
22
Title: Learning Graphs from Data via Spectral Constraints
3-
Version: 0.1.3.9000
4-
Date: 2019-09-23
3+
Version: 0.1.4
4+
Date: 2019-10-07
55
Description: Block coordinate descent estimators to learn k-component, bipartite,
66
and k-component bipartite graphs from data by imposing spectral constraints
77
on the eigenvalues and eigenvectors of the Laplacian and adjacency matrices.

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Changes in spectralGraphTopology version 0.1.4 (2019-10-07)
2+
3+
* Added state of the art algorithms (CGL, GLE-MM, and GLE-ADMM) for learning connected graphs.
4+
15
## Changes in spectralGraphTopology version 0.1.1 (2019-05-31)
26

37
* Minor changes in the DESCRIPTION file to conform with CRAN.

R/combinatorialGraphLaplacian.R

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,34 @@
99
#' @param S sample covariance matrix
1010
#' @param A_mask binary adjacency matrix of the graph
1111
#' @param alpha L1-norm regularization hyperparameter
12-
#' @param prob_tol minimum relative error considered for the stopping criteri
12+
#' @param reltol minimum relative error considered for the stopping criteri
1313
#' @param max_cycle maximum number of cycles
14-
#' @param reg_type type of L1-norm regularization. If reg_type == 1, then all
14+
#' @param regtype type of L1-norm regularization. If reg_type == 1, then all
1515
#' elements of the Laplacian matrix will be regularized. If reg_type == 2,
16-
#' only the off-diagonal elements will be regularized.
16+
#' only the off-diagonal elements will be regularized
17+
#' @param record_objective whether or not to record the objective function value
18+
#' at every iteration. Default is FALSE
19+
#' @param verbose if TRUE, then a progress bar will be displayed in the console. Default is TRUE
1720
#' @return A list containing possibly the following elements
18-
#' \item{\code{Laplacian}}{the estimated Laplacian Matrix}
21+
#' \item{\code{Laplacian}}{estimated Laplacian Matrix}
1922
#' \item{\code{elapsed_time}}{elapsed time recorded at every iteration}
23+
#' \item{\code{frod_norm}}{relative Frobenius norm between consecutive estimates of the Laplacian matrix}
24+
#' \item{\code{convergence}}{whether or not the algorithm has converged within the tolerance and max number of iterations}
25+
#' \item{\code{obj_fun}}{objective function value at every iteration, in case record_objective = TRUE}
2026
#' @references H. E. Egilmez, E. Pavez and A. Ortega, "Graph Learning From Data
2127
#' Under Laplacian and Structural Constraints", in IEEE Journal of
2228
#' Selected Topics in Signal Processing, vol. 11, no. 6, pp. 825-841, Sept. 2017.
2329
#' Original MATLAB source code is available at: https://github.com/STAC-USC/Graph_Learning
2430
#' @export
25-
learn_combinatorial_graph_laplacian <- function(S, A_mask = NULL, alpha = 0, prob_tol = 1e-5,
31+
learn_combinatorial_graph_laplacian <- function(S, A_mask = NULL, alpha = 0, reltol = 1e-5,
2632
max_cycle = 10000, regtype = 1,
2733
record_objective = FALSE, verbose = TRUE) {
2834
n <- nrow(S)
2935
if (is.null(A_mask))
3036
A_mask <- matrix(1, n, n) - diag(n)
3137
e_v <- rep(1, n) / sqrt(n)
3238
dc_var <- t(e_v) %*% S %*% e_v
33-
isshifting <- c(abs(dc_var) < prob_tol)
39+
isshifting <- c(abs(dc_var) < reltol)
3440
if (isshifting) {
3541
S <- S + 1 / n
3642
}
@@ -111,16 +117,19 @@ learn_combinatorial_graph_laplacian <- function(S, A_mask = NULL, alpha = 0, pro
111117
time_seq <- c(time_seq, proc.time()[3] - start_time)
112118
frob_norm <- c(frob_norm, norm(O_old - O, 'F') / norm(O_old, "F"))
113119
if (i > 6) {
114-
if (frob_norm[i] < prob_tol) {
120+
if (frob_norm[i] < reltol) {
115121
O_best <- O
116122
C_best <- C
117123
break
118124
}
119125
}
120126
}
127+
if (i < max_cycle) has_converged = TRUE
128+
else has_converged = FALSE
121129
O <- O_best - (1 / n)
122130
C <- C_best - (1 / n)
123-
results <- list(Laplacian = O, frob_norm = frob_norm, elapsed_time = time_seq)
131+
results <- list(Laplacian = O, frob_norm = frob_norm,
132+
elapsed_time = time_seq, convergence = has_converged)
124133
if (record_objective)
125134
results$obj_fun <- fun
126135
return(results)

R/graphLaplacianEstimation.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ get_incidence_from_adjacency <- function(A) {
2222
#' @title Learn the weighted Laplacian matrix of a graph using the MM method
2323
#'
2424
#' @param S a pxp sample covariance/correlation matrix
25-
#' @param A the binary adjacency matrix of the graph
25+
#' @param A_mask the binary adjacency matrix of the graph
2626
#' @param alpha L1 regularization hyperparameter
2727
#' @param maxiter the maximum number of iterations
2828
#' @param reltol relative tolerance on the weight vector w
29-
#' @param abstol absolute tolerance on the weight vector w
3029
#' @param record_objective whether or not to record the objective function. Default is FALSE
3130
#' @param verbose if TRUE, then a progress bar will be displayed in the console. Default is TRUE
3231
#' @return A list containing possibly the following elements:
@@ -107,7 +106,7 @@ obj_func <- function(E, K, w, J) {
107106
#' @title Learn the weighted Laplacian matrix of a graph using the ADMM method
108107
#'
109108
#' @param S a pxp sample covariance/correlation matrix
110-
#' @param A the binary adjacency matrix of the graph
109+
#' @param A_mask the binary adjacency matrix of the graph
111110
#' @param alpha L1 regularization hyperparameter
112111
#' @param rho ADMM convergence rate hyperparameter
113112
#' @param maxiter the maximum number of iterations

tests/testthat/test-learnGraphTopology.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ with_parameters_test_that("we can recover a simple connected graph with the GLE-
2424
Y <- MASS::mvrnorm(n * 250, rep(0, n), MASS::ginv(Laplacian))
2525
res <- func(cov(Y), A_mask = A_mask, record_objective = TRUE, reltol = 1e-7)
2626
expect_true(res$convergence)
27-
expect_true(relative_error(Laplacian, res$Laplacian) < 1e-1)
28-
expect_true(metrics(Laplacian, res$Laplacian, 1e-1)[1] > .9)
27+
expect_true(relative_error(Laplacian, res$Laplacian) < 2e-1)
28+
expect_true(fscore(Laplacian, res$Laplacian, 1e-1) > .8)
2929
},
3030
cases(list(func = learn_laplacian_gle_mm),
31-
list(func = learn_laplacian_gle_admm))
31+
list(func = learn_laplacian_gle_admm),
32+
list(func = learn_combinatorial_graph_laplacian))
3233
)
3334

3435
test_that("learn_k_component_graph with diamond graph", {

0 commit comments

Comments
 (0)