Skip to content

Commit 9220355

Browse files
authored
Merge pull request #553 from Mamba413/develop_graph
Develop graph
2 parents 145ff17 + 37189ca commit 9220355

21 files changed

+2351
-38
lines changed

R-package/DESCRIPTION

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: abess
22
Type: Package
33
Title: Fast Best Subset Selection
4-
Version: 0.4.10
5-
Date: 2025-04-05
4+
Version: 0.4.11
5+
Date: 2025-10-10
66
Authors@R: c(
77
person(given = "Jin", family = "Zhu", email = "zhuj37@mail2.sysu.edu.cn", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-8550-5822")),
88
person(given = "Zezhi", family = "Wang", email = "homura@mail.ustc.edu.cn", role = c("aut")),
@@ -18,8 +18,8 @@ Authors@R: c(
1818
person(given = "Xueqin", family = "Wang", email = "wangxq20@ustc.edu.cn", role = c("aut"), comment = c(ORCID = "0000-0001-5205-9950")),
1919
person("spectra contributors", role = c("cph"), comment = "Spectra implementation")
2020
)
21-
Maintainer: Jin Zhu <zhuj37@mail2.sysu.edu.cn>
22-
Description: Extremely efficient toolkit for solving the best subset selection problem <https://www.jmlr.org/papers/v23/21-1060.html>. This package is its R interface. The package implements and generalizes algorithms designed in <doi:10.1073/pnas.2014241117> that exploits a novel sequencing-and-splicing technique to guarantee exact support recovery and globally optimal solution in polynomial times for linear model. It also supports best subset selection for logistic regression, Poisson regression, Cox proportional hazard model, Gamma regression, multiple-response regression, multinomial logistic regression, ordinal regression, (sequential) principal component analysis, and robust principal component analysis. The other valuable features such as the best subset of group selection <doi:10.1287/ijoc.2022.1241> and sure independence screening <doi:10.1111/j.1467-9868.2008.00674.x> are also provided.
21+
Maintainer: Jin Zhu <zhuj1jqx@gmail.com>
22+
Description: Extremely efficient toolkit for solving the best subset selection problem <https://www.jmlr.org/papers/v23/21-1060.html>. This package is its R interface. The package implements and generalizes algorithms designed in <doi:10.1073/pnas.2014241117> that exploits a novel sequencing-and-splicing technique to guarantee exact support recovery and globally optimal solution in polynomial times for linear model. It also supports best subset selection for logistic regression, Poisson regression, Cox proportional hazard model, Gamma regression, multiple-response regression, multinomial logistic regression, ordinal regression, Ising model reconstruction <https://arxiv.org/abs/2310.09257>, (sequential) principal component analysis, and robust principal component analysis. The other valuable features such as the best subset of group selection <doi:10.1287/ijoc.2022.1241> and sure independence screening <doi:10.1111/j.1467-9868.2008.00674.x> are also provided.
2323
License: GPL (>= 3) | file LICENSE
2424
Encoding: UTF-8
2525
LazyData: true
@@ -28,11 +28,12 @@ Imports:
2828
Rcpp,
2929
MASS,
3030
methods,
31-
Matrix
31+
Matrix,
32+
igraph
3233
LinkingTo:
3334
Rcpp,
3435
RcppEigen
35-
RoxygenNote: 7.2.3
36+
RoxygenNote: 7.3.3
3637
Suggests:
3738
testthat,
3839
knitr,

R-package/NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ export(abess)
1818
export(abesspca)
1919
export(abessrpca)
2020
export(extract)
21+
export(generate.bmn.data)
2122
export(generate.data)
2223
export(generate.matrix)
2324
export(generate.spc.matrix)
25+
export(slide)
2426
import(Matrix)
2527
importFrom(MASS,cov.rob)
2628
importFrom(MASS,mvrnorm)

R-package/NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# abess 0.4.11
2+
* Add a new function `slide` that supports Ising model reconstruction
3+
* The maintainer's changed from <zhuj37@mail2.sysu.edu.cn> to <zhuj1jqx@gmail.com>.
4+
15
# abess 0.4.10
26
* Fix note in NOTE about possible bashisms.
37

R-package/R/abess.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ abess <- function(x, ...) UseMethod("abess")
7878
#' \code{3} for \code{"cox"}. Default is \code{normalize = NULL}.
7979
#' @param fit.intercept A boolean value indicating whether to fit an intercept.
8080
#' We assume the data has been centered if \code{fit.intercept = FALSE}.
81-
#' Default: \code{fit.intercept = FALSE}.
81+
#' Default: \code{fit.intercept = TRUE}.
8282
#' @param beta.low A single value specifying the lower bound of \eqn{\beta}. Default is \code{-.Machine$double.xmax}.
8383
#' @param beta.high A single value specifying the upper bound of \eqn{\beta}. Default is \code{.Machine$double.xmax}.
8484
#' @param c.max an integer splicing size. Default is: \code{c.max = 2}.

R-package/R/abessgraph.R

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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

Comments
 (0)