GANs
How generative adversarial networks train a generator and a discriminator against each other to produce realistic synthetic images, signals and designs, and what makes them hard to train.
What it is
A generative adversarial network (GAN), introduced by Ian Goodfellow and colleagues in 2014, is a generative model made of two neural networks that compete. The generator G turns random noise z into synthetic samples, such as images, spectra or molecular structures. The discriminator D receives either real data or the generator’s fakes and tries to tell them apart. As D improves at spotting fakes, G is pushed to produce more convincing ones, and training ends ideally when the fakes are indistinguishable from real data. The analogy is a forger and an art detective improving each other. GANs produced the first photorealistic synthetic faces (StyleGAN) and have been used for image translation, super-resolution, data augmentation, simulation of detector or physical fields, and design of materials and molecules, though diffusion models now lead in many image tasks (see diffusion models).
It answers questions such as: Can realistic additional training data be synthesized where real data are scarce? How can an image be converted from one style or modality to another, for example a sketch to a photo or MRI to CT? Can a fast generative model stand in for an expensive simulator? What does the learned distribution of designs look like? Their main weakness is unstable training.
Fundamentals
The adversarial game
GAN training is a two-player minimax game over the value function V(D, G) = Ex∼pdata[log D(x)] + Ez∼pz[log(1 − D(G(z)))], with min over G and max over D. D outputs the probability that its input is real. For a fixed G, the optimal discriminator is D*(x) = pdata(x)/(pdata(x) + pg(x)), and substituting it shows that G minimizes the Jensen–Shannon divergence between the real distribution and the generator’s distribution pg. At the ideal equilibrium pg = pdata and D = 1/2 everywhere. In practice, the generator uses the non-saturating loss, maximizing log D(G(z)) instead of minimizing log(1 − D(G(z))), because early in training D easily rejects fakes and the original objective gives G almost no gradient. Training alternates: a few updates of D on real and fake batches, then an update of G through D, usually with Adam and a small learning rate (2 × 10−4, β1 = 0.5 in the DCGAN recipe).
Training difficulties
The game is not a simple minimization, so there is no guarantee of convergence, and the losses do not reflect sample quality. Typical failures: mode collapse, where G produces only a few distinct outputs that fool D; vanishing gradients, when D becomes too strong; oscillation or divergence; and sensitivity to hyperparameters and architecture. Stabilization tricks include balanced updates, label smoothing, adding instance noise, minibatch statistics, spectral normalization of D, the two time-scale update rule, and monitoring generated samples during training. The Wasserstein GAN (WGAN) replaces the JS divergence with the Earth Mover distance, which gives meaningful gradients even when distributions do not overlap, and the critic is constrained to be 1-Lipschitz, by weight clipping or the better gradient penalty (WGAN-GP), and its loss correlates with sample quality. Other variants use least-squares or hinge losses.
Architectures and variants
- DCGAN: convolutional generators with transposed convolutions and batch normalization, the baseline recipe for images.
- Conditional GAN: both networks receive a label or other information c, so generation can be controlled (class, property, text).
- pix2pix and CycleGAN: image-to-image translation with paired data or, via a cycle-consistency loss, unpaired data.
- Progressive GAN, StyleGAN (1–3), BigGAN: large, high-resolution, controllable image generators with style-based latent control.
- Super-resolution (SRGAN), inpainting, and GANs for time series, tabular data and graphs, including CTGAN for synthetic tabular data and MolGAN for molecules.
Evaluation
Judging generative models is hard. Common metrics: Inception Score (quality and diversity from a classifier), Fréchet Inception Distance (FID), which compares the mean and covariance of deep features of real and generated sets, FID = ‖μr − μg‖2 + Tr(Σr + Σg − 2(ΣrΣg)1/2) (lower is better), and precision and recall for generative models, which separate fidelity from coverage. For scientific data, domain-specific checks matter more: do generated samples obey physical constraints, reproduce summary statistics and correlations, and match the distribution of properties such as energy, power spectra or particle-shower shapes? Visual inspection is not enough, and generated data must not be assumed to carry real information beyond what the training data contained. Memorization of training examples should be tested by nearest-neighbor search against the training set.
Typical applications and limits
Applications: augmenting small medical or industrial data sets (with caution), fast surrogates for particle detector or cosmology simulations, microstructure and materials generation, image enhancement, anonymization, and art and design. Risks: deepfakes and misinformation, privacy leakage, bias amplified from training data, and generated data that look plausible but are physically wrong. Limits: unstable training, mode collapse, no explicit likelihood, and the dominance of newer models in many tasks. Frameworks: PyTorch and TensorFlow, with reference implementations such as StyleGAN from NVIDIA.
Basic operation
- Prepare the data. Collect a clean, representative training set and normalize it.
- Define the networks. Build the generator and discriminator with a stable architecture.
- Choose the loss. Start with a non-saturating, WGAN-GP or hinge loss.
- Train alternately. Update the discriminator, then the generator, and save samples regularly.
- Watch for failure. Check for mode collapse and oscillation.
- Evaluate. Compute FID or domain-specific statistics, and test for memorization.
- Generate. Sample new noise vectors to produce outputs, and filter them with checks.
- Collect the output. You obtain synthetic samples; stabilization methods and evaluation are covered in the video.
Good practice
- Inspect samples often. Loss curves alone mislead.
- Use proven recipes. Start from a stable architecture such as DCGAN or WGAN-GP.
- Test diversity. Check for mode collapse and missing classes.
- Validate against physics. Compare statistics and constraints with real data.
- Check for memorization. Compare samples with training data.
- Label synthetic content. Do not use GANs to create deceptive media or fabricated scientific data, and disclose when synthetic data are used in research or in training medical models.
Key terms
- Generator — the network that creates synthetic samples from noise.
- Discriminator — the network that judges whether a sample is real or generated.
- Mode collapse — the generator producing only a narrow set of outputs.
- Latent vector — the random input from which the generator builds a sample.
- Wasserstein distance — a measure of the cost of moving one distribution to another, used by WGAN.
- Conditional GAN — a GAN steered by labels or other inputs.
- FID — a score comparing the feature statistics of real and generated data.
Video coming soon
About five minutes on GANs: how it works in detail, how the data is acquired, and how it is analyzed.
More in 4.3 AI and Machine Learning
- Regularized linear models
- Decision trees and random forests
- Gradient boosting (XGBoost)
- Support vector machines
- k-NN
- k-means
- Gaussian processes
- Neural networks
- CNNs
- RNN/LSTM
- Transformers
- Autoencoders
- GANs
- Diffusion models
- Graph neural networks
- Reinforcement learning
- Transfer learning
- Federated learning
- Explainable AI (SHAP, LIME)
- Physics-informed neural networks
- Bayesian optimization
- Active learning
- Symbolic regression
- Genetic algorithms and particle swarm optimization
- Dimensionality reduction (t-SNE, UMAP)
- NLP and large language models
- Retrieval-augmented generation
- Computer vision (detection, segmentation)
- Anomaly detection
- Machine-learned interatomic potentials
- AutoML
