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

ENH Add positive constraint to L1, WeightedL1 and L1_plus_L2 #110

Merged
merged 27 commits into from Dec 5, 2022

Conversation

PABannier
Copy link
Collaborator

@PABannier PABannier commented Oct 25, 2022

Add positivity constraints to these penalties and corresponding estimators.

Question: do we want it enabled for WeightedL1? It seems more consistent and is not tricky to do.

Closes #107, #132

@PABannier
Copy link
Collaborator Author

So far, it's working with ws_strategy="fixpoint", there remains to write the correct distance to the subdifferential for all these penalties.

@PABannier
Copy link
Collaborator Author

PABannier commented Oct 30, 2022

Anyone to discuss with me about the impact of the positive constraint on the distance to the subdifferential? I try to do the maths, but I'm stuck... (poke @mathurinm @Klopfe @QB3 @Badr-MOUFAD )

@mathurinm
Copy link
Collaborator

For L1 + positivity constraint, when x is strictly negative, the penalty is + infty and the subdifferential is empty, so distance is infinite. When x is 0, the subdiff is ]-infty,1]. When x is > 0, the subdiff is the singleton 1

@PABannier
Copy link
Collaborator Author

Note to self: do same for L21, docstrings and implem might need compression

@mathurinm mathurinm requested a review from QB3 November 15, 2022 15:33
Copy link
Collaborator

@Badr-MOUFAD Badr-MOUFAD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hats off @PABannier for this work!

Some remarks and some suggestions ⬇️

if w[j] == 0:
# distance of - grad_j to [-alpha, alpha]
subdiff_dist[idx] = max(0, np.abs(grad[idx]) - self.alpha)
if self.positive:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion that I think would enhance the readability of this part

# case of positivity constraints on coefficients 
if positive:
    # loop over features to compute subdiff distance
    ...
    ...
    return subdiff distance

# usual case
...
....
...

WDTY? (@mathurinm any thoughts?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i find it redundant. I think it's already quite readable. @mathurinm ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from that, anything else? (any suggestions @mathurinm ?)

skglm/utils.py Outdated Show resolved Hide resolved
skglm/estimators.py Show resolved Hide resolved
@PABannier
Copy link
Collaborator Author

@mathurinm @Badr-MOUFAD should be mergeable

subdiff_dist[idx] = max(0, - grad[idx] - self.alpha * self.l1_ratio)
else:
# distance of -grad_j to alpha * {l1_ratio + (1 - l1_ratio) * w[j]}
subdiff_dist[idx] = np.abs(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all is good for me, except for this line (the one below also): it's difficult to read as it spans multiple lines.

Any suggestions @PABannier to increase its readability?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find it particularly hard to read. But one thing that could be improved is to factor the alpha for less redundancy.

Copy link
Collaborator

@Badr-MOUFAD Badr-MOUFAD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Many thanks @PABannier.

We should consider adding this feat to Lasso, WeightedLasso and ElasticNet estimators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants