def test_tv1_prox(): """ Use the properties of strongly convex functions to test the implementation of the TV1D proximal operator. In particular, we use the following inequality applied to the proximal objective function: if f is mu-strongly convex then f(x) - f(x^*) >= ||x - x^*||^2 / (2 mu) where x^* is the optimum of f. """ n_features = 10 gamma = np.random.rand() epsilon = 1e-10 # account for some numerical errors tv_norm = lambda x: np.sum(np.abs(np.diff(x))) for _ in range(1000): x = np.random.randn(n_features) x_next = tv_prox.prox_tv1d(x, gamma) diff_obj = tv_norm(x) - tv_norm(x_next) testing.assert_array_less(((x - x_next)**2).sum() / gamma, (1 + epsilon) * diff_obj)
def prox(self, x, step_size): # imported here to avoid circular imports from copt import tv_prox return tv_prox.prox_tv1d(x, step_size * self.alpha)