Skip to content
Draft
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3232c37
Fix bug in glmnet solver
jolars Nov 30, 2021
df67ce6
add debug script
mathurinm Dec 1, 2021
6aa76de
add computation of objective functions
mathurinm Dec 1, 2021
47ed265
test that for lambda just below lambda max both solutions are non zero
mathurinm Dec 1, 2021
4d24648
Drop unnecessary computation of lambda_max
jolars Dec 1, 2021
fed8fa4
Harmonize lambda scaling for glmnet solver
jolars Dec 1, 2021
93f5a40
Merge branch 'main' of github.com:jolars/benchmark_lasso
jolars Dec 1, 2021
790607a
Switch benchopt method to use tolerance instead
jolars Dec 6, 2021
8f947d8
tweaks to test_glmnet
mathurinm Dec 6, 2021
1be208a
change glmnet criterion to use a higher patience
mathurinm Dec 6, 2021
46f6f04
faster tol decrease for glmnet, try to have common initial point
mathurinm Dec 7, 2021
68a379c
increase patience again
mathurinm Dec 7, 2021
c57994d
get common starting point, comment code
mathurinm Dec 8, 2021
43723de
CLN remove test_glmnet.py
mathurinm Dec 8, 2021
5fa72e9
more comments on glmnet behavior
mathurinm Dec 8, 2021
96e5292
Update solvers/glmnet.py
tomMoral Dec 9, 2021
f182a0b
Merge branch 'main' of github.com:benchopt/benchmark_lasso
jolars Apr 12, 2022
749dacf
Merge branch 'main' of github.com:benchopt/benchmark_lasso
jolars Apr 22, 2022
e9da0b3
Merge branch 'main' of github.com:benchopt/benchmark_lasso
jolars May 11, 2022
a721f82
Merge branch 'main' of github.com:benchopt/benchmark_lasso
jolars May 12, 2022
704f1ea
fix(ci): try to fix failing MacOS julia tests
jolars May 12, 2022
5670ac5
Merge branch 'main' of github.com:benchopt/benchmark_lasso
jolars May 17, 2022
227a574
Merge branch 'main' of github.com:benchopt/benchmark_lasso
jolars May 18, 2022
3e1e936
Merge branch 'main' of github.com:benchopt/benchmark_lasso into ncvreg
jolars May 20, 2022
d4bb5a1
ENH add support for ncvreg
jolars May 20, 2022
0f01922
FIX break arguments of function to appease linter
jolars May 20, 2022
75e9b80
Revert "fix(ci): try to fix failing MacOS julia tests"
jolars May 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions solvers/ncvreg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from benchopt import BaseSolver, safe_import_context

with safe_import_context() as import_ctx:
import numpy as np
from benchopt.helpers.r_lang import import_rpackages
from rpy2 import robjects
from rpy2.robjects import numpy2ri
from scipy import sparse

# Setup the system to allow rpy2 running
numpy2ri.activate()
import_rpackages("ncvreg")


class Solver(BaseSolver):
name = "ncvreg"

install_cmd = "conda"
requirements = ["r-base", "rpy2", "r-ncvreg"]
references = [
'P. Breheny and J. Huang, "Coordinate descent algorithms for nonconvex'
"penalized regression, with applications to biological feature"
'selection," The Annals of Applied Statistics, vol. 5, no. 1, pp.'
"232–253, Mar. 2011, doi: 10.1214/10-AOAS388."
]

def set_objective(self, X, y, lmbd, fit_intercept):
self.lmbd = lmbd
self.fit_intercept = fit_intercept
self.n, self.p = X.shape

penalty_factor = np.ones(self.p)

# NOTE(jolars): To fit the intercept, we add a column of ones at the
# end of X and set its penalty factor to zero.
self.X = X

if self.fit_intercept:
X = np.hstack((X, np.ones((self.n, 1))))
penalty_factor = np.hstack((penalty_factor, np.array([0.0])))

self.penalty_factor = robjects.vectors.FloatVector(penalty_factor)

self.Xmod = robjects.r.matrix(X, X.shape[0], X.shape[1])
self.y = robjects.vectors.FloatVector(y)

# Standardization of X cannot be turned off in standard interface to
# ncvreg, so we have to use ncvfit directly instead
self.ncvfit = robjects.r["ncvfit"]

def skip(self, X, y, lmbd, fit_intercept):
if sparse.issparse(X):
return True, "ncvreg does not support sparse X"

return False, None

def run(self, n_iter):
fit_dict = {
"max.iter": n_iter,
"lambda": self.lmbd / self.n,
"penalty.factor": self.penalty_factor,
}

self.fit = self.ncvfit(
self.Xmod,
self.y,
penalty="lasso",
eps=1e-15,
**fit_dict
)

def get_result(self):
results = dict(zip(self.fit.names, list(self.fit)))

return results["beta"]