Skip to main content

entropy

Function entropy 

Source
pub fn entropy(p: &[f64]) -> f64
Expand description

The entropy (bits) of a distribution, the zero probabilities left out:

$$ H(p) = -\sum_{i:, p_{i} > 0} p_{i} \log_{2} p_{i}. $$

§Examples

use comnum_math::entropy;
assert_eq!(entropy(&[0.25; 4]), 2.0);
assert_eq!(entropy(&[1.0, 0.0]), 0.0);