Java Utililty Methods Entropy Calculate

List of utility methods to do Entropy Calculate

Description

The list of methods to do Entropy Calculate are organized into topic(s).

Method

doublecalcEntropyOfDiscreteProbDist(Double[] probDist)
calc Entropy Of Discrete Prob Dist
double entropy = 0.0;
for (double x : probDist) {
    entropy -= x * Math.log(x) / Math.log(2);
return entropy;
doublecomputeEntropy(int pos, int neg)
Computes the entropy of two numbers.
if (pos == 0 || neg == 0)
    return 0d;
final double total = (double) pos + neg;
final double posRatio = pos / total;
final double negRatio = neg / total;
final double entropy = -posRatio * log2(posRatio) - negRatio * log2(negRatio);
return entropy;
doublediscreteEntropy(int[] sequence, int numStates)
discrete Entropy
int[] p = new int[numStates];
return discreteEntropy(sequence, p);
int[]discretiseMaxEntropy(double data[], int numBins)
Discretizes using a maximum entropy partitioning
int[] newData = new int[data.length];
double[] tempData = new double[data.length];
System.arraycopy(data, 0, tempData, 0, data.length);
Arrays.sort(tempData);
int compartmentSize;
double[] cutOffValues = new double[numBins];
for (int i = 0; i < numBins; i++) {
    compartmentSize = (int) ((double) (i + 1) * (double) (data.length) / (double) numBins) - 1;
...
floatentropy(byte[] f)
entropy
int counts[] = new int[256];
float entropy = 0;
float total = f.length;
for (byte b : f)
    counts[b + 128]++;
for (int c : counts) {
    if (c == 0)
        continue;
...
doubleentropy(double[] distribution)
entropy
double entropy = 0;
for (double prob : distribution) {
    if (prob != 0) {
        entropy -= prob * Math.log(prob) / Math.log(2);
return entropy;
Doubleentropy(double[] p)
entropy
double h = 0;
for (int i = 0; i < p.length; i++) {
    h += (p[i] > 0) ? p[i] * Math.log(p[i]) : 0.0;
return -h;
doubleentropy(double[] vals)
entropy
double entropy = 0;
for (double v : vals) {
    entropy += v * ln(v);
return -entropy;
floatentropy(int hist[])
Entropy.
int n = hist.length;
int t = 0;
for (int i = 0; i < n; i++)
    t += hist[i];
float h = 0;
for (int i = 0; i < n; i++) {
    if (hist[i] != 0) {
        float f = (float) hist[i] / (float) (t);
...
doubleentropy(int numBins, double[] _f)
entropy
double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
for (double x : _f) {
    if (x < min)
        min = x;
    if (x > max)
        max = x;
int[] v = new int[numBins];
...