コード例 #1
0
def pr_d(d, 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 = d_Pcn.transpose(2, 0, 1)
    return d
コード例 #2
0
def resolvent_d_l2(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_l2(y - s, 1 / rho) + s)
    return np.concatenate([d, y], 0)
コード例 #3
0
    def __init__(self, D0, lmbda=None, opt=None, dimK=None, dimN=2):
        """
        Parameters
        ----------
        D0 : array_like
          Initial dictionary array
        lmbda : float
          Regularisation parameter
        opt : :class:`OnlineConvBPDNDictLearn.Options` object
          Algorithm options
        dimK : 0, 1, or None, optional (default None)
          Number of signal dimensions in signal array passed to
          :meth:`solve`. If there will only be 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 = OnlineConvBPDNDictLearn.Options()
        if not isinstance(opt, OnlineConvBPDNDictLearn.Options):
            raise TypeError('Parameter opt must be an instance of '
                            'OnlineConvBPDNDictLearn.Options')
        self.opt = opt

        if dimN != 2 and opt['CUDA_CBPDN']:
            raise ValueError('CUDA CBPDN solver can only be used when dimN=2')

        if opt['CUDA_CBPDN'] and cuda.device_count() == 0:
            raise ValueError('SPORCO-CUDA not installed or no GPU available')

        self.dimK = dimK
        self.dimN = dimN

        # DataType option overrides data type inferred from __init__
        # parameters of derived class
        self.set_dtype(opt, D0.dtype)

        # Initialise attributes representing algorithm parameter
        self.lmbda = lmbda
        self.eta_a = opt['eta_a']
        self.eta_b = opt['eta_b']
        self.set_attr('eta',
                      opt['eta_a'] / opt['eta_b'],
                      dval=2.0,
                      dtype=self.dtype)

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

        # Construct object representing problem dimensions
        self.cri = None

        # Normalise dictionary
        ds = cr.DictionarySize(self.dsz, dimN)
        dimCd = ds.ndim - dimN - 1
        D0 = cr.stdformD(D0, ds.nchn, ds.nflt, dimN).astype(self.dtype)
        self.D = cr.Pcn(D0,
                        self.dsz, (),
                        dimN,
                        dimCd,
                        crp=True,
                        zm=opt['ZeroMean'])
        self.Dprv = self.D.copy()

        # Create constraint set projection function
        self.Pcn = cr.getPcn(self.dsz, (),
                             dimN,
                             dimCd,
                             crp=True,
                             zm=opt['ZeroMean'])

        # Initalise iterations stats list and iteration index
        self.itstat = []
        self.j = 0

        # Configure status display
        self.display_config()
コード例 #4
0
mu = 0.1
optx = cbpdn.ConvBPDNJoint.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.ConvCnstrMODOptions({'Verbose': False, 'MaxMainIter': 1,
            'rho': 10.0*cri.K, 'AutoRho': {'Period': 10, 'AutoScaling': False,
            'RsdlRatio': 10.0, 'Scaling': 2.0, 'RsdlTarget': 1.0}},
            method='ism')


"""
Normalise dictionary according to dictionary Y update options.
"""

D0n = cnvrep.Pcn(D0, D0.shape, cri.Nv, dimN=2, dimC=0, crp=True,
                 zm=optd['ZeroMean'])


"""
Update D update options to include initial values for Y and U.
"""

optd.update({'Y0': cnvrep.zpad(cnvrep.stdformD(D0n, cri.Cd, cri.M), cri.Nv),
             'U0': np.zeros(cri.shpD)})


"""
Create X update object.
"""

xstep = cbpdn.ConvBPDNJoint(D0n, sh, lmbda, mu, optx)
コード例 #5
0
    def __init__(self,
                 D0,
                 S,
                 lmbda,
                 W,
                 opt=None,
                 xmethod=None,
                 dmethod=None,
                 dimK=1,
                 dimN=2):
        """

        |

        **Call graph**

        .. image:: ../_static/jonga/cbpdnmddl_init.svg
           :width: 20%
           :target: ../_static/jonga/cbpdnmddl_init.svg

        |


        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) after reshaping to the shape determined by
          :func:`.cnvrep.mskWshape`.
        opt : :class:`ConvBPDNMaskDictLearn.Options` object
          Algorithm options
        xmethod : string, optional (default 'admm')
          String selecting sparse coding solver. Valid values are
          documented in function :func:`.ConvBPDNMask`.
        dmethod : string, optional (default 'pgm')
          String selecting dictionary update solver. Valid values are
          documented in function :func:`.ConvCnstrMODMask`.
        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 = ConvBPDNMaskDictLearn.Options(xmethod=xmethod,
                                                dmethod=dmethod)
        if xmethod is None:
            xmethod = opt.xmethod
        if dmethod is None:
            dmethod = opt.dmethod
        if opt.xmethod != xmethod or opt.dmethod != dmethod:
            raise ValueError('Parameters xmethod and dmethod must have the '
                             'same values used to initialise the Options '
                             'object')
        self.opt = opt
        self.xmethod = xmethod
        self.dmethod = dmethod

        # 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 Y
        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 = cr.zpad(cr.stdformD(D0, cri.Cd, cri.M, dimN), cri.Nv)
        if dmethod == 'pgm':
            opt['CCMOD'].update({'X0': Y0b1})
        else:
            if dmethod == 'cns':
                Y0 = Y0b1
            else:
                Y0 = np.concatenate((Y0b0, Y0b1), axis=cri.axisM)
            opt['CCMOD'].update({'Y0': Y0})

        # Create X update object
        xstep = ConvBPDNMask(D0,
                             S,
                             lmbda,
                             W,
                             opt['CBPDN'],
                             method=xmethod,
                             dimK=dimK,
                             dimN=dimN)

        # Create D update object
        dstep = ConvCnstrMODMask(None,
                                 S,
                                 W,
                                 dsz,
                                 opt['CCMOD'],
                                 method=dmethod,
                                 dimK=dimK,
                                 dimN=dimN)

        # Configure iteration statistics reporting
        isc = dictlrn.IterStatsConfig(isfld=dc.isfld(xmethod, dmethod, opt),
                                      isxmap=dc.isxmap(xmethod, opt),
                                      isdmap=dc.isdmap(dmethod),
                                      evlmap=dc.evlmap(opt['AccurateDFid']),
                                      hdrtxt=dc.hdrtxt(xmethod, dmethod, opt),
                                      hdrmap=dc.hdrmap(xmethod, dmethod, opt),
                                      fmtmap={
                                          'It_X': '%4d',
                                          'It_D': '%4d'
                                      })

        # Call parent constructor
        super(ConvBPDNMaskDictLearn, self).__init__(xstep, dstep, opt, isc)
