Skip to content

Commit

Permalink
change Mahout to breeze in doc
Browse files Browse the repository at this point in the history
use a simple lower bound to avoid unnecessary distance computation
  • Loading branch information
mengxr committed Mar 18, 2014
1 parent 6f5cdde commit 07c3cf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,16 @@ object KMeans {
var bestIndex = 0
var i = 0
centers.foreach { center =>
val distance: Double = fastSquaredDistance(center, point)
if (distance < bestDistance) {
bestDistance = distance
bestIndex = i
// Since `\|a - b\| \geq |\|a\| - \|b\||`, we can use this lower bound to avoid unnecessary
// distance computation.
var lowerBoundOfSqDist = math.sqrt(center.squaredNorm) - math.sqrt(point.squaredNorm)
lowerBoundOfSqDist = lowerBoundOfSqDist * lowerBoundOfSqDist
if (lowerBoundOfSqDist < bestDistance) {
val distance: Double = fastSquaredDistance(center, point)
if (distance < bestDistance) {
bestDistance = distance
bestIndex = i
}
}
i += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait Vector extends Serializable {
def size: Int

/**
* Converts the instance to a Mahout vector wrapper.
* Converts the instance to a breeze vector.
*/
private[mllib] def toBreeze: BreezeVector[Double]
}
Expand Down

0 comments on commit 07c3cf2

Please sign in to comment.