Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST add sparse group lasso testing against GSROPTIM #268

Open
mathurinm opened this issue Jul 14, 2024 · 1 comment
Open

TST add sparse group lasso testing against GSROPTIM #268

mathurinm opened this issue Jul 14, 2024 · 1 comment
Labels
good first issue Good for newcomers

Comments

@mathurinm
Copy link
Collaborator

for the record, if one want s to compare against gsrpotim (by Eugene Ndiaye), here's a script showing that we get the same results:

from skglm.utils.data import make_correlated_data
from skglm.datafits import QuadraticGroup
from skglm.penalties import WeightedL1GroupL2
from skglm import GeneralizedLinearEstimator
from skglm.utils.data import (make_correlated_data, grp_converter)
from skglm.solvers import GroupBCD

from gsroptim.sgl import sgl_path


import numpy as np

n_features = 30
n_samples= 40
X, y, _ = make_correlated_data(n_features=n_features, n_samples=n_samples, random_state=0)

grp_indices, grp_ptr = grp_converter(3, n_features)
n_groups = len(grp_ptr) - 1

alpha = 0.1
weights_g = np.ones(n_groups, dtype=np.float64)
# beware of tau in GSR optim implem: need to scale alpha by 2
res = sgl_path(X, y, size_groups=[3] * n_groups, lambdas=[alpha*2 * n_samples], omega=weights_g)[0]

weights_f = 1. * np.ones(n_features)
pen = WeightedL1GroupL2(
    alpha=alpha, weights_groups=weights_g,
    weights_features=weights_f, grp_indices=grp_indices, grp_ptr=grp_ptr)

solver = GroupBCD(ws_strategy="fixpoint", verbose=3,
                    fit_intercept=False, tol=1e-10)

model = GeneralizedLinearEstimator(
    QuadraticGroup(grp_ptr, grp_indices), pen, solver=solver)

model.fit(X, y)
print(model.coef_.reshape([-1, 3]))
print(res.reshape([-1, 3]))

gsroptim requires a bit of work to install on the CI but it's doable

@mathurinm
Copy link
Collaborator Author

@wassimmazouz maybe you can have a look
install gsrtopim in the test requirement of pyproject.tom by adding "gsroptim@git+https://github.com/EugeneNdiaye/Gap_Safe_Rules/" to the list of requirements for test
then one needs to install Cython I reckon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant