示例#1
0
 def test_03(self):
     lmbda = 1e-1
     opt = parcnsdl.ConvBPDNDictLearn_Consensus.Options({'MaxMainIter': 10})
     try:
         b = parcnsdl.ConvBPDNDictLearn_Consensus(self.D0, self.S, lmbda,
                                                  opt=opt, nproc=0)
         b.solve()
     except Exception as e:
         print(e)
         assert(0)
示例#2
0
 def test_04(self):
     N = 16
     Nc = 3
     Nd = 5
     M = 4
     K = 3
     D0 = np.random.randn(Nd, Nd, Nc, M)
     S = np.random.randn(N, N, Nc, K)
     lmbda = 1e-1
     opt = parcnsdl.ConvBPDNDictLearn_Consensus.Options({'MaxMainIter': 10})
     try:
         b = parcnsdl.ConvBPDNDictLearn_Consensus(D0, S, lmbda, opt=opt,
                                                  nproc=2)
         b.solve()
     except Exception as e:
         print(e)
         assert(0)
示例#3
0
 def test_05(self):
     lmbda = 1e-1
     Nit = 10
     opts = cbpdndl.ConvBPDNDictLearn.Options(
         {'MaxMainIter': Nit, 'AccurateDFid': True,
          'CBPDN': {'RelaxParam': 1.0, 'AutoRho': {'Enabled': False}},
          'CCMOD': {'RelaxParam': 1.0, 'AutoRho': {'Enabled': False}}})
     bs = cbpdndl.ConvBPDNDictLearn(self.D0, self.S, lmbda, opt=opts,
                                    method='cns')
     Ds = bs.solve()
     optp = parcnsdl.ConvBPDNDictLearn_Consensus.Options(
         {'MaxMainIter': Nit})
     bp = parcnsdl.ConvBPDNDictLearn_Consensus(self.D0, self.S, lmbda,
                                               opt=optp, nproc=2)
     Dp = bp.solve()
     assert(np.linalg.norm(Ds - Dp) < 1e-7)
     assert(np.abs(bs.getitstat().ObjFun[-1] - bp.getitstat().ObjFun[-1])
            < 1e-7)
示例#4
0
"""
Set regularization parameter and options for dictionary learning solver.
"""

lmbda = 0.2
opt = parcnsdl.ConvBPDNDictLearn_Consensus.Options({'Verbose': True,
                        'MaxMainIter': 200,
                        'CBPDN': {'rho': 50.0*lmbda + 0.5},
                        'CCMOD': {'rho': 1.0, 'ZeroMean': True}})


"""
Create solver object and solve.
"""

d = parcnsdl.ConvBPDNDictLearn_Consensus(D0, sh, lmbda, opt)
D1 = d.solve()
print("ConvBPDNDictLearn_Consensus solve time: %.2fs" %
      d.timer.elapsed('solve'))


"""
Display initial and final dictionaries.
"""

D1 = D1.squeeze()
fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), fig=fig, title='D0')
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), fig=fig, title='D1')