The Optimal Discriminator
Proposition 1: D*(x) = p_data(x) / (p_data(x) + p_g(x))
By the end of this lesson you can
- Derive the optimal discriminator for a fixed generator
- Interpret D* as a density ratio
- See why D* = 1/2 everywhere when p_g = p_data
Before analysing the whole game, the paper asks a simpler question: if the generator stands still, what is the best possible discriminator? The answer has a closed form, and it is the key that unlocks the rest of the theory.
Proposition 1
The analysis in Section 4 is done in a non-parametric setting: D can be any function at all, as if the network had infinite capacity. Keep that assumption in mind.
The Proof, Step by Step
Step 1: write both terms as one integral over x
The second term of V is an expectation over noise z. But G(z) with z ∼ p_z is by definition a sample from p_g, so it can be rewritten as an expectation over x ∼ p_g:
= ∫ [ p_data(x) log D(x) + p_g(x) log(1 − D(x)) ] dx
Step 2: maximise pointwise
D is an arbitrary function, so its value at each x can be chosen independently. To maximise the integral, maximise the integrand separately at every x. At a fixed x, write a = p_data(x), b = p_g(x) and y = D(x). We need to maximise:
Step 3: one line of calculus
The second derivative, −a/y² − b/(1 − y)², is negative, so this is a maximum. The paper states it as: for any (a, b) ∈ ℝ² \ {(0, 0)}, the function y ↦ a log(y) + b log(1 − y) achieves its maximum in [0, 1] at a/(a+b). Substituting back gives D*_G(x). The paper also notes D need not be defined outside Supp(p_data) ∪ Supp(p_g), since the integrand is zero there.
Reading D* as a Density Ratio
D* compares two densities at the same point. Rearranging:
So the odds that D* assigns are exactly the ratio of the two densities, and the logit log(D*/(1 − D*)) is the log density ratio. A trained discriminator is a density ratio estimator: without knowing either density, it learns how much more likely x is under the data than under the generator.
- Where only the data puts mass (p_g(x) = 0): D*(x) = 1.
- Where only the generator puts mass (p_data(x) = 0): D*(x) = 0.
- Where the generator over-produces (p_g > p_data): D* < 1/2.
- Where the generator under-produces (p_g < p_data): D* > 1/2.
This is exactly the signal G needs: D* is high where G should send more samples and low where it should send fewer.
The Perfect Generator Case
If p_g = p_data, then at every x the ratio is p / (p + p) = 1/2. The best possible discriminator is a coin flip. This is the flat blue line at 1/2 in panel (d) of the paper's Figure 1.
Edit the code and press Ctrl + Enter to run it in your browser.
At some point x, p_data(x) = 0.3 and p_g(x) = 0.1. What is D*(x)? What if p_g(x) = 0 there? What should the generator do near this x?
A well-trained discriminator outputs D(x) = 0.8 on some input x. Without knowing either density, what can you say about p_data(x) / p_g(x)? Why is this called density ratio estimation?
The proof maximises the integrand separately at each x. Which assumption makes this legitimate, and what breaks when D is a small network (for example D(x) = σ(w·x) in the lesson 4 code)?
Key takeaway
For a fixed G, the best discriminator is the ratio p_data / (p_data + p_g); it outputs 1/2 exactly when the generator is perfect.
Up next
Plug D* back into V and a famous divergence appears.