From d77f0a9fad5c0fd855c8277b97fd0bf5118eb466 Mon Sep 17 00:00:00 2001 From: Michael Weylandt Date: Fri, 20 Aug 2021 14:15:53 -0500 Subject: [PATCH 1/3] Test new prox --- src/ExclusiveLasso.cpp | 63 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/src/ExclusiveLasso.cpp b/src/ExclusiveLasso.cpp index 3e543a4..f6ac262 100644 --- a/src/ExclusiveLasso.cpp +++ b/src/ExclusiveLasso.cpp @@ -55,13 +55,72 @@ double exclusive_lasso_penalty(const arma::vec& x, const arma::ivec& groups){ return ans / 2.0; } -// [[Rcpp::export]] +arma::vec exclusive_lasso_new_prox_inner(const arma::vec& z, + const arma::ivec& groups, + double lambda){ + + arma::uword p = z.n_elem; + arma::vec beta(p); + + // TODO -- parallelize? + // Loop over groups + for(arma::sword g = arma::min(groups); g <= arma::max(groups); g++){ + // Identify elements in group + arma::uvec g_ix = arma::find(g == groups); + int g_n_elem = g_ix.n_elem; + + arma::vec z_g = z(g_ix); + arma::uvec z_g_sort_ix = arma::sort_index(z_g, "descend"); + arma::vec z_g_sorted = arma::sort(z_g, "descend"); + + arma::vec s = arma::cumsum(z_g_sorted); + arma::vec L = arma::regspace(1, g_n_elem); + // Remove the factor of 2 here and in beta_g to match our other scaling + arma::vec alpha = s / (1 + lambda * L); + double alpha_bar = arma::max(alpha); + + arma::vec beta_g = (z_g - lambda * alpha_bar); + beta_g = beta_g % (beta_g >= 0); + + beta(g_ix) = beta_g; + } + return beta; +} + + +//[[Rcpp::export]] arma::vec exclusive_lasso_prox(const arma::vec& z, - const arma::ivec& groups, + const arma::ivec groups, double lambda, const arma::vec& lower_bound, const arma::vec& upper_bound, double thresh=1e-7){ + bool apply_box_constraints = arma::any(lower_bound != -EXLASSO_INF) || arma::all(upper_bound != EXLASSO_INF); + + if(apply_box_constraints){ + Rcpp::stop("Box constraints not yet supported in new prox."); + } + + arma::vec result = arma::sign(z) % exclusive_lasso_new_prox_inner(arma::abs(z), groups, lambda); + + for(int i=0; i Date: Fri, 20 Aug 2021 15:35:02 -0500 Subject: [PATCH 2/3] Update build --- .github/workflows/check.yml | 6 +++--- DESCRIPTION | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 52b8cbb..e52f3db 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -19,10 +19,10 @@ jobs: fail-fast: false matrix: config: - - {os: windows-latest, r: '3.6'} - - {os: macOS-latest, r: '3.6'} + - {os: windows-latest, r: '4.0'} + - {os: macOS-latest, r: '4.0'} - {os: macOS-latest, r: 'devel'} - - {os: ubuntu-16.04, r: '3.6', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"} + - {os: ubuntu-20.04, r: '4.0', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true diff --git a/DESCRIPTION b/DESCRIPTION index 7fbc23c..4276e14 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,7 @@ Description: Fit Generalized Linear Models ("GLMs") using the "Exclusive Lasso" License: GPL (>= 2) Imports: Rcpp (>= 0.12.12), Matrix, RColorBrewer, foreach LinkingTo: Rcpp, RcppArmadillo (>= 0.8.300.1.0) -Suggests: testthat, knitr, microbenchmark, glmnet, ncvreg, grpreg, covr, nnls +Suggests: testthat, knitr, microbenchmark, glmnet, ncvreg, grpreg, covr, nnls, rmarkdown VignetteBuilder: knitr BugReports: https://github.com/DataSlingers/ExclusiveLasso/issues URL: https://github.com/DataSlingers/ExclusiveLasso From 80e0663436f39e3cc1c9938fad0dbdb7942f6eb1 Mon Sep 17 00:00:00 2001 From: Michael Weylandt Date: Fri, 20 Aug 2021 17:04:58 -0500 Subject: [PATCH 3/3] Fall back to CD for prox + box constraints --- src/ExclusiveLasso.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExclusiveLasso.cpp b/src/ExclusiveLasso.cpp index f6ac262..9b713aa 100644 --- a/src/ExclusiveLasso.cpp +++ b/src/ExclusiveLasso.cpp @@ -98,7 +98,7 @@ arma::vec exclusive_lasso_prox(const arma::vec& z, bool apply_box_constraints = arma::any(lower_bound != -EXLASSO_INF) || arma::all(upper_bound != EXLASSO_INF); if(apply_box_constraints){ - Rcpp::stop("Box constraints not yet supported in new prox."); + return exclusive_lasso_prox_old(z, groups, lambda, lower_bound, upper_bound, thresh); } arma::vec result = arma::sign(z) % exclusive_lasso_new_prox_inner(arma::abs(z), groups, lambda);