code: public static <E> double entropy(Counter<E> c) {
      double entropy = 0.0;
      double total = c.totalCount();
      for (E key : c.keySet()) {
        double count = c.getCount(key);
        if (count == 0) {
          continue; // 0.0 doesn't add entropy but may cause -Inf
        }
        count /= total; // use normalized count
        entropy -= count * (Math.log(count) / LOG_E_2);
      }
      return entropy;
    }
docs: Calculates the entropy of the given counter (in bits). This method
  internally uses normalized counts (so they sum to one), but the value
  returned is meaningless if some of the counts are negative.
  
  @return The entropy of the given counter (in bits)