Generative Adversarial Networks

Dive into Deep Learning · §16

Generative Adversarial Networks
implicit density estimation · minimax two-sample games · f-divergences & IPMs · rotational dynamics & gradient penalties · conditional generation & perceptual critics

Training Implicit Generators Without a Likelihood

Central Problem

An implicit generator draws a latent vector \mathbf{z} \sim \mathcal{N}(\mathbf{0}, \mathbf{I}_{d_z}) (d_z = 100) and produces an image \mathbf{x}' = G(\mathbf{z}) \in \mathbb{R}^{d_x} in a single forward pass—defining a sampling procedure without a tractable density q(\mathbf{x}) to maximize:

  • Low-dimensional manifold support: Mapping 100 latent coordinates into 784 (Fashion-MNIST) or 12{,}288 (64 \times 64 RGB) pixels concentrates generated samples on a thin surface with no Lebesgue density.
  • Why likelihood misleads (Theis et al., 2016): Mixing the true density with 99\% noise, \tilde{p} = 0.01\,p_{\textrm{data}} + 0.99\,p_{\textrm{noise}}, satisfies \log \tilde{p}(\mathbf{x}) \ge \log p_{\textrm{data}}(\mathbf{x}) - \log 100—within 4.6 nats of the optimal model (out of thousands of nats on images) while emitting 99\% pure noise.
  • Core idea: Replace likelihood evaluation with a learned two-sample critic D that inspects generated samples directly.

Two-Sample Classification as Density-Ratio Estimation

The Core Mechanism

Goodfellow et al. (2014) turned two-sample binary classification into a generative training principle by pitting a generator G against a discriminator (critic) D:

  • Balanced two-sample game: Label real draws x \sim p with y = 1 and generated draws x' = G(z) \sim q with y = 0, each with prior probability \frac{1}{2}.
  • Optimal critic recovers the log density ratio: Minimizing binary log loss yields the Bayes posterior \sigma(D^\star(x)) = \frac{p(x)}{p(x) + q(x)}, so the optimal logit is: D^\star(x) = \log \frac{p(x)}{q(x)} = \lambda(x)
  • Gradients without densities: Backpropagating through D pushes generated samples x' = G(z) uphill along \nabla_x D(x'), moving probability mass from over-represented regions (q > p \implies D^\star < 0) toward under-represented regions (p > q \implies D^\star > 0).

Three Design Axes of Every Adversarial Game

Unifying Framework

  • Why classic minimax saturates: When generated samples miss the data support, \max_D V(D) = 2\,\mathrm{JS}(p, q) - 2\log 2 flattens at \mathrm{JS}(p, q) = \log 2 \approx 0.6931 nats with vanishing gradient.
  • Three orthogonal modifications: Every GAN objective changes what the critic estimates (D^\star(\lambda) vs. witness T), how samples are scored (single-sample vs. Bradley–Terry pairs), or how critic gradients are regularized (R_1 + R_2).
  • Modernized R3GAN recipe (Huang et al., 2024): Combines pairwise ranking (RpGAN) with zero-centered penalties R_1 + R_2 to damp rotational dynamics without BatchNorm.

Chapter 16 Roadmap: Theory, Dynamics, and Systems

Architectural & Mathematical Roadmap

  • Part I: Objectives & Divergences (§§16.1–16.3): From log-loss density-ratio estimation (D^\star = \log(p/q)) and non-saturating weights (2\,D_{\textrm{KL}}(m \,\|\, p)) to f-divergences, IPMs (W_1, MMD), and relativistic pairing (d_{\mathrm{Rp}}).
  • Part II: Dynamics & Convergence (§16.4): Why unpenalized minimax steps orbit or spiral outward on the Dirac-GAN, and how zero-centered penalties R_1 + R_2 shift Jacobian eigenvalues into the open left half-plane.
  • Part III: Images, Conditioning & Applications (§§16.5–16.7): DCGAN vs. normalization-free backbones, FID/KID and K-NN precision/recall, projection critics, and diffusion distillation (ADD/DMD2).

Running Benchmarks and Study Guide

Pedagogical Thread

  • Exact-density 2D Gaussians & mixtures (§16.1–16.3): Check critic logits against analytical \lambda(x) = \log(p(x)/q(x)) and measure generator fit in exact nats of D_{\textrm{KL}}(q \,\|\, p) and \mathrm{JS}(p, q).
  • 25-Gaussian 5 \times 5 grid (§16.4): Isolate whether pairwise ranking or R_1 + R_2 gradient penalties eliminate mode dropping.
  • Image & conditional synthesis (§16.1, §16.5–16.6): Fashion-MNIST (28 \times 28), Pokémon sprites (64 \times 64), and 10-class CIFAR-10 (32 \times 32).
  • Bimodal regression & distillation (§16.7): Two-band benchmark x = c \pm 1 + 0.05\,\xi with an exact closed-form denoising teacher.

Concept Check: Navigating Adversarial Formulation

Check Your Understanding

Test your intuition on three foundational scenarios from the chapter overview:

  1. Reading an optimal critic’s logit: An optimal log-loss critic returns D^\star(x_1) = 1.2 at point x_1 and D^\star(x_2) = -2.0 at point x_2. What is the density ratio p(x)/q(x) at each point, and near which point should the generator reduce its sample density?
  2. Diagnosing three failure modes: During training, you observe: (a) generated samples sit far from the data and generator gradients are nearly zero; (b) both losses hover near equilibrium while generated samples orbit in a cycle; (c) requesting a “bird” always returns the exact same canonical bird. Which chapter mechanism addresses each symptom?

Answers:

  1. Since D^\star(x) = \log(p(x)/q(x)), we have p(x_1)/q(x_1) = e^{1.2} \approx \mathbf{3.32} (real data is 3.3\times denser) and p(x_2)/q(x_2) = e^{-2.0} \approx \mathbf{0.135} (the generator is \approx 7.4\times too dense). The generator must move probability mass away from x_2 toward x_1.
  2. (a) Use a non-saturating generator loss (§16.1) or smooth/penalized critic (§16.2) so rejected samples (D(x') \ll 0) retain unit gradient weight. (b) Add zero-centered gradient penalties R_1 + R_2 (§16.4) and exponential moving average (EMA, §16.5) to damp rotational minimax dynamics. (c) Measure per-class K-NN recall (§16.6) to catch intra-class mode collapse hidden by high classifier alignment.

Summary: Core Notation and Chapter Synthesis

Key Takeaways

  • Two-sample domain & log-ratio: Real draws x \sim p and generated draws x' = G(z) \sim q form the balanced mixture m = \frac{1}{2}(p + q), with optimal critic target \lambda(x) = \log(p(x)/q(x)) and Bayes posterior \eta(x) = \sigma(\lambda(x)).
  • Per-sample generator weights: Rescale \nabla_\theta D(G_\theta(z)) by w_{\textrm{sat}} = \sigma(D(x')), w_{\textrm{ns}} = \sigma(-D(x')), or shift-invariant 1 - w_{\textrm{Rp}} = \mathbb{E}_p[\sigma(D(x) - D(x'))].
  • Equilibrium damping: Zero-centered penalties R_1 + R_2 = \frac{\gamma}{2}(\mathbb{E}_p\|\nabla_x D\|^2 + \mathbb{E}_q\|\nabla_{x'} D\|^2) vanish at q = p (\nabla_x D^\star = \mathbf{0}) while stabilizing minimax trajectories.