Created
July 23, 2017 14:26
-
-
Save 0x0L/a81c624bd1b4ca8384869091b7e33367 to your computer and use it in GitHub Desktop.
l1 projection
This file contains 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
def l1_simplex_proj(x, radius=1.0): | |
z = np.abs(x) | |
mu = np.sort(z)[::-1] | |
cmu = np.cumsum(mu) | |
f = mu * np.arange(1, 1 + len(x)) - (cmu - radius) | |
rho = np.where(f > 0)[0][-1] | |
theta = (cmu[rho] - radius) / (1.0 + rho) | |
y = np.sign(x) * np.maximum(z - theta, 0) | |
return y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment