Ejemplo n.º 1
0
def par_y1step(i):
    r"""Minimise Augmented Lagrangian with respect to
    :math:`\mathbf{y}_{1,G_i}`, one of the disjoint problems of
    optimizing :math:`\mathbf{y}_1`.

    Parameters
    ----------
    i : int
      Index of grouping to update
    """

    global mp_Y1
    grpind = slice(mp_grp[i], mp_grp[i+1])
    XU1 = mp_X[grpind] + 1/mp_alpha*mp_U1[grpind]
    if mp_wl1.shape[mp_axisM] is 1:
        gamma = mp_lmbda/(mp_alpha**2*mp_rho)*mp_wl1
    else:
        gamma = mp_lmbda/(mp_alpha**2*mp_rho)*mp_wl1[grpind]
    Y1 = sp.prox_l1(XU1, gamma)
    if mp_NonNegCoef:
        Y1[Y1 < 0.0] = 0.0
    if mp_NoBndryCross:
        for n in range(len(mp_Nv)):
            Y1[(slice(None),) + (slice(None),)*n +
               (slice(1-mp_Dshp[n], None),)] = 0.0
    mp_Y1[mp_grp[i]:mp_grp[i+1]] = Y1
Ejemplo n.º 2
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        self.Y = np.asarray(sp.prox_l1(self.S - self.AX - self.U,
                                       self.lmbda/self.rho), dtype=self.dtype)
Ejemplo n.º 3
0
def cbpdn_ystep(k):
    """Do the Y step of the cbpdn stage. The only parameter is the slice
    index `k` and there are no return values; all inputs and outputs are
    from and to global variables.
    """

    AXU = mp_Z_X[k] + mp_Z_U[k]
    mp_Z_Y[k] = sp.prox_l1(AXU, (mp_lmbda/mp_xrho))
Ejemplo n.º 4
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`."""

        self.Y = np.asarray(sp.prox_l1(self.AX + self.U,
                                       (self.lmbda / self.rho) * self.wl1),
                            dtype=self.dtype)
        super(BPDN, self).ystep()
Ejemplo n.º 5
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`."""

        AXU = self.AX + self.U
        self.Y[..., 0:-1] = sp.prox_l2(AXU[..., 0:-1], self.mu/self.rho)
        self.Y[..., -1] = sp.prox_l1(AXU[..., -1],
                                     (self.lmbda/self.rho) * self.Wl1)
Ejemplo n.º 6
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`."""

        AXU = self.AX + self.U
        self.block_sep0(self.Y)[:] = sp.prox_l1(
            self.block_sep0(AXU), (self.lmbda/self.rho) * self.Wl1)
        self.block_sep1(self.Y)[:] = sp.prox_l2(
            self.block_sep1(AXU), self.mu/self.rho, axis=(self.cri.axisC, -1))
Ejemplo n.º 7
0
def resolvent_d(d, y, s, rho, N, M, d_size):
    rootN = int(np.sqrt(N))
    d = d.reshape(M, rootN, rootN)
    d = d.transpose(1, 2, 0)
    d_Pcn = cnvrep.Pcn(d.reshape(rootN, rootN, 1, 1, M), (d_size, d_size, M),
                       Nv=(rootN, rootN)).squeeze()
    d_Pcn = d_Pcn.transpose(2, 0, 1)
    d = d_Pcn.reshape(N * M)
    y = y - (pr.prox_l1(y - s, 1 / rho) + s)
    return np.concatenate([d, y], 0)
Ejemplo n.º 8
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        self.Y[..., 0:-1] = prox_l2(self.AX[..., 0:-1] + self.U[..., 0:-1],
                                    (self.lmbda / self.rho) * self.Wtvna,
                                    axis=self.saxes)
        self.Y[..., -1] = prox_l1(self.AX[..., -1] + self.U[..., -1] - self.S,
                                  (1.0 / self.rho) * self.Wdf)
