Normalizing Flows: Foundations
Invertible transformations for density estimation: the change of variables formula, coupling layers, autoregressive flows, and the tradeoff between expressiveness and computational cost.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- The Change of Variables Formula
- Designing Invertible Transformations
- Coupling Layers (RealNVP)
- Autoregressive Flows (MAF/IAF)
- Residual Flows
- Training via Maximum Likelihood
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Derive the change of variables formula and the role of the Jacobian determinant.
- Explain coupling layers and why their Jacobian is triangular.
- Compare autoregressive flows (fast density, slow sampling) vs inverse autoregressive (fast sampling, slow density).
- Derive the maximum likelihood training objective for normalizing flows.
- Analyze the expressiveness-computation tradeoff.
Notation
- — base distribution
- — invertible transformation
- — generated sample
- — Jacobian determinant of
Core Intuition
A normalizing flow transforms a simple distribution (Gaussian) into a complex one (data distribution) through a chain of invertible functions. Because each function is invertible, we can compute the exact likelihood of any data point — unlike VAEs (approximate) or GANs (no likelihood). The cost: invertibility constrains the architecture.
Interactive: Normalizing Flow Transformation
z ~ N(0, I)
x = f(z)
Flow type:
The Change of Variables Formula
If where is a diffeomorphism:
Log-likelihood:
Composition of flows: :
Designing Invertible Transformations
Requirements:
- Must be invertible (bijective).
- Jacobian determinant must be efficiently computable (not ).
- Must be expressive enough to model complex distributions.
Strategies for efficient Jacobian:
- Triangular Jacobian: product of diagonal → .
- Fixed-point iteration for inversion.
- Structured matrices (orthogonal, permutation).
Coupling Layers (RealNVP)
Split input :
where are arbitrary neural networks (no invertibility constraint on them).
Inverse (trivial):
Jacobian: Lower triangular → . Cost: .
Expressiveness: Alternate which dimensions are "frozen" () vs "transformed" () across layers.
Autoregressive Flows (MAF/IAF)
Masked Autoregressive Flow (MAF):
- Density evaluation: passes (all known → parallel).
- Sampling: sequential steps (must compute in order).
Inverse Autoregressive Flow (IAF): Reverse the direction:
- Sampling: passes (fast).
- Density: sequential steps (slow).
Tradeoff: MAF for density estimation; IAF for fast generation.
Residual Flows
where is Lipschitz-constrained () to ensure invertibility.
Jacobian: Use the matrix determinant lemma or Hutchinson's trace estimator:
Advantage: More expressive than coupling layers (transforms all dimensions simultaneously).
Training via Maximum Likelihood
No adversarial training, no reconstruction loss, no variational bound — exact maximum likelihood.
Common Pitfalls
Pitfall 1. Using too few coupling layers. Each layer only transforms half the dimensions; many layers needed for full expressiveness.
Pitfall 2. Forgetting the log-det-Jacobian term. Without it, the model ignores volume changes and produces poor density estimates.
Pitfall 3. Assuming flows scale to high dimensions easily. The invertibility constraint limits expressiveness; flows typically underperform diffusion models on image generation.
Summary
- Normalizing flows: exact likelihood via change of variables.
- Coupling layers: Split-transform-merge; triangular Jacobian, cost.
- Autoregressive: Full expressiveness but sequential in one direction.
- Residual flows: Lipschitz-constrained for invertibility; trace estimation for Jacobian.
- Training: straightforward maximum likelihood.
Exercises
Exercise 1. Derive the Jacobian determinant for a coupling layer (equation 4).
Exercise 2. Prove that a composition of invertible functions is invertible with Jacobian = product of Jacobians.
Exercise 3. Show that MAF is equivalent to a Gaussian autoregressive model with learned mean and variance.
Exercise 4. For a residual flow with : bound the condition number of the Jacobian.
Exercise 5. Compare the sample quality (FID) achievable by normalizing flows vs diffusion models on CIFAR-10. Explain the gap.