Esempio n. 1
0
 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(ifftn(
         fftn(D, (N, N), (0, 1)) * 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-9,
         'L': L,
         'Backtrack': BacktrackStandard()
     })
     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
Esempio n. 2
0
    def test_13(self):
        N = 64
        M = 4
        Nd = 8
        D0 = cr.normalise(cr.zeromean(np.random.randn(Nd, Nd, M), (Nd, Nd, M),
                                      dimN=2),
                          dimN=2)
        X = np.zeros((N, N, M))
        xr = np.random.randn(N, N, M)
        xp = np.abs(xr) > 3
        X[xp] = np.random.randn(X[xp].size)
        S = np.sum(ifftn(
            fftn(D0, (N, N), (0, 1)) * fftn(X, None, (0, 1)), None,
            (0, 1)).real,
                   axis=2)
        L = 0.5
        opt = ccmod.ConvCnstrMOD.Options({
            'Verbose': False,
            'MaxMainIter': 3000,
            'ZeroMean': True,
            'RelStopTol': 0.,
            'L': L,
            'Backtrack': BacktrackStandard()
        })
        Xr = X.reshape(X.shape[0:2] + (
            1,
            1,
        ) + X.shape[2:])
        Sr = S.reshape(S.shape + (1, ))
        c = ccmod.ConvCnstrMOD(Xr, Sr, D0.shape, opt)
        c.solve()
        D1 = cr.bcrop(c.X, D0.shape).squeeze()

        assert rrs(D0, D1) < 1e-4
        assert np.array(c.getitstat().Rsdl)[-1] < 1e-5
Esempio n. 3
0
 def test_08(self):
     N = 8
     M = 16
     D = np.random.randn(N, M)
     s = np.random.randn(N, 1)
     dt = np.float64
     opt = bpdn.BPDN.Options({
         'Verbose': False,
         'MaxMainIter': 20,
         'Backtrack': BacktrackStandard(gamma_u=1.1),
         'DataType': dt
     })
     b = bpdn.BPDN(D, s, lmbda=1.0, opt=opt)
     b.solve()
     assert b.X.dtype == dt
     assert b.Y.dtype == dt
Esempio n. 4
0
 def test_05(self):
     N = 8
     M = 8
     D = np.random.randn(N, M)
     s = np.random.randn(N, 1)
     try:
         opt = bpdn.BPDN.Options({
             'FastSolve': True,
             'Verbose': False,
             'MaxMainIter': 10,
             'Backtrack': BacktrackStandard()
         })
         b = bpdn.BPDN(D, s, lmbda=1.0, opt=opt)
         b.solve()
     except Exception as e:
         print(e)
         assert 0
Esempio n. 5
0
 def test_03(self):
     N = 8
     M = 16
     D = np.random.randn(N, M)
     s = np.random.randn(N, 1)
     try:
         opt = bpdn.BPDN.Options({
             'Verbose': False,
             'MaxMainIter': 80,
             'Backtrack': BacktrackStandard(),
             'RelStopTol': 1e-4
         })
         b = bpdn.BPDN(D, s, lmbda=1.0, opt=opt)
         b.solve()
     except Exception as e:
         print(e)
         assert 0
     assert np.array(b.getitstat().Rsdl).min() < 2e-4
Esempio n. 6
0
 def test_05(self):
     N = 16
     M = 4
     Nd = 8
     X = np.random.randn(N, N, 1, 1, M)
     S = np.random.randn(N, N, 1)
     dt = np.float64
     opt = ccmod.ConvCnstrMOD.Options({
         'Verbose': False,
         'MaxMainIter': 20,
         'Backtrack': BacktrackStandard(),
         'DataType': dt
     })
     c = ccmod.ConvCnstrMOD(X, S, (Nd, Nd, M), opt=opt)
     c.solve()
     assert c.X.dtype == dt
     assert c.Xf.dtype == complex_dtype(dt)
     assert c.Yf.dtype == complex_dtype(dt)
Esempio n. 7
0
 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': BacktrackStandard(),
         'DataType': dt
     })
     lmbda = 1e-1
     b = cbpdn.ConvBPDN(D, s, lmbda, opt=opt)
     b.solve()
     assert b.X.dtype == dt
     assert b.Xf.dtype == fft.complex_dtype(dt)
     assert b.Yf.dtype == fft.complex_dtype(dt)
Esempio n. 8
0
"""

D = util.convdicts()['RGB:8x8x3x64']
plot.imview(util.tiledict(D), fgsz=(7, 7))
"""
Set :class:`.pgm.cbpdn.ConvBPDN` solver options. Note the possibility of changing parameters in the backtracking algorithm.
"""

lmbda = 1e-1
L = 1e1
opt = cbpdn.ConvBPDN.Options({
    'Verbose': True,
    'MaxMainIter': 250,
    'RelStopTol': 8e-5,
    'L': L,
    'Backtrack': BacktrackStandard(maxiter=15)
})
"""
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))
Esempio n. 9
0
si = np.random.permutation(list(range(0, M - 1)))
x0[si[0:L]] = np.random.randn(L, 1)

# Construct reference and noisy signal
s0 = D.dot(x0)
s = s0 + sigma * np.random.randn(N, 1)
"""
Set regularisation parameter and options for BPDN solver with standard PGM backtracking.
"""

lmbda = 2.98e1
L_sc = 9.e2
opt = bpdn.BPDN.Options({
    'Verbose': True,
    'MaxMainIter': 50,
    'Backtrack': BacktrackStandard(),
    'L': L_sc
})
"""
Initialise and run BPDN object
"""

b1 = bpdn.BPDN(D, s, lmbda, opt)
x1 = b1.solve()

print("BPDN standard PGM backtracking solve time: %.2fs" %
      b1.timer.elapsed('solve'))
"""
Set options for BPDN solver with robust PGM backtracking.
"""
Esempio n. 10
0
D0 = np.random.randn(16, 16, 3, 96)
"""
Set regularization parameter and options for dictionary learning solver. Note the multi-scale dictionary filter sizes. Also note the possibility of changing parameters in the backtracking algorithm.
"""

lmbda = 0.2
L_sc = 36.0
L_du = 50.0
dsz = ((8, 8, 3, 32), (12, 12, 3, 32), (16, 16, 3, 32))
opt = cbpdndl.ConvBPDNDictLearn.Options(
    {
        'Verbose': True,
        'MaxMainIter': 200,
        'DictSize': dsz,
        'CBPDN': {
            'Backtrack': BacktrackStandard(gamma_u=1.1),
            'L': L_sc
        },
        'CCMOD': {
            'Backtrack': BacktrackStandard(),
            'L': L_du
        }
    },
    xmethod='pgm',
    dmethod='pgm')
"""
Create solver object and solve.
"""

d = cbpdndl.ConvBPDNDictLearn(D0, sh, lmbda, opt, xmethod='pgm', dmethod='pgm')
D1 = d.solve()