Ejemplo n.º 9
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`."""

        AXU = self.AX + self.U
        self.Y[..., 0:-1] = sp.prox_l2(AXU[..., 0:-1],
                                       self.mu / self.rho,
                                       axis=(self.cri.axisM, -1))
        self.Y[..., -1] = sp.prox_l1(AXU[..., -1],
                                     (self.lmbda / self.rho) * self.Wl1)
Ejemplo n.º 10
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`."""

        AXU = self.AX + self.U
        self.block_sep0(self.Y)[:] = sp.prox_l1(
            self.block_sep0(AXU), (self.lmbda / self.rho) * self.Wl1)
        self.block_sep1(self.Y)[:] = sp.prox_l2(self.block_sep1(AXU),
                                                self.mu / self.rho,
                                                axis=(self.cri.axisC, -1))
Ejemplo n.º 11
0
    def prox_g(self, V):
        """Compute proximal operator of :math:`g`."""

        U = prox_l1(V, (self.lmbda / self.L) * self.wl1)
        if self.opt['NonNegCoef']:
            U[U < 0.0] = 0.0
        if self.opt['NoBndryCross']:
            for n in range(0, self.cri.dimN):
                U[(slice(None), ) * n +
                  (slice(1 - self.D.shape[n], None), )] = 0.0
        return U
Ejemplo n.º 12
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        self.Y[..., 0:-1] = sp.prox_l2(
            self.AX[..., 0:-1] + self.U[..., 0:-1],
            (self.lmbda/self.rho)*self.Wtvna, axis=self.saxes)
        self.Y[..., -1] = sp.prox_l1(
            self.AX[..., -1] + self.U[..., -1] - self.S,
            (1.0/self.rho)*self.Wdf)
Ejemplo n.º 13
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        AXU = self.AX + self.U
        Y0 = np.asarray(sp.prox_l1(self.block_sep0(AXU), self.wl1 / self.rho),
                        dtype=self.dtype)
        if self.opt['NonNegCoef']:
            Y0[Y0 < 0.0] = 0.0
        Y1 = sl.proj_l2ball(self.block_sep1(AXU), self.S, self.epsilon, axes=0)
        self.Y = self.block_cat(Y0, Y1)
Ejemplo n.º 14
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`."""

        scalar_factor = (self.lmbda / self.rho) * self.wl1
        print('AX dtype %s \n' % (self.AX.dtype, ))
        print('U dtype %s \n' % (self.U.dtype, ))
        print('sc_factor shape %s \n' % (scalar_factor.shape, ))

        self.Y = sp.prox_l1(self.AX + self.U,
                            (self.lmbda / self.rho) * self.wl1)
        super(KConvBPDN, self).ystep()
Ejemplo n.º 15
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        AXU = self.AX + self.U
        Y0 = np.asarray(sp.prox_l1(self.block_sep0(AXU), self.wl1 / self.rho),
                        dtype=self.dtype)
        if self.opt['NonNegCoef']:
            Y0[Y0 < 0.0] = 0.0
        Y1 = sl.proj_l2ball(self.block_sep1(AXU), self.S, self.epsilon, axes=0)
        self.Y = self.block_cat(Y0, Y1)
Ejemplo n.º 16
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        AXU = self.AX + self.U
        Y0 = sp.prox_l1(self.block_sep0(AXU) - self.S, (1.0/self.rho)*self.W)
        Y1 = sp.prox_l1l2(self.block_sep1(AXU), 0.0,
                         (self.lmbda/self.rho)*self.wl21,
                         axis=self.cri.axisC)
        self.Y = self.block_cat(Y0, Y1)
        cbpdn.ConvTwoBlockCnstrnt.ystep(self)
Ejemplo n.º 17
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        AXU = self.AX + self.U
        Y0 = sp.prox_l1(self.block_sep0(AXU) - self.S, (1.0/self.rho)*self.W)
        Y1 = sp.prox_sl1l2(self.block_sep1(AXU), 0.0,
                           (self.lmbda/self.rho)*self.wl21,
                           axis=self.cri.axisC)
        self.Y = self.block_cat(Y0, Y1)
        cbpdn.ConvTwoBlockCnstrnt.ystep(self)
