Here you can find the source of entropy(int numBins, double[] _f)
public static double entropy(int numBins, double[] _f)
//package com.java2s; // it under the terms of the GNU General Public License as published by // public class Main { public static double entropy(int numBins, double[] _f) { double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; for (double x : _f) { if (x < min) min = x;//from w ww .j ava2 s .c o m if (x > max) max = x; } int[] v = new int[numBins]; double width = max - min; for (int i = 0; i < _f.length; i++) { double x = _f[i]; double x3 = (x - min) / width; // 0 to 1 int bin = (int) (x3 * (numBins - 1)); // 0 to numBins - 1 v[bin]++; } // Calculate entropy. double sum = 0.0; for (int i = 0; i < v.length; i++) { if (v[i] != 0) { double p = v[i] / (double) (numBins - 1); sum += p * Math.log(p); } } return -sum; } }