4.5.7 · D3Generative Models

Worked examples — Generator and discriminator dynamics

3,172 words14 min readBack to topic

This deep dive is the practice arena for the parent note on GAN dynamics. There we built the machinery: the objective , the optimal discriminator , the vanishing-gradient trap, and the equilibrium. Here we throw every kind of scenario at that machinery and solve each one completely.

Before we start, one promise: every symbol below was earned in the parent, but we re-anchor the critical ones so you never feel lost.

Recall The six symbols we lean on
  • ::: the discriminator's output — a number between and , "probability this input is REAL".
  • ::: the generator turning a random noise vector into a fake sample.
  • ::: how likely real data is to look like (a probability density).
  • ::: how likely the generator is to produce something looking like .
  • (read "D-star") ::: the best possible discriminator for a fixed generator; from the parent .
  • ::: the game's score for the discriminator — bigger is better for D, smaller is better for G.

The scenario matrix

Every problem this topic can throw sits in one of these cells. Think of it like a chessboard: we must visit each square at least once. The table has two axes: the rows are the training regime / probability structure (what state the game is in), and the columns are what makes the cell special (which extreme, zero, or twist it isolates).

Cell Row: regime Column: what is extreme / degenerate / applied Which example
A Early training — G failing, gradient vanishes Ex 1
B Late training — G winning Ex 2
C Perfect equilibrium , so everywhere Ex 3
D Optimal at a point plug densities into formula Ex 4
E Degenerate zero or at a point Ex 5
F Gradient regime saturating vs non-saturating gradient, compared numerically Ex 6
G Real-world word problem fraud/counterfeit framing, compute Ex 7
H Exam twist value of the game at equals Ex 8
I Mode collapse limiting case G ignores a mode, measure the miss Ex 9

Read the table down: rows A–B fix who is winning, C–E fix the probability structure (matched, single point, degenerate zero), F fixes the gradient regime, and G–I are applied and exam-style variants. Visiting every row → covering the topic.

Prerequisite links you may want open: binary cross-entropy, Nash equilibrium, and for where this leads, mode collapse and Wasserstein GAN.

