Ejemplo n.º 1
0
 def test_19(self):
     V2_a2, rsi = prox.ndto2d(self.V2, axis=2)
     V2_r = prox.ndfrom2d(V2_a2, rsi)
     assert (metric.mse(self.V2, V2_r) < 1e-14)
     V2_a1, rsi = prox.ndto2d(self.V2, axis=1)
     V2_r = prox.ndfrom2d(V2_a1, rsi)
     assert (metric.mse(self.V2, V2_r) < 1e-14)
     V2_a0, rsi = prox.ndto2d(self.V2, axis=0)
     V2_r = prox.ndfrom2d(V2_a0, rsi)
     assert (metric.mse(self.V2, V2_r) < 1e-14)
Ejemplo n.º 2
0
 def test_26(self):
     B0 = np.arange(1, 7).reshape(3, 2)
     C0 = np.arange(1, 5).reshape(2, 2)
     A0 = np.kron(B0, C0)
     B, C = linalg.nkp(A0, B0.shape, C0.shape)
     assert mse(A0, np.kron(B, C)) < 1e-12
     r = B0[0, 0] / B[0, 0]
     B *= r
     C /= r
     assert mse(B0, B) < 1e-12
     assert mse(C0, C) < 1e-12
Ejemplo n.º 3
0
 def test_39(self):
     B0 = np.arange(1, 7).reshape(3, 2)
     C0 = np.arange(1, 5).reshape(2, 2)
     A0 = np.kron(B0, C0)
     B, C = util.nkp(A0, B0.shape, C0.shape)
     assert (metric.mse(A0, np.kron(B, C)) < 1e-12)
     r = B0[0, 0] / B[0, 0]
     B *= r
     C /= r
     assert (metric.mse(B0, B) < 1e-12)
     assert (metric.mse(C0, C) < 1e-12)
Ejemplo n.º 4
0
 def test_28(self):
     alpha = np.random.randn()
     N = 7
     M = 10
     X0 = np.random.randn(N, M)
     A = np.random.randn(N, 1)
     B = np.random.randn(1, M)
     C = A * X0 * B + alpha * X0
     X1 = linalg.solve_symmetric_sylvester(A, B, C, alpha)
     assert mse(X0, X1) < 1e-14
     A = A[:, 0]
     B = B[0]
     X1 = linalg.solve_symmetric_sylvester(A, B, C, alpha)
     assert mse(X0, X1) < 1e-14
Ejemplo n.º 5
0
 def test_29(self):
     alpha = np.random.randn()
     N = 7
     M = 10
     X0 = np.random.randn(N, M)
     A = np.random.randn(N, 1)
     Bg = np.random.randn(M, 4)
     B = Bg.dot(Bg.T)
     C = A * X0.dot(B) + alpha * X0
     X1 = linalg.solve_symmetric_sylvester(A, B, C, alpha)
     assert mse(X0, X1) < 1e-12
     Lambda, Q = np.linalg.eigh(B)
     X1 = linalg.solve_symmetric_sylvester(A, (Lambda, Q), C, alpha)
     assert mse(X0, X1) < 1e-12
Ejemplo n.º 6
0
 def test_30(self):
     alpha = np.random.randn()
     N = 7
     M = 10
     X0 = np.random.randn(N, M)
     Ag = np.random.randn(4, N)
     A = Ag.T.dot(Ag)
     B = np.random.randn(1, M)
     C = A.dot(X0) * B + alpha * X0
     X1 = linalg.solve_symmetric_sylvester(A, B, C, alpha)
     assert mse(X0, X1) < 1e-12
     Lambda, Q = np.linalg.eigh(A)
     X1 = linalg.solve_symmetric_sylvester((Lambda, Q), B, C, alpha)
     assert mse(X0, X1) < 1e-12
Ejemplo n.º 7
0
 def test_40(self):
     B0 = np.random.randn(3, 5, 2)
     C0 = np.random.randn(4, 6, 2)
     A0 = kronsum(np.ones((2, )), B0, C0)
     S, B, C = util.kpsvd(A0, B0.shape[0:2], C0.shape[0:2])
     A = kronsum(S, B[..., 0:2], C[..., 0:2])
     assert (metric.mse(A0, A) < 1e-12)
Ejemplo n.º 8
0
 def test_11(self):
     for beta in [0.0, 0.5, 1.0]:
         for alpha in self.alpha:
             pV1 = prox.prox_dl1l2(self.V1, alpha, beta=beta, axis=0)
             for k in range(pV1.shape[1]):
                 pV1k = prox.prox_dl1l2(self.V1[:, k], alpha, beta=beta)
                 assert metric.mse(pV1[:, k], pV1k) < 1e-12
