GAN Discriminator Loss
Compute the discriminator loss for a Generative Adversarial Network.
The discriminator tries to maximize:
Given the discriminator's output for real data and for fake data (both are probabilities in ), compute the discriminator loss.
Clip probabilities to where to avoid log(0).
Return the loss rounded to 4 decimal places. Note: the loss is a positive number (we negate the objective).
Example
d_real = [0.9, 0.8] d_fake = [0.1, 0.2]
0.3285
- Inputs:
d_realholds the discriminator's probability that each real sample is real, andd_fakeits probability that each generated sample is real. Here and pairs line up by index: and . - Clipping: every value already lies well inside , so nothing changes. Clipping only matters for outputs of exactly or , where the log would be .
- Pair 1: .
- Pair 2: .
- Average and negate: the pair total is ; dividing by gives , and the minus sign in turns it into
0.3285(rounded to 4 decimal places). - Notice: a confident, correct discriminator drives every log toward , so the loss falls toward . A discriminator that outputs everywhere scores , the value of pure guessing.
Constraints
- d_real: list of discriminator outputs for real data (probabilities)
- d_fake: list of discriminator outputs for fake data (probabilities)
- Clip to [1e-7, 1-1e-7] before taking log
- Return the discriminator loss (positive) rounded to 4 decimal places