Skip to content

Commit 7f8f1c3

Browse files
author
Gsaes
committed
Youpi ! RPCA, EM_sampler, docs et mocker
1 parent b97d0bc commit 7f8f1c3

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

docs/EM_sampler.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,7 @@ The resulting imputed data is the final imputed array, obtained at convergence.
210210
Multivariate time series
211211
************************
212212

213-
To explicitely take into account the temporal aspect of the data
214-
(temporal correlations), we construct an extended matrix :math:`\mathbf{X}^{ext}`
215-
by considering the shifted columns, i.e.
216-
:math:`\mathbf{X}^{ext} := [\mathbf{X}, \mathbf{X}^{s+1}, \mathbf{X}^{s-1}]` where
217-
:math:`\mathbf{X}^{s+1}` (resp. :math:`\mathbf{X}^{s-1}`) is the :math:`\mathbf{X}` matrix
218-
where all columns are shifted +1 for one step backward in time (resp. -1 for one step forward in time).
219-
The covariance matrix :math:`\mathbf{\Sigma}^{ext}` is therefore richer in information since the presence of additional
220-
(temporal) correlations.
221-
222-
.. image:: images/extended_matrix.png
213+
The class VAR1EM takes into account the temporal structure of the data by using likelihood based on a VAR(1) assumption. Stay tuned for more details!
223214

224215

225216

docs/RPCA.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ Some algorithms are implemented:
7777
& \text{s.t.} \quad \mathbf{D} = \mathbf{X} + \mathbf{A}
7878
\end{align*}
7979
80-
* :class:`GraphRPCA` class (based on this `paper <https://arxiv.org/abs/1507.08173>`__). The optimisation problem is the following
80+
..
81+
* :class:`GraphRPCA` class (based on this `paper <https://arxiv.org/abs/1507.08173>`__). The optimisation problem is the following
8182
8283
.. math::
8384
@@ -95,7 +96,8 @@ By defining :math:`\Vert \mathbf{XH_k} \Vert_p` is either :math:`\Vert \mathbf{X
9596
\text{minimise} \quad \Vert P_{\Omega}(\mathbf{X}+\mathbf{A}-\mathbf{D}) \Vert_F^2 + \lambda_1 \Vert \mathbf{X} \Vert_* + \lambda_2 \Vert \mathbf{A} \Vert_1 + \sum_{k=1}^K \eta_k \Vert \mathbf{XH_k} \Vert_p
9697
9798
98-
* :class:`OnlineTemporalRPCA` class. This class implements the online version of the above problem using stochastic optimisation (based on this `paper <https://www.hindawi.com/journals/jat/2018/7191549/>`__ and this `paper <https://dl.acm.org/doi/10.5555/2999611.2999657>`__). This allows to deal with large ammount of data or data that arrives continuously and does not assume a stable subspace.
99+
..
100+
* :class:`OnlineTemporalRPCA` class. This class implements the online version of the above problem using stochastic optimisation (based on this `paper <https://www.hindawi.com/journals/jat/2018/7191549/>`__ and this `paper <https://dl.acm.org/doi/10.5555/2999611.2999657>`__). This allows to deal with large ammount of data or data that arrives continuously and does not assume a stable subspace.
99101
100102

101103
The operator :math:`P_{\Omega}` is the projection operator such that

qolmat/utils/plot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def plot_images(
157157

158158
def make_ellipses(
159159
X: np.ndarray,
160-
ax: Any,
160+
ax: mpl.axes.Axes,
161161
color: Union[str, Tuple[float, float, float]],
162162
):
163163
"""Draw ellipses on a figure
@@ -223,9 +223,9 @@ def compare_covariances(
223223

224224
def multibar(
225225
df: pd.DataFrame,
226-
ax: Any = None,
226+
ax: Optional[mpl.axes.Axes] = None,
227227
orientation: str = "vertical",
228-
colors=None,
228+
colors: Any = None,
229229
decimals: float = 0,
230230
):
231231
"""Create a multi-bar graph to represent the values of the different dataframe columns.

tests/utils/test_plot.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
import scipy.sparse
88
from qolmat.utils import plot
9+
from pytest_mock.plugin import MockerFixture
910

1011
plt.switch_backend("Agg")
1112

@@ -33,48 +34,57 @@
3334
}
3435

3536

