Section 3b: The convex conjugate and the variational bound
Rewrite D_f using only sample averages. The convex conjugate turns the density ratio into a critic game — the GAN objective in disguise.
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 3a: f-divergences.
Symbol cheat-sheet
| Symbol | Say it as | In plain words |
|---|---|---|
| ”x” | one data point, e.g. one image as a list of numbers | |
| ”script X” | the set of all possible data points | |
| ”P-x of x” | how likely real data is to land at the point (the true density) | |
| “P-theta of x” | how likely the model is to produce the point | |
| “f of u” | a convex penalty function applied to the density ratio | |
| “f-star of t” | the convex conjugate of : the biggest vertical gap between the line and the curve | |
| “domain of f-star” | the set of slopes where is finite | |
| ”f-prime of u” | the slope (derivative) of at | |
| “T of x” | the critic / auditor function: takes a point and outputs a score | |
| ”script T” | the family of allowed critic functions (e.g. neural networks ) | |
| , | “soup”, “max” | the best (largest) value achievable |
| ”arg-min” | the knob setting that makes something smallest | |
| ”expected value of h, with x drawn from p” | the average value of over random draws from | |
| “D-f hat” | our sample-average estimate of the true divergence |
Section 3b: The convex conjugate and the variational bound
This is the last part of Week 1, and it fixes the catch from Section 3a: we cannot compute directly because it needs the densities and , and we only have samples. By the end of this section, is rewritten using only averages over samples. That rewritten form is the GAN objective in disguise.
1. Intuition first
A bowl-shaped curve can be rebuilt entirely from its tangent lines: draw enough of them, and their top edge traces the curve. Straight lines are simpler to work with than curves, so we replace with “the best of all straight lines.” When we do that inside the divergence, the unknown ratio disappears and we are left with two plain averages: one over real data, one over model data. Measuring the divergence becomes a search for the scoring function that best tells the two apart.
2. Real-world analogy
You hire an auditor: a function that looks at any single request and gives it a score.
- The auditor gains credit for scoring real requests high: .
- The auditor pays a penalty for scoring synthetic requests high: .
The net score needs only request samples from both sources, never a formula. A lazy auditor gets a low net score; the best possible auditor’s net score equals the true divergence. In a GAN, the discriminator is this auditor, and the generator tries to fool it.
3. Visual: the conjugate as tangent lines
The core picture is how a convex relates to its conjugate . Here (the forward-KL ). Drag the slope and watch the tangent line slide along the curve.
Things to watch:
- Slide : for each slope , the dashed line sits above the curve at some points. The coral gap between the dashed line and the curve is . Shift the dashed line down by that exact gap and you get the green tangent line.
- Turn on the envelope: the green tangent lines all sit on or below the purple curve, and their top edge traces the curve itself ().
4. The formula, decoded
The target result:
Read aloud: “the f-divergence is at least the best value, over all scoring functions in the family , of: the average score gives to real data, minus the average of -star of the score gives to model data.”
In plain words: the divergence is at least as large as the best auditor’s net score, which is “score real data high, score model data low.”
Prerequisites, each as a detour: , derivatives for finding a maximum, the conjugate itself, choosing the best option at each point, and restricted searches.
Detour 1: sup vs max
(“supremum”) means the smallest value that nothing in the set exceeds. Example: the values () never reach 1, but their sup is 1.
In plain words: “the best achievable value, even if it is only approached.” For this course, read as .
Back to the main thread. Every below means “the best possible.”
Detour 2: Finding a maximum with the derivative
The derivative is the slope of at . At the top of a smooth hill the ground is flat, so a maximum satisfies
Read aloud: “h-prime at u-star equals zero.”
In plain words: the best point is where the slope becomes zero.
Two derivative rules we will use:
Read aloud: “the derivative with respect to of times equals .”
In plain words: a straight line with slope has slope everywhere.
Read aloud: “the derivative with respect to of equals .”
In plain words: from the product rule, “slope of the first times the second, plus the first times the slope of the second,” which gives .
Back to the main thread. We will use these two rules to compute for forward KL.
Detour 3: The convex conjugate
The convex conjugate is defined as
Read aloud: “f-star of is the largest value, over all allowed inputs , of times minus of .”
Piece by piece:
- : a slope (a single number).
- : a straight line through the origin with that slope.
- : the curve.
- : the vertical height of the line above the curve at .
- : the inputs where is defined.
In plain words: is the biggest vertical gap by which a line of slope rises above the curve . In the widget, it is the coral segment.
Computing it for :
Step 1, the gap we want to maximise:
In plain words: the height of the line above the curve at .
Step 2, set the slope to zero (Detour 2):
In plain words: the gap is largest where the line and the curve have equal slopes.
Step 3, solve for :
In plain words: the best point is raised to . That is the “touch ” point in the widget.
Step 4, plug back in:
In plain words: after the terms cancel, the biggest gap is simply .
Check at : , and . The widget shows the exact same numbers.
Two key properties of the conjugate: first, is also convex. Second, taking the conjugate twice returns the original function ():
Read aloud: ” of equals the largest value, over all slopes , of times minus -star of .”
In plain words: each is a tangent line (slope , shifted down by the gap ). The curve’s value at equals the highest tangent line at . That is the envelope picture in the widget. Lower-semicontinuity from 3a is the technical condition that makes this exact.
Back to the main thread. This is the key move: it replaces the curved with straight lines in . Since straight lines are linear, when is a ratio of densities, the denominator can be multiplied away.
Detour 4: The best choice at each point becomes a function
Read aloud: “adding up the best value at each equals the best value, over all functions , of adding up with plugged in.”
In plain words: picking the best price for each product separately is the same as picking the best price table for the whole catalogue. The lookup table is the function .
Back to the main thread. This is where a single number becomes a function : the best slope depends on .
Detour 5: A restricted search can only do worse
Read aloud: “the best found in a smaller set is at most the best found in everything.”
In plain words: the best restaurant within 1 km is never better than the best in the whole city.
Back to the main thread. We can only search a limited family (later, neural networks of a fixed shape), so the result becomes "" instead of "".
The derivation, step by step
Step 1, start from the definition (3a):
In plain words: the model-weighted total mismatch penalty.
Step 2, replace with its tangent-line form (Detour 3), with :
What changed: became “the best tangent line.” In plain words: the same total, but each penalty is now computed as a highest straight line.
Step 3, move inside the sup:
What changed: multiplying by a non-negative number does not change which is best, so can move inside; then it cancels the denominator of the ratio. In plain words: the division by an unknown density is gone. This is the crucial step.
Step 4, let the best depend on (Detour 4):
What changed: “best number at each point” became “best function .” In plain words: we are now searching for an entire scoring rule .
Step 5, search a limited family and split the integral (Detour 5):
What changed: “all functions” became “functions in that we can actually search over,” which turns "" into ”.” In plain words: our best searchable auditor can only underestimate the divergence.
Step 6, recognise each integral as an expectation (3a, Detour 3):
What changed: “density times function, integrated” was renamed “average under that distribution.” In plain words: two averages, one over real data and one over model data. No density values needed.
One-sentence summary of the derivation: by writing the penalty as its best tangent line and letting the slope vary with , the divergence becomes the best achievable “real-score minus model-penalty” over scoring functions, and that only needs samples.
| Piece | Type | In plain words |
|---|---|---|
| function | the auditor’s score for point | |
| a family of functions | the auditors we are allowed to try | |
| a number | average score on real data | |
| a number | average penalty for scores on model data | |
| — | use the best auditor in the family |
Turning it into sample averages. Recall the Law of Large Numbers from Section 1:
In plain words: with enough random draws, the plain average of the samples is close to the true expected value.
Applying it to both terms gives our computable estimator:
with from the dataset and (random noise vectors).
Read aloud: “the estimated divergence is approximately the average score over the real data points, minus the average of -star of the scores over generated points.”
In plain words: score the real data, score the fake data, and take the difference of the averages. Only samples are needed.
Bonus fact (standard in the f-GAN literature): the bound is exact when
Read aloud: “the best auditor’s score at is the slope of at the density ratio.”
In plain words: the perfect auditor is secretly measuring the real-to-model density ratio at each point.
5. Tiny worked example
Same coins as 3a: and . Using forward KL, , and the true KL is .
An auditor is two scores, , one per outcome:
Read aloud: “the bound is the real-weighted average score, minus the model-weighted average of to the power (score minus 1).”
In plain words: credit for scoring real outcomes, minus a penalty for scoring model outcomes.
| Auditor | Real-score average | Model-penalty average | Bound | vs 0.223 |
|---|---|---|---|---|
| Lazy , same score for both | 1.000 | 0.000 | far below | |
| Decent | 1.150 | 0.165 | closer | |
| Best | 1.223 | 0.223 | exact ✓ |
What the numbers show:
- Every auditor gives a lower bound; none overshoots .
- Better auditors score outcome 2 higher. That is the outcome the model under-produces (), so it “looks most real.”
- The best auditor uses (from Detour 2) at the true ratios, and recovers the KL divergence exactly.
Notes on the lecture slides
- The slides write : the auditor’s scores must lie where is defined. For KL that is every real number. Other choices of restrict the domain, which is why Week 2 adds an output activation to squash the network’s output into .
- Step 6 of the derivation matches the opening line of Week 2: .
6. Connect back
Week 2 replaces the auditor with a neural network (weights ) and wraps a minimisation over the generator around the bound:
Read aloud: “find the generator weights that minimise, and the critic weights that maximise, the gap between the critic’s average score on real data and its average penalty on generated data.”
In plain words: the critic tries to measure the divergence as accurately as possible; the generator tries to shrink it. This is Variational Divergence Minimisation (VDM).
With the JS-like , the objective becomes the classic GAN loss:
Read aloud: “the average log of the discriminator’s real-probability on real data, plus the average log of one minus its real-probability on generated data.”
In plain words: the discriminator wants to output near 1 (“real”) for real data and near 0 (“fake”) for generated data. The generator wants to fool it.
| Week 1 idea | Week 2 name |
|---|---|
| auditor | discriminator |
| discriminator training (gradient ascent on ) | |
| minimising the bound over | generator training (gradient descent on ) |
| tightness of the bound | how good the discriminator is |
Quick check (optional)
- In the worked example, why can no auditor give a bound above 0.223?
- Which step in the derivation removed the unknown density ratio, and what did it do?
- In , where do the two sets of samples come from?