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.

Advanced

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. The Minimax Game
  5. Optimal Discriminator
  6. Generator Objective and Jensen-Shannon Divergence
  7. Training Algorithm
  8. Mode Collapse and Training Instability
  9. Wasserstein GAN (WGAN)
  10. Common Pitfalls
  11. Research Perspective
  12. Summary
  13. Exercises

Learning Objectives

  1. Formulate the GAN training as a two-player minimax game.
  2. Derive the optimal discriminator for fixed generator.
  3. Prove that at optimality, the generator minimizes JSD(pdatapg)\text{JSD}(p_{\text{data}} \| p_g).
  4. Explain mode collapse and why it occurs.
  5. Derive the Wasserstein distance and the WGAN objective.

Notation

  • pdata(x)p_{\text{data}}(\mathbf{x}) — true data distribution
  • pz(z)p_z(\mathbf{z}) — latent prior (e.g., N(0,I)\mathcal{N}(\mathbf{0}, \mathbf{I}))
  • G(z;θg)G(\mathbf{z}; \theta_g) — generator (maps latent to data space)
  • D(x;θd)D(\mathbf{x}; \theta_d) — discriminator (outputs probability of "real")
  • pg(x)p_g(\mathbf{x}) — implicit distribution induced by generator
  • JSD\text{JSD} — 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

Real p(x)G(z) μ=2.50D boundaryG minimizes JS divergence · D maximizes classification
JS(P‖G) = 0.5944
Step
0
Real dataGenerator
Insight: The generator learns to match the real distribution while the discriminator learns to tell them apart. As training progresses, JS divergence drops and the generator distribution converges to real data.

The Minimax Game

The GAN value function:

minGmaxDV(D,G)=Expdata[logD(x)]+Ezpz[log(1D(G(z)))].(1)\min_G \max_D V(D, G) = \mathbb{E}_{\mathbf{x} \sim p_{\text{data}}}[\log D(\mathbf{x})] + \mathbb{E}_{\mathbf{z} \sim p_z}[\log(1 - D(G(\mathbf{z})))]. \tag{1}

The discriminator DD maximizes VV (correctly classifying real/fake). The generator GG minimizes VV (fooling the discriminator).


Optimal Discriminator

Theorem. For fixed GG, the optimal discriminator is:

D(x)=pdata(x)pdata(x)+pg(x).(2)D^*(\mathbf{x}) = \frac{p_{\text{data}}(\mathbf{x})}{p_{\text{data}}(\mathbf{x}) + p_g(\mathbf{x})}. \tag{2}

Proof. For fixed GG, the objective for DD is:

V(D)=[pdata(x)logD(x)+pg(x)log(1D(x))]dx.(3)V(D) = \int \left[p_{\text{data}}(\mathbf{x})\log D(\mathbf{x}) + p_g(\mathbf{x})\log(1 - D(\mathbf{x}))\right]d\mathbf{x}. \tag{3}

For each x\mathbf{x}, the integrand alogy+blog(1y)a\log y + b\log(1-y) (with a=pdataa = p_{\text{data}}, b=pgb = p_g) is maximized at:

y=aa+b=pdata(x)pdata(x)+pg(x).y^* = \frac{a}{a+b} = \frac{p_{\text{data}}(\mathbf{x})}{p_{\text{data}}(\mathbf{x}) + p_g(\mathbf{x})}. \quad \blacksquare

Generator Objective and Jensen-Shannon Divergence

Theorem. With optimal discriminator DD^*, the generator minimizes the Jensen-Shannon divergence.

Proof. Substituting DD^* into VV:

V(D,G)=Epdata[logpdatapdata+pg]+Epg[logpgpdata+pg].(4)V(D^*, G) = \mathbb{E}_{p_{\text{data}}}\left[\log\frac{p_{\text{data}}}{p_{\text{data}} + p_g}\right] + \mathbb{E}_{p_g}\left[\log\frac{p_g}{p_{\text{data}} + p_g}\right]. \tag{4}

