Class: Rlid::CosineDistanceModel
- Inherits:
-
FrequencyModel
- Object
- Model
- NGramModel
- FrequencyModel
- Rlid::CosineDistanceModel
- Defined in:
- lib/rlid/models/cosine_distance_model.rb
Constant Summary
Constants inherited from FrequencyModel
Instance Method Summary collapse
Methods inherited from FrequencyModel
filename, #generate_model, #initialize, #load, #save
Methods inherited from NGramModel
Methods inherited from Model
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 |