code: public static double KullbackLeiblerDivergence(double[] p, double[] q) {
          boolean intersection = false;
          double k = 0;
  
          for (int i = 0; i < p.length; i++) {
              if (p[i] != 0 && q[i] != 0) {
                  intersection = true;
                  k += p[i] * Math.log(p[i] / q[i]);
              }
          }
  
          if (intersection)
              return k;
          else
              return Double.POSITIVE_INFINITY;
      }
docs: Gets the Kullback Leibler divergence.
  
  @param p P vector.
  @param q Q vector.
  @return The Kullback Leibler divergence between u and v.