code: public static double JensenShannonDivergence(SparseArray x, double[] y) {
          if (x.isEmpty()) {
              throw new IllegalArgumentException("List x is empty.");
          }
  
          Iterator<SparseArray.Entry> iter = x.iterator();
  
          double js = 0.0;
          while (iter.hasNext()) {
              SparseArray.Entry b = iter.next();
              int i = b.i;
              double mi = (b.x + y[i]) / 2;
              js += b.x * Math.log(b.x / mi);
              if (y[i] > 0) {
                  js += y[i] * Math.log(y[i] / mi);
              }
          }
  
          return js / 2;
      }
docs: Jensen-Shannon divergence JS(P||Q) = (KL(P||M) + KL(Q||M)) / 2, where
  M = (P+Q)/2. The Jensen-Shannon divergence is a popular
  method of measuring the similarity between two probability distributions.
  It is also known as information radius or total divergence to the average.
  It is based on the Kullback-Leibler divergence, with the difference that
  it is always a finite value. The square root of the Jensen-Shannon divergence
  is a metric.