The figure above is our map: each region is a cell of the matrix, plotted on the "value of " line from (D sure it's fake) to (D fooled).


Cell A — Early training, G is failing

Forecast: guess before reading — will the original loss be near or a big number? (It will be near — that's the whole problem.)

  1. Original loss value. . Why this step? The parent's minimax objective makes G minimize ; we evaluate it at the current D-output to see how "alive" it is. This is tiny — nearly flat. A flat loss means a tiny slope, means almost no learning signal.

  2. Non-saturating loss value. . Why this step? The parent's fix was to maximize , i.e. minimize . We evaluate the alternative at the same point to compare. A big number — steep, lots of signal.

  3. Interpret. The original sits at (flat lake), the non-saturating at (steep cliff). G learns from the cliff, not the lake. Why this step? Learning speed is proportional to slope; the non-saturating loss keeps a strong slope exactly when .

Verify: sanity check with logs — and . Ratio of magnitudes stronger for non-saturating. Units: both are dimensionless log-probabilities. ✓


Cell B — Late training, G is winning

Forecast: G is doing well now — should its original loss be very negative or near zero?

  1. G's original loss. . Why this step? This is the term G minimizes; a very negative value means G is happy (it drove D's fake-probability up). Strongly negative → G is succeeding.

  2. D's contribution for this fake. For a fake, D wants large (close to ), but here it is , deeply negative. Why this step? D maximizes ; a big negative term means D is being punished — it got fooled.

  3. Contrast with Ex 1. In cell A the same term was (D happy). Here (D unhappy). The tables turned. Why this step? Placing the two extremes side by side shows the term's full range — near-zero when G fails, deeply negative when G wins — so no value in between will surprise the reader.

Verify: . Consistent with . ✓


Cell C — Perfect equilibrium

Forecast: if D outputs exactly , what is ? Same as — so both terms coincide.

  1. Plug into . From the parent, . Set : Why this step? Equilibrium in a Nash sense means neither player can improve; the parent showed this happens precisely when the two densities match, forcing the ratio to .

  2. This holds for all where — the cancels regardless of its value. Why this step? We must cover every , not one point; the cancellation is universal.

  3. Losses at . Real term ; fake term . Why this step? At equilibrium D can do no better than guessing — its per-sample log-score bottoms out at .

  4. Averaged value . Using this page's definition : Why this step? We stated in per-sample averaged form up top; showing its equilibrium number here makes that floor concrete and gives Ex 7 a benchmark to compare against.

Verify: for any , , and the averaged . ✓


Cell D — Optimal at a specific point

Forecast: is exactly halfway between the two means (0 and 2). Guess: .

  1. Densities at . Using the Gaussian density defined at the top of this page, . Why this step? needs both densities; by symmetry the exponents match at the midpoint.

  2. Plug into . Why this step? Equal densities → the Bayes-optimal detector is a coin flip; it genuinely cannot decide.

  3. Compare to parent's endpoints (, ). At the midpoint, — a smooth crossover. Why this step? Checking the midpoint against the two centres confirms varies monotonically across the axis (real-confident at , coin-flip at , fake-confident at ), so we have mapped the detector's behaviour over the whole line, not just one point.

Verify: exponents and are both , so the fraction is exactly . ✓


Cell E — Degenerate zero density

Forecast: if there is zero chance the sample is fake, D should be 100% sure it's real.

  1. Plug in the zero. Why this step? The formula still applies as long as the denominator is nonzero; here it is .

  2. The other degenerate direction. If instead but (generator hallucinates something real data never does): Why this step? We must cover both signs of degeneracy — a in the numerator vs a in the second density.

  3. The truly undefined case. If both and , the fraction is — undefined. D never sees such points, so its behaviour there is arbitrary; this is exactly the "empty region" where GANs behave unpredictably. Why this step? Limiting/degenerate inputs are a matrix cell we must not skip.

  4. Warning sign. means D is perfectly confident — a region where G contributes nothing. If large regions have , G is missing whole chunks of the data: the seed of mode collapse.

Verify: and . The case is correctly flagged undefined. ✓


Cell F — Gradient comparison, the two G-losses

Forecast: at low the non-saturating should dominate; near , the original should.

  1. Define the ratio , writing for . Why this step? A ratio strips away the shared factor, isolating which regime each loss favours.

  2. At : . Non-saturating is stronger. At : . They tie. At : . Now the original is stronger. Why this step? We test all three sub-regimes (failing, tied, winning) — that is what "cover every case" demands.

  3. Interpret. Early on ( small, G failing) the non-saturating loss wins — precisely when we need signal. This is why the non-saturating loss is the one practitioners actually train with: it keeps a strong gradient in exactly the regime where the theoretically-correct original loss goes flat and stalls learning. Why this step? The ratio is a raw number; connecting it to the practical training choice explains why we computed it and stands on its own without needing the parent open.

The figure above plots the two gradient-magnitude factors, (original, orange) and (non-saturating, magenta), across all from to . Read it left-to-right: on the left (G failing, small) the magenta curve rockets up while orange stays flat near — the non-saturating loss delivers a huge push exactly when the original goes flat. The two dashed violet lines mark our three test points; they cross at , the tie from step 2. On the right (G winning, near ) the roles swap: orange climbs, magenta flattens. The picture is step 2, made continuous.

Verify: gives , , and at . ✓


Cell G — Real-world word problem

Forecast: D is right-ish on both (high for real, low-ish for fake) — expect a modestly negative (log scores are always ).

  1. Real term. . Why this step? This is the first objective term — reward for calling real "real".

  2. Fake term. . Why this step? Second objective term — reward for calling the counterfeit "fake"; higher is better for D.

  3. Average with the . . Why this step? We use the page's definition — the -averaged form — so this single number is directly comparable to the equilibrium value computed in Ex 3.

  4. Winning? From Ex 3 the equilibrium floor is . Since , D scores above the coin-flip floor — the detective is winning this batch: it is doing measurably better than blind guessing. Why this step? "Winning" only means something relative to the equilibrium baseline; comparing our to that floor turns a bare number into a verdict.

Verify: , , mean , which exceeds . ✓


Cell H — Exam twist: the value of the game

Forecast: two terms, each ; summed → ; halved → .

  1. Substitute . Both objective terms become . Using the expectation fact from the top ( of a constant is that constant), the sum is Why this step? At equilibrium (cell C) everywhere, so each averaged term is just the constant .

  2. Add the logs (the classic form). Why this step? Log turns the product into a sum (the parent's reason for using log); the famous textbook constant is this summed value.

  3. Reconcile with this page's . Our carries a , so our equilibrium value is — exactly the floor used in Ex 3 and Ex 7. The textbook "" and our "" differ only by the averaging factor. Why this step? This ties the two conventions together so nothing looks contradictory across the page.

Verify: summed ; halved . ✓


Cell I — Mode collapse limiting case

Forecast: at the abandoned mode , D should be certain it's real (); at the over-produced mode, D leans fake.

  1. At (abandoned mode). Why this step? Same degenerate-zero logic as cell E — G never visits here, so any sample here is surely real.

  2. At (over-produced mode). Why this step? Here G floods the region, so real is outnumbered → D leans "fake", giving only probability of "real".

  3. Quantify the miss. A healthy GAN would have everywhere. We measure how far the collapsed generator drags D from that ideal by summing the two deviations: Why this step? A single scalar lets you compare training runs; it is only at true equilibrium and grows as collapse worsens.

  4. Interpret and tie up. The score (versus for a healthy GAN) says the generator has drifted badly from equilibrium: it is certain-real at one mode and outnumbered at the other. In real training this shows up as D easily flagging the abandoned mode ( there) while G keeps flooding a single mode — the diagnostic signature of mode collapse. A fix like the Wasserstein GAN changes the objective to keep gradients meaningful even in these lopsided regions.

Verify: , , and . ✓


Recall drills

Recall Quick self-test

At perfect equilibrium, what does equal for every ? ::: Exactly — D cannot tell real from fake. Why is the original G-loss dangerous early in training? ::: When , is flat, so the gradient vanishes. What is the summed value of the game at equilibrium, and its -averaged form? ::: Summed ; averaged . If but , what is ? ::: — D is certain such a sample is real. Which G-loss gives stronger gradients when G is failing? ::: The non-saturating loss .