Ejemplo n.º 9
0
 def test_01(self):
     N = 64
     L = 20
     x = np.cos(np.linspace(0, np.pi, N))[np.newaxis, :]
     y = np.cos(np.linspace(0, np.pi, N))[:, np.newaxis]
     U = x * y
     V = np.random.randn(N, N)
     t = np.sort(np.abs(V).ravel())[V.size - L]
     V[np.abs(V) < t] = 0
     D = U + V
     lmbda = 0.1
     opt = spline.SplineL1.Options({
         'Verbose': False,
         'gEvalY': False,
         'MaxMainIter': 250,
         'RelStopTol': 5e-4,
         'DFidWeight': V == 0,
         'AutoRho': {
             'Enabled': True
         }
     })
     b = spline.SplineL1(D, lmbda, opt)
     X = b.solve()
     assert (np.abs(b.itstat[-1].ObjFun - 0.333606246) < 1e-6)
     assert (sm.mse(U, X) < 1e-6)
Ejemplo n.º 10
0
 def test_12(self):
     Nr = 32
     Nc = 31
     Nd = 5
     M = 4
     D = np.random.randn(Nd, Nd, M).astype(np.float32)
     s = np.random.randn(Nr, Nc).astype(np.float32)
     frc = 0.5
     msk = su.rndmask(s.shape, frc, dtype=np.float32)
     s *= msk
     lmbda = 1e-1
     mu = 1e-2
     # Since cucbpdn.cbpdngrdmsk automatically ensures that the ℓ2 of
     # gradient term is not applied to the AMS impulse filter, while
     # cbpdn.AddMaskSim does not, we have to pass a GradWeight array
     # with a zero entry corresponding to the AMS impulse filter to
     # cbpdn.AddMaskSim
     Wgrdi = np.hstack((np.ones(M,), np.zeros((1,))))
     opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False,
             'MaxMainIter': 50, 'AutoRho': {'Enabled': False}})
     opt['GradWeight'] = Wgrdi
     b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, s, msk, lmbda, mu, opt)
     X1 = b.solve()
     opt['GradWeight'] = 1.0
     X2 = cucbpdn.cbpdngrdmsk(D, s, msk, lmbda, mu, opt)
     assert(sm.mse(X1, X2) < 1e-10)
Ejemplo n.º 11
0
 def test_13(self):
     Nr = 32
     Nc = 31
     Nd = 5
     M = 4
     D = np.random.randn(Nd, Nd, M).astype(np.float32)
     s = np.random.randn(Nr, Nc).astype(np.float32)
     frc = 0.5
     msk = su.rndmask(s.shape, frc, dtype=np.float32)
     s *= msk
     lmbda = 1e-1
     mu = 1e-2
     Wl1 = np.random.randn(1, 1, M).astype(np.float32)
     Wl1i = np.concatenate((Wl1, np.ones(Wl1.shape[0:-1] + (1,))),
                           axis=-1)
     Wgrdi = np.hstack((np.ones(M,), np.zeros((1,))))
     opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False,
             'MaxMainIter': 50, 'AutoRho': {'Enabled': False}})
     opt['L1Weight'] = Wl1i
     opt['GradWeight'] = Wgrdi
     b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, s, msk, lmbda, mu, opt)
     X1 = b.solve()
     opt['L1Weight'] = Wl1
     opt['GradWeight'] = 1.0
     X2 = cucbpdn.cbpdngrdmsk(D, s, msk, lmbda, mu, opt)
     assert(sm.mse(X1, X2) < 1e-10)
Ejemplo n.º 12
0
 def test_27(self):
     B0 = np.random.randn(3, 5, 2)
     C0 = np.random.randn(4, 6, 2)
     A0 = kronsum(np.ones((2, )), B0, C0)
     S, B, C = linalg.kpsvd(A0, B0.shape[0:2], C0.shape[0:2])
     A = kronsum(S, B[..., 0:2], C[..., 0:2])
     assert mse(A0, A) < 1e-12
