Method: LicenseMatcher::TFRubyMatcher#cos_sim
- Defined in:
- lib/license_matcher/tf_ruby_matcher.rb
#cos_sim(mat1, mat2) ⇒ Object
Calculates cosine similarity between 2 TF-IDF vector
75 76 77 78 79 80 |
# File 'lib/license_matcher/tf_ruby_matcher.rb', line 75 def cos_sim(mat1, mat2) length = (mat1 * mat2).sum norm = Math::sqrt((mat1 ** 2).sum) * Math::sqrt((mat2 ** 2).sum) ( norm > 0 ? length / norm : 0.0) end |