Esempio n. 1
0
    'rho': cri.K,
    'AutoRho': {
        'Period': 10,
        'AutoScaling': False,
        'RsdlRatio': 10.0,
        'Scaling': 2.0,
        'RsdlTarget': 1.0
    }
})

# Normalise dictionary according to Y update options
D0n = ccmod.getPcn0(optd['ZeroMean'], D0.shape, dimN=2, dimC=1)(D0)

# Update D update options to include initial values for Y and U
optd.update({
    'Y0': ccmod.zpad(ccmod.stdformD(D0n, cri.C, cri.M), cri.Nv),
    'U0': np.zeros(cri.shpD)
})

# Create X update object
xstep = cbpdn.ConvBPDN(D0n, sh, lmbda, optx)

# Create D update object
dstep = ccmod.ConvCnstrMOD(None, sh, D0.shape, optd)

# Create DictLearn object
opt = dictlrn.DictLearn.Options({'Verbose': True, 'MaxMainIter': 100})
d = dictlrn.DictLearn(xstep, dstep, opt)
D1 = d.solve()
print("DictLearn solve time: %.2fs" % d.runtime, "\n")
Esempio n. 2
0
    def __init__(self, D0, S, lmbda=None, opt=None, dimK=1, dimN=2):
        """
        Initialise a ConvBPDNDictLearn object with problem size and options.

        Parameters
        ----------
        D0 : array_like
          Initial dictionary array
        S : array_like
          Signal array
        lmbda : float
          Regularisation parameter
        opt : :class:`ConvBPDNDictLearn.Options` object
          Algorithm options
        dimK : int, optional (default 1)
          Number of signal dimensions
        dimN : int, optional (default 2)
          Number of spatial/temporal dimensions
        """

        if opt is None:
            opt = ConvBPDNDictLearn.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 = ccmod.ConvRepIndexing(dsz, S, dimK, dimN)

        # Normalise dictionary
        D0 = ccmod.getPcn0(opt['CCMOD', 'ZeroMean'], dsz, dimN,
                           dimC=cri.dimCd)(D0)

        # Modify D update options to include initial values for Y and U
        opt['CCMOD'].update({
            'Y0':
            ccmod.zpad(ccmod.stdformD(D0, cri.C, cri.M, dimN), cri.Nv),
            'U0':
            np.zeros(cri.shpD)
        })

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

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

        # Configure iteration statistics reporting
        isc = dictlrn.IterStatsConfig(isfld=[
            'Iter', 'ObjFun', 'DFid', 'RegL1', 'Cnstr', 'XPrRsdl', 'XDlRsdl',
            'XRho', 'DPrRsdl', 'DDlRsdl', 'DRho', 'Time'
        ],
                                      isxmap={
                                          'ObjFun': 'ObjFun',
                                          'DFid': 'DFid',
                                          'RegL1': 'RegL1',
                                          'XPrRsdl': 'PrimalRsdl',
                                          'XDlRsdl': 'DualRsdl',
                                          'XRho': 'Rho'
                                      },
                                      isdmap={
                                          'Cnstr': 'Cnstr',
                                          'DPrRsdl': 'PrimalRsdl',
                                          'DDlRsdl': 'DualRsdl',
                                          'DRho': 'Rho'
                                      },
                                      evlmap={},
                                      hdrtxt=[
                                          'Itn', 'Fnc', 'DFid', 'l1', 'Cnstr',
                                          'r_X', 's_X',
                                          u('ρ_X'), 'r_D', 's_D',
                                          u('ρ_D')
                                      ],
                                      hdrmap={
                                          'Itn': 'Iter',
                                          'Fnc': 'ObjFun',
                                          'DFid': 'DFid',
                                          'l1': 'RegL1',
                                          'Cnstr': 'Cnstr',
                                          'r_X': 'XPrRsdl',
                                          's_X': 'XDlRsdl',
                                          u('ρ_X'): 'XRho',
                                          'r_D': 'DPrRsdl',
                                          's_D': 'DDlRsdl',
                                          u('ρ_D'): 'DRho'
                                      })

        # Call parent constructor
        super(ConvBPDNDictLearn, self).__init__(xstep, dstep, opt, isc)
