The Kullback-Leibler (KL) divergence, also known as relative entropy, measures how one probability distribution P differs from a second, reference probability distribution Q. It quantifies the information lost when Q is used to approximate P.[1][2][5]
The formula for KL divergence depends on whether the probability distributions are discrete or continuous:[4][6][7]
1. Discrete Probability Distributions:
Let P(x) and Q(x) be two discrete probability distributions defined over the same set of events X.[4][5] The KL divergence of Q from P, denoted as DKL(P || Q), is calculated as:
2. Continuous Probability Distributions:
Let p(x) and q(x) be two probability density functions defined over the same continuous variable x.[4][5] The KL divergence is calculated using an integral:
Key Points about KL Divergence:
- Non-negativity: DKL(P || Q) ≥ 0.[3][4][5]
- Identity: DKL(P || Q) = 0 if and only if P and Q are identical distributions.[4][5]
- Asymmetry: KL divergence is not a true distance metric because it is asymmetric, meaning DKL(P || Q) ≠ DKL(Q || P) in general.[4][5] DKL(P || Q) measures the information lost when approximating P with Q, while DKL(Q || P) measures the loss when approximating Q with P.[4][5]
- Interpretation: It can be interpreted as the expected excess surprise or the expected number of extra bits required to code samples from P when using a code based on Q instead of P.[4][5]
KL divergence is widely used in fields like statistics, machine learning, information theory, and neuroscience.[4][5]