f-Divergences

Dive into Deep Learning · §37.3

f-Divergences and Variational Duals
density ratios · forward vs. reverse KL · total variation · Pinsker’s inequality · Fenchel duality · f-GAN

Why Disjoint Supports Break Density-Ratio Losses

Motivation: The Point-Mass Diagnostic

Compare two point masses P = \delta_0 and Q = \delta_d separated by distance d > 0:

  • Frozen f-divergences (u = p/q): For every d > 0, D_{\textrm{KL}} = \infty, \textrm{JS} = \log 2 \approx 0.693, and \textrm{TV} = 1.000, providing zero gradient to pull Q toward P.
  • Geometry-aware metrics: RBF \textrm{MMD}^2 = 2(1 - e^{-d^2/(2\ell^2)}) supplies local gradients, and Wasserstein W_1(\delta_0, \delta_d) = |d| supplies unit gradient \pm 1 at all distances.

Checking the Point-Mass Diagnostic in Code

Five Comparisons on Disjoint Atoms

Representing \delta_0 and \delta_d as probability vectors (1, 0) and (0, 1) on atoms \{0, d\} reproduces the table directly:

d =   0.01: KL inf  JS 0.6931  TV 1  MMD^2 0.0001  W1 0.01
d =    1.0: KL inf  JS 0.6931  TV 1  MMD^2 0.7869  W1 1
d =  100.0: KL inf  JS 0.6931  TV 1  MMD^2 2  W1 100
  • This section studies the density-ratio family (f-divergences) to answer three questions: (1) how forward and reverse KL differ on misspecified models, (2) what total variation and Pinsker’s inequality guarantee for statistical detectors, and (3) how convex duality estimates any D_f from samples via a critic network.

Divergences Versus True Probability Metrics

Mathematical Foundations

  • Divergence axioms: D(P, Q) \ge 0 and D(P, Q) = 0 \iff P = Q.
  • True metric axioms: Also requires symmetry D(P, Q) = D(Q, P) and the triangle inequality D(P, R) \le D(P, Q) + D(Q, R) (satisfied by TV, d_{\mathrm{H}}, \sqrt{\textrm{JS}}, MMD, W_1, W_2).
  • Why KL is not a metric: Asymmetric (0.318 \neq 0.807 on \mathcal{N}(0,1) vs. \mathcal{N}(0,4)) and behaves like a squared distance \tfrac12(\mu_1 - \mu_2)^2, violating the triangle inequality (2 > \tfrac12 + \tfrac12).

The f-Divergence Template and Non-Negativity

Unifying Density-Ratio Divergences

Rewriting KL divergence as \mathbb{E}_{x \sim Q}[u(x)\log u(x)] where u(x) = p(x)/q(x) is the density ratio reveals a general template: replace u \log u with any convex function f : (0, \infty) \to \mathbb{R} satisfying f(1) = 0 (assuming P \ll Q):

D_f(P \| Q) = \mathbb{E}_{x \sim Q}\!\left[f\!\left(\frac{p(x)}{q(x)}\right)\right]

  • One-line proof of non-negativity (Jensen’s inequality): Because the density ratio averages to 1 under Q (\mathbb{E}_Q[u] = \sum_x q(x)\frac{p(x)}{q(x)} = \sum_x p(x) = 1), convexity of f immediately yields: D_f(P \| Q) = \mathbb{E}_Q[f(u)] \ge f(\mathbb{E}_Q[u]) = f(1) = 0
  • Strict positivity and affine invariance: If f is strictly convex at u = 1 (f(u) > c(u-1) for all u \neq 1), then D_f(P \| Q) = 0 \iff u(x) = 1 everywhere (P = Q). Moreover, adding c(u - 1) to f(u) changes no divergence because \mathbb{E}_Q[c(u - 1)] = 0.

Common Divergence Functions and Their Properties