コード例 #6
0
ファイル: cbpdndl.py プロジェクト: young-oct/complex_sporco
    def __init__(self,
                 D0,
                 S,
                 lmbda=None,
                 opt=None,
                 xmethod=None,
                 dmethod=None,
                 dimK=1,
                 dimN=2):
        """

        |

        **Call graph**

        .. image:: ../_static/jonga/cbpdndl_init.svg
           :width: 20%
           :target: ../_static/jonga/cbpdndl_init.svg

        |


        Parameters
        ----------
        D0 : array_like
          Initial dictionary array
        S : array_like
          Signal array
        lmbda : float
          Regularisation parameter
        opt : :class:`ConvBPDNDictLearn.Options` object
          Algorithm options
        xmethod : string, optional (default 'admm')
          String selecting sparse coding solver. Valid values are
          documented in function :func:`.ConvBPDN`.
        dmethod : string, optional (default 'fista')
          String selecting dictionary update solver. Valid values are
          documented in function :func:`.ConvCnstrMOD`.
        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 = ConvBPDNDictLearn.Options(xmethod=xmethod, dmethod=dmethod)
        if xmethod is None:
            xmethod = opt.xmethod
        if dmethod is None:
            dmethod = opt.dmethod
        if opt.xmethod != xmethod or opt.dmethod != dmethod:
            raise ValueError('Parameters xmethod and dmethod must have the '
                             'same values used to initialise the Options '
                             'object')
        self.opt = opt
        self.xmethod = xmethod
        self.dmethod = dmethod

        # 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 value for Y
        optname = 'X0' if dmethod == 'fista' else 'Y0'
        opt['CCMOD'].update(
            {optname: cr.zpad(cr.stdformD(D0, cri.Cd, cri.M, dimN), cri.Nv)})

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

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

        # Configure iteration statistics reporting
        isc = dictlrn.IterStatsConfig(isfld=dc.isfld(xmethod, dmethod, opt),
                                      isxmap=dc.isxmap(xmethod, opt),
                                      isdmap=dc.isdmap(dmethod),
                                      evlmap=dc.evlmap(opt['AccurateDFid']),
                                      hdrtxt=dc.hdrtxt(xmethod, dmethod, opt),
                                      hdrmap=dc.hdrmap(xmethod, dmethod, opt),
                                      fmtmap={
                                          'It_X': '%4d',
                                          'It_D': '%4d'
                                      })

        # Call parent constructor
        super(ConvBPDNDictLearn, self).__init__(xstep, dstep, opt, isc)
コード例 #7
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.ConvCnstrMODMask(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)
コード例 #8
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. 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 = 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 = 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
        opt['CCMOD'].update(
            {'X0': cr.zpad(cr.stdformD(D0, cri.C, cri.M, dimN), cri.Nv)})

        # Create X update object
        xstep = Fcbpdn.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)

        print("L xstep in cbpdndl: ", xstep.L)
        print("L dstep in cbpdndl: ", dstep.L)

        # Configure iteration statistics reporting
        isfld = ['Iter', 'ObjFun', 'DFid', 'RegL1', 'Cnstr']
        hdrtxt = ['Itn', 'Fnc', 'DFid', u('ℓ1'), 'Cnstr']
        hdrmap = {
            'Itn': 'Iter',
            'Fnc': 'ObjFun',
            'DFid': 'DFid',
            u('ℓ1'): 'RegL1',
            'Cnstr': 'Cnstr'
        }

        if self.opt['AccurateDFid']:
            isxmap = {
                'X_F_Btrack': 'F_Btrack',
                'X_Q_Btrack': 'Q_Btrack',
                'X_ItBt': 'IterBTrack',
                'X_L': 'L',
                'X_Rsdl': 'Rsdl'
            }
            evlmap = {'ObjFun': 'ObjFun', 'DFid': 'DFid', 'RegL1': 'RegL1'}
        else:
            isxmap = {
                'ObjFun': 'ObjFun',
                'DFid': 'DFid',
                'RegL1': 'RegL1',
                'X_F_Btrack': 'F_Btrack',
                'X_Q_Btrack': 'Q_Btrack',
                'X_ItBt': 'IterBTrack',
                'X_L': 'L',
                'X_Rsdl': 'Rsdl'
            }
            evlmap = {}

        # If Backtracking enabled in xstep display the BT variables also
        if xstep.opt['BackTrack', 'Enabled']:
            isfld.extend(
                ['X_F_Btrack', 'X_Q_Btrack', 'X_ItBt', 'X_L', 'X_Rsdl'])
            hdrtxt.extend(['F_X', 'Q_X', 'It_X', 'L_X'])
            hdrmap.update({
                'F_X': 'X_F_Btrack',
                'Q_X': 'X_Q_Btrack',
                'It_X': 'X_ItBt',
                'L_X': 'X_L'
            })
        else:  # Add just L value to xstep display
            isfld.extend(['X_L', 'X_Rsdl'])
            hdrtxt.append('L_X')
            hdrmap.update({'L_X': 'X_L'})

        isdmap = {
            'Cnstr': 'Cnstr',
            'D_F_Btrack': 'F_Btrack',
            'D_Q_Btrack': 'Q_Btrack',
            'D_ItBt': 'IterBTrack',
            'D_L': 'L',
            'D_Rsdl': 'Rsdl'
        }

        # If Backtracking enabled in dstep display the BT variables also
        if dstep.opt['BackTrack', 'Enabled']:
            isfld.extend([
                'D_F_Btrack', 'D_Q_Btrack', 'D_ItBt', 'D_L', 'D_Rsdl', 'Time'
            ])
            hdrtxt.extend(['F_D', 'Q_D', 'It_D', 'L_D'])
            hdrmap.update({
                'F_D': 'D_F_Btrack',
                'Q_D': 'D_Q_Btrack',
                'It_D': 'D_ItBt',
                'L_D': 'D_L'
            })
        else:  # Add just L value to dstep display
            isfld.extend(['D_L', 'D_Rsdl', 'Time'])
            hdrtxt.append('L_D')
            hdrmap.update({'L_D': 'D_L'})

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

        # Call parent constructor
        super(ConvBPDNDictLearn, self).__init__(xstep, dstep, opt, isc)
コード例 #9
0
ファイル: cbpdndl.py プロジェクト: wmvanvliet/alphacsc
    def __init__(self,
                 D0,
                 S,
                 lmbda,
                 W,
                 opt=None,
                 method='cns',
                 dimK=1,
                 dimN=2):
        """
        Initialise a ConvBPDNMaskDcplDictLearn object with problem size and
        options.

        |

        **Call graph**

        .. image:: _static/jonga/cbpdnmddl_init.svg
           :width: 20%
           :target: _static/jonga/cbpdnmddl_init.svg

        |


        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:`ConvBPDNMaskDcplDictLearn.Options` object
          Algorithm options
        method : string, optional (default 'cns')
          String selecting dictionary update solver. Valid values are
          documented in function :func:`.ConvCnstrMODMaskDcpl`.
        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(method=method)
        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 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 = cr.zpad(cr.stdformD(D0, cri.Cd, cri.M, dimN), cri.Nv)
        if method == 'cns':
            Y0 = Y0b1
        else:
            Y0 = np.concatenate((Y0b0, Y0b1), axis=cri.axisM)
        opt['CCMOD'].update({'Y0': Y0})

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

        # Create D update object
        dstep = ccmodmd.ConvCnstrMODMaskDcpl(None,
                                             S,
                                             W,
                                             dsz,
                                             opt['CCMOD'],
                                             method=method,
                                             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)
