Skip to content

Commit abe3d05

Browse files
committed
COSMIT micro-optimize norm computation in NMF
... for clarity, although it should also be slightly faster, and corrected a docstring while I was there.
1 parent b2c5f4d commit abe3d05

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sklearn/decomposition/nmf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def norm(x):
4040

4141

4242
def trace_dot(X, Y):
43-
"""Trace of np.dot(X, Y)."""
43+
"""Trace of np.dot(X, Y.T)."""
4444
return np.dot(X.ravel(), Y.ravel())
4545

4646

@@ -527,7 +527,7 @@ def fit_transform(self, X, y=None):
527527
error = norm(X - np.dot(W, H))
528528
else:
529529
sqnorm_X = np.dot(X.data, X.data)
530-
norm_WHT = trace_dot(np.dot(H.T, np.dot(W.T, W)).T, H)
530+
norm_WHT = trace_dot(np.dot(np.dot(W.T, W), H), H)
531531
cross_prod = trace_dot((X * H.T), W)
532532
error = sqrt(sqnorm_X + norm_WHT - 2. * cross_prod)
533533

0 commit comments

Comments
 (0)