Esempio n. 1
0
    def __init__(self,
                 A,
                 y,
                 proxg,
                 eps,
                 x=None,
                 G=None,
                 max_iter=100,
                 tau=None,
                 sigma=None,
                 show_pbar=True):
        self.y = y
        self.x = x
        self.y_device = backend.get_device(y)
        if self.x is None:
            with self.y_device:
                self.x = self.y_device.xp.zeros(A.ishape, dtype=self.y.dtype)

        self.x_device = backend.get_device(self.x)
        if G is None:
            self.max_eig_app = MaxEig(A.H * A,
                                      dtype=self.x.dtype,
                                      device=self.x_device,
                                      show_pbar=show_pbar)

            proxfc = prox.Conj(prox.L2Proj(A.oshape, eps, y=y))
        else:
            proxf1 = prox.L2Proj(A.oshape, eps, y=y)
            proxf2 = proxg
            proxfc = prox.Conj(prox.Stack([proxf1, proxf2]))
            proxg = prox.NoOp(A.ishape)
            A = linop.Vstack([A, G])

        if tau is None or sigma is None:
            max_eig = MaxEig(A.H * A,
                             dtype=self.x.dtype,
                             device=self.x_device,
                             show_pbar=show_pbar).run()
            tau = 1
            sigma = 1 / max_eig

        with self.y_device:
            self.u = self.y_device.xp.zeros(A.oshape, dtype=self.y.dtype)

        alg = PrimalDualHybridGradient(proxfc,
                                       proxg,
                                       A,
                                       A.H,
                                       self.x,
                                       self.u,
                                       tau,
                                       sigma,
                                       max_iter=max_iter)

        super().__init__(alg, show_pbar=show_pbar)
Esempio n. 2
0
 def test_L2Proj(self):
     shape = [6]
     epsilon = 1.0
     P = prox.L2Proj(shape, epsilon)
     x = util.randn(shape)
     y = P(1.0, x)
     npt.assert_allclose(y, x / np.linalg.norm(x.ravel()))