Class: Clusterer::WeightNormalizedMultinomialBayes

Inherits:
MultinomialBayes show all
Includes:
WeightNormalized
Defined in:
lib/clusterer/bayes.rb

Overview

Hopefully an improved MultinomialBayes, based on the same ideas as the WeightNormalizedComplementBayes only using MultinomialBayes as the base. The weights are normalized, before using this algorithm.

Instance Attribute Summary

Attributes inherited from Bayes

#categories

Instance Method Summary collapse

Methods included from WeightNormalized

#initialize, #train, #untrain

Methods inherited from MultinomialBayes

#train, #untrain

Methods inherited from Bayes

#classify, #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Clusterer::Bayes

Instance Method Details

#distribution(document) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/clusterer/bayes.rb', line 247

def distribution(document)
  self.class.superclass.superclass.instance_method(:distribution).bind(self).call do |cl,ind|
    we, sum = weighted_likelihood(cl), 0.0
    document.each {|term,freq| sum += freq * (we[term] || 0)}
    sum
  end
end