From 75edc549bb6c7c254070af7d4a57bdfcf0e62d5c Mon Sep 17 00:00:00 2001 From: Mathieu Blondel Date: Sat, 2 Nov 2019 00:55:25 +0100 Subject: [PATCH] Cosmit. --- polytopes.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/polytopes.py b/polytopes.py index ee72d54..7e3c57e 100644 --- a/polytopes.py +++ b/polytopes.py @@ -431,13 +431,17 @@ def _Euclidean_project(self, theta): w = np.array(w) if not self.w_sorted: w = w[np.argsort(w)[::-1]] + perm = np.argsort(theta)[::-1] theta = theta[perm] - dual_sol = isotonic_regression(w - theta, increasing=True) - primal_sol = dual_sol + theta + + dual_sol = isotonic_regression(theta - w, increasing=False) + # Or equivalently - #dual_sol = isotonic_regression(theta - w, increasing=False) - #primal_sol = theta - dual_sol + #dual_sol = -isotonic_regression(w - theta, increasing=True) + + primal_sol = theta - dual_sol + return primal_sol[inv_permutation(perm)] def _KL_project(self, theta):