Skip to content

Instantly share code, notes, and snippets.

@danielperezr88
Created February 21, 2017 12:19
Show Gist options
  • Save danielperezr88/dfe55e5ca696ff9b74a73732fd59c71d to your computer and use it in GitHub Desktop.
Save danielperezr88/dfe55e5ca696ff9b74a73732fd59c71d to your computer and use it in GitHub Desktop.
diff --git a/nmf.py b/nmf.py
index dda116c..1cf6bd8 100644
--- a/nmf.py
+++ b/nmf.py
@@ -74,7 +74,7 @@ def _safe_compute_error(X, W, H):
norm_X = np.dot(X.data, X.data)
norm_WH = trace_dot(np.dot(np.dot(W.T, W), H), H)
cross_prod = trace_dot((X * H.T), W)
- error = sqrt(norm_X + norm_WH - 2. * cross_prod)
+ error = sqrt(np.max([0, norm_X + norm_WH - 2. * cross_prod]))
return error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment