private static double computeCosineSimilarity ( DoubleTuple t0 , DoubleTuple t1 ) { Utils . checkForEqualSize ( t0 , t1 ) ; double dot = DoubleTuples . dot ( t0 , t1 ) ; final double epsilon = 1e-10 ; if ( Math . abs ( dot ) < epsilon ) { return 0 ; } double tt0 = DoubleTuples . computeL2 ( t0 ) ; double tt1 = DoubleTuples . computeL2 ( t1 ) ; double tt = tt0 * tt1 ; double result = clamp ( dot / tt , - 1.0 , 1.0 ) ; return result ; }
Computes the cosine similarity between the given tuples