Ejemplo n.º 18
0
def cbpdnmd_ystep(k):
    """Do the Y step of the cbpdn stage. The only parameter is the slice
    index `k` and there are no return values; all inputs and outputs are
    from and to global variables.
    """

    if mp_W.shape[0] > 1:
        W = mp_W[k]
    else:
        W = mp_W
    AXU0 = mp_DX[k] - mp_S[k] + mp_Z_U0[k]
    AXU1 = mp_Z_X[k] + mp_Z_U1[k]
    mp_Z_Y0[k] = mp_xrho*AXU0 / (W**2 + mp_xrho)
    mp_Z_Y1[k] = sp.prox_l1(AXU1, (mp_lmbda/mp_xrho))
Ejemplo n.º 19
0
def cbpdnmd_ystep(k):
    """Do the Y step of the cbpdn stage. The only parameter is the slice
    index `k` and there are no return values; all inputs and outputs are
    from and to global variables.
    """

    if mp_W.shape[0] > 1:
        W = mp_W[k]
    else:
        W = mp_W
    AXU0 = mp_DX[k] - mp_S[k] + mp_Z_U0[k]
    AXU1 = mp_Z_X[k] + mp_Z_U1[k]
    mp_Z_Y0[k] = mp_xrho*AXU0 / (W**2 + mp_xrho)
    mp_Z_Y1[k] = sp.prox_l1(AXU1, (mp_lmbda/mp_xrho))
Ejemplo n.º 20
0
def dictionary_learning_by_L1_Dstep(Xf, S, G1, H1, G0, H0, parameter_rho_dic,
                                    iteration, cri, dsz):
    GH = con.convert_to_Df(G1 - H1, S, cri)
    GSH = con.convert_to_Sf(G0 + S - H0, cri)
    b = GH + sl.inner(np.conj(Xf), GSH, cri.axisK)
    Df = sl.solvemdbi_ism(Xf, 1, b, cri.axisM, cri.axisK)
    D = con.convert_to_D(Df, dsz, cri)

    XfDf = np.sum(Xf * Df, axis=cri.axisM)
    XD = con.convert_to_S(XfDf, cri)
    G0 = sp.prox_l1(XD - S + H0, (1 / parameter_rho_dic))

    H0 = H0 + XD - G0 - S

    return D, G0, H0, XD
Ejemplo n.º 21
0
    def test_03(self):
        N = 64
        lmbda = 0.1
        s = np.random.randn(N, 1)

        def proxf(x, rho):
            return s / (1 + rho) + (rho / (1 + rho)) * x

        def proxg(x, rho):
            return sp.prox_l1(x, lmbda / rho)

        opt = ppp.PPPConsensus.Options({'Verbose': False, 'RelStopTol': 1e-5,
                                        'MaxMainIter': 100, 'rho': 8e-1})
        b = ppp.PPPConsensus(s.shape, (proxf,), proxg=proxg, opt=opt)
        xce = b.solve()
        xdrct = sp.prox_l1(s, lmbda)
        assert sm.mse(xdrct, xce) < 1e-9
