Class KLDivergence

java.lang.Object
es.uam.eps.ir.relison.utils.indexes.KLDivergence

public class KLDivergence
extends java.lang.Object
Computes the KL divergence as a distance between two distributions (an original one, P(x), and an estimated one from real data Q(x). By definition, the Kullback-Leibler divergence can only be computed if Q(x) = 0 implies that P(x) = 0.

Reference S. Kullback, R.A. Leibler. On Information and Sufficiency. Annals of Mathematical Statistics 22(1), pp. 78-86 (1951)

  • Constructor Summary

    Constructors 
    Constructor Description
    KLDivergence()  
  • Method Summary

    Modifier and Type Method Description
    double compute​(java.util.List<java.lang.Double> p, java.util.List<java.lang.Double> q)
    Computes the Kullback-Leibler divergence for two different distributions
    double compute​(java.util.List<java.lang.Double> p, java.util.List<java.lang.Double> q, double sumP, double sumQ)
    Computes the Kullback-Leibler divergence for two different distributions
    double compute​(java.util.stream.Stream<java.lang.Double> p, java.util.stream.Stream<java.lang.Double> q)
    Computes the Kullback-Leibler divergence for two different distributions
    double compute​(java.util.stream.Stream<java.lang.Double> p, java.util.stream.Stream<java.lang.Double> q, double sumP, double sumQ)
    Computes the Kullback-Leibler divergence for two different distributions

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • compute

      public double compute​(java.util.List<java.lang.Double> p, java.util.List<java.lang.Double> q)
      Computes the Kullback-Leibler divergence for two different distributions
      Parameters:
      p - the distribution
      q - proxy to the real distribution (i.e. the distribution we estimate from data)
      Returns:
      the value of the Kullback-Leibler divergence
    • compute

      public double compute​(java.util.List<java.lang.Double> p, java.util.List<java.lang.Double> q, double sumP, double sumQ)
      Computes the Kullback-Leibler divergence for two different distributions
      Parameters:
      p - the distribution
      q - proxy to the real distribution (i.e. the distribution we estimate from data)
      sumP - the sum of the values in P
      sumQ - the sum of the values in Q
      Returns:
      the value of the Kullback-Leibler divergence
    • compute

      public double compute​(java.util.stream.Stream<java.lang.Double> p, java.util.stream.Stream<java.lang.Double> q)
      Computes the Kullback-Leibler divergence for two different distributions
      Parameters:
      p - the distribution
      q - proxy to the real distribution (i.e. the distribution we estimate from data)
      Returns:
      the value of the Kullback-Leibler divergence
    • compute

      public double compute​(java.util.stream.Stream<java.lang.Double> p, java.util.stream.Stream<java.lang.Double> q, double sumP, double sumQ)
      Computes the Kullback-Leibler divergence for two different distributions
      Parameters:
      p - the distribution
      q - proxy to the real distribution (i.e. the distribution we estimate from data)
      sumP - the sum of the values in P
      sumQ - the sum of the values in Q
      Returns:
      the value of the Kullback-Leibler divergence