6.3 GANs and normalizing flows (brief)
1. Learn
Section titled “1. Learn”- Understanding Deep Learning (Prince)chapter 15 Generative adversarial networks, sections 15.1–15.2, and chapter 16 Normalizing flows, sections 16.1–16.3
- Goodfellow et al., Generative Adversarial Netssection 4: Proposition 1 and Theorem 1 (the optimal discriminator and the JS divergence)
- Dinh, Sohl-Dickstein and Bengio, Density estimation using Real NVPsection 3: change of variables, coupling layers and masking
2. Bridge
Section titled “2. Bridge”Two other answers to the same question. A VAE (6.2) turns noise into data with a decoder and trains on a bound. GANs and normalizing flows also map noise z to data x with a network, but train it differently. This module is brief: diffusion and flow matching (6.4–6.6) build on the flow idea, and you will not train a GAN (Prince, chapters 15–16).
GANs. A discriminator D learns to tell real samples from generated ones, and the generator learns to fool it (Goodfellow et al. 2014). For a fixed generator the best discriminator is D*(x) = pdata(x) / (pdata(x) + pg(x)), and against it the generator’s objective is 2 JS(pdata ‖ pg) − log 4 (their Proposition 1 and Theorem 1). No density is ever written down, which is why GAN samples can be sharp, and also why training can oscillate or drop modes. In practice the generator minimises −log D(g(z)) instead of log(1 − D(g(z))), which gives it a gradient even when the discriminator wins easily.
Flows. Make the generator invertible, with a Jacobian whose determinant is cheap. Where the generator f⁻¹ stretches space, density thins out by the same factor (where f stretches, it rises), so the change-of-variables formula gives an exact density, log p(x) = log pz(f(x)) + log |det ∂f/∂x|, and training is plain maximum likelihood (Prince, chapter 16). An affine coupling layer keeps half the coordinates fixed and scales and shifts the rest by amounts computed from the fixed half. The Jacobian is triangular, so its log-determinant is the sum of the log-scales, and inverting it needs no network inverse (Dinh et al. 2016, section 3).
The catch. Every layer must be invertible, so a flow keeps the data’s dimension throughout and cannot tear space: one connected Gaussian can only be stretched into two moons with a thin bridge between them (Dinh et al. 2016, figure 1 shows the same smooth warping). Diffusion and flow matching (6.6) keep the continuous, invertible picture but learn it one small time step at a time.
3. Explore
Section titled “3. Explore”GANs and normalizing flows: edit exercises/stubs/m6_3_flows.py on your own machine. This task needs PyTorch, which the in-page runner does not have.
pip install torch # CPU build is enough for the tests
mlc check 6.3Optionally, train a flow yourself. Open notebooks/6.3-flow.ipynb (a CPU is enough) and paste in your 6.3 file. It trains your flow on two moons and on a ring of eight Gaussians, plots samples and densities, and shows how depth and the tanh on the scale affect training.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.