code: public static double entropy(int[] a) {
          double sum = sum(a);
          double entropy = 0;
          for (int x : a) {
              double p = x / sum;
              if (p != 0d)
                  entropy += Math.log(p) * p;
          }
          return -entropy;
      }
docs: Returns the entropy of an array representing a (potentially) unormalized
  probability distribution).  Note that this method uses the natural log
  when computing the entropy.