Class: Rlid::CosineDistanceModel

Inherits:
FrequencyModel show all
Defined in:
lib/rlid/models/cosine_distance_model.rb

Constant Summary

Constants inherited from FrequencyModel

FrequencyModel::N

Instance Method Summary collapse

Methods inherited from FrequencyModel

filename, #generate_model, #initialize, #load, #save

Methods inherited from NGramModel

#initialize, language_models

Methods inherited from Model

#initialize

Constructor Details

This class inherits a constructor from Rlid::FrequencyModel

Instance Method Details

#-(other) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# 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