class ShannonEntropy {

    public static double computeWithFrequencies(Collection<Double> frequencies) {
        if (frequencies.contains(0D)) {
            throw new IllegalArgumentException(
                    "Values with null frequency are not permitted when computing Shannon entropy");
        }

        if (frequencies.isEmpty()) {
            return Double.MAX_VALUE;
        }
        double entropy = frequencies.stream().mapToDouble(d -> d).map(s -> s * Math.log(s)).sum();
        entropy = (-entropy / Math.log(2));

        return Math.abs(entropy);
    }

}