Total Probability, Total Expectation, and the GAN Discriminator Loss
Law of total probability (marginalization), law of total expectation, and how averaging binary cross-entropy over real and fake images gives the GAN discriminator loss.
Law of total probability (marginalization)
If the cases cover every possibility and never overlap, split an event by case, then add the cases back up:
When the cases are binary, :
Summing a joint distribution over , , is called marginalization. It is the same law, because .
Law of total expectation
The same split works for an average. Average the quantity within each case, then weight each case by its probability:
Written compactly, this is . The inner expectation averages within one case, and the outer one averages over the cases.
From BCE to the discriminator loss
A GANβs discriminator outputs , its estimated probability that an image is real. The label is for a real image and for a fake image , where is the generator and is a random noise vector. The binary cross-entropy (BCE) loss for one image is
Step 1: the loss in each case. Substituting the label makes one term vanish:
- If : .
- If : .
Step 2: split the expected loss by label. Let be the fraction of images that are real. The law of total expectation gives
averages over real images and averages over noise vectors.
Step 3: equal batches. GAN training shows equal numbers of real and fake images, so . Multiplying by 2 gives
The factor of 2 does not change which minimizes the loss.
Example. Take one real image with and one fake with . Then
and the expected BCE over this pool is .
Caveat. The original GAN paper writes directly as βloss on real + loss on fakeβ. The total-expectation derivation is a way to interpret it, not how the paper derives it.