4.5.6 · D3Generative Models

Worked examples — Generative Adversarial Networks (GAN) framework

1,687 words8 min readBack to topic

This page is a drill deck. The parent note built the value function and the optimal discriminator. Here we use those formulas on every case that training can throw at you.

Before we start, one symbol reminder so no notation is used blind:


The scenario matrix

Cell Case class What breaks / what to watch Example
A (perfect convergence) everywhere, Ex 1
B far off (early training) on real, on fake Ex 2
C Sign / direction of the gradient minimax vs non-saturating loss Ex 3
D Degenerate: (fake-only region) , division safe? Ex 4
E Degenerate: (mode dropped) , links to Mode Collapse Solutions Ex 5
F Limiting: disjoint supports JSD saturates → vanishing gradient, Waserstein GAN (WGAN) Ex 6
G Real-world word problem (image batch) plug numbers into losses Ex 7
H Exam twist: verify from JSD algebra of the theorem Ex 8

We now hit every cell.


Worked examples

Forecast: guess before reading — should the perfect detective say "real", "fake", or shrug?

  1. Plug into the master formula. Why this step? is a ratio "how much of the stuff at is real, out of all the stuff at ". Half is real, half is fake.
  2. Simplify. . Why this step? Equal numerator-and-denominator-half always gives — the shrug.

Verify: the detective outputting is exactly the equilibrium the parent note promised: maximum uncertainty, the counterfeiter has won. ✓ ()


Forecast: which one gets pushed toward , which toward ?

  1. Real point. Why this step? At almost everything present is real, so the ratio is near .
  2. Fake point. Why this step? At almost everything is fake, so the "fraction real" is tiny.

Verify: (near 1) and (near 0) — this matches the parent's "Epoch 10" trace (, ): an easy job for when is weak. ✓


Forecast: which loss gives the poor generator a stronger push?

Look at the shape of both curves before computing.

Figure — Generative Adversarial Networks (GAN) framework
  1. Original loss slope. The generator minimizes , so its gradient (w.r.t. ) is Why this step? The slope size tells us how hard is pushed. Look at the pink curve on the figure: near it is almost flat — small slope, weak signal.
  2. Non-saturating loss slope. The generator maximizes , gradient Why this step? The blue curve is steep near : magnitude vs — about 19× stronger.
  3. Same fixed point. Both are optimized when larger (generator wants fooled); crucially both agree is where is confused, but the blue one fights harder when is small. Why this step? This is the parent note's "vanishing gradient" fix in one number.

Verify: ratio . The non-saturating loss is ~19× stronger here. ✓


Forecast: a spot with no real support — what should the detective say?

  1. Plug in. Why this step? Numerator is but the denominator , so no division by zero — the ratio is cleanly .
  2. Interpret. = "certainly fake", correct: nothing real lives here. Why this step? This is the only place can be perfectly confident and be right, so gets a huge push to abandon .

Verify: , and the denominator was nonzero so the formula is well-defined. ✓


Forecast: a real mode the generator ignores — confident or confused?

  1. Plug in. Why this step? All mass here is real, so fraction-real : "surely real".
  2. Interpret. means flags this region as always real — the generator gets zero reward for producing it, so it has no direct pull back to cover "7". This is precisely the failure Mode Collapse Solutions attacks. Why this step? is the fingerprint of a dropped mode in the matrix.

Verify: (denominator , safe). ✓


Forecast: if the two curves never touch, can the generator ever get a useful gradient?

  1. On (real only): so . On (fake only):** so . Why this step? becomes a perfect classifier — it is never wrong, so it never leaks information about direction to .
  2. JSD is maxed. For fully disjoint distributions , so Why this step? is its maximum; the value function pins to and its gradient w.r.t. vanishes — this is the theoretical reason Waserstein GAN (WGAN) replaces JSD with a distance that still slopes across a gap.

Verify: (since ). ✓ And . ✓


Forecast: is the discriminator doing well (small ) at this snapshot?

  1. Real-term sum. . Why this step? Each rewards confidence-on-real; closer to is better.
  2. Fake-term sum. . Why this step? Rewards confidence-on-fake ( near ).
  3. Combine. . Why this step? The turns "reward" into "loss to minimize".
  4. Generator loss. . . Why this step? is large because still catches the fakes ( small) — the generator has work to do.

Verify: , . Both positive (losses), and signals a strong discriminator winning the round. ✓ (See Cross-Entropy Loss — this is averaged binary cross-entropy.)


Forecast: what happens to JSD when two identical curves are compared?

  1. JSD of a curve with itself is . By definition (a distance from something to itself). Why this step? JSD is a divergence: zero iff the distributions match, and here they match exactly.
  2. Substitute. . Why this step? The bonus term vanishes, leaving the constant floor.
  3. Cross-check via . With , . Then Why this step? Two independent routes give the same number — this is the Nash Equilibrium value of the game.

Verify: and — identical. ✓


Recall Self-test: which cell?

at a point means... ::: the generator has dropped that mode ( there) — Cell E. Disjoint supports give JSD = ... and ... ::: , and ; gradients vanish (Cell F). The non-saturating generator loss exists to fix... ::: weak/vanishing gradients when is small (Cell C). At convergence ... and ... ::: and (Cells A/H).