Created
April 11, 2019 14:34
-
-
Save razhangwei/57985c730184d2d5d31d720a807a6034 to your computer and use it in GitHub Desktop.
Several proximal operators implemented in #PyTorch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
# > https://github.com/pmelchior/proxmin/blob/master/proxmin/operators.py | |
def _step_gamma(step, gamma): | |
"""Update gamma parameter for use inside of continuous proximal operator. | |
Every proximal operator for a function with a continuous parameter, | |
e.g. gamma ||x||_1, needs to update that parameter to account for the | |
stepsize of the algorithm. | |
Returns: | |
gamma * step | |
""" | |
return gamma * step | |
def prox_plus(X, step): | |
"""Projection onto non-negative numbers | |
""" | |
return torch.clamp(X, min=0) | |
def prox_soft(X, step, thresh=0): | |
"""Soft thresholding proximal operator | |
""" | |
thresh_ = _step_gamma(step, thresh) | |
return torch.sign(X) * prox_plus(torch.abs(X) - thresh_, step) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment