コード例 #1
0
ファイル: test_cbpdn.py プロジェクト: wmvanvliet/alphacsc
 def test_11(self):
     N = 63
     M = 4
     Nd = 8
     D = np.random.randn(Nd, Nd, M)
     X0 = np.zeros((N, N, M))
     xr = np.random.randn(N, N, M)
     xp = np.abs(xr) > 3
     X0[xp] = np.random.randn(X0[xp].size)
     S = np.sum(sl.ifftn(
         sl.fftn(D, (N, N), (0, 1)) * sl.fftn(X0, None, (0, 1)), None,
         (0, 1)).real,
                axis=2)
     lmbda = 1e-2
     L = 1e3
     opt = cbpdn.ConvBPDN.Options({
         'Verbose': False,
         'MaxMainIter': 2000,
         'RelStopTol': 1e-5,
         'L': L,
         'BackTrack': {
             'Enabled': False
         }
     })
     b = cbpdn.ConvBPDN(D, S, lmbda, opt)
     b.solve()
     X1 = b.X.squeeze()
     assert (sl.rrs(X0, X1) < 5e-4)
     Sr = b.reconstruct().squeeze()
     assert (sl.rrs(S, Sr) < 2e-4)
コード例 #2
0
ファイル: test_cbpdn.py プロジェクト: wmvanvliet/alphacsc
 def test_05(self):
     N = 16
     Nd = 5
     K = 2
     M = 4
     D = np.random.randn(Nd, Nd, M)
     s = np.random.randn(N, N, K)
     lmbda = 1e-1
     b = cbpdn.ConvBPDN(D, s, lmbda)
     assert (b.cri.dimC == 0)
     assert (b.cri.dimK == 1)
コード例 #3
0
ファイル: test_cbpdn.py プロジェクト: wmvanvliet/alphacsc
 def test_03(self):
     N = 16
     Nd = 5
     Cd = 3
     M = 4
     D = np.random.randn(Nd, Nd, Cd, M)
     s = np.random.randn(N, N, Cd)
     lmbda = 1e-1
     b = cbpdn.ConvBPDN(D, s, lmbda)
     assert (b.cri.dimC == 1)
     assert (b.cri.dimK == 0)
コード例 #4
0
 def test_01(self):
     N = 16
     Nd = 5
     Cs = 3
     M = 4
     D = np.random.randn(Nd, Nd, M)
     s = np.random.randn(N, N, Cs)
     lmbda = 1e-1
     b = cbpdn.ConvBPDN(D, s, lmbda, dimK=0)
     assert b.cri.dimC == 1
     assert b.cri.dimK == 0
コード例 #5
0
ファイル: test_cbpdn.py プロジェクト: wmvanvliet/alphacsc
 def test_02(self):
     N = 16
     Nd = 5
     Cs = 3
     K = 5
     M = 4
     D = np.random.randn(Nd, Nd, M)
     s = np.random.randn(N, N, Cs, K)
     lmbda = 1e-1
     b = cbpdn.ConvBPDN(D, s, lmbda)
     assert (b.cri.dimC == 1)
     assert (b.cri.dimK == 1)
コード例 #6
0
ファイル: test_cbpdn.py プロジェクト: wmvanvliet/alphacsc
 def test_09(self):
     N = 16
     Nd = 5
     M = 4
     D = np.random.randn(Nd, Nd, M)
     s = np.random.randn(N, N)
     try:
         b = cbpdn.ConvBPDN(D, s)
         b.solve()
     except Exception as e:
         print(e)
         assert (0)
コード例 #7
0
 def test_04(self):
     N = 16
     Nd = 5
     Cd = 3
     K = 5
     M = 4
     D = np.random.randn(Nd, Nd, Cd, M)
     s = np.random.randn(N, N, Cd, K)
     lmbda = 1e-1
     b = cbpdn.ConvBPDN(D, s, lmbda)
     assert b.cri.dimC == 1
     assert b.cri.dimK == 1
