Adversarial Objectives and Divergences

Dive into Deep Learning · §16.2

Adversarial Objectives and Divergences
classification payoffs & f-divergences · optimal critic links · Fenchel–Young f-GAN dual · MMD & Wasserstein-1 IPMs · gradients on separated supports

Why GAN Codebases Offer a Menu of Objectives

Motivation

  • 1. Population divergence saturation: When supports separate (e.g., \mathcal{N}(0, 1) vs. \mathcal{N}(7, 1)), \mathrm{JS}(p, q) sits within 0.1\% of \log 2 with derivative 0.0013.
  • 2. Critic function-class geometry (\mathcal{T}): Does the critic D \in \mathcal{T} jump discontinuously between supports, or maintain a nonzero spatial gradient \nabla_x D(x') across the empty gap?
  • 3. Generator loss weighting: Does the generator loss transmit \nabla_x D(x') (w_ns ≈ 1) or multiply it by an exponentially vanishing weight (w_sat ≈ e^D → 0)?

A General Template for Adversarial Discrepancies

Unifying Formulation

d(p, q) = \sup_{T \in \mathcal{T}} \Big\{ \mathbb{E}_{x \sim p}\big[\ell_p(T(x))\big] + \mathbb{E}_{x' \sim q}\big[\ell_q(T(x'))\big] \Big\}

  • Classification payoffs (\mathcal{T} unconstrained): Nonlinear margin losses (\ell_p, \ell_q) estimate monotone links of \lambda(x) = \log(p/q) and evaluate f-divergences (or product-space JS under pairing).
  • Integral probability metrics (\mathcal{T} constrained): Linear payoffs \ell_p(t) = t, \ell_q(t) = -t on an RKHS ball (MMD) or 1-Lipschitz ball (W_1).
  • Convexity in measure space: As a supremum of linear expectations in q, d(p, q) is always convex in q (though nonconvex in generator weights \theta).

From Posterior Probability to Bayes-Risk Gaps

Two-Outcome Intuition

  • Two-state example (p = (\frac{3}{4}, \frac{1}{4}), q = (\frac{1}{4}, \frac{3}{4})): Every classification loss scores the exact same Bayes posterior \eta(x) = \frac{p(x)}{p(x) + q(x)} (\frac{3}{4} on heads, \frac{1}{4} on tails) against the blind-guess baseline \eta = \frac{1}{2}.
  • Induced divergences from the Bayes-risk gap \Delta_\ell = L(\frac{1}{2}) - \mathbb{E}_m[L(\eta)]:
    • Logistic: \log 2 - H_b(\frac{3}{4}) \approx 0.131\text{ nats} = \mathrm{JS}(p, q).
    • Squared (LSGAN): \frac{1}{4} - \frac{3}{16} = \frac{1}{16} = \frac{1}{4}\chi^2(p \,\|\, m).
    • Hinge: 1 - \frac{1}{2} = \frac{1}{2} = \mathrm{TV}(p, q).

Theorem: Every Classification Loss Is an f-Divergence

The Bayes-Risk Gap

\Delta_\ell(p, q) = D_f(p \,\|\, q), \qquad f(u) = L(\tfrac{1}{2}) - \frac{u + 1}{2}\,L\!\left(\frac{u}{u + 1}\right)

  • Concave conditional Bayes risk: L(\eta) = \inf_t \{-\eta\,\ell(t) - (1 - \eta)\,\ell(-t)\} is concave on [0, 1] as an infimum of affine functions of \eta.
  • Convex f-divergence generator: Changing to the density ratio u = p(x)/q(x) (where \eta = u/(u+1)) makes f(u) convex on [0, \infty) with f(1) = 0.
  • Monotone critic link D^\star(\lambda): The pointwise optimal critic is a monotone function of the log density ratio \lambda = \log(p/q).

The Fenchel–Young Variational Bound (f-GAN)

Asymmetric & Unbounded Divergences

