Generative Adversarial Networks
The minimax game formulation: deriving the GAN objective, proving the optimal discriminator, showing that the generator minimizes Jensen-Shannon divergence, training dynamics, mode collapse, and Wasserstein distance improvements.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- The Minimax Game
- Optimal Discriminator
- Generator Objective and Jensen-Shannon Divergence
- Training Algorithm
- Mode Collapse and Training Instability
- Wasserstein GAN (WGAN)
- Common Pitfalls
- Research Perspective
- Summary
- Exercises
Learning Objectives
- Formulate the GAN training as a two-player minimax game.
- Derive the optimal discriminator for fixed generator.
- Prove that at optimality, the generator minimizes .
- Explain mode collapse and why it occurs.
- Derive the Wasserstein distance and the WGAN objective.
Notation
- — true data distribution
- — latent prior (e.g., )
- — generator (maps latent to data space)
- — discriminator (outputs probability of "real")
- — implicit distribution induced by generator
- — Jensen-Shannon divergence
Core Intuition
The generator tries to produce fake samples indistinguishable from real data. The discriminator tries to tell real from fake. This adversarial game drives both networks to improve until the generator's output distribution matches the true data distribution — at which point the discriminator can do no better than random guessing.
GAN Training Dynamics
The Minimax Game
The GAN value function:
The discriminator maximizes (correctly classifying real/fake). The generator minimizes (fooling the discriminator).
Optimal Discriminator
Theorem. For fixed , the optimal discriminator is:
Proof. For fixed , the objective for is:
For each , the integrand (with , ) is maximized at:
Generator Objective and Jensen-Shannon Divergence
Theorem. With optimal discriminator , the generator minimizes the Jensen-Shannon divergence.
Proof. Substituting into :
Let . Then:
The minimum is achieved when , giving and .
Training Algorithm
Alternating optimization:
For each training iteration:
- Update discriminator ( steps): sample real batch and fake batch; maximize w.r.t. .
- Update generator (1 step): sample latent codes; minimize w.r.t. (or equivalently, maximize ).
Non-saturating loss (practical modification): Instead of minimizing (which has near-zero gradient when is confident), maximize . This provides stronger gradients early in training.
Mode Collapse and Training Instability
Mode collapse: The generator learns to produce only a few modes of the data distribution, ignoring the rest. Mathematically, concentrates on a low-entropy subset.
Why it happens: The minimax game is a saddle-point problem. Gradient descent on and ascent on can oscillate rather than converge. If becomes too strong, the gradient signal to vanishes; if collapses to one mode, can only indicate "that mode is overrepresented."
Training instability indicators:
- Discriminator loss → 0 (too strong)
- Generator loss oscillates without decreasing
- Generated samples lack diversity
Wasserstein GAN (WGAN)
Replace JSD with the Wasserstein-1 (Earth Mover's) distance:
By the Kantorovich-Rubinstein duality:
where the supremum is over 1-Lipschitz functions .
WGAN objective: Replace with a "critic" (no sigmoid, unconstrained output) and enforce the Lipschitz constraint:
Advantages: Wasserstein distance is continuous even when supports don't overlap (unlike JSD which saturates). Provides meaningful gradients everywhere. The critic loss correlates with sample quality.
Lipschitz enforcement: Weight clipping (original WGAN) or gradient penalty (WGAN-GP): .
Common Pitfalls
Pitfall 1. Training to convergence before updating . If is perfect, receives no useful gradient. Balance is key.
Pitfall 2. Using batch normalization in the discriminator for WGAN. BN introduces dependencies between samples, violating the per-sample Lipschitz constraint. Use layer normalization or spectral normalization instead.
Pitfall 3. Evaluating GAN quality by discriminator loss alone. Low loss doesn't imply good generation. Use FID, IS, or visual inspection.
Research Perspective
GANs (Goodfellow et al., 2014) demonstrated that implicit generative models trained via adversarial objectives could produce sharp, realistic images. Key developments include DCGAN (architectural guidelines), Progressive GAN, StyleGAN (state-of-the-art image synthesis), and theoretical advances (WGAN, spectral normalization). Diffusion models have largely superseded GANs for image generation due to more stable training and better diversity, but GANs remain relevant for real-time generation and video.
Summary
- GANs formulate generation as a minimax game between generator and discriminator.
- The optimal discriminator recovers the likelihood ratio; the generator minimizes JSD.
- Training is a saddle-point problem — prone to oscillation and mode collapse.
- WGAN uses Wasserstein distance with a Lipschitz-constrained critic for more stable gradients.
- The global optimum is where everywhere.
Exercises
Exercise 1. Verify that for all when .
Exercise 2. Derive equation (5) step by step, showing the connection to JSD.
Exercise 3. Show that the non-saturating generator loss minimizes under the optimal discriminator (and explain why this can cause mode collapse).
Exercise 4. Prove the Kantorovich-Rubinstein duality (equation 7) for discrete distributions.
Exercise 5. For two 1D Gaussians and , compute and and show that varies smoothly with while JSD saturates.