Skip to content

Commit

Permalink
fix #55 -- MCPSCAD now working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tabpeter committed Apr 20, 2024
1 parent c58de94 commit 7ef6552
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
11 changes: 2 additions & 9 deletions inst/tinytest/test_biglasso_fit.r
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ fit1b <- biglasso_fit(X.bm, y, lambda = 0.05, xtx=xtx, r = resid,
fit2b <- ncvfit(X = X, y = y, lambda = 0.05, xtx = xtx, r = resid,
penalty = "MCP", max.iter = 10000)

tinytest::expect_equivalent(fit1b$resid, fit2b$resid, tolerance = 0.1)
tinytest::expect_equivalent(fit1b$beta, fit2b$beta, tolerance = 0.1)

# the tests below fail -- does this signal a problem?
tinytest::expect_equivalent(fit1b$resid, fit2b$resid, tolerance = 0.01)
tinytest::expect_equivalent(fit1b$beta, fit2b$beta, tolerance = 0.01)

Expand All @@ -49,12 +45,9 @@ fit1c <- biglasso_fit(X.bm, y, lambda = 0.05, xtx=xtx, r = resid,
fit2c <- ncvfit(X = X, y = y, lambda = 0.05, xtx = xtx, r = resid,
penalty = "SCAD", max.iter = 10000)

tinytest::expect_equivalent(fit1c$resid, fit2c$resid, tolerance = 0.1)
tinytest::expect_equivalent(fit1c$beta, fit2c$beta, tolerance = 0.1)

# the tests below fail -- does this signal a problem?
# tinytest::expect_equivalent(fit1c$resid, fit2c$resid, tolerance = 0.01)
# tinytest::expect_equivalent(fit1c$beta, fit2c$beta, tolerance = 0.01)
tinytest::expect_equivalent(fit1c$resid, fit2c$resid, tolerance = 0.01)
tinytest::expect_equivalent(fit1c$beta, fit2c$beta, tolerance = 0.01)

# Prostate data ------------------------------------------------------------
data("Prostate") # part of ncvreg
Expand Down
12 changes: 7 additions & 5 deletions src/gaussian_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ RcppExport SEXP cdfit_gaussian_simple(SEXP X_,
l2 = lambda * m[j] * (1-alpha);
// TODO: add SCAD and MCP to the below
// Rprintf("\nCalling lasso");
b[j] = lasso(z[j], l1, l2, xtx[j]);


if (strcmp(penalty,"MCP")==0) b[j] = MCP(z[j], l1, l2, gamma, xtx[j]);
if (strcmp(penalty,"SCAD")==0) b[j] = SCAD(z[j], l1, l2, gamma, xtx[j]);
if (strcmp(penalty,"lasso")==0) b[j] = lasso(z[j], l1, l2, xtx[j]);

// if something enters, update active set and residuals
if (b[j] != 0) {
ever_active[j] = 1;
Expand Down Expand Up @@ -343,8 +344,9 @@ RcppExport SEXP cdfit_gaussian_simple_path(SEXP X_,
l2 = lambda[l] * m[j] * (1-alpha);
// TODO: add SCAD and MCP to the below
// Rprintf("\nCalling lasso");
beta(j,l) = lasso(z[j], l1, l2, xtx[j]);

if (strcmp(penalty,"MCP")==0) beta(j,l) = MCP(z[j], l1, l2, gamma, xtx[j]);
if (strcmp(penalty,"SCAD")==0) beta(j,l) = SCAD(z[j], l1, l2, gamma, xtx[j]);
if (strcmp(penalty,"lasso")==0) beta(j,l) = lasso(z[j], l1, l2, xtx[j]);

// if something enters, update active set and residuals
if (beta(j,l) != 0) {
Expand Down

0 comments on commit 7ef6552

Please sign in to comment.