Module: Octo::KLDivergence

Included in:
Trendable
Defined in:
lib/octocore-cassandra/kldivergence.rb

Instance Method Summary collapse

Instance Method Details

#kl_divergence(p, q) ⇒ Float

Calculates the KL-Divergance of two probabilities en.wikipedia.org/wiki/Kullback–Leibler_divergence

Parameters:

  • p (Float)

    The first or observed probability

  • q (Float)

    The second or believed probability. Must be non-zero

Returns:

  • (Float)

    KL-Divergance score



10
11
12
# File 'lib/octocore-cassandra/kldivergence.rb', line 10

def kl_divergence(p, q)
  p * Math.log(p/q)
end