Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/117#discussion_r10863319
--- Diff: mllib/src/main/scala/org/apache/spark/mllib/util/MLUtils.scala ---
@@ -106,18 +111,46 @@ object MLUtils {
}
/**
- * Return the squared Euclidean distance between two vectors.
+ * Returns the squared Euclidean distance between two vectors. The
following formula will be used
+ * if it does not introduce too much numerical error:
+ * <pre>
+ * \|a - b\|_2^2 = \|a\|_2^2 + \|b\|_2^2 - 2 a^T b.
+ * </pre>
+ * When both vector norms are given, this is faster than computing the
squared distance directly,
+ * especially when one of the vectors is a sparse vector.
--- End diff --
I don't have a reference for this formula...
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---