Skip to main content

kl_divergence

Function kl_divergence 

Source
pub fn kl_divergence(
    ref_logits: &[f32],
    cand_logits: &[f32],
    scratch: &mut [f64],
) -> f64
Expand description

KL-divergence D(reference ‖ candidate) between the two softmax distributions, in nats. = Σ p_ref · (log p_ref − log p_cand), computed via log-softmax for stability. Non-negative.