The f-Divergence Catalog

  • Asymmetric generators: Forward KL (u\log u, f''(1)=1), Reverse KL (-\log u, f''(1)=1), and Pearson \chi^2 ((u-1)^2, f''(1)=2).
  • Symmetric & metric generators: Squared Hellinger ((\sqrt{u}-1)^2, f''(1)=1/2), Jensen–Shannon (f''(1)=1/4, \sqrt{\textrm{JS}} \le \sqrt{\log 2}), and Total Variation (\tfrac12|u-1|, V-corner at u=1).

Geometry of Divergence Generators Near u = 1

Comparing Penalty Shapes

Shifting each smooth generator by f'(1)(u - 1) so all curves touch zero tangentially at u = 1 reveals how they agree locally yet diverge in the tails:

  • Near u = 1 (local agreement): Every smooth curve is a parabola \tfrac12 f''(1)(u - 1)^2, while Total Variation has a V-shaped corner.
  • As u \to 0 (p \ll q, model places mass in empty regions): Reverse KL (-\log u) blows up to +\infty, heavily penalizing spurious model modes.
  • As u \to \infty (p \gg q, model misses data): Forward KL (u \log u) and \chi^2 ((u-1)^2) grow superlinearly, whereas TV and JS grow only linearly.
image/svg+xml Matplotlib v3.11.2, https://matplotlib.org/

Boundary Rules: Why Disjoint Supports Freeze D_f

Singular Measures & Disjoint Supports

What happens to D_f(P \| Q) when P and Q place mass on regions where the other vanishes?

  • Boundary limits at p = 0 and q = 0:
    • Where p(x) = 0 < q(x) (u = 0), the contribution is q(x)\,f(0) with f(0) = \lim_{u \downarrow 0} f(u).
    • Where q(x) = 0 < p(x) (u \to \infty), taking \lim_{q \downarrow 0} q\,f(p/q) = p \lim_{t \to \infty} f(t)/t gives p(x)\,f'(\infty) where f'(\infty) = \lim_{t \to \infty} f(t)/t.
  • Universal constant on disjoint point masses (d \neq 0): At x = 0 (p=1, q=0) and x = d (p=0, q=1): D_f(\delta_0 \| \delta_d) = f(0) + f'(\infty) \quad \text{for every } d \neq 0
    • Forward KL (u\log u): f(0) = 0, f'(\infty) = \infty \implies D_{\textrm{KL}}(\delta_0 \| \delta_d) = \infty.
    • Jensen–Shannon: f(0) = \tfrac12\log 2, f'(\infty) = \tfrac12\log 2 \implies \textrm{JS}(\delta_0, \delta_d) = \log 2.
    • Total Variation (\tfrac12|u-1|): f(0) = \tfrac12, f'(\infty) = \tfrac12 \implies \textrm{TV}(\delta_0, \delta_d) = 1.

Evaluating Six f-Divergences on the Running Pair

Numerical Comparison

On P = (0.6, 0.3, 0.1) and Q = (0.2, 0.5, 0.3), the six divergences span an order of magnitude (0.091 to 1.013), yet rescaling by 2/f''(1) makes 2\,\textrm{KL} = 0.79, 4\,d_{\mathrm{H}}^2 = 0.74, and 8\,\textrm{JS} = 0.73 nearly coincide:

KL           D_f(P||Q) = 0.3961   D_f(Q||P) = 0.3653
reverse KL   D_f(P||Q) = 0.3653   D_f(Q||P) = 0.3961
chi^2        D_f(P||Q) = 1.0133   D_f(Q||P) = 0.8000
Hellinger^2  D_f(P||Q) = 0.1862   D_f(Q||P) = 0.1862
TV           D_f(P||Q) = 0.4000   D_f(Q||P) = 0.4000
JS           D_f(P||Q) = 0.0911   D_f(Q||P) = 0.0911

Local Quadratic Theorem: All Smooth D_f Agree

Second-Order Taylor Expansion