D_f(p \,\|\, q) \ge \mathbb{E}_{x \sim p}\big[T(x)\big] - \mathbb{E}_{x' \sim q}\big[f^*(T(x'))\big]

  • Why asymmetric payoffs \ell_p \neq \ell_q are needed: Any symmetric margin loss has bounded gap \Delta_\ell \le L(\frac{1}{2}) and cannot represent unbounded asymmetric divergences like forward KL D_{\textrm{KL}}(p \,\|\, q).
  • Fenchel conjugate f^*(t) = \sup_u \{ut - f(u)\}: Tight at T^\star(x) = f'(p(x)/q(x)); for forward KL (f(u) = u\log u), f^*(t) = e^{t-1} and T^\star(x) = 1 + \lambda(x).

Integral Probability Metrics (IPMs) and MMD

Constraining the Critic Class

Whereas f-divergences pair an unconstrained critic with nonlinear payoffs, integral probability metrics (IPMs) use linear payoffs \ell_p(t) = t and \ell_q(t) = -t over a constrained symmetric function class \mathcal{F}:

  • IPM definition: d_{\mathcal{F}}(p, q) = \sup_{T \in \mathcal{F}} \Big\{ \mathbb{E}_{x \sim p}\big[T(x)\big] - \mathbb{E}_{x' \sim q}\big[T(x')\big] \Big\}
  • Maximum Mean Discrepancy (MMD; Gretton et al., 2012): Choosing \mathcal{F} as the unit ball of an RKHS with positive-definite kernel k(x, x') (e.g., Gaussian RBF e^{-\|x - x'\|^2 / (2s^2)}) yields a closed-form squared distance requiring no critic network: \mathrm{MMD}^2(p, q) = \mathbb{E}_{p,p}[k(x, \tilde{x})] + \mathbb{E}_{q,q}[k(x', \tilde{x}')] - 2\mathbb{E}_{p,q}[k(x, x')]
def mmd2_unbiased(K_pp, K_qq, K_pq):
    """Unbiased MMD^2 from the kernel matrices within p, within q, and
    across; the diagonals (a point with itself) are left out."""
    m, n = len(K_pp), len(K_qq)
    return ((K_pp.sum() - K_pp.diagonal().sum()) / (m * (m - 1))
            + (K_qq.sum() - K_qq.diagonal().sum()) / (n * (n - 1))
            - 2 * K_pq.mean())

Wasserstein-1 Distance and Lipschitz Critics

Optimal Transport Duality

W_1(p, q) = \sup_{\|T\|_{\mathrm{Lip}} \le 1} \Big\{ \mathbb{E}_{x \sim p}\big[T(x)\big] - \mathbb{E}_{x' \sim q}\big[T(x')\big] \Big\}

  • Kantorovich–Rubinstein duality: Constraining the IPM witness class \mathcal{F} to 1-Lipschitz functions (|T(x) - T(y)| \le \|x - y\|) recovers the Earth Mover’s distance W_1(p, q).
  • Three neural enforcement mechanisms: Weight clipping (restricts capacity), WGAN-GP ray gradient penalty (two-sided unit-slope target creates a barrier at q = p), and spectral normalization (W \leftarrow W/\sigma_{\max}(W)).

Sample Complexity in High Dimensions: MMD vs. W₁

Statistical Scaling Pitfalls

  • Fixed-kernel MMD (O(n^{-1/2}) in any dimension): The unbiased U-statistic estimator mmd2_unbiased converges at the parametric rate O(n^{-1/2}) independent of d_x.
  • Empirical W_1 (O(n^{-1/d_x}) for d_x > 2): True empirical optimal transport suffers from the curse of dimensionality (Weed & Bach, 2019); WGAN works in practice because its smooth neural architecture acts as a parametric witness.
  • Variational f-GAN variance explosion: In the forward-KL dual, e^{T^\star(x')-1} = p(x')/q(x') has variance \chi^2(p \,\|\, q), which can diverge even when D_{\textrm{KL}}(p \,\|\, q) < \infty.

Population Divergence Slope vs. Separation

Gradients Far from the Data

Comparing 1D unit-variance Gaussians p = \mathcal{N}(0, 1) and q = \mathcal{N}(\mu, 1) across separation \mu > 0 shows how each population divergence responds when distributions separate:

  • Wasserstein-1 (W_1(p, q) = \mu): Maintains a constant unit derivative \frac{d}{d\mu}W_1 = 1 at every separation \mu.
  • Gaussian-kernel \mathrm{MMD}^2 (bandwidth s = 4): \mathrm{MMD}^2(\mu) = \frac{2s}{\sqrt{s^2 + 2}}\!\left(1 - \exp\!\left(-\frac{\mu^2}{2(s^2 + 2)}\right)\right) Its slope peaks at \mu = \sqrt{s^2 + 2} \approx 4.2 before decaying in the Gaussian tail.
  • Jensen–Shannon \mathrm{JS}(p, q): Its slope drops from 0.20 at \mu = 1 to 0.0013 at \mu = 7 and 1.5 \times 10^{-22} at \mu = 20.

mu =  1: JS slope 0.1987, JS / log 2 = 0.1607, MMD^2 slope 0.1019
mu =  7: JS slope 0.001264, JS / log 2 = 0.9990, MMD^2 slope 0.188
mu = 20: JS slope 1.549e-22, JS / log 2 = 1.0000, MMD^2 slope 3.303e-05
MMD^2 slope peaks at mu = 4.2 with 0.269

Geometry of Optimal Critics on Disjoint Supports

Why Smooth Critics Provide Gradients

  • Left (Unconstrained JS critic \log(p/q)): Evaluates to +\infty on \operatorname{supp}(p) and -\infty on \operatorname{supp}(q), with zero spatial slope on both clouds.
  • Middle (W_1 Kantorovich potential): A linear ramp of unit slope connecting q to p, providing a constant restoring gradient across the gap.
  • Right (MMD witness w(x) = \mathbb{E}_p[k(x, \cdot)] - \mathbb{E}_q[k(x, \cdot)]): A smooth difference of kernel bumps whose tail slopes toward p over distances comparable to the bandwidth s.

Implementing MMD and WGAN-GP Gradient Penalties

Code Primitives

mmd2_loss sums RBF kernels over several bandwidths; mmd2_median sets one bandwidth to the median pairwise distance of the pooled minibatch:

def mmd2_loss(x, y, bandwidths=(0.5, 1.0, 2.0)):
    """Unbiased MMD^2 under the sum of RBF kernels of the given bandwidths."""
    def kernel(a, b):
        sq_dist = torch.cdist(a, b) ** 2
        return sum(torch.exp(-sq_dist / (2 * s ** 2)) for s in bandwidths)
    return mmd2_unbiased(kernel(x, x), kernel(y, y), kernel(x, y))

def mmd2_median(x, y):
    """MMD^2 with one RBF kernel, its bandwidth the median pairwise distance
    of the pooled batch, held constant in the gradient."""
    xy = torch.cat([x, y])
    return mmd2_loss(x, y, (torch.cdist(xy, xy).median().detach(),))

Implementing MMD and WGAN-GP Gradient Penalties (cont.)

Code Primitives

gradient_penalty evaluates either the two-sided WGAN-GP penalty (|D'(x)| - 1)^2 or the one-sided Lipschitz penalty \max(0, |D'(x)| - 1)^2 at random interpolants \tilde{x} = uX + (1 - u)X':

def gradient_penalty(D, X, fake, u, one_sided=False):
    """Mean (|D'(x)| - 1)^2 at the points u X + (1 - u) fake (inputs 1-D);
    one-sided, only slopes steeper than one pay: max(0, |D'(x)| - 1)^2."""
    x = (u * X + (1 - u) * fake).requires_grad_()
    grad, = torch.autograd.grad(D(x).sum(), x, create_graph=True)
    excess = grad.abs() - 1
    return ((excess.clamp(min=0) if one_sided else excess) ** 2).mean()

Trained Neural Critics from a Separated Start

Theory vs. Neural Practice

We fit a 1D location generator q_\theta = \mathcal{N}(\theta, 1) (x' = \theta + z) starting at \theta_0 = 6.0 to p = \mathcal{N}(0, 1) using vanilla SGD on \theta (so step sizes directly reflect gradient magnitudes) against a 2-layer ReLU MLP critic updated 5 times per generator step:

                 |grad|   theta at steps 0, 100, 300, 1000, 1500  arrival  farthest
logistic, sat.  0  0.007    6.00   5.99   5.96   5.85   5.77  not reached
logistic, sat.  1  0.009    6.00   5.98   5.95   5.85   5.76  not reached
logistic, sat.  2  0.015    6.00   5.98   5.96   5.85   5.77  not reached
logistic, NS    0  2.812    6.00   3.30   0.79   0.03   0.00      383      0.50
logistic, NS    1  2.876    6.00   3.26   0.78   0.02   0.00      380      0.50
logistic, NS    2  2.730    6.00   3.35   0.80   0.02   0.00      388      0.50
...
W1 + 1-sided GP 0  1.265    6.00   4.75   2.40   0.01   0.02      478      0.49
W1 + 1-sided GP 1  1.262    6.00   4.74   2.39  -0.01   0.03      477      0.49
W1 + 1-sided GP 2  1.265    6.00   4.74   2.40   0.02  -0.05      477      0.50
MMD, median     0  0.210    6.00   5.79   5.34   3.34   1.32  not reached
MMD, median     1  0.210    6.00   5.79   5.34   3.34   1.32  not reached
MMD, median     2  0.210    6.00   5.79   5.34   3.35   1.32  not reached

Why finite neural critics move even under logistic and hinge loss: Although the unconstrained optimal hinge critic \operatorname{sign}(\lambda) is flat on both clouds, a finite ReLU MLP interpolates linearly across the gap with slope 1.1\text{--}1.7. A distant generator moves whenever its trained critic has a nonzero slope at x' and the generator loss does not saturate (logistic, NS arrives before step 400; logistic, sat. stalls at 5.76).

Why Two-Sided WGAN-GP Overshoots at Equilibrium

The Unit-Slope Barrier Pitfall

Both W_1 arms pull the generator to |\theta| < 0.5 near step 500, yet every two-sided W1 + GP run subsequently overshoots (|\theta| > 1.1, up to > 7), whereas every one-sided W1 + 1-sided GP run settles within 0.06 of the origin:

                   theta D'(theta)  active    D'(0)  active  (of 32 units per layer)
W1 + GP         0   0.30      0.00   14  0     0.00   14  0
W1 + GP         1  -7.18      1.34   11  8     1.35   12  9
W1 + GP         2  -7.61     -0.65   12  7    -0.65   12  7
W1 + 1-sided GP 0   0.02      0.41   30  3     0.41   30  3
W1 + 1-sided GP 1   0.03      0.65   25  4     0.65   25  4
W1 + 1-sided GP 2  -0.05     -0.16   30  7    -0.16   30  7
  • The zero-slope barrier: Once \theta crosses 0, the critic must reverse its slope D' from negative to positive. Because the two-sided penalty \gamma(|D'| - 1)^2 charges \gamma at D' = 0, the critic either remains trapped on its old slope sign (pushing \theta outward) or kills all hidden ReLU units (active = 0).
  • One-sided remedy: Penalizing \gamma\max(0, |D'| - 1)^2 charges nothing when |D'| \le 1, allowing the critic slope to pass freely through zero as q reaches p.

Comparing Five Objectives on a 2D Gaussian Mixture

Overlapping Supports Benchmark

When the initial generator already overlaps the data (\mathrm{JS}(p, q_0) = 0.529 nats on our 3-component 2D Gaussian mixture), we compare five objectives over 6{,}000 alternating steps across three seeds each:

  • All five non-saturating objectives converge: Every arm reduces \mathrm{JS}(p, q_t) from 0.529 nats to a few thousandths of a nat or less.
  • Direct multi-bandwidth MMD (s \in \{0.5, 1, 2\}): Needs no critic network and achieves the tightest final fit (0.0001 nats).
  • Smooth links vs. hinge step link: Logistic, least squares, and squared hinge all reach \le 0.0024 nats, whereas the discontinuous hinge link (\operatorname{sign}\lambda) plateaus slightly higher (0.003\text{--}0.007 nats).

Comparing Five Objectives on a 2D Gaussian Mixture (cont.)

Overlapping Supports Benchmark

For each objective and seed, the median JS over the last 2,000 steps and the first steps at which JS drops below 0.1 and 0.01:

three runs:   median JS, last 2,000 steps       first JS < 0.1      first JS < 0.01
logistic           0.0008  0.0008  0.0008     2000  2000  2200     2400  2400  2400
least squares      0.0009  0.0009  0.0008     2000  2200  1800     2200  2400  2200
hinge              0.0070  0.0071  0.0033     1800  1800  1400     2000  2000  2400
squared hinge      0.0013  0.0008  0.0024     1400  1400  1400     2200  2200  2200
MMD                0.0001  0.0001  0.0001     1200  1200  1200     2600  2600  2600

Summary: Adversarial Objectives and Divergences

Key Takeaways

Objective Family Critic Loss / Constraint Population Discrepancy Optimal Critic D^\star Behavior on Separated Supports
Logistic (Non-Sat.) \operatorname{softplus}(-D(x)) + \operatorname{softplus}(D(x')) \mathrm{JS}(p, q) (G descends 2\,D_{\textrm{KL}}(m \,\|\, p)) \lambda(x) = \log \frac{p(x)}{q(x)} Population \mathrm{JS} saturates; neural critic + w_{\textrm{ns}} moves G
Least Squares (LSGAN) \frac{1}{2}(D(x) - 1)^2 + \frac{1}{2}D(x')^2 \frac{1}{8}\int \frac{(p - q)^2}{p + q} (\frac{1}{4}\chi^2(p \,\|\, m)) \sigma(\lambda(x)) = \frac{p(x)}{p(x) + q(x)} Bounded link \sigma(\lambda) \in (0, 1) flattens far in tails
Hinge / Squared Hinge \max(0, 1 - D(x)) + \max(0, 1 + D(x')) \mathrm{TV}(p, q) (or \chi^2(p \,\|\, m) for sq. hinge) \operatorname{sign}(\lambda(x)) (or \tanh \frac{\lambda}{2}) Linear slope out to 2/\kappa when paired with \kappa-Lipschitz critic

Summary: Adversarial Objectives and Divergences (cont.)

Key Takeaways

Objective Family Critic Loss / Constraint Population Discrepancy Optimal Critic D^\star Behavior on Separated Supports
f-GAN Dual Bound -\mathbb{E}_p[T(x)] + \mathbb{E}_q[f^*(T(x'))] Any f-divergence D_f(p \,\|\, q) f'(p(x)/q(x)) Can target forward KL (1 + \lambda), but high estimator variance
Kernel MMD Closed-form U-statistic (no critic net) \mathrm{MMD}^2(p, q) in RKHS ball Witness \mathbb{E}_p[k(x, \cdot)] - \mathbb{E}_q[k(x, \cdot)] O(n^{-1/2}) in any dimension; strong slope up to bandwidth s
Wasserstein-1 (W_1) \mathbb{E}_q[T(x')] - \mathbb{E}_p[T(x)] + Lipschitz reg. W_1(p, q) (Earth Mover’s distance) Kantorovich potential (\|\nabla T^\star\| = 1) Unit slope at all distances; two-sided GP overshoots at q = p