Skip to content

[WIP] cd_fast speedup #15931

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
14 changes: 5 additions & 9 deletions sklearn/linear_model/_cd_fast.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,18 @@ def enet_coordinate_descent(floating[::1] w,

w_ii = w[ii] # Store previous value

if w_ii != 0.0:
# R += w_ii * X[:,ii]
_axpy(n_samples, w_ii, &X[0, ii], 1, &R[0], 1)

# tmp = (X[:,ii]*R).sum()
tmp = _dot(n_samples, &X[0, ii], 1, &R[0], 1)
# tmp = (X[:,ii]*R).sum() + w_ii * norm_cols_X[ii]
tmp = _dot(n_samples, &X[0, ii], 1, &R[0], 1) + w_ii * norm_cols_X[ii]

if positive and tmp < 0:
w[ii] = 0.0
else:
w[ii] = (fsign(tmp) * fmax(fabs(tmp) - alpha, 0)
/ (norm_cols_X[ii] + beta))

if w[ii] != 0.0:
# R -= w[ii] * X[:,ii] # Update residual
_axpy(n_samples, -w[ii], &X[0, ii], 1, &R[0], 1)
if (w_ii - w[ii]) != 0.0:
# R += (w_ii - w[ii]) * X[:,ii] # Update residual
_axpy(n_samples, w_ii - w[ii], &X[0, ii], 1, &R[0], 1)

# update the maximum absolute coefficient update
d_w_ii = fabs(w[ii] - w_ii)
Expand Down