Skip to content

Commit 7fb0c56

Browse files
Julien RousselJulien Roussel
authored andcommitted
progress bars conditioned by verbose
1 parent 1d52ab2 commit 7fb0c56

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

README.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ With just these few lines of code, you can see how easy it is to
7070
from qolmat.utils import data
7171
7272
# load and prepare csv data
73+
7374
df_data = data.get_data("Beijing")
7475
columns = ["TEMP", "PRES", "WSPM"]
7576
df_data = df_data[columns]
7677
df_with_nan = data.add_holes(df_data, ratio_masked=0.2, mean_size=120)
7778
7879
# impute and compare
79-
imputer_mean = imputers.ImputerSimple(strategy="mean", groups=("station",))
80+
imputer_median = imputers.ImputerSimple(groups=("station",))
8081
imputer_interpol = imputers.ImputerInterpolation(method="linear", groups=("station",))
8182
imputer_var1 = imputers.ImputerEM(model="VAR", groups=("station",), method="mle", max_iter_em=50, n_iter_ou=15, dt=1e-3, p=1)
8283
dict_imputers = {
83-
"mean": imputer_mean,
84+
"median": imputer_median,
8485
"interpolation": imputer_interpol,
8586
"VAR(1) process": imputer_var1
8687
}

qolmat/imputations/em_sampler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,9 @@ def fit_X(self, X: NDArray) -> None:
435435
X = self._maximize_likelihood(X_imp, mask_na)
436436

437437
for iter_em in tqdm(
438-
range(self.max_iter_em), desc="EM parameters estimation"
438+
range(self.max_iter_em),
439+
desc="EM parameters estimation",
440+
disable=not self.verbose,
439441
):
440442
X = self._sample_ou(X, mask_na)
441443

@@ -477,6 +479,7 @@ def fit(self, X: NDArray) -> "EM":
477479
if hasattr(self, "p_to_fit") and self.p_to_fit:
478480
aics: List[float] = []
479481
for p in range(self.max_lagp + 1):
482+
print("p=", p)
480483
self.p = p
481484
self.fit_X(X)
482485
n1, n2 = self.X.shape

qolmat/imputations/rpca/rpca_noisy.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def decompose_with_basis(
201201
max_iterations=self.max_iterations,
202202
tolerance=self.tolerance,
203203
norm=self.norm,
204+
verbose=self.verbose,
204205
)
205206

206207
self._check_cost_function_minimized(D, M, A, Omega, tau, lam)
@@ -220,6 +221,7 @@ def minimise_loss(
220221
max_iterations: int = 10000,
221222
tolerance: float = 1e-6,
222223
norm: str = "L2",
224+
verbose: bool = False,
223225
) -> Tuple:
224226
"""Compute the noisy RPCA with a L2 time penalisation.
225227
@@ -256,6 +258,9 @@ def minimise_loss(
256258
consecutive iterations. Defaults to 1e-6.
257259
norm : str, optional
258260
Error norm, can be "L1" or "L2". Defaults to "L2".
261+
verbose : bool, optional
262+
Verbosity level, if False the warnings are silenced. Defaults to
263+
False.
259264
260265
Returns
261266
-------
@@ -313,7 +318,9 @@ def minimise_loss(
313318
In = identity(n_rows)
314319

315320
for _ in tqdm(
316-
range(max_iterations), desc="Noisy RPCA loss minimization"
321+
range(max_iterations),
322+
desc="Noisy RPCA loss minimization",
323+
disable=not verbose,
317324
):
318325
M_temp = M.copy()
319326
A_temp = A.copy()

qolmat/imputations/rpca/rpca_pcp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ def decompose(self, D: NDArray, Omega: NDArray) -> Tuple[NDArray, NDArray]:
127127

128128
M: NDArray = D - A
129129
for iteration in tqdm(
130-
range(self.max_iterations), desc="RPCA PCP decomposition"
130+
range(self.max_iterations),
131+
desc="RPCA PCP decomposition",
132+
disable=not self.verbose,
131133
):
132134
M = rpca_utils.svd_thresholding(D - A + Y / mu, 1 / mu)
133135
A = rpca_utils.soft_thresholding(D - M + Y / mu, lam / mu)

qolmat/imputations/softimpute.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ def decompose(self, X: NDArray, Omega: NDArray) -> Tuple[NDArray, NDArray]:
148148
M = A @ B.T
149149
cost_start = SoftImpute.cost_function(X, M, A, Omega, tau)
150150
for iter_ in tqdm(
151-
range(self.max_iterations), desc="Soft Impute decomposition"
151+
range(self.max_iterations),
152+
desc="Soft Impute decomposition",
153+
disable=not self.verbose,
152154
):
153155
U_old = U
154156
V_old = V

0 commit comments

Comments
 (0)