Skip to content

Commit 26a246e

Browse files
committed
More formatting and cleaning
1 parent e0ecb03 commit 26a246e

File tree

8 files changed

+6
-28
lines changed

8 files changed

+6
-28
lines changed
File renamed without changes.

src/skmatter/decomposition/_kernel_pcovc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,11 @@ def fit(self, X, Y, W=None):
297297
else:
298298
classifier = self.classifier
299299

300+
# for convergence warnings
300301
if hasattr(classifier, "max_iter") and (
301302
classifier.max_iter is None or classifier.max_iter < 500
302303
):
303-
classifier.max_iter = 500 # for convergence warnings
304+
classifier.max_iter = 500
304305

305306
# Check if classifier is fitted; if not, fit with precomputed K
306307
self.z_classifier_ = check_cl_fit(classifier, K, Y)
@@ -318,7 +319,7 @@ def fit(self, X, Y, W=None):
318319
self._fit(K, Z, W)
319320

320321
self.ptk_ = self.pt__ @ K
321-
# ("KPCovc"+str(self.ptk_[:10][1]))
322+
322323
if self.fit_inverse_transform:
323324
self.ptx_ = self.pt__ @ X
324325

src/skmatter/decomposition/_kpcov.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ def _fit(self, K, Yhat, W):
106106
"""Fit the model with the computed kernel and approximated properties."""
107107
K_tilde = pcovr_kernel(mixing=self.mixing, X=K, Y=Yhat, kernel="precomputed")
108108

109-
# print("KPCovC K: " + str(K[:5, 0]))
110-
# print("KPCovC Yhat: " + str(Yhat[:5, 0]))
111-
# print("KPCovC K_tilde: " + str(K_tilde[:5, 0]))
112-
113109
if self.fit_svd_solver_ == "full":
114110
_, S, Vt = self._decompose_full(K_tilde)
115111
elif self.fit_svd_solver_ in ["arpack", "randomized"]:

src/skmatter/decomposition/_pcov.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ def _fit_feature_space(self, X, Y, Yhat, compute_pty_=True):
133133
self.pty_ = np.linalg.multi_dot([S_sqrt_inv, Vt, iCsqrt, X.T, Y])
134134

135135
def _fit_sample_space(self, X, Y, Yhat, W, compute_pty_=True):
136-
# Kt = pcovr_kernel(mixing=self.mixing, X=X, Y=Yhat)
137136
Kt = pcovr_kernel(mixing=self.mixing, X=X, Y=Yhat)
138-
# print("PCovC X: " + str(X[:5, 0]))
139-
# print("PCovC Yhat: " + str(Yhat[:5, 0]))
140-
# print("PcovC Kt: " + str(Kt[:5, 0]))
141137

142138
if self.fit_svd_solver_ == "full":
143139
U, S, Vt = self._decompose_full(Kt)
@@ -155,15 +151,13 @@ def _fit_sample_space(self, X, Y, Yhat, W, compute_pty_=True):
155151
)
156152

157153
P = (self.mixing * X.T) + (1.0 - self.mixing) * W @ Yhat.T
158-
# print("PCovC P: " + str(P[:5, 0]))
154+
159155
S_sqrt_inv = np.diagflat([1.0 / np.sqrt(s) if s > self.tol else 0.0 for s in S])
160156
T = Vt.T @ S_sqrt_inv
161157

162158
self.pxt_ = P @ T
163159
self.ptx_ = T.T @ X
164160

165-
# print("PcovC pxt: " + str(self.pxt_[:5, 0]))
166-
167161
if compute_pty_:
168162
self.pty_ = T.T @ Y
169163

src/skmatter/decomposition/_pcovc.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ def fit(self, X, Y, W=None):
292292

293293
Z = X @ W
294294

295-
# print(f"PCovC Z {Z[:5, 0]}")
296295
if self.space_ == "feature":
297296
self._fit_feature_space(X, Y, Z)
298297
else:
@@ -305,18 +304,13 @@ def fit(self, X, Y, W=None):
305304
self.ptz_ = self.classifier_.coef_.T
306305
self.pxz_ = self.pxt_ @ self.ptz_
307306

