Skip to main content

kl_divergence

Function kl_divergence 

Source
pub fn kl_divergence(p: &[f64], q: &[f64]) -> Option<f64>
Expand description

Kullback–Leibler divergence D(p‖q) = Σ pᵢ·log₂(pᵢ/qᵢ) (bits). Both inputs are normalized internally. None on a length mismatch, empty input, or if qᵢ = 0 where pᵢ > 0 (the divergence is then infinite — refuse rather than fabricate).