|
| 1 | +#' |
| 2 | +#' Sparsity Learning for Ising moDel rEconstruction (SLIDE) |
| 3 | +#' |
| 4 | +#' @inheritParams abess.default |
| 5 | +#' |
| 6 | +#' @param max.support.size The maximum node degree in the estimated graph. If prior information is available, we recommend setting this value accordingly. Otherwise, it is internally set to \eqn{n / (\log p \log \log n)} by default. |
| 7 | +#' @param graph.threshold A numeric value specifying the post-thresholding level for graph estimation. If prior knowledge about the minimum signal strength is available, this can be set to approximately half of that value. The default is \code{0.0}, which means no thresholding is applied. |
| 8 | +#' |
| 9 | +#' @return a sparse interaction matrix estimation |
| 10 | +#' @export |
| 11 | +#' @references Reconstruct Ising Model with Global Optimality via SLIDE. Xuanyu Chen, Jin Zhu, Junxian Zhu, Xueqin Wang, Heping Zhang (2025). Journal of the American Statistical Association (Accepted) |
| 12 | +#' |
| 13 | +#' @examples |
| 14 | +#' p <- 16 |
| 15 | +#' n <- 1e3 |
| 16 | +#' library(abess) |
| 17 | +#' train <- generate.bmn.data(n, p, type = 3, graph.seed = 1, seed = 1, beta = 0.4) |
| 18 | +#' res <- slide(train[["data"]], train[["weight"]], tune.type = "gic", |
| 19 | +#' max.support.size = rep(4, p), support.size = rep(4, p)) |
| 20 | +#' all((res[[1]] != 0) == (train[["theta"]] != 0)) |
| 21 | +#' |
| 22 | +slide <- function(x, weight = NULL, c.max = 8, max.support.size = NULL, tune.type = "cv", foldid = NULL, support.size = NULL, ic.scale = 1, graph.threshold = 0.0, newton = 'approx') |
| 23 | +{ |
| 24 | + p <- ncol(x) |
| 25 | + if (is.null(max.support.size)) { |
| 26 | + max.support.size <- min(c(p - 2, 100)) |
| 27 | + max.support.size <- rep(max.support.size, p) |
| 28 | + } |
| 29 | + if (is.null(foldid) && tune.type == "cv") { |
| 30 | + foldid <- c() |
| 31 | + nfolds <- 2 |
| 32 | + } else if (tune.type == "cv") { |
| 33 | + nfolds <- length(unique(foldid)) |
| 34 | + } else { |
| 35 | + nfolds <- 1 |
| 36 | + } |
| 37 | + |
| 38 | + theta <- matrix(0, p, p) |
| 39 | + for (node in 1:p) { |
| 40 | + init.active.set <- NULL |
| 41 | + selected_edge <- which(abs(theta[-node, node]) > 0) |
| 42 | + if (length(selected_edge) > 0) { |
| 43 | + init.active.set <- selected_edge |
| 44 | + } |
| 45 | + model_node <- |
| 46 | + abess::abess( |
| 47 | + x = x[, -node], |
| 48 | + y = x[, node], ## it would be convert to {0, 1} vector in the `abess` function |
| 49 | + weight = weight, |
| 50 | + family = "binomial", |
| 51 | + tune.path = "sequence", |
| 52 | + support.size = 0:max.support.size[node], |
| 53 | + tune.type = tune.type, |
| 54 | + normalize = 0, ## to facilitate the subsequently graphical thresholding |
| 55 | + init.active.set = init.active.set, |
| 56 | + ic.scale = ic.scale, |
| 57 | + nfolds = nfolds, |
| 58 | + foldid = foldid, |
| 59 | + c.max = as.integer(min(round(max.support.size[node] / 2), c.max)), |
| 60 | + max.splicing.iter = 100, |
| 61 | + newton = newton, |
| 62 | + newton.thresh = 1e-10, |
| 63 | + max.newton.iter = 100, |
| 64 | + num.threads = nfolds, |
| 65 | + seed = 1 |
| 66 | + ) |
| 67 | + if (is.null(support.size)) { |
| 68 | + est_theta_node <- as.vector(extract(model_node)[["beta"]]) |
| 69 | + } else { |
| 70 | + est_theta_node <- as.vector(extract(model_node, support.size = support.size[node])[["beta"]]) |
| 71 | + } |
| 72 | + theta[node, -node] <- est_theta_node |
| 73 | + } |
| 74 | + theta <- (t(theta) + theta) / 2 |
| 75 | + theta <- theta / 2 # convert the coefficient from {0, 1} to {-1, 1} |
| 76 | + |
| 77 | + if (graph.threshold > 0.0 && is.null(support.size)) { |
| 78 | + theta <- thres_bmn_est(theta, graph.threshold) |
| 79 | + } |
| 80 | + |
| 81 | + res_out <- list( |
| 82 | + omega = theta |
| 83 | + ) |
| 84 | + class(res_out) <- "abessbmn" |
| 85 | + res_out |
| 86 | +} |
| 87 | + |
| 88 | + |
| 89 | +thres_bmn_est <- function(theta, thres) { |
| 90 | + if (thres > 0) { |
| 91 | + theta[abs(theta) <= thres] <- 0 |
| 92 | + } else if (thres < 0) { |
| 93 | + theta_vec <- as.vector(theta) |
| 94 | + ## TODO: use finite mixture model to cluster |
| 95 | + } |
| 96 | + theta |
| 97 | +} |
0 commit comments