Skip to content

FIX - add alpha to SLOPE penalty #316

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

Merged
merged 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions skglm/penalties/non_separable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class SLOPE(BasePenalty):
Contain regularization levels for every feature.
When ``alphas`` contain a single unique value, ``SLOPE``
is equivalent to the ``L1``penalty.
alpha : float, default=1.0
Scaling factor for the penalty. `alphas` is multiplied by this value.

References
----------
Expand All @@ -23,24 +25,26 @@ class SLOPE(BasePenalty):
https://doi.org/10.1214/15-AOAS842
"""

def __init__(self, alphas):
def __init__(self, alphas, alpha=1):
self.alphas = alphas
self.alpha = alpha

def get_spec(self):
spec = (
('alpha', float64),
('alphas', float64[:]),
)
return spec

def params_to_dict(self):
return dict(alphas=self.alphas)
return dict(alphas=self.alphas, alpha=self.alpha)

def value(self, w):
"""Compute the value of SLOPE at w."""
return np.sum(np.sort(np.abs(w)) * self.alphas[::-1])
return np.sum(np.sort(np.abs(w)) * self.alphas[::-1] * self.alpha)

def prox_vec(self, x, stepsize):
alphas = self.alphas
alphas = self.alphas * self.alpha
prox = np.zeros_like(x)

abs_x = np.abs(x)
Expand Down
7 changes: 7 additions & 0 deletions skglm/tests/test_estimators.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,5 +622,12 @@ def test_SparseLogReg_elasticnet(X, l1_ratio):
estimator_sk.intercept_, estimator_ours.intercept_, rtol=1e-4)


def test_SLOPE_printing():
alphas = [0.5, 0.1]
model = GeneralizedLinearEstimator(penalty=SLOPE(alphas))
res = repr(model)
assert isinstance(res, str)


if __name__ == "__main__":
pass