Java Entropy Calculate entropy(int hist[])

Here you can find the source of entropy(int hist[])

Description

Entropy.

License

Open Source License

Parameter

Parameter Description
hist the hist

Return

the float

Declaration

static float entropy(int hist[]) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  w w.j  a  va 2 s  .  c  o m
     * Entropy.
     * 
     * @param hist
     *            the hist
     * @return the float
     */
    static float entropy(int hist[]) {
        int n = hist.length;
        int t = 0;

        for (int i = 0; i < n; i++)
            t += hist[i];

        float h = 0;

        // System.out.print("[ " + hist[0] + "," + hist[1] + "] -> ");

        for (int i = 0; i < n; i++) {
            if (hist[i] != 0) {
                float f = (float) hist[i] / (float) (t);
                h -= Math.log(f) * f;
            }
        }
        // System.out.println("" + h);
        return h;
    }
}

Related

  1. discretiseMaxEntropy(double data[], int numBins)
  2. entropy(byte[] f)
  3. entropy(double[] distribution)
  4. entropy(double[] p)
  5. entropy(double[] vals)
  6. entropy(int numBins, double[] _f)
  7. entropy(int total, double[] data)
  8. entropy(int[] histogram)
  9. longPseudoEntropy()