Function information::entropy::entropy
source · [−]Expand description
Entropy
Calculates the empirical entropy of a probability array measured in nats.
https://en.wikipedia.org/wiki/Entropy_(information_theory)
This assumes that the provided array is the probability (and sums to one).
The entropy is calculated as follows:
H(X) = -Σ p(x) * ln[ p(x) ]
Usage:
use ndarray::array;
use information::{entropy, prob1d};
let x = array![0, 0, 1, 1];
let p_x = prob1d(&x, 2).unwrap();
let h_x = entropy(&p_x);
assert_eq!(h_x, 0.6931471805599453)