コード例 #10
0
ファイル: cbpdndl.py プロジェクト: wmvanvliet/alphacsc
    def __init__(self,
                 D0,
                 S,
                 lmbda=None,
                 opt=None,
                 method='cns',
                 dimK=1,
                 dimN=2,
                 stopping_pobj=None):
        """
        Initialise a ConvBPDNDictLearn object with problem size and options.

        |

        **Call graph**

        .. image:: _static/jonga/cbpdndl_init.svg
           :width: 20%
           :target: _static/jonga/cbpdndl_init.svg

        |


        Parameters
        ----------
        D0 : array_like
          Initial dictionary array
        S : array_like
          Signal array
        lmbda : float
          Regularisation parameter
        opt : :class:`ConvBPDNDictLearn.Options` object
          Algorithm options
        method : string, optional (default 'cns')
          String selecting dictionary update solver. Valid values are
          documented in function :func:`.ConvCnstrMOD`.
        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 = ConvBPDNDictLearn.Options(method=method)
        self.opt = opt

        self.stopping_pobj = stopping_pobj

        # 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 Y and U
        opt['CCMOD'].update(
            {'Y0': cr.zpad(cr.stdformD(D0, cri.C, cri.M, dimN), cri.Nv)})

        # 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'],
                                   method=method,
                                   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(ConvBPDNDictLearn, self).__init__(xstep, dstep, opt, isc)