Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/skmatter/preprocessing/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,15 @@ def fit(self, Knm, Kmm, y=None, sample_weight=None):
if self.with_trace:
Knm_centered = Knm - self.K_fit_rows_

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

self.scale_ = np.sqrt(np.trace(Khat) / Knm.shape[0])
self.scale_ = Khat_trace / Knm.shape[0]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did the square root go to?

else:
self.scale_ = 1.0

Expand Down
Loading