Esempio n. 3
0
    def __init__(self, D0, S, lmbda, W, opt=None, dimK=1, dimN=2):
        """
        Initialise a ConvBPDNMaskDcplDictLearn 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:`.ccmod.ConvRepIndexing` for a
          discussion of the distinction between *external* and *internal*
          data layouts).
        opt : :class:`ConvBPDNMaskDcplDictLearn.Options` object
          Algorithm options
        method : string, optional (default 'ism')
          String selecting dictionary update solver
        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 = ConvBPDNMaskDcplDictLearn.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 = ccmod.ConvRepIndexing(dsz, S, dimK, dimN)

        # Normalise dictionary
        D0 = ccmod.getPcn0(opt['CCMOD', 'ZeroMean'], dsz, dimN=dimN,
                           dimC=cri.dimCd)(D0)

        # Modify D update options to include initial values for Y and U
        if cri.C == cri.Cd:
            Y0b0 = np.zeros(cri.Nv + (cri.C, 1, cri.K))
        else:
            Y0b0 = np.zeros(cri.Nv + (1, 1, cri.C * cri.K))
        Y0b1 = ccmod.zpad(ccmod.stdformD(D0, cri.Cd, cri.M, dimN), cri.Nv)
        opt['CCMOD'].update({'Y0' : np.concatenate((Y0b0, Y0b1),
                            axis=cri.axisM)})

        # Create X update object
        xstep = cbpdn.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 = {}
        isc = dictlrn.IterStatsConfig(
            isfld=['Iter', 'ObjFun', 'DFid', 'RegL1', 'Cnstr', 'XPrRsdl',
                   'XDlRsdl', 'XRho', 'DPrRsdl', 'DDlRsdl', 'DRho', 'Time'],
            isxmap=isxmap,
            isdmap={'Cnstr' :  'Cnstr', 'DPrRsdl' : 'PrimalRsdl',
                    'DDlRsdl' : 'DualRsdl', 'DRho' : 'Rho'},
            evlmap=evlmap,
            hdrtxt=['Itn', 'Fnc', 'DFid', u('ℓ1'), 'Cnstr', 'r_X', 's_X',
                    u('ρ_X'), 'r_D', 's_D', u('ρ_D')],
            hdrmap={'Itn' : 'Iter', 'Fnc' : 'ObjFun', 'DFid' : 'DFid',
                    u('ℓ1') : 'RegL1', 'Cnstr' : 'Cnstr', 'r_X' : 'XPrRsdl',
                    's_X' : 'XDlRsdl', u('ρ_X') : 'XRho', 'r_D' : 'DPrRsdl',
                    's_D' : 'DDlRsdl', u('ρ_D') : 'DRho'}
            )

        # Call parent constructor
        super(ConvBPDNMaskDcplDictLearn, self).__init__(xstep, dstep, opt, isc)
Esempio n. 4
0
# X and D update options
lmbda = 0.2
optx = cbpdn.ConvBPDN.Options({'Verbose' : False, 'MaxMainIter' : 1,
                               'rho' : 50.0*lmbda + 0.5,
                    'AutoRho' : {'Period' : 10, 'AutoScaling' : False,
                    'RsdlRatio' : 10.0, 'Scaling': 2.0, 'RsdlTarget' : 1.0}})
optd = ccmod.ConvCnstrMOD.Options({'Verbose' : False, 'MaxMainIter' : 1,
                                   'rho' : cri.K,
                    'AutoRho' : {'Period' : 10, 'AutoScaling' : False,
                    'RsdlRatio' : 10.0, 'Scaling': 2.0, 'RsdlTarget' : 1.0}})

# Normalise dictionary according to Y update options
D0n = ccmod.getPcn0(optd['ZeroMean'], D0.shape, dimN=2, dimC=0)(D0)

# Update D update options to include initial values for Y and U
optd.update({'Y0' : ccmod.zpad(ccmod.stdformD(D0n, cri.C, cri.M), cri.Nv),
             'U0' : np.zeros(cri.shpD)})

# Create X update object
xstep = cbpdn.ConvBPDN(D0n, sh, lmbda, optx)

# Create D update object
dstep = ccmod.ConvCnstrMOD(None, sh, D0.shape, optd)

# Create DictLearn object
opt = dictlrn.DictLearn.Options({'Verbose' : True, 'MaxMainIter' : 100})
d = dictlrn.DictLearn(xstep, dstep, opt)
D1 = d.solve()
print("DictLearn solve time: %.2fs" % d.timer.elapsed('solve'), "\n")

Esempio n. 5
0
lmbda = 0.2
optx = cbpdn.ConvBPDNMaskDcpl.Options({'Verbose' : False, 'MaxMainIter' : 1,
                    'rho' : 20.0*lmbda, 'AutoRho' : {'Enabled' : False}})
optd = ccmod.ConvCnstrMODMaskDcpl.Options({'Verbose' : False,
                    'MaxMainIter' : 1, 'rho' : 2*cri.K,
                    'AutoRho' : {'Enabled' : False}})


# Normalise dictionary according to Y update options
D0n = ccmod.getPcn0(optd['ZeroMean'], D0.shape, dimN=2, dimC=0)(D0)


# Modify D update options to include initial value for Y (this procedure
# is essential to correct algorithm performance)
Y0b0 = np.zeros(cri.Nv + (cri.C, 1, cri.K))
Y0b1 = ccmod.zpad(ccmod.stdformD(D0n, cri.C, cri.M), cri.Nv)
optd.update({'Y0' : np.concatenate((Y0b0, Y0b1), axis=cri.axisM)})


# Create X update object
xstep = cbpdn.ConvBPDNMaskDcpl(D0n, shp, lmbda, W, optx)


# Create D update object
dstep = ccmod.ConvCnstrMODMaskDcpl(None, shp, W, D0.shape, optd)


# Create DictLearn object
opt = dictlrn.DictLearn.Options({'Verbose' : True, 'MaxMainIter' : 100})
d = dictlrn.DictLearn(xstep, dstep, opt)
D1 = d.solve()