Skip to content

Instantly share code, notes, and snippets.

@treper
Last active December 23, 2015 07:59
Show Gist options
  • Save treper/a32266904e16744b2630 to your computer and use it in GitHub Desktop.
Save treper/a32266904e16744b2630 to your computer and use it in GitHub Desktop.
import spark.util.Vector
import scala.math.sqrt
def cosineDist(a:Vector,b:Vector):Double = {
if(a.length==b.length){
(a dot b)/(sqrt(a.squaredDist(Vector.zeros(a.length))*b.squaredDist(Vector.zeros(b.length))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment