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

Add prox operators for simple constraints #13

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

thomaskeefe
Copy link
Collaborator

Isotonic, LinearEquality, L2Ball constraints

@thomaskeefe thomaskeefe requested a review from idc9 October 5, 2021 17:17
def __init__(self, A, b):
self.A = A
self.b = b
self.pinvA = np.linalg.pinv(A)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Collaborator

@idc9 idc9 left a 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.

@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes this is true.

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?
Copy link
Collaborator

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forgot what this was?

@thomaskeefe
Copy link
Collaborator Author

Think we're ready to go here?

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

Successfully merging this pull request may close these issues.

None yet

2 participants