code: public static double KullbackLeiblerDivergence(double[] x, double[] y) {
          boolean intersection = false;
          double kl = 0.0;
  
          for (int i = 0; i < x.length; i++) {
              if (x[i] != 0.0 && y[i] != 0.0) {
                  intersection = true;
                  kl += x[i] * Math.log(x[i] / y[i]);
              }
          }
  
          if (intersection) {
              return kl;
          } else {
              return Double.POSITIVE_INFINITY;
          }
      }
docs: Kullback-Leibler divergence. The Kullback-Leibler divergence (also
  information divergence, information gain, relative entropy, or KLIC)
  is a non-symmetric measure of the difference between two probability
  distributions P and Q. KL measures the expected number of extra bits
  required to code samples from P when using a code based on Q, rather
  than using a code based on P. Typically P represents the "true"
  distribution of data, observations, or a precise calculated theoretical
  distribution. The measure Q typically represents a theory, model,
  description, or approximation of P.
  <p>
  Although it is often intuited as a distance metric, the KL divergence is
  not a true metric - for example, the KL from P to Q is not necessarily
  the same as the KL from Q to P.