|
9 | 9 | #' @param S sample covariance matrix |
10 | 10 | #' @param A_mask binary adjacency matrix of the graph |
11 | 11 | #' @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 |
13 | 13 | #' @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 |
15 | 15 | #' 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 |
17 | 20 | #' @return A list containing possibly the following elements |
18 | | -#' \item{\code{Laplacian}}{the estimated Laplacian Matrix} |
| 21 | +#' \item{\code{Laplacian}}{estimated Laplacian Matrix} |
19 | 22 | #' \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} |
20 | 26 | #' @references H. E. Egilmez, E. Pavez and A. Ortega, "Graph Learning From Data |
21 | 27 | #' Under Laplacian and Structural Constraints", in IEEE Journal of |
22 | 28 | #' Selected Topics in Signal Processing, vol. 11, no. 6, pp. 825-841, Sept. 2017. |
23 | 29 | #' Original MATLAB source code is available at: https://github.com/STAC-USC/Graph_Learning |
24 | 30 | #' @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, |
26 | 32 | max_cycle = 10000, regtype = 1, |
27 | 33 | record_objective = FALSE, verbose = TRUE) { |
28 | 34 | n <- nrow(S) |
29 | 35 | if (is.null(A_mask)) |
30 | 36 | A_mask <- matrix(1, n, n) - diag(n) |
31 | 37 | e_v <- rep(1, n) / sqrt(n) |
32 | 38 | dc_var <- t(e_v) %*% S %*% e_v |
33 | | - isshifting <- c(abs(dc_var) < prob_tol) |
| 39 | + isshifting <- c(abs(dc_var) < reltol) |
34 | 40 | if (isshifting) { |
35 | 41 | S <- S + 1 / n |
36 | 42 | } |
@@ -111,16 +117,19 @@ learn_combinatorial_graph_laplacian <- function(S, A_mask = NULL, alpha = 0, pro |
111 | 117 | time_seq <- c(time_seq, proc.time()[3] - start_time) |
112 | 118 | frob_norm <- c(frob_norm, norm(O_old - O, 'F') / norm(O_old, "F")) |
113 | 119 | if (i > 6) { |
114 | | - if (frob_norm[i] < prob_tol) { |
| 120 | + if (frob_norm[i] < reltol) { |
115 | 121 | O_best <- O |
116 | 122 | C_best <- C |
117 | 123 | break |
118 | 124 | } |
119 | 125 | } |
120 | 126 | } |
| 127 | + if (i < max_cycle) has_converged = TRUE |
| 128 | + else has_converged = FALSE |
121 | 129 | O <- O_best - (1 / n) |
122 | 130 | 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) |
124 | 133 | if (record_objective) |
125 | 134 | results$obj_fun <- fun |
126 | 135 | return(results) |
|
0 commit comments