35 — Generative & Prob.

GANs — Generative Adversarial Networks#

GenerativeMathematical
◆ The PatternTwo networks competing: generator vs discriminator

GANs pit a Generator G against a Discriminator D in a minimax game.

min_G max_D V(D,G) = E[log D(x)] + E[log(1−D(G(z)))]
Minimax objective: at equilibrium D(x) = 0.5 everywhere.
// GAN training dynamics
Mode collapse: The biggest GAN failure — G learns only a few convincing samples. WGAN and gradient penalty (WGAN-GP) are the standard fixes.
Pattern bridge: The generator-discriminator game is two opposing forces that produce something neither could alone. In markets, contrarian vs. herd is the same adversarial dynamic.
Worked example

Real data centred at 0 and a generator centred at 3. The best possible discriminator outputs 0.999 at −1, 0.989 at 0, 0.5 at 1.5 and 0.011 at 3 — easy to tell apart. When the generator matches the data it can only say 0.5 everywhere, and the game’s value reaches −log 4 = −1.386, the equilibrium.

Where it misleads
  • When the discriminator wins too easily, the generator’s gradient vanishes; Wasserstein GANs change the objective to fix this (Arjovsky et al. 2017).
  • Generators can collapse to a few outputs that fool the discriminator (mode collapse).
  • GAN training has no single loss that tracks progress; sample quality must be measured separately.
In code
from math import erf, sqrt, exp, pi
pdf = lambda x, m: exp(-(x - m) ** 2 / 2) / sqrt(2 * pi)
d_star = lambda x, m_g: pdf(x, 0) / (pdf(x, 0) + pdf(x, m_g))   # best discriminator: data at 0, generator at m_g
far = [round(d_star(x, 3), 3) for x in (-1, 0, 1.5, 3)]
equal = [round(d_star(x, 0), 3) for x in (-1, 0, 1.5, 3)]       # generator matches the data
value_at_equilibrium = 2 * np.log(0.5)
Python, in your browser — edit the code and run it again

Assumes import numpy as np. Each snippet carries its own example numbers; the comments say which are made up or simulated.

Sources
  • I. Goodfellow et al., “Generative Adversarial Nets”, NeurIPS, 2014
  • M. Arjovsky, S. Chintala & L. Bottou, “Wasserstein Generative Adversarial Networks”, ICML, 2017
  • T. Salimans et al., “Improved Techniques for Training GANs”, NeurIPS, 2016

Last reviewed October 2026 · How this site checks its content · Report a mistake

Linked from 2
← Previous
Diffusion Models
Open in the full reader, with the topic sidebar