def __init__(self, D0, S, lmbda=None, opt=None): """ Initialise a BPDNDictLearn object with problem size and options. Parameters ---------- D0 : array_like, shape (N, M) Initial dictionary matrix S : array_like, shape (N, K) Signal vector or matrix lmbda : float Regularisation parameter opt : :class:`BPDNDictLearn.Options` object Algorithm options """ if opt is None: opt = BPDNDictLearn.Options() self.opt = opt # Normalise dictionary according to D update options D0 = cmod.getPcn(opt['CMOD', 'ZeroMean'])(D0) # Modify D update options to include initial values for Y and U Nc = D0.shape[1] opt['CMOD'].update({'Y0' : D0, 'U0' : np.zeros((S.shape[0], Nc))}) # Create X update object xstep = bpdn.BPDN(D0, S, lmbda, opt['BPDN']) # Create D update object Nm = S.shape[1] dstep = cmod.CnstrMOD(xstep.Y, S, (Nc, Nm), opt['CMOD']) # 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', 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(BPDNDictLearn, self).__init__(xstep, dstep, opt, isc)
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)
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)
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)
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)
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)