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
Show file tree
Hide file tree
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
working BCD FISTA gram with weights
  • Loading branch information
PABannier committed Apr 25, 2022
commit 552485e2679a790f029f0191c3b4d4d8f72d5f45
6 changes: 3 additions & 3 deletions skglm/gram_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
alpha_max = norm(X.T @ y, ord=np.inf)

# Hyperparameters
max_iter = 1000
max_iter = 10_000
tol = 1e-8
reg = 0.1
group_size = 3
Expand Down Expand Up @@ -53,13 +53,13 @@
w = gram_group_lasso(X, y, alpha, group_size, max_iter, tol, weights=weights_grp)
gram_group_lasso_time = time() - start
start = time()
w_fista = gram_fista_group_lasso(X, y, alpha, group_size, max_iter, tol,
w_fista = gram_fista_group_lasso(X, y, alpha, group_size, max_iter, tol,
weights=weights_grp)
gram_fista_group_lasso_time = time() - start

np.testing.assert_allclose(w, w_fista, rtol=1e-4)

# clf_celer = GroupLasso(group_size, alpha, tol=tol, weights=weights_grp,
# clf_celer = GroupLasso(group_size, alpha, tol=tol, weights=weights_grp,
# fit_intercept=False)
# start = time()
# clf_celer.fit(X, y)
Expand Down
23 changes: 10 additions & 13 deletions skglm/solvers/gram.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def gram_fista_lasso(X, y, alpha, max_iter, tol, w_init=None, weights=None,

def gram_fista_group_lasso(X, y, alpha, groups, max_iter, tol, w_init=None,
weights=None, check_freq=50):
p_obj_prev = np.inf
n_features = X.shape[1]
norm_y2 = y @ y

grp_ptr, grp_indices = _grp_converter(groups, X.shape[1])
n_groups = len(grp_ptr) - 1
Expand All @@ -168,31 +168,28 @@ def gram_fista_group_lasso(X, y, alpha, groups, max_iter, tol, w_init=None,
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)
weights = weights if weights is not None else np.ones(n_groups)
# tiled_weights = np.repeat(weights, grp_size)

G = X.T @ X
Xty = X.T @ y

lipschitz = np.zeros(n_groups, dtype=X.dtype)
for g in range(n_groups):
X_g = X[:, grp_indices[grp_ptr[g]:grp_ptr[g + 1]]]
lipschitz[g] = norm(X_g, ord=2) ** 2 / len(y)
tiled_lipschitz = np.repeat(lipschitz[np.newaxis, :], grp_size)
L = np.linalg.norm(X, ord=2) ** 2 / len(y)

for n_iter in range(max_iter):
t_old = t_new
t_new = (1 + np.sqrt(1 + 4 * t_old ** 2)) / 2
w_old = w.copy()
z -= (G @ z - Xty) / tiled_lipschitz / len(y)
w = BST_vec(z, alpha / lipschitz, grp_size)
z -= (G @ z - Xty) / L / len(y)
w = BST_vec(z, alpha / L * weights, grp_size)
z = w + (t_old - 1.) / t_new * (w - w_old)

if n_iter % check_freq == 0:
p_obj = primal_grp(alpha, y, X, w, grp_ptr, grp_indices, np.ones(n_groups))
print(f"iter {n_iter} :: p_obj {p_obj:.5f}")
if p_obj_prev - p_obj < tol:
p_obj, d_obj, d_gap = dual_gap_grp(y, X, w, alpha, norm_y2, grp_ptr,
grp_indices, weights)
print(f"iter {n_iter} :: p_obj {p_obj:.5f} :: d_obj {d_obj:.5f} " +
f":: gap {d_gap:.5f}")
if d_gap < tol:
print("Convergence reached!")
break
p_obj_prev = p_obj
return w


Expand Down