Skip to content

Commit 57d74b5

Browse files
Merge pull request #33 from Quantmetry/patch_rpca_reshaping
Patch rpca reshaping
2 parents 3ecaaf2 + 58e5459 commit 57d74b5

File tree

11 files changed

+38
-23
lines changed

11 files changed

+38
-23
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.0.10
2+
current_version = 0.0.11
33
commit = True
44
tag = True
55

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ qolmat/.converge
5757
examples/*.ipynb
5858
examples/figures/*
5959
examples/data/*
60-
examples/*.ipynb
60+
examples/local
6161

6262

6363
# VSCode

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = "Quantmetry"
2323

2424
# The full version, including alpha/beta/rc tags
25-
version = "0.0.10"
25+
version = "0.0.11"
2626
release = version
2727

2828

examples/benchmark.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ imputer_spline = imputers.ImputerInterpolation(groups=["station"], method="splin
131131
imputer_shuffle = imputers.ImputerShuffle(groups=["station"])
132132
imputer_residuals = imputers.ImputerResiduals(groups=["station"], period=7, model_tsa="additive", extrapolate_trend="freq", method_interpolation="linear")
133133

134-
imputer_rpca = imputers.ImputerRPCA(groups=["station"], columnwise=True, period=365, max_iter=200, tau=2, lam=.3)
135-
imputer_rpca_opti = imputers.ImputerRPCA(groups=["station"], columnwise=True, period=365, max_iter=100)
134+
imputer_rpca = imputers.ImputerRPCA(groups=["station"], columnwise=True, period=7, max_iter=200, tau=2, lam=.3)
135+
imputer_rpca_opti = imputers.ImputerRPCA(groups=["station"], columnwise=True, period=7, max_iter=100)
136136

137137
imputer_ou = imputers.ImputerEM(groups=["station"], model="multinormal", method="sample", max_iter_em=34, n_iter_ou=15, dt=1e-3)
138138
imputer_tsou = imputers.ImputerEM(groups=["station"], model="VAR1", method="sample", max_iter_em=34, n_iter_ou=15, dt=1e-3)
@@ -154,8 +154,8 @@ dict_imputers = {
154154
# "OU": imputer_ou,
155155
# "TSOU": imputer_tsou,
156156
# "TSMLE": imputer_tsmle,
157-
# "RPCA": imputer_rpca,
158-
# "RPCA_opti": imputer_rpca_opti,
157+
"RPCA": imputer_rpca,
158+
"RPCA_opti": imputer_rpca_opti,
159159
# "locf": imputer_locf,
160160
# "nocb": imputer_nocb,
161161
# "knn": imputer_knn,
@@ -203,7 +203,7 @@ results
203203

204204
```python
205205
df_plot = results.loc["energy", "All"]
206-
plt.bar(df_plot.index, df_plot, color=tab10(0))
206+
plt.barh(df_plot.index, df_plot, color=tab10(0))
207207
plt.show()
208208
```
209209

qolmat/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.10"
1+
__version__ = "0.0.11"

qolmat/benchmark/cross_validation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import logging
22
from typing import Any, Callable, Dict, List, Union
3-
from skopt.space import Categorical, Dimension, Integer, Real
3+
44
import numpy as np
55
import pandas as pd
66
import skopt
7+
from skopt.space import Categorical, Dimension, Integer, Real
78

89
from qolmat.benchmark.missing_patterns import _HoleGenerator
910

qolmat/imputations/rpca/rpca.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,22 @@ def _prepare_data(self, X: NDArray) -> NDArray:
5858
return X.copy()
5959
else:
6060
raise ValueError("`n_rows` should not be specified when imputing 2D data.")
61+
62+
def get_shape_original(self, M: NDArray, X: NDArray) -> NDArray:
63+
"""Shapes an output matrix from the RPCA algorithm into the original shape.
64+
65+
Parameters
66+
----------
67+
M : NDArray
68+
Matrix to reshape
69+
X : NDArray
70+
Matrix of the desired shape
71+
72+
Returns
73+
-------
74+
NDArray
75+
Reshaped matrix
76+
"""
77+
size = X.size
78+
M_flat = M.flatten()[:size]
79+
return M_flat.reshape(X.shape)

qolmat/imputations/rpca/rpca_noisy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def decompose_rpca_signal(
366366
elif self.norm == "L2":
367367
M, A, U, V, errors = self.decompose_rpca_L2(D_proj, Omega, lam, tau, rank)
368368

369-
M = M.reshape(X.shape)
370-
A = A.reshape(X.shape)
369+
M_final = self.get_shape_original(M, X)
370+
A_final = self.get_shape_original(A, X)
371371

372-
return M, A
372+
return M_final, A_final

qolmat/imputations/rpca/rpca_pcp.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ def decompose_rpca_signal(
9999
D = self._prepare_data(X)
100100
M, A = self.decompose_rpca(D)
101101

102-
# U, _, V = np.linalg.svd(M, full_matrices=False, compute_uv=True)
103-
104-
# if X.shape[0] == 1:
105-
# M = M.reshape(1, -1)[:, : X.size]
106-
# M = M.reshape(X)
107-
# A = A.reshape(1, -1)[:, : X.size]
108-
M = M.reshape(X.shape)
109-
A = A.reshape(X.shape)
110-
return M, A
102+
M_final = self.get_shape_original(M, X)
103+
A_final = self.get_shape_original(A, X)
104+
return M_final, A_final

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import find_packages, setup
44

55
DISTNAME = "qolmat"
6-
VERSION = "0.0.10"
6+
VERSION = "0.0.11"
77
DESCRIPTION = "Tools to impute"
88
LONG_DESCRIPTION_CONTENT_TYPE = "text/x-rst"
99
with codecs.open("README.rst", encoding="utf-8-sig") as f:

0 commit comments

Comments
 (0)