class Rlid::CosineDistanceModel

Public Instance Methods

-(other) click to toggle source
# File lib/rlid/models/cosine_distance_model.rb, line 51
def -(other)
  if not other.is_a?(CosineDistanceModel)
    raise InvalidArgument
  end
  prod = 0
  other.ngram_frequency.each do |ngram, freq_other|
    freq_self = ngram_frequency[ngram]
    if freq_self != nil
      prod += (freq_self * freq_other)**0.2
    end
  end
  1 - prod
end