Let m=(pdata+pg)/2m = (p_{\text{data}} + p_g)/2. Then:

V(D,G)=KL(pdatam)+KL(pgm)2log2=2JSD(pdatapg)2log2.(5)V(D^*, G) = \text{KL}(p_{\text{data}} \| m) + \text{KL}(p_g \| m) - 2\log 2 = 2\,\text{JSD}(p_{\text{data}} \| p_g) - 2\log 2. \tag{5}

The minimum is achieved when pg=pdatap_g = p_{\text{data}}, giving JSD=0\text{JSD} = 0 and V=2log2V = -2\log 2. \blacksquare


Training Algorithm

Alternating optimization:

For each training iteration:

  1. Update discriminator (kk steps): sample real batch and fake batch; maximize VV w.r.t. θd\theta_d.
  2. Update generator (1 step): sample latent codes; minimize VV w.r.t. θg\theta_g (or equivalently, maximize E[logD(G(z))]\mathbb{E}[\log D(G(\mathbf{z}))]).

Non-saturating loss (practical modification): Instead of minimizing log(1D(G(z)))\log(1-D(G(\mathbf{z}))) (which has near-zero gradient when DD is confident), maximize logD(G(z))\log D(G(\mathbf{z})). 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, pgp_g concentrates on a low-entropy subset.

Why it happens: The minimax game is a saddle-point problem. Gradient descent on GG and ascent on DD can oscillate rather than converge. If DD becomes too strong, the gradient signal to GG vanishes; if GG collapses to one mode, DD 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:

W(pdata,pg)=infγΠ(pdata,pg)E(x,y)γ[xy].(6)W(p_{\text{data}}, p_g) = \inf_{\gamma \in \Pi(p_{\text{data}}, p_g)} \mathbb{E}_{(\mathbf{x}, \mathbf{y}) \sim \gamma}[\lVert\mathbf{x} - \mathbf{y}\rVert]. \tag{6}

By the Kantorovich-Rubinstein duality:

W(pdata,pg)=supfL1[Epdata[f(x)]Epg[f(x)]],(7)W(p_{\text{data}}, p_g) = \sup_{\lVert f\rVert_L \leq 1}\left[\mathbb{E}_{p_{\text{data}}}[f(\mathbf{x})] - \mathbb{E}_{p_g}[f(\mathbf{x})]\right], \tag{7}

where the supremum is over 1-Lipschitz functions ff.

WGAN objective: Replace DD with a "critic" ff (no sigmoid, unconstrained output) and enforce the Lipschitz constraint:

maxfL1[Epdata[f(x)]Ez[f(G(z))]].(8)\max_{\lVert f\rVert_L \leq 1}\left[\mathbb{E}_{p_{\text{data}}}[f(\mathbf{x})] - \mathbb{E}_{\mathbf{z}}[f(G(\mathbf{z}))]\right]. \tag{8}

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): λE[(f(x^)1)2]\lambda\mathbb{E}[(\lVert\nabla f(\hat{\mathbf{x}})\rVert - 1)^2].


Common Pitfalls

Pitfall 1. Training DD to convergence before updating GG. If DD is perfect, GG 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 DD 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 pg=pdatap_g = p_{\text{data}} where D=1/2D^* = 1/2 everywhere.

Exercises

Exercise 1. Verify that D(x)=1/2D^*(\mathbf{x}) = 1/2 for all x\mathbf{x} when pg=pdatap_g = p_{\text{data}}.

Exercise 2. Derive equation (5) step by step, showing the connection to JSD.

Exercise 3. Show that the non-saturating generator loss logD(G(z))-\log D(G(\mathbf{z})) minimizes KL(pgpdata)\text{KL}(p_g \| p_{\text{data}}) 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 p=N(0,1)p = \mathcal{N}(0,1) and q=N(μ,1)q = \mathcal{N}(\mu, 1), compute W(p,q)W(p,q) and JSD(pq)\text{JSD}(p \| q) and show that WW varies smoothly with μ\mu while JSD saturates.