Foundation reference

Normalizing Flows: Exact Likelihood via Invertible Transforms

Discrete normalizing flows give exact log-likelihoods, unlike GANs, and sample by transforming a base draw without Markov chain sampling, which energy-based models typically use. Continuous flows require numerical ODE integration for sampling and likelihood evaluation.

A newer notebook covers this concept. This older page keeps its summary, math and sources.

Concept 39 of 100Generative ModelsStudy phase 4
Key equation
log⁡px(x)=log⁡pz(f−1(x))+log⁡∣det⁡∂f−1∂x∣\log p_x(x) = \log p_z(f^{-1}(x)) + \log \left| \det \frac{\partial f^{-1}}{\partial x} \right|
Reading map and next steps

Study guide

Where to start

Concept 39 of 100Normalizing FlowsGenerative Models · Study phase 4: Generative modeling families
Question

Why must a flow be invertible and also have a Jacobian determinant that is cheap to compute, and how do coupling layers and autoregressive flows achieve both?

How to study this pagePredict · Check · Generalize · Continue
PredictSay what you expect.

Before you use the demo in the newer notebook, say what you expect to change.

CheckCheck against the math and the papers.

Compare what the notebook demo shows with the key equation here and with the papers cited below.

GeneralizeName what stays the same.

Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.

ContinueContinue in the newer notebook.

The newer notebook covers the same concept and has an interactive demo.

Why It Matters for Modern Models

  • Discrete normalizing flows give exact log-likelihoods, unlike GANs, and sample by transforming a base draw without Markov chain sampling, which energy-based models typically use. Continuous flows require numerical ODE integration for sampling and likelihood evaluation.
  • Continuous normalizing flows are the model class that flow matching trains, so flows are the direct ancestor of flow-matching generators (Lipman et al., 2023).
  • The requirements of invertibility and a cheap Jacobian determinant explain the shape of flow architectures such as coupling and autoregressive layers.

Questions to Think About

  • A VAE optimizes a lower bound on log p(x) while a flow computes it exactly; what does the flow pay for that exactness?
  • How does flow matching avoid Jacobian determinants during training, and why is the flow it learns not, in general, the optimal transport map?

Interactive Demo

The interactive demo for this concept is in the newer notebook.

Open the notebook demo

Core Math

If you prefer intuition first, try the demo in the newer notebook, then come back for the math.

Key Equation
log⁡px(x)=log⁡pz(f−1(x))+log⁡∣det⁡∂f−1∂x∣\log p_x(x) = \log p_z(f^{-1}(x)) + \log \left| \det \frac{\partial f^{-1}}{\partial x} \right|

Normalizing flows transform a simple base distribution pz(z)p_z(z), usually a standard Gaussian, through an invertible, differentiable function ff:

x=f(z),z∼pzx = f(z), \quad z \sim p_z

The change-of-variables formula gives the exact log-likelihood:

log⁡px(x)=log⁡pz(f−1(x))+log⁡∣det⁡∂f−1∂x∣\log p_x(x) = \log p_z(f^{-1}(x)) + \log \left| \det \frac{\partial f^{-1}}{\partial x} \right|

Composition. For f=fK∘⋯∘f1f = f_K \circ \cdots \circ f_1 with zk=fk(zk−1)z_k = f_k(z_{k-1}), z0=zz_0 = z and zK=xz_K = x, the log-determinants add up:

log⁡px(x)=log⁡pz(z0)−∑k=1Klog⁡∣det⁡∂fk∂zk−1∣\log p_x(x) = \log p_z(z_0) - \sum_{k=1}^K \log \left| \det \frac{\partial f_k}{\partial z_{k-1}} \right|

The minus sign appears because these are the Jacobians of the forward maps, from noise toward data; it is the same formula as above. Coupling layers make each Jacobian triangular, so its determinant is just the product of the diagonal (Dinh et al., 2017).

Continuous flows. In the limit of many small steps, a flow becomes an ordinary differential equation dz/dt=vθ(z,t)dz/dt = v_\theta(z, t), whose log-density changes by −tr⁡(∂vθ/∂z)-\operatorname{tr}(\partial v_\theta / \partial z) along the path (Chen et al., 2018). Flow matching trains such a velocity field by regression, without integrating the equation during training (Lipman et al., 2023).

Key Papers

Variational Inference with Normalizing Flows

Rezende & Mohamed2015ICML
Read paper →

Density estimation using Real NVP

Dinh, Sohl-Dickstein & Bengio2017ICLR
Read paper →

Glow: Generative Flow with Invertible 1×1 Convolutions

Kingma & Dhariwal2018NeurIPS
Read paper →

Normalizing Flows for Probabilistic Modeling and Inference

Papamakarios et al.2021JMLR
Read paper →

Connections

Where to go next

A newer notebook covers Normalizing Flows, with an interactive demo.

Continue in the newer notebook