示例#1
0
 def _prox(self, alpha, input):
     return thresh.soft_thresh(self.lamda * alpha, input)
示例#2
0
 def _prox(self, alpha, input):
     u, s, vh = np.linalg.svd(input, full_matrices=False)
     s_max = np.max(s)
     # print('Eigen Value:{}'.format(np.diag(s)))
     s_t = thresh.soft_thresh(self.lamda * alpha * s_max, s)
     return np.matmul(u, s_t[..., None] * vh)
示例#3
0
    def test_soft_thresh(self):
        x = np.array([-2, -1.5, -1, 0.5, 0, 0.5, 1, 1.5, 2])
        y = np.array([-1, -0.5, 0, 0, 0, 0, 0, 0.5, 1])

        npt.assert_allclose(thresh.soft_thresh(1, x), y)
示例#4
0
        def test_soft_thresh_cuda(self):
            x = cp.array([-2, -1.5, -1, 0.5, 0, 0.5, 1, 1.5, 2])
            y = cp.array([-1, -0.5, 0, 0, 0, 0, 0, 0.5, 1])
            lamda = cp.array([1.0])

            cp.testing.assert_allclose(thresh.soft_thresh(lamda, x), y)
示例#5
0
 def _prox(self, alpha, input):
     with backend.get_device(input):
         return thresh.soft_thresh(self.lamda * alpha, input)