Ejemplo n.º 13
0
 def test_14(self):
     Nr = 32
     Nc = 31
     Nd = 5
     M = 4
     D = np.random.randn(Nd, Nd, M).astype(np.float32)
     s = np.random.randn(Nr, Nc).astype(np.float32)
     frc = 0.5
     msk = su.rndmask(s.shape, frc, dtype=np.float32)
     s *= msk
     lmbda = 1e-1
     mu = 1e-2
     # Create a random ℓ2 of gradient term weighting array. There is no
     # need to extend this array to account for the AMS impulse filter
     # since this is taken care of automatically by cucbpdn.cbpdngrdmsk
     Wgrd = np.random.randn(M).astype(np.float32)
     # Append a zero entry to the GradWeight array, corresponding to
     # the impulse filter appended to the dictionary by cbpdn.AddMaskSim,
     # since this is not done automatically by cbpdn.AddMaskSim
     Wgrdi = np.hstack((Wgrd, np.zeros((1,))))
     opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False,
             'MaxMainIter': 50, 'AutoRho': {'Enabled': False}})
     opt['GradWeight'] = Wgrdi
     b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, s, msk, lmbda, mu, opt)
     X1 = b.solve()
     opt['GradWeight'] = Wgrd
     X2 = cucbpdn.cbpdngrdmsk(D, s, msk, lmbda, mu, opt)
     assert(sm.mse(X1, X2) < 1e-10)
Ejemplo n.º 14
0
 def test_11(self):
     Nr = 32
     Nc = 31
     Nd = 5
     M = 4
     D = np.random.randn(Nd, Nd, M).astype(np.float32)
     s = np.random.randn(Nr, Nc).astype(np.float32)
     frc = 0.5
     msk = su.rndmask(s.shape, frc, dtype=np.float32)
     s *= msk
     lmbda = 1e-1
     # Create a random ℓ1 term weighting array. There is no need to
     # extend this array to account for the AMS impulse filter since
     # this is taken care of automatically by cucbpdn.cbpdnmsk
     Wl1 = np.random.randn(1, 1, M).astype(np.float32)
     # Append a zero entry to the L1Weight array, corresponding to
     # the impulse filter appended to the dictionary by cbpdn.AddMaskSim,
     # since this is not done automatically by cbpdn.AddMaskSim
     Wl1i = np.concatenate((Wl1, np.zeros(Wl1.shape[0:-1] + (1,))),
                           axis=-1)
     opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 50,
                                   'AutoRho': {'Enabled': False}})
     opt['L1Weight'] = Wl1i
     b = cbpdn.AddMaskSim(cbpdn.ConvBPDN, D, s, msk, lmbda, opt=opt)
     X1 = b.solve()
     opt['L1Weight'] = Wl1
     X2 = cucbpdn.cbpdnmsk(D, s, msk, lmbda, opt)
     assert(sm.mse(X1, X2) < 1e-10)
Ejemplo n.º 15
0
 def test_01(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Denoise.Options({'Verbose': False, 'gEvalY': False,
                                     'MaxMainIter': 300, 'rho': 75*lmbda})
     b = tvl2.TVL2Denoise(self.D, lmbda, opt)
     X = b.solve()
     assert(np.abs(b.itstat[-1].ObjFun - 32.875710674129564) < 1e-3)
     assert(sm.mse(self.U,X) < 1e-3)
Ejemplo n.º 16
0
 def test_01(self):
     lmbda = 3
     opt = tvl1.TVL1Denoise.Options({'Verbose': False, 'gEvalY': False,
                                     'MaxMainIter': 250})
     b = tvl1.TVL1Denoise(self.D, lmbda, opt)
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 447.78101756451662) < 1e-6
     assert sm.mse(self.U, X) < 1e-6
Ejemplo n.º 17
0
 def test_02(self):
     lmbda = 3
     opt = tvl1.TVL1Deconv.Options({'Verbose': False, 'gEvalY': False,
                                    'MaxMainIter': 250, 'rho': 10.0})
     b = tvl1.TVL1Deconv(np.ones((1, 1)), self.D, lmbda, opt, axes=(0, 1))
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 12364.029061174046) < 1e-5
     assert sm.mse(self.U, X) < 1e-4
