-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add prox operators for simple constraints #13
base: main
Are you sure you want to change the base?
Conversation
ya_glm/opt/constraint/convex.py
Outdated
def __init__(self, A, b): | ||
self.A = A | ||
self.b = b | ||
self.pinvA = np.linalg.pinv(A) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should avoid computing this in init (sometimes we initialize this object just to check if it is proximable). Maybe we should cache it the first time we call prox? I've also though about having a .setup()
method that precomputes required data for these functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll do it as a @property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Let's change project_simplex as you suggested.
ya_glm/opt/constraint/convex.py
Outdated
@@ -58,8 +75,9 @@ def is_proximable(self): | |||
# See https://gist.github.com/mblondel/6f3b7aaad90606b98f71 | |||
# for more algorithms. | |||
def project_simplex(v, z=1): | |||
if np.sum(v) <= z: | |||
return v | |||
# z is what the entries need to add up to, e.g. z=1 for probability simplex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is true.
ya_glm/opt/constraint/convex.py
Outdated
if np.sum(v) <= z: | ||
return v | ||
# z is what the entries need to add up to, e.g. z=1 for probability simplex | ||
if np.sum(v) <= z: # don't we want the simplex to mean sum == z not sum <= z? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but perhaps up to machine precision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can just delete this sum <= z check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes on second thought anytime we are calling project it's probably safe to assume we were not originally on the simplex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
ya_glm/opt/constraint/convex.py
Outdated
return v | ||
# z is what the entries need to add up to, e.g. z=1 for probability simplex | ||
if np.sum(v) <= z: # don't we want the simplex to mean sum == z not sum <= z? | ||
return v # also this doesn't work when v has, say, all negative entries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya actually we should probably check if it's positive too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot what this was?
Think we're ready to go here? |
Isotonic, LinearEquality, L2Ball constraints