Here you can find the source of discreteEntropy(int[] sequence, int numStates)
public static double discreteEntropy(int[] sequence, int numStates)
//package com.java2s; //License from project: Open Source License public class Main { public static double discreteEntropy(int[] sequence, int[] p) { double v = 0.0; double vt = 0.0; int i = 0; int numStates = p.length; for (i = 0; i < numStates; i++) { p[i] = 0;//from w w w. j a va2 s.c o m } for (i = 0; i < sequence.length; i++) { p[sequence[i]]++; } for (i = 0; i < numStates; i++) { if (p[i] > 0) { vt = ((double) p[i]) / ((double) sequence.length); v = v - vt * Math.log(vt); } } if (v <= 0.0) { v = 0.0; } return v; } public static double discreteEntropy(int[] sequence, int numStates) { int[] p = new int[numStates]; return discreteEntropy(sequence, p); } }