Skip to main content

shannon_entropy

Function shannon_entropy 

Source
pub fn shannon_entropy<I>(weights: I) -> f64
where I: Iterator<Item = f64> + Clone,
Available on crate feature vcs-git only.
Expand description

Shannon entropy (base 2, in bits) of a weight distribution.

Weights are normalised to a probability distribution pᵢ = wᵢ / Σw and the entropy is -Σ pᵢ·log₂(pᵢ). Non-positive weights contribute nothing (a file with zero churn in a commit, or an absent edge). An empty distribution, an all-zero distribution, and a single non-zero weight all yield 0.0 — there is no uncertainty to measure.

Takes a cloneable iterator rather than a slice so callers on the per-commit walk (churn distribution) and per-file finalise (edge weights) feed it directly, with no intermediate Vec; the two passes (total, then sum) clone the iterator.