Kullback-Leibler Divergence
Kullback-Leibler (KL) divergence, also known as relative-entropy, is a fundamental measure in information theory and mathematical statistics that quantifies how much one probability distribution differs from a reference probability distribution.
In machine learning and statistics, it is typically used to measure the difference between a βtrueβ data distribution and an approximating model distribution .
1. Definition & Mathematical Formulation
For two probability distributions and defined over the same probability space, the KL divergence from to is defined as:
Discrete Distributions
Continuous Distributions
Note: In these formulations, represents the true distribution or target data distribution, while represents the approximation, model, or prior distribution.
2. Key Features & Properties
- Non-Negativity (Gibbsβ Inequality): . The divergence is strictly non-negative, and it equals if and only if almost everywhere.
- Asymmetry (Non-Symmetric): . Because the order of distributions matters, KL divergence is not a true distance metric.
- No Triangle Inequality: Unlike true mathematical metrics, KL divergence does not satisfy the triangle inequality.
- Additive for Independent Distributions: If and are independent joint distributions, then .
3. Related Topics & Information Theory Connections
- cross-entropy: The cross-entropy between two distributions is directly related to the Shannon entropy and KL divergence: In many deep learning contexts (such as classification tasks), minimizing the cross-entropy loss is equivalent to minimizing the KL divergence since the true data distributionβs entropy is constant.
- Mutual Information: The mutual information between two random variables and can be expressed as the KL divergence between their joint distribution and the product of their marginal distributions:
- Jensen-Shannon Divergence: A symmetric and bounded alternative to KL divergence, defined as the average KL divergence of and to their average distribution.
4. Key Applications in AI/ML
- variational-autoencoders (VAEs): In variational inference, VAEs utilize KL divergence as a regularization term in the Evidence Lower Bound (ELBO) loss. It constrains the learned latent representation distribution to be close to a known prior distribution (typically a standard Gaussian).
- reinforcement-learning: Policy optimization algorithms such as Trust Region Policy Optimization (TRPO) and Proximal Policy Optimization (PPO) employ KL divergence constraints to ensure policy updates do not deviate too far from the previous, stable policy.
- Data Drift and Model Monitoring: In production environments, KL divergence is used to monitor input distributions and detect covariate/concept drift between training baseline distributions and real-world inference data.