Here you can find the source of entropy(double[] distribution)
Parameter | Description |
---|---|
distribution | assume distribution sums up to 1 |
public static double entropy(double[] distribution)
//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; } }