308-
# print(f"PCovC ptz: {self.ptz_.shape}")
309-
# print(f"PCovC classifier_ coef n_classes: {len(self.classifier_.classes_)}")
310-
311-
# print(f"PCovC pxz: {self.pxz_.shape}")
312307
if len(Y.shape) == 1 and type_of_target(Y) == "binary":
313308
self.pxz_ = self.pxz_.reshape(
314309
X.shape[1],
315310
)
316311
self.ptz_ = self.ptz_.reshape(
317312
self.n_components_,
318313
)
319-
# print(f"PCovC pxz: {self.pxz_.shape}")
320314

321315
self.components_ = self.pxt_.T # for sklearn compatibility
322316
return self

tests/test_kernel_pcovc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def test_reconstruction_errors(self):
111111
Xr = kpcovc.inverse_transform(kpcovc.transform(self.X))
112112
error = np.linalg.norm(self.X - Xr) ** 2.0 / np.linalg.norm(self.X) ** 2.0
113113

114-
print(error)
115114
with self.subTest(error=error):
116115
self.assertFalse(np.isnan(error))
117116
with self.subTest(error=error, alpha=round(mixing, 4)):
@@ -198,10 +197,10 @@ def test_centerer(self):
198197

199198
def test_prefit_classifier(self):
200199
# in KPCovC, our classifiers don't compute the kernel for us, hence we only
201-
# allow prefit classifiers on K, y
200+
# allow prefit classifiers on K and y
202201
kernel_params = {"kernel": "rbf", "gamma": 0.1, "degree": 3, "coef0": 0}
203-
204202
K = pairwise_kernels(self.X, metric="rbf", filter_params=True, **kernel_params)
203+
205204
classifier = LinearSVC()
206205
classifier.fit(K, self.Y)
207206

tests/test_kernel_pcovr.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def test_reconstruction_errors(self):
9090

9191
error = np.linalg.norm(K - t @ t.T) ** 2.0 / np.linalg.norm(K) ** 2.0
9292
x_error = np.linalg.norm(self.X - x) ** 2.0 / np.linalg.norm(self.X) ** 2.0
93-
print(np.linalg.norm(K - t @ t.T) ** 2.0 / np.linalg.norm(K) ** 2.0)
9493

9594
with self.subTest(error=error):
9695
self.assertFalse(np.isnan(error))
@@ -254,7 +253,6 @@ def test_incompatible_coef_shape(self):
254253
kpcovr = self.model(mixing=0.5, regressor=regressor)
255254

256255
# Dimension mismatch
257-
print(self.Y.shape, np.zeros(self.Y.shape + (2,)).shape)
258256
with self.assertRaises(ValueError) as cm:
259257
kpcovr.fit(self.X, self.Y)
260258
self.assertEqual(
@@ -366,7 +364,6 @@ def test_linear_matches_pcovr(self):
366364
t_ref = ref_pcovr.transform(self.X)
367365
t = kpcovr.transform(self.X)
368366

369-
print(np.linalg.norm(t_ref - t))
370367
K = kpcovr._get_kernel(self.X)
371368

372369
k_ref = t_ref @ t_ref.T
@@ -381,8 +378,6 @@ def test_linear_matches_pcovr(self):
381378
round(ly_ref, rounding),
382379
)
383380

384-
print(lk, lk_ref)
385-
386381
self.assertEqual(
387382
round(lk, rounding),
388383
round(lk_ref, rounding),

tests/test_pcovc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ def test_precomputed_classification(self):
479479
pcovc3.fit(self.X, self.Y)
480480
t3 = pcovc3.transform(self.X)
481481

482-
print(np.linalg.norm(t1), np.linalg.norm(t2), np.linalg.norm(t3))
483482
self.assertTrue(np.linalg.norm(t3 - t2) < self.error_tol)
484483
self.assertTrue(np.linalg.norm(t3 - t1) < self.error_tol)
485484

0 commit comments

Comments
 (0)