Java Entropy Calculate entropy(double[] distribution)

Here you can find the source of entropy(double[] distribution)

Description

entropy

License

Apache License

Parameter

Parameter Description
distribution assume distribution sums up to 1

Declaration

public static double entropy(double[] distribution) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   w w  w  .j  a  va 2s .  co  m*/
     *
     * @param distribution  assume distribution sums up to 1
     * @return
     */
    public static double entropy(double[] distribution) {
        double entropy = 0;
        for (double prob : distribution) {
            if (prob != 0) {
                entropy -= prob * Math.log(prob) / Math.log(2);
            }
        }
        return entropy;
    }
}

Related

  1. calcEntropyOfDiscreteProbDist(Double[] probDist)
  2. computeEntropy(int pos, int neg)
  3. discreteEntropy(int[] sequence, int numStates)
  4. discretiseMaxEntropy(double data[], int numBins)
  5. entropy(byte[] f)
  6. entropy(double[] p)
  7. entropy(double[] vals)
  8. entropy(int hist[])
  9. entropy(int numBins, double[] _f)