Skip to content

Commit

Permalink
rpca anomaly projection changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Roussel authored and Julien Roussel committed Feb 13, 2024
1 parent e20b61c commit 71fd49d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
10 changes: 4 additions & 6 deletions qolmat/imputations/rpca/rpca_noisy.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def decompose_on_basis(
A_Omega = rpca_utils.soft_thresholding(D - L @ Q, lam)
A_Omega_C = D - L @ Q
A = np.where(Omega, A_Omega, A_Omega_C)
# A = np.where(Omega, A_Omega, 0)

Ac = np.linalg.norm(A - A_prev, np.inf)
Lc = np.linalg.norm(L - L_prev, np.inf)
Expand Down Expand Up @@ -229,11 +230,7 @@ def decompose_rpca(
f"than the number of rows in the matrix but {period} >= {n_rows}!"
)

print("before")
print(D)
D = utils.linear_interpolation(D)
print("after")
print(D)

M, A, L, Q = self.decompose_rpca_algorithm(
D,
Expand Down Expand Up @@ -421,8 +418,9 @@ def decompose_rpca_algorithm(
)

A_Omega = rpca_utils.soft_thresholding(D - X, lam)
A_Omega_C = D - X
A = np.where(Omega, A_Omega, A_Omega_C)
# A_Omega_C = D - X
# A = np.where(Omega, A_Omega, A_Omega_C)
A = np.where(Omega, A_Omega, 0)

Q = scp.linalg.solve(
a=tau * Ir + mu * (L.T @ L),
Expand Down
2 changes: 0 additions & 2 deletions qolmat/imputations/rpca/rpca_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def approx_rank(
"""
if threshold == 1:
return min(M.shape)
print("approx_rank")
print(M)
_, values_singular, _ = np.linalg.svd(M, full_matrices=True)

cum_sum = np.cumsum(values_singular) / np.sum(values_singular)
Expand Down
2 changes: 0 additions & 2 deletions tests/imputations/rpca/test_rpca_noisy.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ def test_rpca_noisy_zero_tau_zero_lambda(X: NDArray, X_interpolated: NDArray):
"""Test RPCA noisy results if tau and lambda equal zero."""
rpca = RPCANoisy(tau=0, lam=0, norm="L2")
Omega = ~np.isnan(X)
print(X)
print(Omega)
X_result, A_result, _, _ = rpca.decompose_rpca(X, Omega)
np.testing.assert_allclose(X_result, X_interpolated, atol=1e-4)
np.testing.assert_allclose(A_result, np.full_like(X, 0), atol=1e-4)
Expand Down

0 comments on commit 71fd49d

Please sign in to comment.