def test_02(self): N = 8 D = np.random.randn(N, N) try: b = rpca.RobustPCA(D) b.solve() except Exception as e: print(e) assert(0)
def test_05(self): N = 8 D = np.random.randn(N, N) dt = np.float64 opt = rpca.RobustPCA.Options({'Verbose': False, 'MaxMainIter': 20, 'AutoRho': {'Enabled': True}, 'DataType': dt}) b = rpca.RobustPCA(D, opt=opt) b.solve() assert(b.X.dtype == dt) assert(b.Y.dtype == dt) assert(b.U.dtype == dt)
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)
def Raman_Robust_PCA(da): """ robust PCA based on sporco module Arguments: da (DataArray): yperspectrum Returns: dX (DataArray): denoised hyperspectrum dY (DataArray): resual spike and noise """ # 3rd party imports from sporco.admm import rpca import xarray as xr # Local application imports from raman_hyperspectra.raman_hyperspectra_read_files import construct_xarray opt = rpca.RobustPCA.Options({ "Verbose": True, "gEvalY": False, "MaxMainIter": 200, "RelStopTol": 5e-4, "AutoRho": { "Enabled": True }, }) A = da.data shape = da.data.shape N_row = shape[0] N_col = shape[1] A = A.reshape((N_row * N_col, -1)) b = rpca.RobustPCA(A, None, opt) X, Y = b.solve() dX = construct_xarray(X.reshape((N_row, N_col, -1)), da.x.values, da.y.values, da.lbd.values) dY = construct_xarray(Y.reshape((N_row, N_col, -1)), da.x.values, da.y.values, da.lbd.values) return dX, dY
S1 = S0.copy() S1[s1gen > 0.75] = 0.0 """ Set options for the Robust PCA solver, create the solver object, and solve, returning the estimates of the low rank and sparse components ``X`` and ``Y``. Unlike most other SPORCO classes for optimisation problems, :class:`.rpca.RobustPCA` has a meaningful default regularization parameter, as used here. """ opt = rpca.RobustPCA.Options({ 'Verbose': True, 'gEvalY': False, 'MaxMainIter': 200, 'RelStopTol': 5e-4, 'AutoRho': { 'Enabled': True } }) b = rpca.RobustPCA(S1, None, opt) X, Y = b.solve() """ Display solve time and low-rank component recovery accuracy. """ print("RobustPCA solve time: %5.2f s" % b.timer.elapsed('solve')) print("Low-rank component SNR: %5.2f dB" % metric.snr(S0, X)) """ Display reference, corrupted, and recovered matrices. """ fig = plot.figure(figsize=(21, 7)) plot.subplot(1, 3, 1) plot.imview(S0, fig=fig, cmap=plot.cm.Blues, title='Original matrix') plot.subplot(1, 3, 2)