Section 4a: From the variational bound to a trainable min-max game
Turn Week 1's abstract sup over functions T into a neural-network critic T_w, creating the two-player saddle-point game J(theta, w).
I am working through Mathematical Foundations of Generative AI, Prof. Prathosh AP’s public lectures. The playlist is the spine. These notes are my deep dive on each section: a visual when the picture is the point, a detour when a prerequisite is doing real work, and every formula read aloud with a plain-words line right after it.
Previously: Section 3b: The convex conjugate and the variational bound.
Week 2 roadmap
Week 2 picks up right where Week 1 stopped. Here is how the four sections of Week 2 fit together:
| Section | Topic |
|---|---|
| 4a (this note) | From the Week 1 lower bound to a trainable min–max game (generator vs critic) |
| 4b | The critic’s output activation and |
| 4c | GAN as a special case: picking one particular gives the familiar GAN loss |
| 4d | Training a GAN in practice: mini-batches and alternating updates |
Prerequisites for this note (detours below): Week 1’s lower bound on , “an average is approximately an expectation”, and what a saddle point is.
Symbol cheat-sheet
| Symbol | Say it as | In plain words |
|---|---|---|
| ”p-x of x” | how likely real data is to land near | |
| “p-theta of x” | how likely the generator model is to produce | |
| “g-theta of z” | the generator neural network with weights , taking noise and outputting a fake sample | |
| “T of x” | a scoring function (critic) that takes one data point and returns one number | |
| ”script T” | the menu (family) of scoring functions we are allowed to pick from | |
| ”T-w of x” | a neural-network critic with weights | |
| “w” | the critic network’s adjustable weights | |
| ”f-star of t” | the convex conjugate of : a fixed penalty transform determined by which divergence we chose | |
| ”J of theta and w” | the single game score: how well critic separates real data from fakes made by generator | |
| “max over T in script-T” | try every function in the family and keep the one giving the biggest value | |
| ”arg-min over theta” | the setting of that makes the expression smallest | |
| ”approximately equals” | close to, but not exact (because we minimise a lower bound) |
Section 4a: From the variational bound to a trainable min-max game
1. Intuition first
In Week 1 we wanted to make our model distribution match the real data distribution by shrinking a distance between them (the f-divergence ). The problem: we cannot compute that distance directly, because we do not know either density formula. We only have samples.
Week 1 ended with a workaround: a lower bound on that only needs averages over samples, but it contains a “maximise over all functions ” step. This section answers: how do you actually maximise over “all functions” on a computer? Answer: use a neural network for , and you get a two-player game.
2. Real-world analogy
Think of a fraud-detection team vs. a fraudster.
- The fraudster (the generator, ) produces fake transactions.
- The fraud team (the critic, ) builds a scoring model that gives real transactions high scores and fakes low scores.
- The quality of the fraud team’s best scoring model is a measure of how different fakes still are from real ones. If even the best detector cannot separate them, the fakes are indistinguishable from real traffic.
- The fraudster improves the fakes to make even the best detector useless.
That is the exact mathematical structure: the critic maximises a separation score, and the generator minimises that best-achievable score.
3. Visual
The critic only ever sees samples (real ones and fake ones), and the generator only ever sees noise. All the learning signal flows through the single game score .
Things to watch in the widget:
- Move the critic slider : the blue curve shows as a hill over . The coral dot is the current critic’s score , which always sits at or below the dashed green ceiling .
- Click “Snap critic to ”: the critic climbs to the top of the hill, where the lower bound touches the true KL divergence.
- Move the generator slider toward : the entire hill sinks down until its peak hits 0 at the saddle point .
4. The formulas, decoded
Before we start, here is a quick recap of the Week 1 ingredient this all rests on.
Detour 1: The Week 1 lower bound (what and are)
In Week 1, the f-divergence was defined as
Read aloud: “the f-divergence from to is: at every point , take the ratio of real density to model density, push it through the function , weight it by how often the model visits , and add up over all .”
In plain words: it is a model-weighted measure of how far the ratio is from 1, on average.
The trouble is that this formula needs the density formulas for and , which we do not have. Week 1’s trick was the convex conjugate : every convex can be rewritten as “the best of many straight lines”,
Read aloud: ” of equals the maximum over of times minus -star of .”
In plain words: any bowl-shaped curve equals the upper envelope of its tangent lines. Plugging that into and swapping the order gave an expression that only contains averages, which we can estimate from samples. The price: we have to choose a slope for every — a whole function — and we only get a lower bound unless we pick perfectly.
Back to the main thread. That brings us to the first equation of Week 2.
Formula 1: The lower bound
Read aloud: “The divergence between the real distribution and the model is at least as big as the best value you can get, over all functions in some family , of: the average of on real samples, minus the average of -of- on model samples.”
Piece by piece:
| Symbol | Everyday meaning | Type / shape |
|---|---|---|
| ”is at least” | comparison | |
| ”try every function in the family and keep the one giving the biggest value” | optimisation over functions | |
| a scoring function: takes one data point, returns one number | function from data space (e.g. ) to | |
| the “menu” of scoring functions we are allowed to pick from | a set of functions | |
| ”the average value you would get if you drew many ‘s from the real data” | a single number | |
| same, but drawing from the model (generated samples) | a single number | |
| the convex conjugate of : a fixed penalty transform that depends on which divergence you chose | function from a number to a number |
In plain words: reward for giving high scores to real data, penalise it (through ) for giving high scores to fake data; the best possible net score is a guaranteed underestimate of how different the two distributions are.
Why it is a lower bound and not an equality: equality only holds if the menu contains the perfect scorer, which Section 3b showed is
Read aloud: “T-star at equals -prime evaluated at the ratio of to .”
In plain words: the ideal critic outputs the slope of at the true density ratio. A smaller menu can only do worse, so the max can only be smaller.
Formula 2: The training objective
We want . Since we cannot compute , we swap it for its lower bound:
Read aloud: “The best generator parameters are approximately those that minimise, over , the best score any critic in can achieve.”
- The outer min is over , the weights of the generator .
- The inner max is over , a class of critic functions .
- The matters: we are minimising a lower bound, not the true divergence. If the critic family is weak, the bound is loose, and the generator may appear to have low loss even when its samples are poor.
In plain words: pick the generator such that even the best possible critic can barely tell real from fake.
Formula 3: Making “max over all functions” computable
“Max over a set of functions” is not something a computer can execute directly. The fix: let the menu be every function a particular neural network architecture can represent. A network with weights is a function; changing changes the function. So “search over functions” becomes “search over weights ”, which gradient ascent can do:
Read aloud: “Find the generator weights and critic weights such that minimises, and maximises, the critic’s net score.”
In plain words: replace the abstract function search with a neural network , so both players are just tuning network weights.
The lectures name the bracket :
Read aloud: “J of theta and w equals the expected value of under minus the expected value of under .”
In plain words: is one single number measuring how well critic separates real data from fake data produced by generator .
One step the slides leave implicit — and the reason gradients can reach — is how enters the second average. Because fake samples are made as with , we rewrite the second term as:
Read aloud: “the expected value of for drawn from equals the expected value of for noise drawn from a standard normal.”
In plain words: averaging over model samples is the exact same thing as drawing random noise vectors , running each one through the generator , and averaging the critic’s penalty on the resulting fakes. We never need a density formula for .
Saddle point and adversarial training
Detour 2: What is a saddle point?
Picture a horse saddle (or a Pringle crisp). Walking front-to-back, the centre is the lowest point; walking side-to-side, it is the highest point. A point that is a minimum in one direction and a maximum in another is a saddle point:
Read aloud: ” at is at most at , which in turn is at most at .”
In plain words: at the saddle point , if the critic changes , the score cannot go up (the critic is already doing its best), and if the generator changes , the score cannot go down (the generator is already doing its best). Neither player wants to move.
Back to the main thread. That is why the lectures call this saddle-point optimisation and an adversarial problem: two players pulling one single number in opposite directions.
| Feature | Ordinary model training | VDM / GAN training |
|---|---|---|
| Players | One network | Two networks (generator , critic ) |
| Goal | Minimise a single loss | |
| Solution geometry | Bottom of a bowl (minimum) | Saddle point (min in , max in ) |
| Training stability | Usually steady descent | Can oscillate because each player’s target moves |
5. Tiny worked example
Use the forward KL divergence from Week 1: , whose conjugate is . Data lives on two points, and :
| Outcome | (real) | (model) |
|---|---|---|
First, the true KL divergence:
Read aloud: “0.5 times natural log of 0.5 over 0.8, plus 0.5 times natural log of 0.5 over 0.2, equals approximately 0.223.”
In plain words: the true KL gap between these two coins is .
Now let three different critics try. For each critic,
Read aloud: ” equals the real average of minus the model average of .”
In plain words: average score on real coin flips minus average exponential penalty on model coin flips.
| Critic | Avg on real | Avg on model | |||
|---|---|---|---|---|---|
| Lazy (constant) | |||||
| Decent | |||||
| Perfect: |
What the table shows:
- Every critic gives (matching the "" in Formula 1), and only the optimal critic hits .
- The good critic scores higher, because is where real data is under-produced by the model ( vs ). That is the critic pointing at what the generator gets wrong.
- Now the generator moves: if changes so , the true KL drops to , and the best any critic can achieve is . The generator wins when no critic can score above zero.
In practice, those averages come from mini-batch samples: for instance, four real draws give sample average , matching the exact expectation by the Law of Large Numbers.
6. Connect back
- Week 1 (Section 3b) gave the variational lower bound with an abstract .
- This note (Section 4a) makes it concrete: becomes a neural network , and training becomes the two-player saddle-point game . This general recipe is called f-GAN or Variational Divergence Minimisation (VDM).
- Next (Section 4b): must output numbers that lie inside (since some only accept restricted ranges), which we enforce with an output activation .
- Section 4c: picking one specific turns into the classic GAN loss .
- Week 6 (WGAN): replaces f-divergences with the Wasserstein distance while keeping this exact generator-vs-critic game shape.
Quick check (optional)
- Why can minimising over fool you into thinking the generator is good, even when it is not?
- In , which of the two averages actually depends on , and how does get in there?
- If the critic network were tiny (say, it could only output constants ), what would always equal, and what would that mean for training?