36-
def show_fake():
37-
pass
38-
39-
40-
@pytest.fixture(autouse=True)
41-
def patch_matplotlib_show(monkeypatch):
42-
monkeypatch.setattr(plt, "show", show_fake)
43-
44-
4537
@pytest.mark.parametrize("list_matrices", [list_matrices])
46-
def test_utils_plot_plot_matrices(list_matrices: List[np.ndarray]) -> None:
38+
def test_utils_plot_plot_matrices(list_matrices: List[np.ndarray], mocker: MockerFixture) -> None:
39+
mocker.patch("matplotlib.pyplot.savefig")
40+
mocker.patch("matplotlib.pyplot.show")
4741
plot.plot_matrices(list_matrices=list_matrices, title="title")
4842
assert len(plt.gcf().get_axes()) > 0
43+
assert plt.savefig.call_count == 1
4944
plt.close("all")
5045

5146

5247
@pytest.mark.parametrize("list_signals", [list_signals])
53-
def test_utils_plot_plot_signal(list_signals: List[np.ndarray]) -> None:
48+
def test_utils_plot_plot_signal(list_signals: List[np.ndarray], mocker: MockerFixture) -> None:
49+
mocker.patch("matplotlib.pyplot.savefig")
50+
mocker.patch("matplotlib.pyplot.show")
5451
plot.plot_signal(list_signals=list_signals, ylabel="ylabel", title="title")
5552
assert len(plt.gcf().get_axes()) > 0
53+
assert plt.savefig.call_count == 1
5654
plt.close("all")
5755

5856

5957
@pytest.mark.parametrize("M, A, E, index_array, dims", [(M, A, E, [0, 1, 2], (10, 10))])
6058
def test__utils_plot_plot_images(
61-
M: np.ndarray, A: np.ndarray, E: np.ndarray, index_array: List[int], dims: Tuple[int, int]
59+
M: np.ndarray,
60+
A: np.ndarray,
61+
E: np.ndarray,
62+
index_array: List[int],
63+
dims: Tuple[int, int],
64+
mocker: MockerFixture,
6265
):
66+
mocker.patch("matplotlib.pyplot.savefig")
67+
mocker.patch("matplotlib.pyplot.show")
6368
plot.plot_images(M, A, E, index_array, dims, filename="filename")
6469
assert len(plt.gcf().get_axes()) > 0
70+
assert plt.savefig.call_count == 1
6571
plt.close("all")
6672

6773

6874
@pytest.mark.parametrize("X", [X])
69-
def test_utils_plot_make_ellipses(X: np.ndarray):
75+
def test_utils_plot_make_ellipses(X: np.ndarray, mocker: MockerFixture):
76+
mocker.patch("matplotlib.pyplot.show")
7077
ax = plt.gca()
7178
plot.make_ellipses(X, ax, color="blue")
7279
assert len(plt.gcf().get_axes()) > 0
7380
plt.close("all")
7481

7582

7683
@pytest.mark.parametrize("df1,df2", [(df1, df2)])
77-
def test_utils_plot_compare_covariances(df1: pd.DataFrame, df2: pd.DataFrame):
84+
def test_utils_plot_compare_covariances(
85+
df1: pd.DataFrame, df2: pd.DataFrame, mocker: MockerFixture
86+
):
87+
mocker.patch("matplotlib.pyplot.show")
7888
ax = plt.gca()
7989
plot.compare_covariances(df1, df2, "x", "y", ax)
8090
assert len(plt.gcf().get_axes()) > 0
@@ -83,14 +93,16 @@ def test_utils_plot_compare_covariances(df1: pd.DataFrame, df2: pd.DataFrame):
8393

8494
@pytest.mark.parametrize("df", [df])
8595
@pytest.mark.parametrize("orientation", ["horizontal", "vertical"])
86-
def test_utils_plot_multibar(df: pd.DataFrame, orientation: str):
96+
def test_utils_plot_multibar(df: pd.DataFrame, orientation: str, mocker: MockerFixture):
97+
mocker.patch("matplotlib.pyplot.show")
8798
plot.multibar(df, orientation=orientation)
8899
assert len(plt.gcf().get_axes()) > 0
89100
plt.close("all")
90101

91102

92103
@pytest.mark.parametrize("df", [df])
93-
def test_utils_plot_plot_imputations(df: pd.DataFrame):
104+
def test_utils_plot_plot_imputations(df: pd.DataFrame, mocker: MockerFixture):
105+
mocker.patch("matplotlib.pyplot.show")
94106
plot.plot_imputations(df, dict_df_imputed)
95107
assert len(plt.gcf().get_axes()) > 0
96108
plt.close("all")

0 commit comments

Comments
 (0)