Skip to main content

jsd

Function jsd 

Source
pub fn jsd(p: &[f64], q: &[f64], bins: usize) -> f64
Expand description

Compute Jensen-Shannon divergence between two distributions.

JSD(P,Q) = ½ D_KL(P||M) + ½ D_KL(Q||M) where M = (P+Q)/2

Symmetric, always finite, and its square root is a proper metric. Use for detecting ANY distribution shift (not just mean shift).

§Arguments

  • p - First distribution’s values
  • q - Second distribution’s values
  • bins - Number of bins for discretization

§Returns

JSD in bits (symmetric, bounded by log₂(bins)).