Equations · Goodfellow et al., “Generative Adversarial Nets” (2014)
The GAN minimax objective, explained term by term
A two-player game. The discriminator tries to tell real data from generated data; the generator tries to fool it. maximizes the value , minimizes it, and training alternates between them.
Term by term
Read from the inside out: for a given generator, the best discriminator maximizes ; the generator then minimizes that best-case value. The subscripts say who controls each step.
The discriminator: a network outputting the probability that its input is real.
The generator: a network that turns a noise vector into a fake data point.
Average over real data: high when says "real" to real examples. The subscript is a label.
Expectation · Distributed as (tilde) · Logarithm · Subscript (index or label)
Average over noise drawn from a simple prior (Gaussian or uniform): high when says "fake" to generated examples. Only this term depends on .
A small worked example
If gives a real image and a fake one : . At the game's equilibrium, matches the data and everywhere, so . Early on gives weak gradients, so the paper suggests training to maximize instead.
In code
import torch
def gan_losses(D, G, x, z):
real, fake = D(x), D(G(z)) # probabilities in (0, 1)
# for the D step, compute fake from G(z).detach()
d_loss = -(torch.log(real) + torch.log(1 - fake)).mean()
g_loss = -torch.log(fake).mean() # the non-saturating version
return d_loss, g_lossEvery symbol in it
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- VAE reparameterization trick
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)