def test_02(self): N = 8 M = 16 D = np.random.randn(N, M) s = np.random.randn(N, 1) try: b = bpdn.BPDN(D, s) b.solve() except Exception as e: print(e) assert 0
def test_01(self): N = 8 M = 16 D = np.random.randn(N, M) s = np.random.randn(N, 1) lmbda = 1e-1 try: b = bpdn.BPDN(D, s, lmbda) b.solve() except Exception as e: print(e) assert 0
def test_10(self): N = 8 M = 16 D = np.random.randn(N, M) s = np.random.randn(N, 1) lmbda = 1e-1 opt = bpdn.BPDN.Options({'Verbose': False, 'MaxMainIter': 10}) b = bpdn.BPDN(D, s, lmbda, opt) bp = pickle.dumps(b) c = pickle.loads(bp) Xb = b.solve() Xc = c.solve() assert np.linalg.norm(Xb - Xc) == 0.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
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
def test_04(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': 50, 'RelStopTol': 1e-4, 'Backtrack': BacktrackRobust(maxiter=20) }) 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
def test_14(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': 50, 'RelStopTol': 1e-4, 'StepSizePolicy': StepSizePolicyBB() }) 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
def test_12(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': 100, 'RelStopTol': 1e-4, 'Momentum': MomentumGenLinear() }) 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
def test_09(self): N = 64 M = 2 * N L = 4 np.random.seed(12345) D = np.random.randn(N, M) x0 = np.zeros((M, 1)) si = np.random.permutation(list(range(0, M - 1))) x0[si[0:L]] = np.random.randn(L, 1) s0 = D.dot(x0) lmbda = 5e-3 opt = bpdn.BPDN.Options({ 'Verbose': False, 'MaxMainIter': 1000, 'RelStopTol': 5e-8, 'Backtrack': BacktrackRobust(gamma_d=0.95) }) b = bpdn.BPDN(D, s0, lmbda, opt) b.solve() x1 = b.Y assert np.abs(b.itstat[-1].ObjFun - 0.012009) < 1e-5 assert np.abs(b.itstat[-1].DFid - 1.9636082e-06) < 1e-5 assert np.abs(b.itstat[-1].RegL1 - 2.401446) < 2e-4 assert np.linalg.norm(x1 - x0) < 1e-3
""" D0 = util.convdicts()['G:8x8x64'] D0 = np.reshape(D0, (np.prod(D0.shape[0:2]), D0.shape[2])) """ Compute sparse representation on current dictionary. """ lmbda = 0.1 opt = bpdn.BPDN.Options({ 'Verbose': True, 'MaxMainIter': 50, 'L': 100, 'Backtrack': BacktrackRobust() }) b = bpdn.BPDN(D0, S, lmbda, opt) X = b.solve() """ Update dictionary for training image set using PGM with Cauchy step size policy :cite:`yuan-2008-stepsize`. """ opt = cmod.CnstrMOD.Options({ 'Verbose': True, 'MaxMainIter': 100, 'L': 50, 'StepSizePolicy': StepSizePolicyCauchy() }) c1 = cmod.CnstrMOD(X, S, None, opt) D11 = c1.solve() print("CMOD solve time: %.2fs" % c1.timer.elapsed('solve')) """
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. """ opt = bpdn.BPDN.Options({ 'Verbose': True, 'MaxMainIter': 50, 'L': L_sc, 'Backtrack': BacktrackRobust() }) """
print("ADMM BPDN solve time: %.2fs" % ba.timer.elapsed('solve')) """ Set options for PGM solver. """ opt_pgm = pbpdn.BPDN.Options({ 'Verbose': True, 'MaxMainIter': 50, 'L': 9e2, 'Backtrack': BacktrackRobust() }) """ Initialise and run PGM solver. """ bp = pbpdn.BPDN(D, s, lmbda, opt_pgm) xp = bp.solve() print("PGM BPDN solve time: %.2fs" % bp.timer.elapsed('solve')) """ Plot comparison of reference and recovered representations. """ plot.plot(np.hstack((x0, xa, xp)), alpha=0.5, title='Sparse representation', lgnd=['Reference', 'Reconstructed (ADMM)', 'Reconstructed (PGM)']) """ Plot functional value, residual, and L """