Ejemplo n.º 18
0
 def test_02(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Deconv.Options({'Verbose': False, 'gEvalY': False,
                                    'MaxMainIter': 250})
     b = tvl2.TVL2Deconv(np.ones((1)), self.D, lmbda, opt, axes=(0,1,2))
     X = b.solve()
     assert(np.abs(b.itstat[-1].ObjFun - 567.72425227) < 1e-3)
     assert(sm.mse(self.U,X) < 1e-3)
Ejemplo n.º 19
0
 def test_01(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Denoise.Options({'Verbose': False, 'gEvalY': False,
                                     'MaxMainIter': 250, 'rho': 10*lmbda})
     b = tvl2.TVL2Denoise(self.D, lmbda, opt, axes=(0, 1, 2))
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 366.04267554965134) < 1e-3
     assert sm.mse(self.U, X) < 1e-3
Ejemplo n.º 20
0
 def test_02(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Deconv.Options({'Verbose': False, 'gEvalY': False,
                                    'MaxMainIter': 250})
     b = tvl2.TVL2Deconv(np.ones((1)), self.D, lmbda, opt, axes=(0, 1, 2))
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 567.72425227) < 1e-3
     assert sm.mse(self.U, X) < 1e-3
Ejemplo n.º 21
0
 def test_02(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Deconv.Options({'Verbose': False, 'gEvalY': False,
                                    'MaxMainIter': 250})
     b = tvl2.TVL2Deconv(np.ones((1)), self.D, lmbda, opt)
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 45.45958573088) < 1e-3
     assert sm.mse(self.U, X) < 1e-3
Ejemplo n.º 22
0
 def test_01(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Denoise.Options({'Verbose': False, 'gEvalY': False,
                                     'MaxMainIter': 300, 'rho': 75*lmbda})
     b = tvl2.TVL2Denoise(self.D, lmbda, opt)
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 32.875710674129564) < 1e-3
     assert sm.mse(self.U, X) < 1e-3
Ejemplo n.º 23
0
 def test_01(self):
     lmbda = 3
     opt = tvl1.TVL1Denoise.Options({'Verbose': False, 'gEvalY': False,
                                     'MaxMainIter': 250})
     b = tvl1.TVL1Denoise(self.D, lmbda, opt, axes=(0, 1, 2))
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 6219.6209699337605) < 1e-6
     assert sm.mse(self.U, X) < 1e-6
Ejemplo n.º 24
0
 def test_02(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Deconv.Options({'Verbose': False, 'gEvalY': False,
                                    'MaxMainIter': 250})
     b = tvl2.TVL2Deconv(np.ones((1)), self.D, lmbda, opt)
     X = b.solve()
     assert(np.abs(b.itstat[-1].ObjFun - 45.45958573088) < 1e-3)
     assert(sm.mse(self.U,X) < 1e-3)
Ejemplo n.º 25
0
 def test_31(self):
     alpha = np.random.randn()
     N = 8
     M = 11
     X0 = np.random.randn(N, M)
     Ag = np.random.randn(4, N)
     A = Ag.T.dot(Ag)
     Bg = np.random.randn(M, 4)
     B = Bg.dot(Bg.T)
     C = A.dot(X0).dot(B) + alpha * X0
     X1 = linalg.solve_symmetric_sylvester(A, B, C, alpha)
     assert mse(X0, X1) < 1e-12
     LambdaA, QA = np.linalg.eigh(A)
     LambdaB, QB = np.linalg.eigh(B)
     X1 = linalg.solve_symmetric_sylvester((LambdaA, QA), (LambdaB, QB), C,
                                           alpha)
     assert mse(X0, X1) < 1e-12
Ejemplo n.º 26
0
 def test_01(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Denoise.Options({'Verbose': False, 'gEvalY': False,
                                     'MaxMainIter': 250, 'rho': 10*lmbda})
     b = tvl2.TVL2Denoise(self.D, lmbda, opt, axes=(0,1,2))
     X = b.solve()
     assert(np.abs(b.itstat[-1].ObjFun - 366.04267554965134) < 1e-3)
     assert(sm.mse(self.U,X) < 1e-3)
Ejemplo n.º 27
0
 def test_02(self):
     lmbda = 3
     opt = tvl1.TVL1Deconv.Options({'Verbose': False, 'gEvalY': False,
                                    'MaxMainIter': 250, 'rho': 10.0})
     b = tvl1.TVL1Deconv(np.ones((1, 1)), self.D, lmbda, opt)
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 831.88219947939172) < 1e-5
     assert sm.mse(self.U, X) < 1e-4
Ejemplo n.º 28
0
 def test_01(self):
     N = 64
     K = 5
     L = 10
     u = np.random.randn(N, K)
     U = np.dot(u, u.T)
     V = np.random.randn(N, N)
     t = np.sort(np.abs(V).ravel())[V.size-L]
     V[np.abs(V) < t] = 0
     D = U + V
     opt = rpca.RobustPCA.Options({'Verbose': False, 'gEvalY': False,
                           'MaxMainIter': 250,
                           'AutoRho': {'Enabled': True}})
     b = rpca.RobustPCA(D, None, opt)
     X, Y = b.solve()
     assert(np.abs(b.itstat[-1].ObjFun - 321.493968419) < 1e-6)
     assert(sm.mse(U,X) < 5e-6)
     assert(sm.mse(V,Y) < 1e-8)
Ejemplo n.º 29
0
 def test_01(self):
     N = 16
     x = np.random.randn(N)
     y = x.copy()
     y[0] = 0
     xe = np.abs(x[0])
     e1 = metric.mae(x, y)
     e2 = metric.mse(x, y)
     assert np.abs(e1 - xe / N) < 1e-12
     assert np.abs(e2 - (xe**2) / N) < 1e-12
Ejemplo n.º 30
0
 def test_01(self):
     lmbda = 3
     opt = tvl1.TVL1Denoise.Options({
         'Verbose': False,
         'gEvalY': False,
         'MaxMainIter': 250
     })
     b = tvl1.TVL1Denoise(self.D, lmbda, opt, axes=(0, 1))
     X = b.solve()
     assert (np.abs(b.itstat[-1].ObjFun - 6219.3241727233126) < 1e-6)
     assert (sm.mse(self.U, X) < 1e-6)
Ejemplo n.º 31
0
 def test_01(self):
     lmbda = 1e-1
     opt = tvl2.TVL2Denoise.Options({
         'Verbose': False,
         'gEvalY': False,
         'MaxMainIter': 250,
         'rho': 10 * lmbda
     })
     b = tvl2.TVL2Denoise(self.D, lmbda, opt, axes=(0, 1))
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 363.0802047) < 1e-3
     assert sm.mse(self.U, X) < 1e-3
