📋 KEY INSIGHTS
- Normalising flows learn an exact, tractable probability density by transforming a simple base distribution (Gaussian) through a sequence of invertible, differentiable functions.
- Unlike VAEs and GANs, flows provide exact log-likelihood computation and exact latent-space inversion — both forward (density evaluation) and inverse (sample generation) are available in closed form.
- RealNVP uses coupling layers — splitting the input, transforming one half conditioned on the other — to build a powerful bijection whose Jacobian determinant is cheap to compute.
- Masked Autoregressive Flow (MAF) achieves higher expressiveness by using autoregressive transformations, but only supports efficient density evaluation (not generation); Inverse Autoregressive Flow (IAF) flips this for fast generation.
- Neural spline flows replace affine coupling layers with monotone rational-quadratic splines, dramatically improving expressiveness per layer with minimal additional computational cost.
- Continuous normalising flows (CNFs) parameterise the flow as an ODE whose vector field is a neural network, enabling flexible density estimation without the layered architecture constraint.
Generative models learn the data distribution P(x). VAEs and GANs are powerful but have limitations: VAEs maximise a lower bound on the likelihood (not the exact likelihood), and GANs do not provide any likelihood estimate at all. Normalising flows take a different approach: construct an invertible transformation from a simple known distribution (usually a standard Gaussian) to the data distribution, so that exact likelihoods can be computed by the change-of-variables formula. This makes flows uniquely valuable for density estimation, anomaly detection, uncertainty quantification, and simulation-based inference.
This guide covers the full normalising flows landscape: the change-of-variables formula and Jacobian determinant, planar and radial flows, RealNVP coupling layers, Glow, Masked Autoregressive Flow (MAF) and Inverse Autoregressive Flow (IAF), neural spline flows, and continuous normalising flows (CNFs) via neural ODEs.
Change of Variables, RealNVP and Autoregressive Flows
The change-of-variables formula is the mathematical foundation of normalising flows. If z ~ p_z(z) is a sample from the base distribution and x = f(z) is a bijective (invertible, differentiable) transformation, then the density of x is log p_x(x) = log p_z(f^{-1}(x)) + log |det J_{f^{-1}}(x)|, where J is the Jacobian matrix of partial derivatives. The log-determinant term accounts for the volume change under the transformation. For a composition of K flows f = f_K ∘ … ∘ f_1, the log-determinant is the sum of individual log-determinants — which is why normalising flows are composable. The key design challenge: choosing transformations f_k that are (1) expressive enough to model complex distributions, (2) computationally efficient to invert, and (3) have tractable log-determinant computation. The connection to our calculus for ML guide is direct: the Jacobian determinant is a matrix derivative — the same chain rule and partial derivative concepts described there for backpropagation determine the log-determinant computation, and autograd frameworks (PyTorch autograd) compute the Jacobian automatically for small-dimensional problems.
RealNVP (Real-valued Non-Volume Preserving transformations, Dinh et al., 2017) uses coupling layers to build an expressive bijection with cheap Jacobian computation. Each coupling layer splits the input x into two halves (x_1, x_2) and transforms only one: x_2′ = x_2 ⊙ exp(s(x_1)) + t(x_1), x_1′ = x_1 unchanged. The scale s and translation t networks can be arbitrary (deep CNNs or MLPs) because they only affect x_2, so the Jacobian of the coupling layer is lower-triangular — its determinant is just the product of diagonal elements exp(Σ s_i(x_1)), computable in O(d) rather than O(d^3). Stacking multiple coupling layers with alternating halves creates a highly expressive bijection. Glow (Kingma and Dhariwal, 2018) adds 1×1 invertible convolutions between coupling layers, enabling full mixing of dimensions and achieving state-of-the-art image generation quality (256×256 natural images) with a flow model. The connection to our neural architectures guide is direct: the scale and translation networks in RealNVP coupling layers are standard CNNs or ResNets — the same architectural building blocks described there (convolutional layers, residual connections, batch norm) are used unchanged inside the flow coupling layers, with the only constraint being that they need not be invertible themselves.
Masked Autoregressive Flow (MAF, Papamakarios et al., 2017) uses an autoregressive transformation: each dimension x_i is transformed conditioned on all previous dimensions x_{1:i-1}: x_i = exp(α_i) z_i + μ_i, where μ_i = f_μ(x_{1:i-1}) and α_i = f_α(x_{1:i-1}) are outputs of a masked autoregressive network (MADE). The Jacobian of an autoregressive transformation is triangular, so the log-determinant is O(d). MAF achieves higher density estimation accuracy than RealNVP on many benchmarks because the autoregressive conditioning is more expressive than the coupling layer split. The trade-off: MAF supports fast density evaluation (a single forward pass through the autoregressive network) but slow sampling (d sequential passes, since each x_i must be sampled before x_{i+1}). Inverse Autoregressive Flow (IAF) flips the dependency: fast sampling, slow density evaluation. The connection to our Transformers guide is direct: MAF’s masked autoregressive network (MADE) uses the same causal masking as the GPT decoder described there — both mask the attention or weight matrix so that position i only attends to positions 1 to i-1, enforcing the autoregressive factorisation.
| Flow Type | Fast Density? | Fast Sampling? | Expressiveness | Key Use |
|---|---|---|---|---|
| RealNVP | Yes | Yes | Medium | Image generation; tabular density |
| Glow | Yes | Yes | Medium-high | High-res image generation |
| MAF | Yes | No (sequential) | High | Density estimation; SBI |
| IAF | No (sequential) | Yes | High | Variational inference posterior |
| Neural Spline Flow | Yes | Yes | Very high | Tabular data; SBI |
| CNF (Neural ODE) | Yes (ODE solve) | Yes (ODE solve) | Very high | Continuous-time; point clouds |
Neural Spline Flows, Continuous Flows and Applications
Neural spline flows (Durkan et al., 2019) replace the affine coupling transformation exp(s) z + t (which maps a line to a line) with a monotone rational-quadratic spline — a piecewise polynomial that can represent highly non-linear monotone functions. Each spline is defined by K knots (positions where the polynomial pieces join), parameterised by a small network. The Jacobian of the spline is the derivative of the spline function, which is analytically available. Neural spline flows achieve 15–20% better density estimation (measured by bits-per-dimension on image benchmarks) than RealNVP with the same number of layers, while adding only a small computational overhead for the spline evaluation. They are now the standard building block for simulation-based inference (SBI) packages (sbi, BayesFlow) because of their accuracy on the multi-modal posteriors typical of astrophysical and neuroscience problems. The connection to our Gaussian processes guide is direct: neural spline flows are related to GP regression via splines — both use piecewise polynomial functions to model smooth, flexible mappings, with the key difference that the flow spline is a deterministic monotone bijection while the GP uses spline basis functions as the kernel.
Continuous normalising flows (CNFs, Chen et al., 2018) parameterise the transformation as the solution to an ODE: dx/dt = f_θ(x, t), where f_θ is a neural network. The flow maps the base distribution at t=0 to the data distribution at t=1 by integrating the ODE. The log-density change is computed by the instantaneous change-of-variables formula: d(log p)/dt = -Tr(∂f/∂x), where the trace of the Jacobian replaces the full log-determinant. The trace can be estimated cheaply using the Hutchinson trace estimator (a stochastic method using random projection vectors). CNFs are more flexible than discrete layered flows because the vector field f_θ can be an arbitrary neural network, and the architecture does not impose any coupling or autoregressive structure. The connection to our Neural ODE guide is direct: CNFs are normalising flows built on neural ODEs — the ODE integration framework described there (adjoint sensitivity method for training, adaptive step-size solvers) is the backbone of CNF training and sampling, and flow matching (a recent efficient CNF training method) connects back to score-based models.
Normalising flows have three primary application domains: (1) exact density estimation for anomaly detection (a test point with log p(x) below a threshold is flagged as an anomaly — unlike VAE reconstruction error, flow log-likelihood is an exact probability score); (2) variational inference as the posterior approximator (IAF produces a flexible posterior q(z|x) that can capture complex dependencies, addressing the mean-field limitation of standard VI); (3) simulation-based inference (MAF and neural spline flows as the posterior estimator in NPE, amortising Bayesian inference for intractable scientific simulators). The connection to our Bayesian deep learning guide is direct: flows as variational posteriors in variational autoencoders and variational inference address the expressiveness limitation of Gaussian posteriors described there — an IAF posterior can capture multi-modality and complex correlations that the diagonal Gaussian posterior of a standard VAE cannot.
✦ SUMMARIZE THIS ARTICLE WITH AI
Calculus for ML (Jacobian determinant computation; chain rule for log-determinant of composed flows) is in our Calculus guide. Neural architectures (CNNs and ResNets inside RealNVP coupling layers) are in our Neural Architectures guide. Transformers (MAF masked autoregressive network connection to GPT causal masking) are in our Transformers guide. Neural ODEs (continuous normalising flows as ODE-parameterised bijections) are in our Neural ODEs guide. Bayesian deep learning (IAF as flexible variational posterior; flows for uncertainty quantification) is in our Bayesian DL guide. Score-based models (flow matching as a bridge between CNFs and diffusion) are in our Score-Based Models guide. Gaussian processes (spline connections; GP as flexible density model alternative) are in our Gaussian Processes guide. ML for astronomy (NPE with neural spline flows for GW parameter estimation) is in our ML for Astronomy guide.



