Beispiel #1
0
        def __init__(self, opt=None, method='cns'):
            """Initialise ConvBPDN dictionary learning algorithm options.

            Valid values for parameter ``method`` are documented in function
            :func:`.ConvCnstrMOD`.
            """

            self.defaults.update({
                'CCMOD':
                copy.deepcopy(
                    ccmod.ConvCnstrMODOptions(method=method).defaults)
            })

            dictlrn.DictLearn.Options.__init__(
                self, {
                    'CBPDN':
                    cbpdn.ConvBPDN.Options({
                        'MaxMainIter': 1,
                        'AutoRho': {
                            'Period': 10,
                            'AutoScaling': False,
                            'RsdlRatio': 10.0,
                            'Scaling': 2.0,
                            'RsdlTarget': 1.0
                        }
                    }),
                    'CCMOD':
                    ccmod.ConvCnstrMODOptions(
                        {
                            'MaxMainIter': 1,
                            'AutoRho': {
                                'Period': 10,
                                'AutoScaling': False,
                                'RsdlRatio': 10.0,
                                'Scaling': 2.0,
                                'RsdlTarget': 1.0
                            }
                        },
                        method=method)
                })

            if opt is None:
                opt = {}
            self.update(opt)
Beispiel #2
0
 def test_08(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.ConvCnstrMODOptions(
         {'Verbose': False, 'MaxMainIter': 20,
          'AutoRho': {'Enabled': True},
          'DataType': dt})
     c = ccmod.ConvCnstrMOD(X, S, (Nd, Nd, M), opt=opt)
     c.solve()
     assert(c.X.dtype == dt)
     assert(c.Y.dtype == dt)
     assert(c.U.dtype == dt)
Beispiel #3
0
 def test_06(self):
     N = 16
     M = 4
     Nc = 3
     Nd = 8
     X = np.random.randn(N, N, Nc, 1, M)
     S = np.random.randn(N, N, Nc)
     try:
         opt = ccmod.ConvCnstrMODOptions({'Verbose': False,
                         'MaxMainIter': 20, 'LinSolveCheck': True})
         c = ccmod.ConvCnstrMOD(X, S, (Nd, Nd, 1, M), opt=opt, dimK=0)
         c.solve()
     except Exception as e:
         print(e)
         assert(0)
     assert(np.array(c.getitstat().XSlvRelRes).max() < 1e-5)
cri = cnvrep.CDU_ConvRepIndexing(D0.shape, sh)


"""
Define X and D update options.
"""

lmbda = 0.2
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.
"""
Beispiel #5
0
D0 = util.convdicts()['G:12x12x36']

# Compute sparse representation on current dictionary
lmbda = 0.01
opt = cbpdn.ConvBPDN.Options({
    'Verbose': True,
    'MaxMainIter': 200,
    'RelStopTol': 5e-3
})
b = cbpdn.ConvBPDN(D0, sh, lmbda, opt)
b.solve()

# Update dictionary for training set sh
opt = ccmod.ConvCnstrMODOptions({
    'Verbose': True,
    'MaxMainIter': 100,
    'rho': 5.0
})
c = ccmod.ConvCnstrMOD(b.Y, sh, D0.shape, opt)
c.solve()
print("ConvCnstrMOD solve time: %.2fs" % c.timer.elapsed('solve'))
D1 = c.getdict().squeeze()

# Display dictionaries
fig1 = plot.figure(1, figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), fgrf=fig1, title='D0')
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), fgrf=fig1, title='D1')
fig1.show()