Measures how distribution P differs from Q. Used in RLHF (KL penalty), VAEs, and information theory.
KL(P || Q) = Σ P[i] × log(P[i] / Q[i])- KL(P || Q) ≠ KL(Q || P) — not symmetric
- KL = 0 when P = Q
- Always ≥ 0 (Gibbs inequality)
kl_divergence([0.5,0.5],[0.4,0.6]) → 0.02041
Round to **5 decimal places**.
Similar Problems
Test Cases (2 visible · 2 hidden)
Case 1: Close distributions
Input: kl_divergence([0.5,0.5],[0.4,0.6])
Expected: 0.02041
Case 2: Identical distributions
Input: kl_divergence([0.5,0.5],[0.5,0.5])
Expected: 0.0
⌘↵ Run · ⌘⇧↵ Submit