Ejemplo n.º 32
0
 def test_01(self):
     Nr = 32
     Nc = 31
     Nd = 5
     M = 4
     D = np.random.randn(Nd, Nd, M).astype(np.float32)
     s = np.random.randn(Nr, Nc).astype(np.float32)
     lmbda = 1e-1
     opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 50,
                              'AutoRho': {'Enabled': False}})
     b = cbpdn.ConvBPDN(D, s, lmbda, opt)
     X1 = b.solve()
     X2 = cucbpdn.cbpdn(D, s, lmbda, opt)
     assert(sm.mse(X1, X2) < 1e-10)
Ejemplo n.º 33
0
 def test_08(self):
     Nr = 32
     Nc = 31
     Nd = 5
     M = 4
     D = np.random.randn(Nd, Nd, M).astype(np.float32)
     s = np.random.randn(Nr, Nc).astype(np.float32)
     lmbda = 1e-1
     mu = 1e-2
     Wl1 = np.random.randn(Nr, Nc, M).astype(np.float32)
     opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False,
             'MaxMainIter': 50, 'L1Weight': Wl1,
             'AutoRho': {'Enabled': False}})
     b = cbpdn.ConvBPDNGradReg(D, s, lmbda, mu, opt)
     X1 = b.solve()
     X2 = cucbpdn.cbpdngrd(D, s, lmbda, mu, opt)
     assert(sm.mse(X1, X2) < 1e-10)
Ejemplo n.º 34
0
 def test_10(self):
     Nr = 32
     Nc = 31
     Nd = 5
     M = 4
     D = np.random.randn(Nd, Nd, M).astype(np.float32)
     s = np.random.randn(Nr, Nc).astype(np.float32)
     frc = 0.5
     msk = su.rndmask(s.shape, frc, dtype=np.float32)
     s *= msk
     lmbda = 1e-1
     opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 50,
                                   'AutoRho': {'Enabled': False}})
     b = cbpdn.AddMaskSim(cbpdn.ConvBPDN, D, s, msk, lmbda, opt=opt)
     X1 = b.solve()
     X2 = cucbpdn.cbpdnmsk(D, s, msk, lmbda, opt)
     assert(sm.mse(X1, X2) < 1e-10)
Ejemplo n.º 35
0
 def test_01(self):
     N = 64
     L = 20
     x = np.cos(np.linspace(0, np.pi, N))[np.newaxis, :]
     y = np.cos(np.linspace(0, np.pi, N))[:, np.newaxis]
     U = x*y
     V = np.random.randn(N, N)
     t = np.sort(np.abs(V).ravel())[V.size-L]
     V[np.abs(V) < t] = 0
     D = U + V
     lmbda = 0.1
     opt = spline.SplineL1.Options({'Verbose': False, 'gEvalY': False,
                           'MaxMainIter': 250, 'RelStopTol': 5e-4,
                           'DFidWeight': V == 0,
                           'AutoRho': {'Enabled': True}})
     b = spline.SplineL1(D, lmbda, opt)
     X = b.solve()
     assert np.abs(b.itstat[-1].ObjFun - 0.333606246) < 1e-6
     assert sm.mse(U, X) < 1e-6