Skip to content

Gram-based CD/BCD/FISTA solvers for (group)Lasso when n_samples >> n_features #4

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

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
FIX prox_L21 for variable size groups
  • Loading branch information
PABannier committed Apr 25, 2022
commit f7bda722b3ba079b5915cf59a8e7b76317614916
17 changes: 14 additions & 3 deletions skglm/solvers/gram.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from numpy.linalg import norm
from celer.homotopy import _grp_converter

from skglm.utils import BST, ST, BST_vec, ST_vec
from skglm.utils import BST, ST, ST_vec


@njit
Expand Down Expand Up @@ -109,6 +109,18 @@ def compute_lipschitz(X, y):
return lipschitz


@njit
def prox_l21(w, u, weights, grp_ptr, grp_indices):
n_groups = len(grp_ptr) - 1
out = w.copy()
for g in range(n_groups):
idx = grp_indices[grp_ptr[g]:grp_ptr[g + 1]]
grp_nrm = norm(w[idx], ord=2)
scaling = np.maximum(1 - u / grp_nrm * weights[g], 0)
out[idx] *= scaling
return out


def gram_lasso(X, y, alpha, max_iter, tol, w_init=None, weights=None, check_freq=100):
n_features = X.shape[1]
norm_y2 = y @ y
Expand Down Expand Up @@ -190,7 +202,6 @@ def gram_fista_group_lasso(X, y, alpha, groups, max_iter, tol, w_init=None,
norm_y2 = y @ y
grp_ptr, grp_indices = _grp_converter(groups, X.shape[1])
n_groups = len(grp_ptr) - 1
grp_size = n_features // n_groups
t_new = 1
w = w_init.copy() if w_init is not None else np.zeros(n_features)
z = w_init.copy() if w_init is not None else np.zeros(n_features)
Expand All @@ -203,7 +214,7 @@ def gram_fista_group_lasso(X, y, alpha, groups, max_iter, tol, w_init=None,
t_new = (1 + np.sqrt(1 + 4 * t_old ** 2)) / 2
w_old = w.copy()
z -= (G @ z - Xty) / L / len(y)
w = BST_vec(z, alpha / L * weights, grp_size)
w = prox_l21(z, alpha / L, weights, grp_ptr, grp_indices)
z = w + (t_old - 1.) / t_new * (w - w_old)
if n_iter % check_freq == 0:
p_obj, d_obj, d_gap = dual_gap_grp(y, X, w, alpha, norm_y2, grp_ptr,
Expand Down