Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Shift half, keep half
Imagine a deck of cards split into two piles. You leave the left pile untouched and use it as instructions for how to slide each card in the right pile. Anyone holding the result can undo it: the left pile is still there, so they can read the same instructions and slide the cards back. That is an additive coupling layer. Because cards are only slid, never stretched, no area is created or destroyed. Alternating which pile gives instructions, many times over, can still bend a simple cloud of points into a complex shape. In the demo, set the scale to 0 to see a purely additive coupling warp a grid.
Volume-preserving flows also appear as symplectic and Hamiltonian maps in physics-inspired models for robot and spacecraft dynamics.
- 1. An additive coupling layer changes one half by…
- 2. Its inverse is computed by…
- 3. Its log-determinant is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The NICE architecture
- Coupling: split x = (x_A, x_B); y_A = x_A, y_B = x_B + m(x_A), where m is any network (ReLU MLP in the paper).
- Inverse: x_A = y_A, x_B = y_B − m(y_A). No need to invert m.
- Jacobian: [[I, 0], [∂m/∂x_A, I]], lower triangular with unit diagonal, so det = 1: each coupling preserves volume.
- Alternation: a layer leaves x_A unchanged, so successive layers swap the roles of the halves (NICE used 4 coupling layers).
- Scaling layer: a final diagonal z = s ⊙ h with log-det Σ log |s_i| lets the model change volume; it is the same for every point.
- Prior: NICE used a factorised standard logistic prior (heavier tails, better-behaved gradients) or a Gaussian.
- Results (2014): log-likelihood on MNIST, TFD, SVHN and CIFAR-10, plus inpainting by projected gradient ascent on the exact likelihood.
- Limit: the only volume change is global, so local density contrasts must come from shearing alone; RealNVP (2016) fixed this with affine coupling.
- 1. NICE's Jacobian per coupling is…
- 2. Why alternate halves?
- 3. The scaling layer's log-det is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Building and training NICE
Exercise 1.
- Additive coupling and its exact inverse.
- The diagonal scaling layer and its log-det.
Practice.
- Test round-trip error and the unit determinant of each coupling on random inputs before training.
- Alternate partitions (or use checkerboard / channel masks on images).
- Learn the scaling layer in log space; initialise it at 0.
- Add dequantisation noise for discrete data; report bits per dimension.
- Compare against an affine (RealNVP) or spline coupling with the same depth before choosing NICE.
import torch, torch.nn as nn
class AdditiveCoupling(nn.Module):
def __init__(self, d, hidden, flip):
super().__init__(); self.flip = flip
self.m = nn.Sequential(nn.Linear(d // 2, hidden), nn.ReLU(), nn.Linear(hidden, d // 2))
def forward(self, x): # data -> latent, log-det 0
a, b = x.chunk(2, -1)
if self.flip: a, b = b, a
b = b + self.m(a)
return torch.cat([b, a] if self.flip else [a, b], -1)- 1. A quick correctness test for a coupling layer is…
- 2. The scaling layer is best parameterised as…
- 3. On images, partitions are made with…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Exact invertibility. y_A = x_A means the conditioner’s input is available in both directions, so m can be any function, even non-invertible; the layer is a bijection because it is a shear.
Volume preservation. The Jacobian is block triangular with identity blocks, so det = 1 regardless of m. A composition of couplings therefore preserves volume, and log p(x) = log p_Z(f(x)) + Σ log |s_i| with the scaling layer as the only volume term.
Expressiveness. Volume-preserving maps can still move mass anywhere, but to increase density in one region they must compensate elsewhere; matching both the shape and the spread of the data relies on the scaling layer and the prior.
Exercise check. With 4 additive layers and no scaling, test NLL on moons was 2.269 nats against 2.739 for a Gaussian; the scaling layer improved it to 2.032 (0.24 nats), and 6 layers to 1.886. The per-point log-det spread was exactly 0: every point had the same log-det, as theory says.
- 1. Additive coupling can use a non-invertible m because…
- 2. A stack of additive couplings changes volume…
- 3. In NICE, point-to-point differences in log-det come from…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How far do volume-preserving coupling layers get on a 2-D density, and what does the scaling layer add?
History.
- L. Dinh, D. Krueger and Y. Bengio, “NICE: Non-linear Independent Components Estimation” (2014, ICLR workshop 2015).
- L. Dinh, J. Sohl-Dickstein and S. Bengio, “Density estimation using Real NVP” (2016): affine coupling.
- Volume-preserving flows: J. M. Tomczak and M. Welling (2016), and Hamiltonian-inspired flows.
Exercise 2. 2000 training and 2000 test points of two moons (noise 0.08, standardised).
- Models: Gaussian (closed form); NICE with 4 additive couplings (MLP 1 → 16 tanh → 1), with and without the scaling layer; NICE with 6 couplings and scaling.
- Training: Adam, learning rate 0.02, batch 256, 400 steps; gradients by hand-written backpropagation.
- Reference: the exact NLL of the generating density (curve convolved with the noise, by quadrature).
| model | seed 0 | seed 1 | seed 2 |
|---|---|---|---|
| Gaussian | 2.739 | 2.732 | 2.718 |
| NICE 4, no scaling | 2.269 | 2.272 | 2.300 |
| NICE 4 + scaling | 2.032 | 2.065 | 2.068 |
| NICE 6 + scaling | 1.886 | 1.936 | 1.973 |
| true density | 1.605 | 1.608 | 1.621 |
- Volume-preserving layers alone beat the Gaussian by about 0.45 nats: shearing bends the cloud into the moons.
- The scaling layer added about 0.2 nats on every seed, and depth helped further.
- Still short: the best model was 0.28 to 0.35 nats above the true density; the thin moons need local volume changes that NICE cannot make.
- Invertibility: round-trip error about 1e-15 (below 1e-12); log-det identical for every test point.
- Caveat: small networks and short training; longer training narrows but does not remove the gap.
NICE in AI, robotics and aerospace
- Historical role: NICE showed that deep models with exact likelihoods and exact inverses were possible, the starting point for RealNVP, Glow and the coupling flows used today.
- Volume-preserving maps: the same shear construction gives symplectic integrators and Hamiltonian flows used for physics-aware dynamics models.
- Invertible networks: additive coupling is the core of reversible residual networks (RevNets, i-RevNet), which save activation memory by recomputing inputs from outputs.
References
- L. Dinh, D. Krueger and Y. Bengio (2015). “NICE: Non-linear independent components estimation.” ICLR Workshop.
- L. Dinh, J. Sohl-Dickstein and S. Bengio (2017). “Density estimation using Real NVP.” ICLR.
- A. N. Gomez, M. Ren, R. Urtasun and R. B. Grosse (2017). “The reversible residual network.” NeurIPS.
- G. Papamakarios et al. (2021). “Normalizing flows for probabilistic modeling and inference.” JMLR.