Skip to content

Commit 436e53c

Browse files
authored
Merge pull request #6 from scottgigante-immunai/patch-1
Add `verbose` argument to `harmonize`
2 parents 23fa8d7 + 4f4cf1b commit 436e53c

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

harmony/harmony.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def harmonize(
2929
random_state: int = 0,
3030
use_gpu: bool = False,
3131
n_jobs: int = -1,
32+
verbose: bool = True,
3233
) -> np.array:
3334
"""
3435
Integrate data using Harmony algorithm.
@@ -87,6 +88,9 @@ def harmonize(
8788
n_jobs: ``int``, optional, default ``-1``
8889
How many CPU threads to use. By default, use all physical cores. If 'use_gpu' is True, this option only affects the KMeans step.
8990
91+
verbose: ``bool``, optional, default ``True``
92+
If ``True``, print verbose output.
93+
9094
Returns
9195
-------
9296
``numpy.array``
@@ -114,9 +118,11 @@ def harmonize(
114118
if use_gpu:
115119
if torch.cuda.is_available():
116120
device_type = "cuda"
117-
print("Use GPU mode.")
121+
if verbose:
122+
print("Use GPU mode.")
118123
else:
119-
print("CUDA is not available on your machine. Use CPU mode instead.")
124+
if verbose:
125+
print("CUDA is not available on your machine. Use CPU mode instead.")
120126

121127
(stride_0, stride_1) = X.strides
122128
if stride_0 < 0 or stride_1 < 0:
@@ -167,7 +173,8 @@ def harmonize(
167173
n_jobs,
168174
)
169175

170-
print("\tInitialization is completed.")
176+
if verbose:
177+
print("\tInitialization is completed.")
171178

172179
for i in range(max_iter_harmony):
173180
clustering(
@@ -189,15 +196,17 @@ def harmonize(
189196
Z_hat = correction(Z, R, Phi, O, ridge_lambda, correction_method, device_type)
190197
Z_norm = normalize(Z_hat, p=2, dim=1)
191198

192-
print(
193-
"\tCompleted {cur_iter} / {total_iter} iteration(s).".format(
194-
cur_iter=i + 1,
195-
total_iter=max_iter_harmony,
199+
if verbose:
200+
print(
201+
"\tCompleted {cur_iter} / {total_iter} iteration(s).".format(
202+
cur_iter=i + 1,
203+
total_iter=max_iter_harmony,
204+
)
196205
)
197-
)
198206

199207
if is_convergent_harmony(objectives_harmony, tol=tol_harmony):
200-
print("Reach convergence after {} iteration(s).".format(i + 1))
208+
if verbose:
209+
print("Reach convergence after {} iteration(s).".format(i + 1))
201210
break
202211

203212
if device_type == "cpu":

0 commit comments

Comments
 (0)