def sklearn__RPCA_OCSVM(data_train,data_test,nu):

    print "sklearn__RPCA_OCSVM========",data_train.shape
    # Obtain the projections for training test
    rpca_train = R_pca(data_train)
    L_train, S = rpca_train.fit(max_iter=10, iter_print=100)
    ## Obtain the projections fro data_test
    rpca_test = R_pca(data_test)
    L_test, S = rpca_test.fit(max_iter=10, iter_print=100)

    print L_train.shape
    print L_test.shape
    nu = 0.05

    clf = svm.OneClassSVM(nu=nu, kernel="rbf", gamma=0.1)
    start_time = time.time()
    clf.fit(L_train)
    trainTime = time.time() - start_time

    start_time = time.time()
    pos_decisionScore = clf.predict(L_train)
    neg_decisionScore = clf.predict(L_test)
    testTime = time.time() - start_time

    return [pos_decisionScore, neg_decisionScore,trainTime,testTime]
예제 #2
0
def bmRPCA(X, mu=None, lmbda=None, color=False, out=False):
    rpca = R_pca(X, mu=mu, lmbda=lmbda)
    A, E = rpca.fit()
    if out:
        print('Rank of A = {}'.format(np.linalg.matrix_rank(A)))
    if color:
        A = A.astype(np.uint8)
        E = np.maximum(E, 0).astype(np.uint8)
    return A, E
예제 #3
0
def RPCA_fit(A, mu=None, lmbda=None, visualze=False):
    rpca = R_pca(A, mu=mu, lmbda=lmbda)
    L, E = rpca.fit(iter_print=np.nan)
    pc = PCA(rpca.L, out=False)
    v1 = pc[0].reshape(-1, 1)
    m1, m2 = np.mean(L, 0)
    slope = v1[1] / v1[0]
    intercept = m2 - m1 * slope
    if visualze:
        visualize2D(L)
        visualize2D(E)
        plt.show()
    return slope, intercept
예제 #4
0
                                      seed=None,
                                      clip=True,
                                      amount=0.05)
corr_img = color.rgb2gray(RGB_noise)
#print corr_img.shape
# apply Robust PCA
#print corr_img
plt.imshow(corr_img, cmap=plt.cm.Greys_r)
plt.show()
Lambda = 0.0625  # close to the default one, but works better
tic = time.time()
#plt.imshow(X, cmap = plt.cm.Greys_r)
#plt.show()

rpca = R_pca(corr_img)
toc = time.time()
L, S = rpca.fit(max_iter=10000, iter_print=100)

original_image = mpimg.imread("boat.png")
RMSE = sqrt(mean_squared_error(L, original_image))
print(RMSE)
plt.imshow(L, cmap=plt.cm.Greys_r)
plt.show()
# plt.imshow(S, cmap = plt.cm.Greys_r)
# plt.show()
# plt.imshow(L+S, cmap = plt.cm.Greys_r)
# plt.show()

#rpca.plot_fit()
#plt.show()
예제 #5
0
파일: decomp.py 프로젝트: zuoshifan/rpca_HI
import healpy
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

out_dir = './decomp/'
if not os.path.exists(out_dir):
    os.mkdir(out_dir)

with h5py.File('corr_data/corr.hdf5', 'r') as f:
    cm_cm_corr = f['cm_cm'][:]
    tt_tt_corr = f['tt_tt'][:]

from r_pca import R_pca
rpca = R_pca(tt_tt_corr, mu=1.0e8, lmbda=None)
L, S, err = rpca.fit(tol=1.0e-14, max_iter=20000, iter_print=100, return_err=True)

# from r_pca import MR_pca
# rpca = MR_pca(tt_tt_corr, mu=1.0e8, lmbda=None)
# L, S, err = rpca.fit(tol=1.0e-14, max_iter=20000, iter_print=100, return_err=True)

# from noncvx_rpca import rpca
# L, S, res = rpca(tt_tt_corr, mu=1.0e7, gamma=1.0, norm_type='1')

print err
print matrix_rank(L)
print matrix_rank(S)
print la.norm(cm_cm_corr - S, ord='fro') / la.norm(cm_cm_corr, ord='fro')
print np.allclose(L, L.T), np.allclose(S, S.T)
# sL, UL = la.eigh(L)
# sS, US = la.eigh(S)
예제 #6
0
npix = ps_map.shape[-1]

# ga_ga_corr = np.dot(ga_map, ga_map.T) / npix
# ga_ps_corr = np.dot(ga_map, ps_map.T) / npix
# ga_cm_corr = np.dot(ga_map, cm_map.T) / npix
# ps_ps_corr = np.dot(ps_map, ps_map.T) / npix
# ps_cm_corr = np.dot(ps_map, cm_map.T) / npix
cm_cm_corr = np.dot(cm_map, cm_map.T) / npix

# fg_fg_corr = np.dot(fg_map, fg_map.T) / npix
# fg_cm_corr = np.dot(fg_map, cm_map.T) / npix

tt_tt_corr = np.dot(tt_map, tt_map.T) / npix

rpca = R_pca(tt_tt_corr, mu=1.0e6, lmbda=None)
L, S = rpca.fit(tol=1.0e-14, max_iter=20000, iter_print=100)
print matrix_rank(L)
print matrix_rank(S)

# plt.figure()
# plt.subplot(221)
# plt.imshow(tt_tt_corr, origin='lower')
# plt.colorbar()
# plt.subplot(222)
# plt.imshow(tt_tt_corr-L-S, origin='lower')
# plt.colorbar()
# plt.subplot(223)
# plt.imshow(L, origin='lower')
# plt.colorbar()
# plt.subplot(224)
# plt.imshow(S, origin='lower')
예제 #7
0
 def _robust_pca(self, sigma: np.ndarray, **kwargs: Any) -> None:
     r_pca = R_pca(sigma, **kwargs)
     L, S = r_pca.fit()
     return L, S