Expanding f(u) around u = 1 and taking \mathbb{E}_Q annihilates the first-order term f'(1)\mathbb{E}_Q[u - 1] = 0:

D_f(P \| Q) \approx \frac{f''(1)}{2}\,\chi^2(P \| Q)

  • Universal local geometry: Near P = Q, 2\,\textrm{KL} \approx 4\,d_{\mathrm{H}}^2 \approx 8\,\textrm{JS} \approx \chi^2.
  • Fisher information metric: For q_{\boldsymbol{\theta}+\mathbf{h}} vs. q_{\boldsymbol{\theta}}, D_f(q_{\boldsymbol{\theta}+\mathbf{h}} \| q_{\boldsymbol{\theta}}) \approx \tfrac12 f''(1)\mathbf{h}^\top\mathbf{I}(\boldsymbol{\theta})\mathbf{h}.

Verifying Local Quadratic Convergence in Code

Asymptotic Agreement

Sliding P_t = Q + t(P - Q) toward Q scales r = 2t; as t drops tenfold from 0.1 to 0.01, the relative gap between D_f(P_t \| Q) and \tfrac12 f''(1)\chi^2(P_t \| Q) drops tenfold to < 1\%:

t =  0.5: KL 0.844  reverse KL 0.747  Hellinger^2 0.789  JS 0.783
t =  0.1: KL 0.956  reverse KL 0.917  Hellinger^2 0.936  JS 0.935
t = 0.01: KL 0.995  reverse KL 0.990  Hellinger^2 0.993  JS 0.993

Forward vs. Reverse KL: Mode-Covering vs. Seeking