Ejemplo n.º 22
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`."""

        if (self.Wg is None or self.mu == 0) and self.gamma == 0:
            # Skip unnecessary inhibition steps and run standard CBPDN
            super(ConvBPDNInhib, self).ystep()

        else:
            # Perform soft-thresholding step of Y subproblem using l1 weights
            self.Y = sp.prox_l1(self.AX + self.U,
                                (self.lmbda * self.wl1 + self.mu * self.wml +
                                 self.gamma * self.wms) / self.rho)

            # Compute the frequency domain representation of the
            # magnitude of X
            Xaf = rfftn(np.abs(self.X), self.cri.Nv, self.cri.axisN)

            if self.mu > 0 and self.Wg is not None:
                # Update previous lateral inhibition term
                self.wml_prev = self.wml
                # Convolve the lateral spatial weighting matrix with the
                # magnitude of X
                WhXal = irfftn(self.Whfl * Xaf, self.cri.Nv, self.cri.axisN)
                # Sum the weights across in-group members for each element
                self.wml = np.dot(np.dot(WhXal, self.Wg.T),
                                  self.Wg) - np.sum(self.Wg, axis=0) * WhXal
                # Smooth lateral inhibition term
                self.wml = self.smooth * self.wml_prev + \
                    (1 - self.smooth) * self.wml

            if self.gamma > 0:
                # Update previous self inhibition term
                self.wms_prev = self.wms
                # Convolve the self spatial weighting matrix with the
                # magnitude of X
                self.wms = irfftn(
                    self.Whfs * Xaf, self.cri.Nv, self.cri.axisN)
                # Smooth self inhibition term
                self.wms = self.smooth * self.wms_prev + \
                    (1 - self.smooth) * self.wms

            # Handle negative coefficients and boundary crossings
            super(cbpdn.ConvBPDN, self).ystep()
Ejemplo n.º 23
0
    def test_01(self):
        N = 64
        lmbda = 0.1
        s = np.random.randn(N, 1)

        def f(x):
            return 0.5 * np.linalg.norm((x - s).ravel())**2

        def gradf(x):
            return x - s

        def proxg(x, L):
            return sp.prox_l1(x, lmbda / L)

        opt = ppp.PPP.Options({'Verbose': False, 'RelStopTol': 1e-5,
                               'MaxMainIter': 100, 'L': 9e-1})
        b = ppp.PPP(s.shape, f, gradf, proxg, opt=opt)
        xppp = b.solve()
        xdrct = sp.prox_l1(s, lmbda)
        assert sm.mse(xdrct, xppp) < 1e-9
Ejemplo n.º 24
0
def projection_to_solution_space_by_L1(D, X, S, Y, U, parameter_rho_coef,
                                       parameter_gamma, iteration, thr, cri,
                                       dsz):
    Df = con.convert_to_Df(D, S, cri)
    Xf = con.convert_to_Xf(X, S, cri)

    for i in range(iteration):

        YSUf = con.convert_to_Sf(Y + S - U, cri)
        b = (1 / parameter_rho_coef) * Xf + np.conj(Df) * YSUf
        Xf = sl.solvedbi_sm(Df, (1 / parameter_rho_coef), b)
        X = con.convert_to_X(Xf, cri)
        #X = np.where(X <= 0, 0, X)

        Xf = con.convert_to_Xf(X, S, cri)
        DfXf = np.sum(Df * Xf, axis=cri.axisM)
        DX = con.convert_to_S(DfXf, cri)
        Y = sp.prox_l1(DX - S + U, (parameter_gamma / parameter_rho_coef))

        U = U + DX - Y - S

    return X, Y, U
Ejemplo n.º 25
0
 def proxg(x, rho):
     return sp.prox_l1(x, lmbda / rho)
Ejemplo n.º 26
0
    def eval_proxop(self, V):
        """Compute proximal operator of :math:`g`."""

        return sp.prox_l1(V, (self.lmbda / self.L) * self.wl1)
Ejemplo n.º 27
0
    def eval_proxop(self, V):
        """Compute proximal operator of :math:`g`."""

        return np.asarray(prox_l1(V, (self.lmbda / self.L) * self.wl1),
                          dtype=self.dtype)
Ejemplo n.º 28
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        self.Y = sp.prox_l1(self.AX - self.S + self.U, self.Wdf / self.rho)
Ejemplo n.º 29
0
 def proxg(x, L):
     return sp.prox_l1(x, lmbda / L)
Ejemplo n.º 30
0
    def ystep(self):
        r"""Minimise Augmented Lagrangian with respect to
        :math:`\mathbf{y}`.
        """

        self.Y = sp.prox_l1(self.AX - self.S + self.U, self.Wdf / self.rho)
Ejemplo n.º 31
0
    def prox_g(self, X, rho):
        r"""
        Proximal operator of :math:`(\lambda/\rho) \|\cdot\|_1`.
        """

        return sp.prox_l1(X, (self.lmbda / rho))
Ejemplo n.º 32
0
    def eval_proxop(self, V):
        """Compute proximal operator of :math:`g`."""

        return np.asarray(sp.prox_l1(V, (self.lmbda / self.L) * self.wl1),
                          dtype=self.dtype)
Ejemplo n.º 33
0
    def eval_proxop(self, V):
        """Compute proximal operator of :math:`g`."""

        return sp.prox_l1(V, (self.lmbda / self.L) * self.wl1)