Skip to content

Commit 2ace3ae

Browse files
committed
Making the trace component of SparseKernelNormalizer more memory-friendly
1 parent 916c37f commit 2ace3ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/skmatter/preprocessing/_data.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,11 @@ def fit(self, Knm, Kmm, y=None, sample_weight=None):
524524
if self.with_trace:
525525
Knm_centered = Knm - self.K_fit_rows_
526526

527-
Khat = Knm_centered @ np.linalg.pinv(Kmm, self.rcond) @ Knm_centered.T
527+
# The following is more correctly written as Knm @ Kmm^{-1} @ Knm.T
528+
# but has been changed to Knm.T @ Knm @ Kmm^{-1} to avoid the memory
529+
# overload often caused by storing n x n matrices. This is fine
530+
# for the following trace, but should not be used for other operations.
531+
Khat = Knm_centered.T @ Knm_centered @ np.linalg.pinv(Kmm, self.rcond)
528532

529533
self.scale_ = np.sqrt(np.trace(Khat) / Knm.shape[0])
530534
else:

0 commit comments

Comments
 (0)