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 } } }, dmethod='cns') bs = cbpdndl.ConvBPDNDictLearn(self.D0, self.S, lmbda, opt=opts, dmethod='cns') Ds = bs.solve() optp = prlcnscdl.ConvBPDNDictLearn_Consensus.Options({ 'MaxMainIter': Nit, 'CBPDN': { 'RelaxParam': 1.0 }, 'CCMOD': { 'RelaxParam': 1.0 } }) bp = prlcnscdl.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)
def par_csc(input_, d_size, lmbda, Iter, visualize=False): D0 = np.random.uniform(-1.0, 1.0, d_size) opt = prlcnscdl.ConvBPDNDictLearn_Consensus.Options({ 'Verbose': True, 'MaxMainIter': Iter, 'CBPDN': { 'rho': 50.0 * lmbda + 0.5 }, 'CCMOD': { 'rho': 1.0, 'ZeroMean': True } }) d = prlcnscdl.ConvBPDNDictLearn_Consensus(D0, input_, lmbda, opt, nproc=12) D1 = d.solve() print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve')) if visualize: plot_2([util.tiledict(D0.squeeze()), util.tiledict(D1.squeeze())], ["initial dictionary", "learned dictionary"]) return d, D1, d.getcoef()
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 = prlcnscdl.ConvBPDNDictLearn_Consensus.Options( {'MaxMainIter': 10}) try: b = prlcnscdl.ConvBPDNDictLearn_Consensus(D0, S, lmbda, opt=opt, nproc=2) b.solve() except Exception as e: print(e) assert 0
""" Set regularization parameter and options for dictionary learning solver. """ lmbda = 0.2 opt = prlcnscdl.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 = prlcnscdl.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), title='D0', fig=fig) plot.subplot(1, 2, 2) plot.imview(util.tiledict(D1), title='D1', fig=fig)