Skip to content

Commit 076ecf9

Browse files
Julien RousselJulien Roussel
authored andcommitted
Merge branch 'main' into dev
2 parents dcd2463 + 57ba597 commit 076ecf9

33 files changed

Lines changed: 151 additions & 151 deletions

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Documenting your change
4646
-----------------------
4747

4848
If you're adding a class or a function, then you'll need to add a docstring with a doctest. We follow the `numpy docstring convention <https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html>`_, so please do too.
49-
Any estimator should follow the [scikit-learn API](https://scikit-learn.org/stable/developers/develop.html), so please follow these guidelines.
49+
Any estimator should follow the `scikit-learn API <https://scikit-learn.org/stable/developers/develop.html>`_, so please follow these guidelines.
5050

5151
Updating changelog
5252
------------------

HISTORY.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ History
55
0.1.10 (2024-??-??)
66
------------------
77
* Long EM and RPCA operations wrapped with tqdm progress bars
8-
* Readme code sample updated, and results table made consistant
8+
* Readme code sample updated, and results table made consistent
99

1010
0.1.9 (2024-08-29)
1111
------------------
@@ -41,7 +41,7 @@ History
4141
* RPCA algorithms now start with a normalizing scaler
4242
* The EM algorithms now include a gradient projection step to be more robust to colinearity
4343
* The EM algorithm based on the Gaussian model is now initialized using a robust estimation of the covariance matrix
44-
* A bug in the EM algorithm has been patched: the normalizing matrix gamma was creating a sampling biais
44+
* A bug in the EM algorithm has been patched: the normalizing matrix gamma was creating a sampling bias
4545
* Speed up of the EM algorithm likelihood maximization, using the conjugate gradient method
4646
* The ImputeRegressor class now handles the nans by `row` by default
4747
* The metric `frechet` was not correctly called and has been patched
@@ -67,9 +67,9 @@ History
6767
-------------------
6868

6969
* VAR(p) EM sampler implemented, founding on a VAR(p) modelization such as the one described in `Lütkepohl (2005) New Introduction to Multiple Time Series Analysis`
70-
* EM and RPCA matrices transposed in the low-level impelmentation, however the API remains unchanged
70+
* EM and RPCA matrices transposed in the low-level implementation, however the API remains unchanged
7171
* Sparse matrices introduced in the RPCA implementation so as to speed up the execution
72-
* Implementation of SoftImpute, which provides a fast but less robust alterantive to RPCA
72+
* Implementation of SoftImpute, which provides a fast but less robust alternative to RPCA
7373
* Implementation of TabDDPM and TsDDPM, which are diffusion-based models for tabular data and time-series data, based on Denoising Diffusion Probabilistic Models. Their implementations follow the work of Tashiro et al., (2021) and Kotelnikov et al., (2023).
7474
* ImputerDiffusion is an imputer-wrapper of these two models TabDDPM and TsDDPM.
7575
* Docstrings and tests improved for the EM sampler
@@ -100,7 +100,7 @@ been changed into tuple attributes so that all are not immutable
100100
0.0.13 (2023-06-07)
101101
-------------------
102102

103-
* Refacto cross validation
103+
* Refactor cross validation
104104
* Fix Readme
105105
* Add test utils.plot
106106

docs/analysis.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Then Qolmat proposes two tests to determine whether the missing data mechanism i
1616
2. How to use the results
1717
-------------------------
1818

19-
At the end of the MCAR test, it can then be assumed whether the missing data mechanism is MCAR or not. This serves three differents purposes:
19+
At the end of the MCAR test, it can then be assumed whether or not the missing data mechanism is MCAR. This serves three different purposes:
2020

2121
a. Diagnosis
2222
^^^^^^^^^^^^
@@ -45,7 +45,7 @@ The MCAR missing-data mechanism means that there is independence between the pre
4545
a. Little's Test
4646
^^^^^^^^^^^^^^^^
4747

48-
The best-known MCAR test is the :ref:`Little [1]<Little-article>` test, and it has been implemented in :class:`LittleTest`. Keep in mind that the Little's test is designed to test the homogeneity of means across the missing patterns and won't be efficient to detect the heterogeneity of covariance accross missing patterns.
48+
The best-known MCAR test is the :ref:`Little [1]<Little-article>` test, and it has been implemented in :class:`LittleTest`. Keep in mind that the Little's test is designed to test the homogeneity of means across the missing patterns and won't be efficient to detect the heterogeneity of covariance across missing patterns.
4949

5050
b. PKLM Test
5151
^^^^^^^^^^^^

docs/explanation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The observations are said to be Missing at Random (MAR) if the probability of an
117117
118118
Finally, the observations are said to be Missing Not at Random (MNAR) in all other cases, i.e. if :math:`P(M | X_{obs}, X_{mis}, \psi)` does not simplify.
119119

120-
Qolmat allows to generate new missing values on a an existing dataset, but only in the MCAR case.
120+
Qolmat allows to generate new missing values on an existing dataset, but only in the MCAR case.
121121

122122
Here are the different classes to generate missing data. We recommend the last 3 for time series.
123123

docs/imputers.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ See the :class:`~qolmat.imputations.imputers.ImputerRpcaPcp` class for implement
4242

4343
**Noisy RPCA** [2, 3, 4]
4444

45-
The class :class:`RpcaNoisy` implements an recommanded improved version, which relies on a decomposition :math:`\mathbf{D} = \mathbf{M} + \mathbf{A} + \mathbf{E}`. The additionnal term encodes a Gaussian noise and makes the numerical convergence more reliable. This class also implements a time-consistency penalization for time series, parametrized by the :math:`\eta_k`and :math:`H_k`. By defining :math:`\Vert \mathbf{MH_k} \Vert_p` is either :math:`\Vert \mathbf{MH_k} \Vert_1` or :math:`\Vert \mathbf{MH_k} \Vert_F^2`, the optimisation problem is the following
45+
The class :class:`RpcaNoisy` implements a recommended improved version, which relies on a decomposition :math:`\mathbf{D} = \mathbf{M} + \mathbf{A} + \mathbf{E}`. The additional term encodes a Gaussian noise and makes the numerical convergence more reliable. This class also implements a time-consistency penalization for time series, parametrized by the :math:`\eta_k`and :math:`H_k`. By defining :math:`\Vert \mathbf{MH_k} \Vert_p` is either :math:`\Vert \mathbf{MH_k} \Vert_1` or :math:`\Vert \mathbf{MH_k} \Vert_F^2`, the optimisation problem is the following
4646

4747
.. math::
4848
\text{min}_{\mathbf{M, A} \in \mathbb{R}^{m \times n}} \quad \frac 1 2 \Vert P_{\Omega} (\mathbf{D}-\mathbf{M}-\mathbf{A}) \Vert_F^2 + \tau \Vert \mathbf{M} \Vert_* + \lambda \Vert \mathbf{A} \Vert_1 + \sum_{k=1}^K \eta_k \Vert \mathbf{M H_k} \Vert_p
@@ -71,15 +71,15 @@ Suppose the data :math:`\mathbf{X}` has a density :math:`p_\theta` parametrized
7171

7272
**Expectation**
7373

74-
Draw samples of :math:`\mathbf{X}` assuming a fixed :math:`\theta`, conditionnaly on the values of :math:`\mathbf{X}_\mathrm{obs}`. This is done by MCMC using a projected Langevin algorithm.
74+
Draw samples of :math:`\mathbf{X}` assuming a fixed :math:`\theta`, conditionally on the values of :math:`\mathbf{X}_\mathrm{obs}`. This is done by MCMC using a projected Langevin algorithm.
7575
This process is characterized by a time step :math:`h`. Given an initial station :math:`X_0`, one can update the state at iteration *t* as
7676

7777
.. math::
7878
\widetilde X_n = X_{n-1} + \Gamma \nabla L_X(X_{n-1}, \theta_n) (X_{n-1} - \mu) h + (2 h \Gamma)^{1/2} Z_n,
7979
80-
where :math:`Z_n` is a vector of independant standard normal random variables and :math:`L` is the log-likelihood.
80+
where :math:`Z_n` is a vector of independent standard normal random variables and :math:`L` is the log-likelihood.
8181
The sampled distribution tends to the target one in the limit :math:`h \rightarrow 0` and the number of iterations :math:`n \rightarrow \infty`.
82-
Sampling from the conditionnal distribution :math:`p(\mathbf{X}_{mis} \vert \mathbf{X}_{obs} ; \theta^{(n)})` (see MCEM [6]) is achieved by projecting the samples at each step.
82+
Sampling from the conditional distribution :math:`p(\mathbf{X}_{mis} \vert \mathbf{X}_{obs} ; \theta^{(n)})` (see MCEM [6]) is achieved by projecting the samples at each step.
8383

8484
.. math::
8585
X_n = Proj_{obs} \left( \widetilde X_n \right),
@@ -113,7 +113,7 @@ Two parametric distributions are implemented:
113113

114114
:class:`~qolmat.imputations.diffusions.ddpms.TabDDPM` is a deep learning imputer based on Denoising Diffusion Probabilistic Models (DDPMs) [8] for handling multivariate tabular data. Our implementation mainly follows the works of [8, 9]. Diffusion models focus on modeling the process of data transitions from noisy and incomplete observations to the underlying true data. They include two main processes:
115115

116-
* Forward process perturbs observed data to noise until all the original data structures are lost. The pertubation is done over a series of steps. Let :math:`X_{obs}` be observed data, :math:`T` be the number of steps that noises :math:`\epsilon \sim N(0,I)` are added into the observed data. Therefore, :math:`X_{obs}^t = \bar{\alpha}_t \times X_{obs} + \sqrt{1-\bar{\alpha}_t} \times \epsilon` where :math:`\bar{\alpha}_t` controls the right amount of noise.
116+
* Forward process perturbs observed data to noise until all the original data structures are lost. The perturbation is done over a series of steps. Let :math:`X_{obs}` be observed data, :math:`T` be the number of steps that noises :math:`\epsilon \sim N(0,I)` are added into the observed data. Therefore, :math:`X_{obs}^t = \bar{\alpha}_t \times X_{obs} + \sqrt{1-\bar{\alpha}_t} \times \epsilon` where :math:`\bar{\alpha}_t` controls the right amount of noise.
117117
* Reverse process removes noise and reconstructs the observed data. At each step :math:`t`, we train an autoencoder :math:`\epsilon_\theta` based on ResNet [10] to predict the added noise :math:`\epsilon_t` based on the rest of the observed data. The objective function is the error between the noise added in the forward process and the noise predicted by :math:`\epsilon_\theta`.
118118

119119
In training phase, we use the self-supervised learning method of [9] to train incomplete data. In detail, our model randomly masks a part of observed data and computes loss from these masked data. Moving on to the inference phase, (1) missing data are replaced by Gaussian noises :math:`\epsilon \sim N(0,I)`, (2) at each noise step from :math:`T` to 0, our model denoises these missing data based on :math:`\epsilon_\theta`.

examples/benchmark.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jupyter:
1717
In Qolmat, a few data imputation methods are implemented as well as a way to evaluate their performance.**
1818

1919

20-
First, import some useful librairies
20+
First, import some useful libraries
2121

2222
```python tags=[]
2323
import warnings
@@ -54,7 +54,7 @@ from qolmat.utils import data, utils, plot
5454

5555

5656
The dataset `Beijing` is the Beijing Multi-Site Air-Quality Data Set. It consists in hourly air pollutants data from 12 chinese nationally-controlled air-quality monitoring sites and is available at https://archive.ics.uci.edu/ml/machine-learning-databases/00501/.
57-
This dataset only contains numerical vairables.
57+
This dataset only contains numerical variables.
5858

5959
```python tags=[]
6060
df_data = data.get_data_corrupted("Beijing", ratio_masked=.2, mean_size=120)
@@ -98,11 +98,11 @@ plt.show()
9898
This part is devoted to the imputation methods. The idea is to try different algorithms and compare them.
9999

100100
<u>**Methods**</u>:
101-
All presented methods are group-wise: here each station is imputed independently. For example ImputerMean computes the mean of each variable in each station and uses the result for imputation; ImputerInterpolation interpolates termporal signals corresponding to each variable on each station.
101+
All presented methods are group-wise: here each station is imputed independently. For example ImputerMean computes the mean of each variable in each station and uses the result for imputation; ImputerInterpolation interpolates temporal signals corresponding to each variable on each station.
102102

103103
<u>**Hyperparameters' search**</u>:
104104
Some methods require hyperparameters. The user can directly specify them, or rather determine them through an optimization step using the `search_params` dictionary. The keys are the imputation method's name and the values are a dictionary specifying the minimum, maximum or list of categories and type of values (Integer, Real, Category or a dictionary indexed by the variable names) to search.
105-
In pratice, we rely on a cross validation to find the best hyperparams values minimizing an error reconstruction.
105+
In practice, we rely on a cross validation to find the best hyperparams values minimizing an error reconstruction.
106106

107107
```python tags=[]
108108
ratio_masked = 0.1
@@ -476,7 +476,7 @@ plt.show()
476476

477477

478478
We first check the covariance. We simply plot one variable versus one another.
479-
One observes the methods provide similar visual resuls: it's difficult to compare them based on this criterion.
479+
One observes the methods provide similar visual results: it's difficult to compare them based on this criterion.
480480

481481
```python
482482
fig = plt.figure(figsize=(6 * n_imputers, 6 * n_columns))
@@ -494,7 +494,7 @@ plt.show()
494494
## Auto-correlation
495495

496496

497-
We are now interested in the auto-correlation function (ACF). As seen before, time series display seaonal patterns.
497+
We are now interested in the auto-correlation function (ACF). As seen before, time series display seasonal patterns.
498498
[Autocorrelation](https://en.wikipedia.org/wiki/Autocorrelation) is the correlation of a signal with a delayed copy of itself as a function of delay. It measures the similarity between observations of a random variable as a function of the time lag between them. The objective is to have an ACF to be similar between the original dataset and the imputed one.
499499

500500
```python

examples/tutorials/plot_tuto_benchmark_TS.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
# For the purpose of this notebook,
4242
# we corrupt the data, with the ``qolmat.utils.data.add_holes`` function
4343
# on three variables: "TEMP", "PRES" and "WSPM"
44-
# and the imputation methods will have acces to two additional features:
44+
# and the imputation methods will have access to two additional features:
4545
# "DEWP" and "RAIN".
4646

4747
df_data = data.get_data("Beijing")
@@ -51,7 +51,7 @@
5151
df = data.add_holes(df_data, ratio_masked=0.15, mean_size=50)
5252
df[["DEWP", "RAIN"]] = df_data[["DEWP", "RAIN"]]
5353
# %%
54-
# Let's take a look a one station, for instance "Aotizhongxin"
54+
# Let's take a look at one station, for instance "Aotizhongxin"
5555

5656
station = "Aotizhongxin"
5757
fig, ax = plt.subplots(len(cols_to_impute), 1, figsize=(13, 8))
@@ -68,7 +68,7 @@
6868
# ---------------------------------------------------------------
6969
# All presented methods are group-wise: here each station is imputed independently.
7070
# For example ImputerMean computes the mean of each variable in each station and uses
71-
# the result for imputation; ImputerInterpolation interpolates termporal
71+
# the result for imputation; ImputerInterpolation interpolates temporal
7272
# signals corresponding to each variable on each station.
7373
# We consider five imputation methods:
7474
# ``median`` for a baseline imputation;
@@ -181,10 +181,10 @@
181181

182182
# %%
183183
# We can also check the covariance. We simply plot one variable versus one another.
184-
# One observes the methods provide similar visual resuls: it's difficult to compare
184+
# One observes the methods provide similar visual results: it's difficult to compare
185185
# them based on this criterion, except the median imputation that greatly differs.
186-
# Black points and ellipses are original datafames
187-
# whiel colored ones are imputed dataframes.
186+
# Black points and ellipses are original dataframes
187+
# while colored ones are imputed dataframes.
188188

189189
n_columns = len(dfs_imputed_station)
190190
fig = plt.figure(figsize=(10, 10))

examples/tutorials/plot_tuto_categorical.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
# %%
5858
# The third approach uses ImputerRegressor which imputes iteratively each column using the other
5959
# ones. The function make_robust_MixteHGB provides an underlying model able to:
60-
# - adress both numerical targets (regression) and categorical targets (classification)
60+
# - address both numerical targets (regression) and categorical targets (classification)
6161
# - manage categorical features though one hot encoding
6262
# - manage missing features (native to the HistGradientBoosting)
6363

@@ -68,7 +68,7 @@
6868
# %%
6969
# 3. Mixed type model selection
7070
# ---------------------------------------------------------------
71-
# Let us now compare these three aproaches by measuring their ability to impute uniformly
71+
# Let us now compare these three approaches by measuring their ability to impute uniformly
7272
# distributed holes.
7373

7474
dict_imputers = {
@@ -101,5 +101,5 @@
101101
results.loc["rmse"].style.highlight_min(color="lightgreen", axis=1)
102102

103103
# %%
104-
# The HGB imputation methods globaly reaches a better accuracy on the categorical data.
104+
# The HGB imputation methods globally reaches a better accuracy on the categorical data.
105105
results.loc["accuracy"].style.highlight_max(color="lightgreen", axis=1)

examples/tutorials/plot_tuto_diffusion_models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
#
5555
# * ``cols_imputed``: list of columns that need to be imputed. Recall that we train the model on
5656
# incomplete data by using the self-supervised learning method. We can set which columns to be
57-
# masked during training. Its defaut value is ``None``.
57+
# masked during training. Its default value is ``None``.
5858
#
59-
# * ``epochs`` : a number of iterations, its defaut value ``epochs=10``. In practice, we should
59+
# * ``epochs`` : a number of iterations, its default value ``epochs=10``. In practice, we should
6060
# set a larger number of epochs e.g., ``epochs=100``.
6161
#
62-
# * ``batch_size`` : a size of batch, its defaut value ``batch_size=100``.
62+
# * ``batch_size`` : a size of batch, its default value ``batch_size=100``.
6363
#
6464
# The following hyperparams are for validation:
6565
#
@@ -198,11 +198,11 @@
198198
#
199199
# For TsDDPM, we have two options for splitting data:
200200
#
201-
# * ``is_rolling=False`` (default value): the data is splited by using
201+
# * ``is_rolling=False`` (default value): the data is split by using
202202
# pandas.DataFrame.resample(rule=freq_str). There is no duplication of row between chunks,
203203
# leading a smaller number of chunks than the number of rows in the original data.
204204
#
205-
# * ``is_rolling=True``: the data is splited by using pandas.DataFrame.rolling(window=freq_str).
205+
# * ``is_rolling=True``: the data is split by using pandas.DataFrame.rolling(window=freq_str).
206206
# The number of chunks is also the number of rows in the original data.
207207
# Note that setting ``is_rolling=True`` always produces better quality of imputations
208208
# but requires a longer training/inference time.

0 commit comments

Comments
 (0)