Пример #1
0
 def test_15(self):
     N = 16
     M = 4
     Nd = 8
     X = np.random.randn(N, N, 1, 1, M)
     S = np.random.randn(N, N)
     W = np.random.randn(N, N)
     try:
         opt = ccmod.ConvCnstrMODMaskDcpl.Options(
                        {'Verbose': False, 'MaxMainIter': 20})
         c = ccmod.ConvCnstrMODMaskDcpl(X, S, W,
                 (Nd, Nd, 1, M), opt=opt, dimK=0)
         c.solve()
     except Exception as e:
         print(e)
         assert(0)
Пример #2
0
 def test_22(self):
     N = 16
     M = 4
     K = 2
     Nc = 3
     Nd = 8
     X = np.random.randn(N, N, Nc, K, M)
     S = np.random.randn(N, N, Nc, K)
     W = np.random.randn(N, N, Nc, K)
     try:
         opt = ccmod.ConvCnstrMODMaskDcpl.Options(
                        {'Verbose': False, 'MaxMainIter': 20})
         c = ccmod.ConvCnstrMODMaskDcpl(X, S, W,
                 (Nd, Nd, Nc, M), opt=opt)
         c.solve()
     except Exception as e:
         print(e)
         assert(0)
Пример #3
0
 def test_23(self):
     N = 16
     M = 4
     Nc = 3
     Nd = 8
     X = np.random.randn(N, N, Nc, 1, M)
     S = np.random.randn(N, N, Nc)
     W = np.random.randn(N, N)
     L = 5e3
     try:
         opt = ccmod.ConvCnstrMODMaskDcpl.Options({'Verbose': False,
                         'MaxMainIter': 200, 'L' : L})
         c = ccmod.ConvCnstrMODMaskDcpl(X, S, W, (Nd, Nd, 1, M),
                                          opt=opt, dimK=0)
         c.solve()
     except Exception as e:
         print(e)
         assert(0)
     assert(np.array(c.getitstat().Rsdl)[-1] < 5e-3)
Пример #4
0
    def __init__(self, D0, S, lmbda, W, opt=None, dimK=1, dimN=2):
        """
        Initialise a MixConvBPDNMaskDcplDictLearn object with problem
        size and options.


        Parameters
        ----------
        D0 : array_like
          Initial dictionary array
        S : array_like
          Signal array
        lmbda : float
          Regularisation parameter
        W : array_like
          Mask array. The array shape must be such that the array is
          compatible for multiplication with the *internal* shape of
          input array S (see :class:`.cnvrep.CDU_ConvRepIndexing` for a
          discussion of the distinction between *external* and *internal*
          data layouts).
        opt : :class:`MixConvBPDNMaskDcplDictLearn.Options` object
          Algorithm options
        dimK : int, optional (default 1)
          Number of signal dimensions. If there is only a single input
          signal (e.g. if `S` is a 2D array representing a single image)
          `dimK` must be set to 0.
        dimN : int, optional (default 2)
          Number of spatial/temporal dimensions
        """

        if opt is None:
            opt = MixConvBPDNMaskDcplDictLearn.Options()
        self.opt = opt

        # Get dictionary size
        if self.opt['DictSize'] is None:
            dsz = D0.shape
        else:
            dsz = self.opt['DictSize']

        # Construct object representing problem dimensions
        cri = cr.CDU_ConvRepIndexing(dsz, S, dimK, dimN)

        # Normalise dictionary
        D0 = cr.Pcn(D0,
                    dsz,
                    cri.Nv,
                    dimN,
                    cri.dimCd,
                    crp=True,
                    zm=opt['CCMOD', 'ZeroMean'])

        # Modify D update options to include initial values for X
        X0 = cr.zpad(cr.stdformD(D0, cri.Cd, cri.M, dimN), cri.Nv)
        opt['CCMOD'].update({'X0': X0})

        # Create X update object
        xstep = Acbpdn.ConvBPDNMaskDcpl(D0,
                                        S,
                                        lmbda,
                                        W,
                                        opt['CBPDN'],
                                        dimK=dimK,
                                        dimN=dimN)

        # Create D update object
        dstep = ccmod.ConvCnstrMODMaskDcpl(None,
                                           S,
                                           W,
                                           dsz,
                                           opt['CCMOD'],
                                           dimK=dimK,
                                           dimN=dimN)

        # Configure iteration statistics reporting
        if self.opt['AccurateDFid']:
            isxmap = {
                'XPrRsdl': 'PrimalRsdl',
                'XDlRsdl': 'DualRsdl',
                'XRho': 'Rho'
            }
            evlmap = {'ObjFun': 'ObjFun', 'DFid': 'DFid', 'RegL1': 'RegL1'}
        else:
            isxmap = {
                'ObjFun': 'ObjFun',
                'DFid': 'DFid',
                'RegL1': 'RegL1',
                'XPrRsdl': 'PrimalRsdl',
                'XDlRsdl': 'DualRsdl',
                'XRho': 'Rho'
            }
            evlmap = {}

        if dstep.opt['BackTrack', 'Enabled']:
            isfld = [
                'Iter', 'ObjFun', 'DFid', 'RegL1', 'Cnstr', 'XPrRsdl',
                'XDlRsdl', 'XRho', 'D_F_Btrack', 'D_Q_Btrack', 'D_ItBt', 'D_L',
                'Time'
            ]
            isdmap = {
                'Cnstr': 'Cnstr',
                'D_F_Btrack': 'F_Btrack',
                'D_Q_Btrack': 'Q_Btrack',
                'D_ItBt': 'IterBTrack',
                'D_L': 'L'
            }
            hdrtxt = [
                'Itn', 'Fnc', 'DFid',
                u('ℓ1'), 'Cnstr', 'r_X', 's_X',
                u('ρ_X'), 'F_D', 'Q_D', 'It_D', 'L_D'
            ]
            hdrmap = {
                'Itn': 'Iter',
                'Fnc': 'ObjFun',
                'DFid': 'DFid',
                u('ℓ1'): 'RegL1',
                'Cnstr': 'Cnstr',
                'r_X': 'XPrRsdl',
                's_X': 'XDlRsdl',
                u('ρ_X'): 'XRho',
                'F_D': 'D_F_Btrack',
                'Q_D': 'D_Q_Btrack',
                'It_D': 'D_ItBt',
                'L_D': 'D_L'
            }

        else:
            isfld = [
                'Iter', 'ObjFun', 'DFid', 'RegL1', 'Cnstr', 'XPrRsdl',
                'XDlRsdl', 'XRho', 'D_L', 'Time'
            ]
            isdmap = {'Cnstr': 'Cnstr', 'D_L': 'L'}
            hdrtxt = [
                'Itn', 'Fnc', 'DFid',
                u('ℓ1'), 'Cnstr', 'r_X', 's_X',
                u('ρ_X'), 'L_D'
            ]
            hdrmap = {
                'Itn': 'Iter',
                'Fnc': 'ObjFun',
                'DFid': 'DFid',
                u('ℓ1'): 'RegL1',
                'Cnstr': 'Cnstr',
                'r_X': 'XPrRsdl',
                's_X': 'XDlRsdl',
                u('ρ_X'): 'XRho',
                'L_D': 'D_L'
            }

        isc = dictlrn.IterStatsConfig(isfld=isfld,
                                      isxmap=isxmap,
                                      isdmap=isdmap,
                                      evlmap=evlmap,
                                      hdrtxt=hdrtxt,
                                      hdrmap=hdrmap)

        # Call parent constructor
        super(MixConvBPDNMaskDcplDictLearn,
              self).__init__(xstep, dstep, opt, isc)