Quiz: generative adversarial networks

Short questions on the generator, the discriminator and the game between them. Try each on paper first, then open the answer. D(x) is the discriminator’s probability that x is real.


Q1. What does the generator of a GAN receive as input, and what does it never see?

Follow the arrows: where do real images go?

Random noise z (for example 128 numbers from \mathcal N(0, 1)). It never sees a real image: it only gets the gradient of the discriminator’s verdict on its own outputs.


Q2. At some x, real data have density 0.3 and generated samples density 0.1. What is the best discriminator’s output there?

D^* = p/(p + q).

0.3/(0.3 + 0.1) = 0.75: three of every four points seen there are real.


Q3. The generator has become perfect. What does the best discriminator output, and what is its loss -\log D(\text{real}) - \log(1 - D(\text{fake}))?

p = q everywhere.

D = \tfrac12 everywhere, and the loss is -\ln\tfrac12 - \ln\tfrac12 = 2\ln 2 = 1.386. The discriminator can do no better than guessing.


Q4. Early in training the discriminator rates the generated samples D(G(z)) = 0.02. Compare the push on the generator from the original loss \log(1 - D) and from the non-saturating loss -\log D.

The derivatives with respect to the discriminator’s logit are -D and -(1 - D).

0.02 against 0.98: the non-saturating loss pushes 49 times harder, exactly when the generator is still bad. The original loss saturates.


Q5. True or false: during GAN training, the generator’s loss should go down steadily, as in ordinary training.

Each loss is measured against an opponent who is also learning.

False. A better discriminator raises the generator’s loss even when the generator improves. In the demo both losses hover around \ln 2 and 2\ln 2 at the end. GAN losses are not a progress bar; look at the samples and at distribution metrics (next unit).


Q6. Name two things a VAE gives you that a GAN does not, and one thing a GAN does better.

Think of the encoder and of the training objective.

A VAE has an encoder (image → code) and a likelihood bound (the ELBO), so it can score how typical an image is. A GAN produces much sharper samples.


Q7. (math) Show that the best discriminator for fixed p and q is D^* = p/(p + q).

Maximise p\log D + q\log(1 - D) at each x separately.

The derivative with respect to D is p/D - q/(1 - D); it is zero at p(1 - D) = qD, i.e. D = p/(p + q). The second derivative -p/D^2 - q/(1 - D)^2 < 0, so it is a maximum.