Asymmetry as a Modeling Choice

  • Forward KL D_{\textrm{KL}}(P \| Q_{\boldsymbol{\theta}}) (Zero-Avoiding / Mode-Covering): Blows up when q_{\boldsymbol{\theta}}(x) \to 0 on data (f'(\infty) = \infty), stretching across all modes of P (maximum likelihood).
  • Reverse KL D_{\textrm{KL}}(Q_{\boldsymbol{\theta}} \| P) (Zero-Forcing / Mode-Seeking): Blows up when p(x) \to 0 on model samples (f(0) = \infty), locking onto a single mode of P at cost -\log w_k (variational inference, RLHF).

Fitting a Single Gaussian to a Bimodal Mixture

Misspecified Model Behavior

Consider fitting Q_{\boldsymbol{\theta}} = \mathcal{N}(\mu, \sigma^2) to the asymmetric bimodal mixture P = 0.7\,\mathcal{N}(-2, 0.6^2) + 0.3\,\mathcal{N}(2, 0.6^2):

  • Exact forward-KL fit (moment matching): Minimizing D_{\textrm{KL}}(P \| \mathcal{N}(\mu, \sigma^2)) matches the mean and variance of P: \mu^* = 0.7(-2) + 0.3(2) = -0.800, \qquad (\sigma^*)^2 = 0.6^2 + 0.7(0.3)(-2 - 2)^2 = 3.72 \implies \sigma^* = 1.929
  • Reverse-KL local minima (mode dropping): If Q_{\boldsymbol{\theta}} matches a single component \mathcal{N}(\mu_k, 0.6^2) carrying mixture weight w_k, then p(x) \approx w_k q_{\boldsymbol{\theta}}(x) across that mode, so: D_{\textrm{KL}}(Q_{\boldsymbol{\theta}} \| P) \approx \mathbb{E}_{Q_{\boldsymbol{\theta}}}\!\left[\log\frac{q_{\boldsymbol{\theta}}(x)}{w_k q_{\boldsymbol{\theta}}(x)}\right] = \log\frac{1}{w_k}
    • Locking onto the 70\% mode (\mu \approx -2, \sigma \approx 0.6) costs \ln(1/0.7) \approx 0.357\text{ nats}; locking onto the 30\% mode (\mu \approx +2) costs \ln(1/0.3) \approx 1.204\text{ nats}.

Visualizing Mode-Covering and Mode-Seeking Fits

Numerical Optimization Demo

Notice how reverse KL underestimates the target standard deviation by >3\times (\sigma = 0.603 vs. 1.929) and converges to whichever mode lies closer to initialization:

fit                             mu  sigma  forward KL  reverse KL
forward-KL fit              -0.800  1.929       0.558       1.274
reverse-KL fit              -1.998  0.603       5.981       0.356
reverse-KL fit, 2nd start   +1.995  0.607      14.534       1.202

Total Variation and Optimal Single-Sample Tests

Operational Meaning of TV

What does a Total Variation distance of \textrm{TV}(P, Q) = 0.4 physically guarantee?

  • Worst-case event discrepancy: \textrm{TV}(P, Q) = \frac{1}{2}\sum_x |p(x) - q(x)| = \sup_{A} |P(A) - Q(A)|
  • Optimal separating event: The supremum is attained by A^\star = \{x : p(x) > q(x)\} because positive and negative lobes of p - q have equal area.
  • Hypothesis testing ceiling: Given one draw equally likely from P or Q, any detector (GAN discriminator or AI-text detector) succeeds with probability at most \tfrac12(1 + \textrm{TV}(P, Q)).
image/svg+xml Matplotlib v3.11.2, https://matplotlib.org/

Pinsker’s Inequality: Bounding TV via KL

Two-Step Proof via Log-Sum

Pinsker’s inequality bounds worst-case event shift via log-probability divergence:

\textrm{TV}(P, Q) \le \sqrt{\tfrac12 D_{\textrm{KL}}(P \| Q)}

  • Step 1 (Coarsen to A^\star = \{p > q\}): With a = P(A^\star), b = Q(A^\star) (a - b = \textrm{TV}), data processing gives D_{\textrm{KL}}(P \| Q) \ge D_{\textrm{KL}}(\textrm{Ber}(a) \| \textrm{Ber}(b)).
  • Step 2 (Bernoulli curvature \ge 4): \frac{d^2}{da^2}D_{\textrm{KL}}(\textrm{Ber}(a)\|\textrm{Ber}(b)) = \frac{1}{a(1-a)} \ge 4 \implies D_{\textrm{KL}} \ge 2(a - b)^2.

Sharpness and Limits of Pinsker’s Inequality

Monte Carlo Verification

Across 10{,}000 random 5-outcome pairs, \textrm{TV}/\sqrt{\textrm{KL}/2} has median 0.81 and never exceeds 1, while nearly fair coins (\delta \to 0) prove that the constant \tfrac12 cannot be improved:

TV / sqrt(KL/2) over 10,000 random pairs: median 0.78, max 0.986
coins 1/2 vs 1/2 +   0.1: TV / sqrt(KL/2) = 0.989881
coins 1/2 vs 1/2 +  0.01: TV / sqrt(KL/2) = 0.999900
coins 1/2 vs 1/2 + 0.001: TV / sqrt(KL/2) = 0.999999

The Data-Processing Inequality for f-Divergences

Monotonicity Under Channels

Can a feature extractor, quantizer, or randomized transformation ever make two distributions P and Q easier to distinguish?

  • Markov channel transformation: Let \kappa(y \mid x) be any transition kernel mapping x \mapsto y, producing output distributions (P\kappa)(y) = \sum_x \kappa(y \mid x)p(x) and (Q\kappa)(y) = \sum_x \kappa(y \mid x)q(x).
  • Universal contraction theorem: Applying Jensen’s inequality under the posterior weights \frac{\kappa(y \mid x)q(x)}{(Q\kappa)(y)} for each output y proves that for every f-divergence: D_f(P\kappa \,\|\, Q\kappa) \le D_f(P \| Q)
  • Two key consequences for deep learning:
    1. Any divergence measured on extracted features \phi(x) is a lower bound on the raw-space divergence D_f(P \| Q).
    2. Any invertible transformation \phi acts as a channel in both directions, forcing D_f(\phi_\# P \| \phi_\# Q) = D_f(P \| Q) (coordinate scale invariance).

Legendre–Fenchel Conjugate and Tangent Bounds

Convex Duality Foundations

How can we estimate D_f(P \| Q) when we have only samples from P and Q and cannot evaluate p(x)/q(x)?

  • Convex conjugate: Every convex function f(u) is the upper envelope of its tangent lines of slope t and intercept -f^*(t): f^*(t) = \sup_{u}\big(ut - f(u)\big)
  • Fenchel–Young inequality: For every u and slope t: f(u) \ge ut - f^*(t) with equality at t = f'(u).
  • Examples: f(u) = u\log u \implies f^*(t) = e^{t-1}; f(u) = (u-1)^2 \implies f^*(t) = t + t^2/4.
image/svg+xml Matplotlib v3.11.2, https://matplotlib.org/

The Variational Critic Bound and f-GAN Training

Estimating Divergences from Samples

Applying f(p/q) \ge (p/q)T(x) - f^*(T(x)) and averaging under Q eliminates the unknown density ratio:

D_f(P \| Q) \ge \mathbb{E}_{x \sim P}[T(x)] - \mathbb{E}_{x \sim Q}\big[f^*(T(x))\big]

  • Optimal critic: Attains equality at T^\star(x) = f'(p(x)/q(x)) (1 + \log(p/q) for KL; 2(p/q - 1) for \chi^2).
  • Original GAN: T(x) = \log D(x) and -f^*(T) = \log(1 - D(x)) recovers 2\,\textrm{JS}(P, Q) - \log 4.

Recovering the Original GAN as a JS Dual

Binary Cross-Entropy Discriminator

The original GAN objective of Goodfellow et al. (2014) is a special case of the f-GAN critic bound:

  • 1. Choose the generator and conjugate: Take f(u) = u\log u - (u+1)\log(u+1), whose conjugate over t < 0 is f^*(t) = -\log(1 - e^t).
  • 2. Parameterize the critic via a sigmoid discriminator D(x) \in (0, 1): Setting T(x) = \log D(x) turns -f^*(T(x)) into \log(1 - D(x)), yielding the binary cross-entropy game: \mathbb{E}_{x \sim P}[T(x)] - \mathbb{E}_{x \sim Q}[f^*(T(x))] = \mathbb{E}_{x \sim P}[\log D(x)] + \mathbb{E}_{x \sim Q}[\log(1 - D(x))]
  • 3. Optimal discriminator and JS value: Setting T^\star(x) = f'(p/q) = \log\frac{p(x)}{p(x)+q(x)} gives the Bayes-optimal discriminator D^\star(x) = \frac{p(x)}{p(x)+q(x)}. Because f(u) = 2f_{\textrm{JS}}(u) - (u-1)\log 2 - \log 4, the value at D^\star is exactly 2\,\textrm{JS}(P, Q) - \log 4.

Practical Pitfalls of Adversarial Critic Bounds

Underestimation & Vanishing Gradients

Training a \chi^2 critic by gradient ascent on P = (0.6, 0.3, 0.1) vs. Q = (0.2, 0.5, 0.3) (\chi^2 = 1.0133) exposes two structural limits of the variational bound:

exact chi^2(P||Q) = 1.0133
steps        0       1       2       5      10      20      50
bound   0.0000  0.2240  0.3935  0.7036  0.9107  1.0013  1.0133
overconfident critic 2 T*: bound = 0.0000

Practical Pitfalls of Adversarial Critic Bounds (cont.)

Underestimation & Vanishing Gradients

  • Downward bias & disjoint-support saturation: Any suboptimal critic (T \neq T^\star, including 2T^\star) underestimates D_f by \tfrac14\mathbb{E}_Q[(T - T^\star)^2]; on disjoint supports, T^\star is constant (f'(\infty) on data, f'(0) on model samples), giving the generator zero gradient.

Concept Check: f-Divergences, Pinsker, Critics

Check Your Understanding

Work through these three calculations:

  1. Hand calculation: For P = (0.6, 0.3, 0.1) and Q = (0.2, 0.5, 0.3), compute \textrm{TV}(P, Q) and Pearson’s \chi^2(P \| Q). Which outcome dominates \chi^2(P \| Q) and why?
  2. AI-text detector ceiling: Suppose human text P and LLM text Q satisfy D_{\textrm{KL}}(P \| Q) = 0.02\text{ nats}. What is the highest accuracy any single-sample detector can achieve on a 50/50 mix? Does passing the text through a feature extractor help?
  3. Interpreting a critic score: A critic trained with the \chi^2 conjugate f^*(t) = t + t^2/4 reports \mathbb{E}_P[T] - \mathbb{E}_Q[f^*(T)] = 0.70 on a fresh held-out test set. What can you conclude about the true \chi^2(P \| Q)?

Answers:

  1. TV & \chi^2: \textrm{TV} = \tfrac12(0.4 + 0.2 + 0.2) = 0.40 (attained on A^\star = \{1\}). \chi^2 = \frac{0.4^2}{0.2} + \frac{0.2^2}{0.5} + \frac{0.2^2}{0.3} = 0.80 + 0.08 + 0.133 = 1.0133; outcome 1 contributes 0.80 because \chi^2 divides by q_1 = 0.2.
  2. Detector ceiling: By Pinsker, \textrm{TV}(P, Q) \le \sqrt{0.02/2} = 0.10, so max accuracy is \tfrac12(1 + \textrm{TV}) \le 55\%. By data processing, no feature extractor can increase D_{\textrm{KL}} or \textrm{TV}.
  3. Critic bound: On fresh samples, \chi^2(P \| Q) \ge 0.70 in expectation—it is a certified lower bound, but could be much larger if T \neq T^\star (as at step 5 of our ascent where truth was 1.0133).

Summary: The f-Divergence Family and Duals

Key Takeaways

Concept / Tool Mathematical Form Key Property / Theorem Deep Learning Role & Caveat
f-Divergence D_f(P \| Q) = \mathbb{E}_Q[f(p/q)] D_f \ge 0 by Jensen; D_f \approx \tfrac12 f''(1)\chi^2 locally Unifies KL, rev-KL, \chi^2, Hellinger, TV, JS; freezes at f(0)+f'(\infty) on disjoint supports
Forward vs. Reverse KL \mathbb{E}_P[\log(p/q)] vs. \mathbb{E}_Q[\log(q/p)] f'(\infty) = \infty (forward) vs. f(0) = \infty (reverse) Forward KL (MLE) covers all modes; Reverse KL (VI) locks onto one mode and underestimates variance
Total Variation (TV) \tfrac12\|p-q\|_1 = \sup_A |P(A)-Q(A)| Optimal 1-sample test accuracy is \tfrac12(1 + \textrm{TV}) True metric in [0, 1]; saturates at 1 on disjoint supports
Pinsker’s Inequality \textrm{TV}(P, Q) \le \sqrt{\tfrac12 D_{\textrm{KL}}(P \| Q)} Sharp constant 1/2 as P \to Q; no converse Converts KL trust regions (PPO) into worst-case event bounds
Data Processing D_f(P\kappa \| Q\kappa) \le D_f(P \| Q) Contraction under any channel \kappa(y \mid x) Feature divergences lower-bound input divergences; scale invariance
Fenchel Critic Bound D_f(P \| Q) \ge \mathbb{E}_P[T] - \mathbb{E}_Q[f^*(T)] Tight at T^\star = f'(p/q); 2\,\textrm{JS} - \log 4 for GAN Enables sample-only adversarial training (f-GAN), but biased low for imperfect T