Here you can find the source of getEntropy(Collection
public static double getEntropy(Collection<Double> values)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { public static double getEntropy(Collection<Double> values) { if (values.isEmpty()) { return -1.0; }//from w w w . j ava 2s . c om double noOfTerms = 0; for (Double frequency : values) { noOfTerms += frequency; } double entropy = 0.0; for (Double frequency : values) { double currentProbability = frequency / noOfTerms; entropy += -currentProbability * Math.log(currentProbability) / Math.log(2); } return entropy; } }