コード例 #8
0
ファイル: test_cbpdn.py プロジェクト: wmvanvliet/alphacsc
 def test_12(self):
     N = 16
     Nd = 5
     Cs = 3
     M = 4
     D = np.random.randn(Nd, Nd, M)
     s = np.random.randn(N, N, Cs)
     lmbda = 1e-1
     L = 1e3
     opt = cbpdn.ConvBPDN.Options({'L': L})
     b = cbpdn.ConvBPDN(D, s, lmbda, opt=opt, dimK=0)
     b.solve()
     assert (np.array(b.getitstat().Rsdl)[-1] < 1e-3)
コード例 #9
0
 def test_13(self):
     N = 16
     Nd = 5
     Cs = 3
     M = 4
     D = np.random.randn(Nd, Nd, M)
     s = np.random.randn(N, N, Cs)
     lmbda = 1e-1
     L = 1e3
     try:
         opt = cbpdn.ConvBPDN.Options({'L': L})
         b = cbpdn.ConvBPDN(D, s, lmbda, opt=opt, dimK=0)
         b.solve()
     except Exception as e:
         print(e)
         assert 0
     assert np.array(b.getitstat().Rsdl)[-1] < 1e-3
コード例 #10
0
ファイル: test_cbpdn.py プロジェクト: wmvanvliet/alphacsc
 def test_06(self):
     N = 16
     Nd = 5
     K = 2
     M = 4
     D = np.random.randn(Nd, Nd, M)
     s = np.random.randn(N, N, K)
     dt = np.float32
     opt = cbpdn.ConvBPDN.Options({
         'Verbose': False,
         'MaxMainIter': 20,
         'BackTrack': {
             'Enabled': True
         },
         'DataType': dt
     })
     lmbda = 1e-1
     b = cbpdn.ConvBPDN(D, s, lmbda, opt=opt)
     b.solve()
     assert (b.X.dtype == dt)
     assert (b.Xf.dtype == sl.complex_dtype(dt))
     assert (b.Yf.dtype == sl.complex_dtype(dt))
コード例 #11
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)
コード例 #12
0
"""
Set :class:`.fista.cbpdn.ConvBPDN` solver options.
"""

lmbda = 5e-2
L = 1e2
opt = cbpdn.ConvBPDN.Options({'Verbose': True, 'MaxMainIter': 250,
            'RelStopTol': 5e-3, 'L': L, 'BackTrack': {'Enabled': True }})


"""
Initialise and run CSC solver.
"""

b = cbpdn.ConvBPDN(D, sh, lmbda, opt, dimK=0)
X = b.solve()
print("ConvBPDN solve time: %.2fs" % b.timer.elapsed('solve'))


"""
Reconstruct image from sparse representation.
"""

shr = b.reconstruct().squeeze()
imgr = sl + shr
print("Reconstruction PSNR: %.2fdB\n" % psnr(img, imgr))


"""
Display low pass component and sum of absolute values of coefficient maps of highpass component.
コード例 #13
0
lmbda = 1e-1
L = 1e2
opt = cbpdn.ConvBPDN.Options({
    'Verbose': True,
    'MaxMainIter': 250,
    'RelStopTol': 8e-5,
    'L': L,
    'BackTrack': {
        'Enabled': True
    }
})
"""
Initialise and run CSC solver.
"""

b = cbpdn.ConvBPDN(D, sh, lmbda, opt)
X = b.solve()
print("ConvBPDN solve time: %.2fs" % b.timer.elapsed('solve'))
"""
Reconstruct image from sparse representation.
"""

shr = b.reconstruct().squeeze()
imgr = sl + shr
print("Reconstruction PSNR: %.2fdB\n" % sm.psnr(img, imgr))
"""
Display low pass component and sum of absolute values of coefficient maps of highpass component.
"""

fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)