Simple Algorithm
Machine Learning · Convergence · 28 min

Normalizing Flows & Deep Density Models

Exact likelihoods through invertible maps.

A normalizing flow turns a simple density into a complicated one through an invertible network, and pays for the flexibility with one bookkeeping term: the log-determinant of a Jacobian. That single term dictates every architecture in the family. This lesson derives the change-of-variables objective, builds layers whose determinants are cheap, proves that triangular maps can carry any positive density onto any other, and follows the idea to continuous-time flows and flow matching, the bridge to diffusion models.

What you’ll learn

  • Derive the change-of-variables formula and the maximum-likelihood objective of a flow, and show that maximizing likelihood minimizes the forward KL divergence.
  • Build coupling layers (NICE, RealNVP, Glow) and autoregressive layers (MAF, IAF) with triangular Jacobians, and explain their trade-off between density evaluation and sampling.
  • Prove the Knothe–Rosenblatt construction, which makes increasing triangular maps universal, and explain the topological limits of flows.
  • Derive the instantaneous change of variables, Hutchinson's trace estimator and the flow-matching objective, and compare flows with VAEs, GANs and diffusion models.

Change of variables and maximum likelihood

A normalizing flow starts from a base density pZp_Z, usually N(0,I)\mathcal N(\mathbf 0,I), and a diffeomorphism g:Rd→Rdg:\R^d\to\R^d. Sampling is z∼pZ\mathbf z\sim p_Z, x=g(z)\mathbf x=g(\mathbf z). Density evaluation runs the inverse f=g−1f=g^{-1}, the direction that "normalizes" data into noise.

DerivationThe change-of-variables formula
  1. pX(x)=pZ(f(x)) f′(x)p_X(x)=p_Z\big(f(x)\big)\,f'(x)

    In one dimension with gg increasing, P(X≤x)=P(Z≤f(x))P(X\le x)=P(Z\le f(x)). Differentiate:

  2. pX(x)=pZ(f(x)) ∣det⁡Jf(x)∣,Jf(x)=∂f∂xp_X(\mathbf x)=p_Z\big(f(\mathbf x)\big)\,\abs{\det J_f(\mathbf x)},\qquad J_f(\mathbf x)=\frac{\partial f}{\partial\mathbf x}

    In dd dimensions the substitution rule for integrals, ∫ApX=∫f(A)pZ\int_Ap_X=\int_{f(A)}p_Z for every set AA, gives the absolute Jacobian determinant, the local factor by which ff stretches volume:

  3. log⁡pX(x)=log⁡pZ(zK)+∑k=1Klog⁡∣det⁡Jfk(zk−1)∣\log p_X(\mathbf x)=\log p_Z(\mathbf z_K)+\sum_{k=1}^K\log\abs{\det J_{f_k}(\mathbf z_{k-1})}

    Stack KK invertible layers, f=fK∘⋯∘f1f=f_K\circ\dots\circ f_1, with z0=x\mathbf z_0=\mathbf x and zk=fk(zk−1)\mathbf z_k=f_k(\mathbf z_{k-1}). Determinants multiply, so log-determinants add:

  4. Epdata[log⁡pθ(x)]=−H(pdata)−DKL(pdata ∥ pθ)\E_{p_{\text{data}}}\big[\log p_\theta(\mathbf x)\big]=-H(p_{\text{data}})-\KL\big(p_{\text{data}}\,\|\,p_\theta\big)

    Fit by maximum likelihood. Averaged over the data distribution, the log-likelihood is minus a cross-entropy, which splits into the data's entropy (fixed) and a KL divergence:

Maximum likelihood therefore minimizes the forward KL divergence, which punishes a model for putting little mass where data occur: flows trained this way are mass-covering. Flows used for variational inference (Rezende & Mohamed, 2015) minimize the reverse divergence DKL(pθ ∥ p)\KL(p_\theta\,\|\,p) instead, which needs only samples from pθp_\theta and an unnormalized target pp.

A general d×dd\times d determinant costs O(d3)O(d^3), hopeless when dd is the number of pixels, so the whole art is to design layers with triangular Jacobians, whose determinants are products of diagonal entries. Two practical details. Discrete data such as 8-bit pixels are dequantized by adding uniform noise on [0,1)[0,1) to each integer value; by Jensen's inequality the continuous model's expected log-density is then a lower bound on the discrete log-likelihood. And image likelihoods are reported in bits per dimension, −log⁡2p(x)/d-\log_2p(\mathbf x)/d on the 0–255 pixel scale.

Check your understanding

A density pXp_X on R100\R^{100} is pushed through y=2x\mathbf y=2\mathbf x. What is log⁡pY(2x)−log⁡pX(x)\log p_Y(2\mathbf x)-\log p_X(\mathbf x)?

  1. +100ln⁡2≈+69.3+100\ln2\approx+69.3 nats
  2. 00: rescaling does not change densities
  3. −100ln⁡2≈−69.3-100\ln2\approx-69.3 nats
  4. −ln⁡2≈−0.69-\ln2\approx-0.69 nats
Show the answer

C. −100ln⁡2≈−69.3-100\ln2\approx-69.3 nats

The inverse map is f(y)=y/2f(\mathbf y)=\mathbf y/2 with det⁡Jf=2−100\det J_f=2^{-100}, so pY(y)=pX(y/2) 2−100p_Y(\mathbf y)=p_X(\mathbf y/2)\,2^{-100}. Stretching every axis by 2 multiplies volume by 21002^{100}, and the same probability spread over more volume means lower density.

Layers with triangular Jacobians

Coupling layers (NICE: Dinh, Krueger & Bengio, 2015; RealNVP: Dinh, Sohl-Dickstein & Bengio, 2017) split x=(xA,xB)\mathbf x=(\mathbf x_A,\mathbf x_B), leave one half alone and transform the other with parameters computed from the first. The networks s\mathbf s and t\mathbf t are arbitrary: they are never inverted.

DerivationAffine coupling: cheap determinant, exact inverse
  1. yA=xA,yB=xB⊙exp⁡(s(xA))+t(xA)\mathbf y_A=\mathbf x_A,\qquad\mathbf y_B=\mathbf x_B\odot\exp\big(\mathbf s(\mathbf x_A)\big)+\mathbf t(\mathbf x_A)

    The forward map:

  2. J=(I0∂yB∂xAdiag⁡(es(xA))),log⁡∣det⁡J∣=∑jsj(xA)J=\begin{pmatrix}I&0\\[2pt]\dfrac{\partial\mathbf y_B}{\partial\mathbf x_A}&\operatorname{diag}\big(e^{\mathbf s(\mathbf x_A)}\big)\end{pmatrix},\qquad\log\abs{\det J}=\sum_js_j(\mathbf x_A)

    The Jacobian is block lower triangular, with the identity in one diagonal block and a diagonal matrix in the other. The messy block ∂yB/∂xA\partial\mathbf y_B/\partial\mathbf x_A does not enter the determinant:

  3. xA=yA,xB=(yB−t(yA))⊙exp⁡(−s(yA))\mathbf x_A=\mathbf y_A,\qquad\mathbf x_B=\big(\mathbf y_B-\mathbf t(\mathbf y_A)\big)\odot\exp\big(-\mathbf s(\mathbf y_A)\big)

    Inversion only re-evaluates s\mathbf s and t\mathbf t on the unchanged half:

Successive layers alternate which half is transformed, so every coordinate gets updated. NICE uses the additive case s=0\mathbf s=\mathbf 0, which preserves volume, plus a final diagonal scaling. Glow (Kingma & Dhariwal, 2018) adds activation normalization and an invertible 1×11\times1 convolution: one learned c×cc\times c matrix WW mixes the channels at each of the h⋅wh\cdot w pixel positions, adding h wlog⁡∣det⁡W∣h\,w\log\abs{\det W} to the log-determinant, and an LU factorization of WW makes that cheap.

Autoregressive flows make each coordinate an affine function of a noise variable, given the coordinates before it: xi=μi(x<i)+σi(x<i) zix_i=\mu_i(\mathbf x_{<i})+\sigma_i(\mathbf x_{<i})\,z_i with σi>0\sigma_i>0. The Jacobian of x↦z\mathbf x\mapsto\mathbf z is triangular, so log⁡∣det⁡Jf∣=−∑ilog⁡σi(x<i)\log\abs{\det J_f}=-\sum_i\log\sigma_i(\mathbf x_{<i}). The masked autoregressive flow (MAF; Papamakarios, Pavlakou & Murray, 2017) computes all μi,σi\mu_i,\sigma_i from x\mathbf x in one pass of a masked network, so density evaluation is fast, but sampling must produce x1,x2,…x_1,x_2,\dots in turn. The inverse autoregressive flow (IAF; Kingma, Salimans, Jozefowicz, Chen, Sutskever & Welling, 2016) conditions on z<i\mathbf z_{<i} instead, making sampling one pass and the density of an arbitrary x\mathbf x sequential. It suits variational posteriors, which only need the densities of their own samples. RealNVP is the special case of MAF in which half the coordinates are left unchanged and the other half are conditioned only on that half.

Layerlog⁡∣det⁡J∣\log\abs{\det J}Density of dataSampling
Additive coupling (NICE)00one passone pass
Affine coupling (RealNVP)∑jsj(xA)\sum_js_j(\mathbf x_A)one passone pass
1×11\times1 convolution (Glow)h wlog⁡∣det⁡W∣h\,w\log\abs{\det W}one passone pass
Masked autoregressive (MAF)−∑ilog⁡σi(x<i)-\sum_i\log\sigma_i(\mathbf x_{<i})one passdd sequential passes
Inverse autoregressive (IAF)∑ilog⁡σi(z<i)\sum_i\log\sigma_i(\mathbf z_{<i}), generator directiondd sequential passesone pass
Coupling layers are cheap both ways but change only half the coordinates per layer, so they need depth. Autoregressive layers are more expressive per layer and fast in one direction only.
python
import torch
import torch.nn as nn

class AffineCoupling(nn.Module):
    """y_A = x_A,  y_B = x_B * exp(s(x_A)) + t(x_A).  d must be even."""
    def __init__(self, d, hidden=256):
        super().__init__()
        self.net = nn.Sequential(nn.Linear(d // 2, hidden), nn.ReLU(),
                                 nn.Linear(hidden, d))   # outputs s and t
    def forward(self, x):                                # x -> (y, log|det J|)
        xa, xb = x.chunk(2, dim=-1)
        s, t = self.net(xa).chunk(2, dim=-1)
        s = torch.tanh(s)                                # keep the scales bounded
        return torch.cat([xa, xb * torch.exp(s) + t], dim=-1), s.sum(dim=-1)
    def inverse(self, y):
        ya, yb = y.chunk(2, dim=-1)
        s, t = self.net(ya).chunk(2, dim=-1)
        s = torch.tanh(s)
        return torch.cat([ya, (yb - t) * torch.exp(-s)], dim=-1)

A full flow stacks such layers with permutations between them, sums the returned log-determinants, and adds log⁡pZ(z)\log p_Z(\mathbf z) of the final output; training maximizes that total over mini-batches.

Triangular maps are universal

DerivationConstruction
  1. u1=F1(x1),ui=Fi(xi∣x1,…,xi−1),Fi(s∣x<i)=P(Xi≤s∣X<i=x<i)u_1=F_1(x_1),\qquad u_i=F_i\big(x_i\mid x_1,\dots,x_{i-1}\big),\qquad F_i(s\mid\mathbf x_{<i})=P\big(X_i\le s\mid\mathbf X_{<i}=\mathbf x_{<i}\big)

    Map pp to the uniform distribution on (0,1)d(0,1)^d one coordinate at a time, using conditional distribution functions:

  2. det⁡JSp(x)=∏i=1dp(xi∣x<i)=p(x)\det J_{S_p}(\mathbf x)=\prod_{i=1}^dp(x_i\mid\mathbf x_{<i})=p(\mathbf x)

    Given X<i\mathbf X_{<i}, the variable Ui=Fi(Xi∣X<i)U_i=F_i(X_i\mid\mathbf X_{<i}) is uniform (the probability integral transform), whatever the condition. So UiU_i is uniform and independent of U1,…,Ui−1U_1,\dots,U_{i-1}, which are functions of X<i\mathbf X_{<i}, and U=Sp(X)\mathbf U=S_p(\mathbf X) is uniform on the cube. The map SpS_p is triangular with ∂ui/∂xi=p(xi∣x<i)>0\partial u_i/\partial x_i=p(x_i\mid\mathbf x_{<i})>0, so

  3. T=Sq−1∘Sp,T(X)∼q  when  X∼pT=S_q^{-1}\circ S_p,\qquad T(\mathbf X)\sim q\ \text{ when }\ \mathbf X\sim p

    Build SqS_q the same way. It is invertible, and the inverse of an increasing triangular map is increasing triangular, as is a composition of two. So TT below pushes pp to qq. Uniqueness: given x<i\mathbf x_{<i}, the ii-th component must carry one conditional distribution onto another monotonically, and in one dimension that map is unique.

Read backward, Sp−1S_p^{-1} generates x\mathbf x coordinate by coordinate from independent uniforms, xi=Fi−1(ui∣x<i)x_i=F_i^{-1}(u_i\mid\mathbf x_{<i}): an autoregressive flow whose ii-th map is a conditional quantile function. So autoregressive flows whose per-coordinate maps can be any increasing function, such as monotone neural networks (Huang, Krueger, Lacoste & Courville, 2018) or monotone splines, are universal density approximators. A single affine layer is not, and depth, permutations between layers or richer monotone maps restore the expressivity. Coupling flows built from affine layers can also approximate a broad class of diffeomorphisms (Teshima et al., 2020).

Limits. A flow is a diffeomorphism of Rd\R^d, so its density is positive everywhere and the Gaussian's single blob can be stretched and folded but never torn. A target whose support has separate pieces or holes can only be approximated by squeezing mass out of the gaps, which takes very large and very small Jacobians, and well-separated modes strain a flow in the same way. Cornish, Caterini, Deligiannidis & Doucet (2020) prove that approximating a target whose support differs topologically from the base's ever more closely forces the flow to become arbitrarily close to non-invertible, numerically. Data concentrated near a lower-dimensional set, as images are, strain flows in a similar way.

Check your understanding

With a standard Gaussian base, which densities can a single affine autoregressive layer xi=μi(x<i)+σi(x<i) zix_i=\mu_i(\mathbf x_{<i})+\sigma_i(\mathbf x_{<i})\,z_i represent?

  1. Any density, because it is autoregressive
  2. Only the standard Gaussian
  3. Only densities with independent coordinates
  4. Exactly those whose conditionals p(xi∣x<i)p(x_i\mid\mathbf x_{<i}) are Gaussian, with means and variances that may depend on x<i\mathbf x_{<i}
Show the answer

D. Exactly those whose conditionals p(xi∣x<i)p(x_i\mid\mathbf x_{<i}) are Gaussian, with means and variances that may depend on x<i\mathbf x_{<i}

Given x<i\mathbf x_{<i}, xix_i is an affine function of one standard normal, so it is Gaussian with mean μi(x<i)\mu_i(\mathbf x_{<i}) and variance σi(x<i)2\sigma_i(\mathbf x_{<i})^2. A bimodal conditional is out of reach; it needs a non-affine monotone map or more layers.

Continuous flows and flow matching

Let depth go to the limit of infinitely many infinitesimal layers. A continuous normalizing flow (Chen, Rubanova, Bettencourt & Duvenaud, 2018) defines z(t)\mathbf z(t) by an ODE, dz/dt=vθ(z(t),t)d\mathbf z/dt=\mathbf v_\theta(\mathbf z(t),t), from z(0)∼p0\mathbf z(0)\sim p_0 to x=z(1)\mathbf x=\mathbf z(1). Any Lipschitz vector field gives an invertible map, since the ODE can be run backward, so the network needs no special structure. The price moves from the architecture to the bookkeeping:

DerivationThe instantaneous change of variables
  1. ∂tpt+∇⋅(pt vθ)=0\partial_tp_t+\nabla\cdot\big(p_t\,\mathbf v_\theta\big)=0

    The density ptp_t of z(t)\mathbf z(t) obeys the continuity equation, conservation of probability mass along the flow:

  2. ddtlog⁡pt(z(t))=∂tpt+vθ⋅∇ptpt=−∇⋅vθ=−tr⁡∂vθ∂z\frac{d}{dt}\log p_t\big(\mathbf z(t)\big)=\frac{\partial_tp_t+\mathbf v_\theta\cdot\nabla p_t}{p_t}=-\nabla\cdot\mathbf v_\theta=-\operatorname{tr}\frac{\partial\mathbf v_\theta}{\partial\mathbf z}

    Follow one trajectory. Since ∇⋅(pv)=v⋅∇p+p ∇⋅v\nabla\cdot(p\mathbf v)=\mathbf v\cdot\nabla p+p\,\nabla\cdot\mathbf v, the total derivative of pt(z(t))p_t(\mathbf z(t)) along the path is

  3. log⁡p1(x)=log⁡p0(z(0))−∫01tr⁡∂vθ∂z(z(t),t) dt\log p_1(\mathbf x)=\log p_0\big(\mathbf z(0)\big)-\int_0^1\operatorname{tr}\frac{\partial\mathbf v_\theta}{\partial\mathbf z}\big(\mathbf z(t),t\big)\,dt

    Integrate from 0 to 1. The sum of log-determinants of a discrete flow becomes an integral of a trace:

  4. tr⁡A=Eε[ε⊤A ε]for any random ε with E[εε⊤]=I\operatorname{tr}A=\E_{\boldsymbol\varepsilon}\big[\boldsymbol\varepsilon^\top A\,\boldsymbol\varepsilon\big]\quad\text{for any random }\boldsymbol\varepsilon\text{ with }\E\big[\boldsymbol\varepsilon\boldsymbol\varepsilon^\top\big]=I

    The exact trace takes about dd vector–Jacobian products. Hutchinson's estimator (Hutchinson, 1989) is unbiased with one, which is how FFJORD (Grathwohl, Chen, Bettencourt, Sutskever & Duvenaud, 2019) scaled continuous flows to images:

Training a continuous flow by maximum likelihood still means solving the ODE at every step. Flow matching (Lipman, Chen, Ben-Hamu, Nickel & Le, 2023) avoids simulation altogether. Choose a path from noise to data, for instance the straight line xt=(1−t)x0+tx1\mathbf x_t=(1-t)\mathbf x_0+t\mathbf x_1 between a noise sample x0∼N(0,I)\mathbf x_0\sim\mathcal N(\mathbf 0,I) and an independent data point x1\mathbf x_1. Conditional on the pair, its velocity is simply x1−x0\mathbf x_1-\mathbf x_0, and the network regresses on that.

DerivationProof of the identity
  1. ∥vθ−w∥2=∥vθ∥2−2 vθ⊤w+∥w∥2\norm{\mathbf v_\theta-\mathbf w}^2=\norm{\mathbf v_\theta}^2-2\,\mathbf v_\theta^\top\mathbf w+\norm{\mathbf w}^2

    Expand both squared errors. The ∥vθ∥2\norm{\mathbf v_\theta}^2 terms are identical, and the terms without vθ\mathbf v_\theta do not depend on θ\theta:

  2. E[vθ(xt,t)⊤(x1−x0)]=E[vθ(xt,t)⊤ E[x1−x0∣xt]]=E[vθ(xt,t)⊤ut(xt)]\E\big[\mathbf v_\theta(\mathbf x_t,t)^\top(\mathbf x_1-\mathbf x_0)\big]=\E\Big[\mathbf v_\theta(\mathbf x_t,t)^\top\,\E\big[\mathbf x_1-\mathbf x_0\mid\mathbf x_t\big]\Big]=\E\big[\mathbf v_\theta(\mathbf x_t,t)^\top\mathbf u_t(\mathbf x_t)\big]

    The cross terms agree by the tower property, conditioning on xt\mathbf x_t:

Sampling solves the learned ODE from noise, and density evaluation integrates the trace along the same path. Diffusion models fit the same frame. Song, Sohl-Dickstein, Kingma, Kumar, Ermon & Poole (2021) showed that a diffusion process has a deterministic ODE with the same marginal distributions, which samples the same distribution and gives exact likelihoods through the instantaneous change of variables; and Gaussian probability paths in flow matching include diffusion-style paths as special cases.

FamilyTrained bylog⁡p(x)\log p(\mathbf x)Sampling costMain weakness
Discrete flowexact maximum likelihoodexactone passlayers restricted to cheap Jacobians
Continuous flow, flow matchinglikelihood with ODE solves, or simulation-free regressionexact, via an ODE and a traceone ODE solve, many network callsslow sampling and likelihood evaluation
Diffusion, score modeldenoising score matching, a weighted ELBObound, or exact via the probability-flow ODEmany denoising stepsslow sampling, though distillation helps
VAEELBOlower bound onlyone passblurrier samples; a gap between the bound and log⁡p\log p
GANadversarial gamenoneone passunstable training; can drop modes
Deep generative models as density estimators. The Artificial Intelligence course's lessons Variational Autoencoders & the ELBO, Generative Adversarial Networks and Diffusion Models develop the last three.

Key takeaways

  • A flow's density is pZ(f(x))∣det⁡Jf(x)∣p_Z(f(\mathbf x))\abs{\det J_f(\mathbf x)}, with log-determinants adding over layers. Maximum likelihood minimizes the forward KL divergence, so flows are mass-covering.
  • Coupling layers (NICE, RealNVP, Glow) and autoregressive layers (MAF, IAF) make Jacobians triangular. Coupling is fast in both directions; MAF is fast for density evaluation and IAF for sampling.
  • The Knothe–Rosenblatt construction, built from conditional distribution functions, shows that increasing triangular maps can push any positive density onto any other, so sufficiently flexible autoregressive flows are universal. Diffeomorphisms cannot change topology, though, so flows strain on supports with holes or separate pieces.
  • Continuous flows replace the log-determinant by −∫tr⁡(∂v/∂z) dt-\int\operatorname{tr}(\partial\mathbf v/\partial\mathbf z)\,dt, estimated with Hutchinson's trick. Flow matching trains them without simulation by regressing on conditional velocities such as x1−x0\mathbf x_1-\mathbf x_0.
  • Diffusion models fit the same frame through their probability-flow ODE, which gives exact likelihoods. Likelihood and sample quality are largely independent measures, so a model must be judged by the one its use requires.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A flow maps data to latents by z=f(x)\mathbf z=f(\mathbf x), with base density pZp_Z. Which expression is log⁡pX(x)\log p_X(\mathbf x)?

  1. log⁡pZ(f(x))−log⁡∣det⁡Jf(x)∣\log p_Z(f(\mathbf x))-\log\abs{\det J_f(\mathbf x)}
  2. log⁡pZ(f(x))+log⁡∣det⁡Jf(x)∣\log p_Z(f(\mathbf x))+\log\abs{\det J_f(\mathbf x)}
  3. log⁡pZ(x)+log⁡∣det⁡Jf(x)∣\log p_Z(\mathbf x)+\log\abs{\det J_f(\mathbf x)}
  4. log⁡pZ(f(x))\log p_Z(f(\mathbf x))
Show the answer

B. log⁡pZ(f(x))+log⁡∣det⁡Jf(x)∣\log p_Z(f(\mathbf x))+\log\abs{\det J_f(\mathbf x)}

Probability is conserved: pX(x) dx=pZ(z) dzp_X(\mathbf x)\,d\mathbf x=p_Z(\mathbf z)\,d\mathbf z, and dz=∣det⁡Jf∣ dxd\mathbf z=\abs{\det J_f}\,d\mathbf x. Where ff expands volume (it spreads data out to look like noise), the data density is correspondingly higher.

Question 2

You train by maximum likelihood on millions of data points and rarely need samples. Which autoregressive layer fits?

  1. IAF, because it samples in one pass
  2. Either: autoregressive layers are equally fast in both directions
  3. Neither: autoregressive flows cannot evaluate densities exactly
  4. MAF, because it evaluates the density of any data point in one pass
Show the answer

D. MAF, because it evaluates the density of any data point in one pass

MAF conditions on x<i\mathbf x_{<i}, so a masked network computes every μi,σi\mu_i,\sigma_i from the data in parallel, and training touches only the fast direction. IAF reverses the trade-off.

Question 3

Why does FFJORD estimate tr⁡(∂v/∂z)\operatorname{tr}(\partial\mathbf v/\partial\mathbf z) with Hutchinson's estimator ε⊤(∂v/∂z) ε\boldsymbol\varepsilon^\top(\partial\mathbf v/\partial\mathbf z)\,\boldsymbol\varepsilon?

  1. The exact trace needs about dd vector–Jacobian products, while the estimate needs one and is unbiased
  2. The trace is undefined for continuous-time flows
  3. It computes the determinant exactly in O(d)O(d) time
  4. It makes the ODE solver more stable
Show the answer

A. The exact trace needs about dd vector–Jacobian products, while the estimate needs one and is unbiased

For any ε\boldsymbol\varepsilon with E[εε⊤]=I\E[\boldsymbol\varepsilon\boldsymbol\varepsilon^\top]=I, E[ε⊤Aε]=tr⁡(A E[εε⊤])=tr⁡A\E[\boldsymbol\varepsilon^\top A\boldsymbol\varepsilon]=\operatorname{tr}(A\,\E[\boldsymbol\varepsilon\boldsymbol\varepsilon^\top])=\operatorname{tr}A, and ε⊤A\boldsymbol\varepsilon^\top A is one reverse-mode product. The noise this adds to the log-likelihood is the price of unconstrained architectures.

Question 4

Flow matching with straight paths regresses vθ(xt,t)\mathbf v_\theta(\mathbf x_t,t) on x1−x0\mathbf x_1-\mathbf x_0, which is random given xt\mathbf x_t. Why does it still learn the right vector field?

  1. Because x1−x0\mathbf x_1-\mathbf x_0 is in fact determined by xt\mathbf x_t
  2. Because the network memorizes each noise–data pair
  3. Because the conditional loss equals the marginal loss plus a constant, so its minimizer is E[x1−x0∣xt]\E[\mathbf x_1-\mathbf x_0\mid\mathbf x_t], the marginal velocity
  4. It does not: training must solve the ODE to correct the targets
Show the answer

C. Because the conditional loss equals the marginal loss plus a constant, so its minimizer is E[x1−x0∣xt]\E[\mathbf x_1-\mathbf x_0\mid\mathbf x_t], the marginal velocity

Squared error is minimized by a conditional mean. Expanding the square, the cross term agrees with the marginal one by the tower property, and the rest does not depend on θ\theta. Training needs no simulation at all.

Further reading

  • L. Dinh, J. Sohl-Dickstein & S. Bengio, "Density estimation using Real NVP," ICLR (2017).
  • G. Papamakarios, T. Pavlakou & I. Murray, "Masked autoregressive flow for density estimation," NeurIPS (2017).
  • R. T. Q. Chen, Y. Rubanova, J. Bettencourt & D. Duvenaud, "Neural ordinary differential equations," NeurIPS (2018).
  • Y. Lipman, R. T. Q. Chen, H. Ben-Hamu, M. Nickel & M. Le, "Flow matching for generative modeling," ICLR (2023).
  • G. Papamakarios, E. Nalisnick, D. J. Rezende, S. Mohamed & B. Lakshminarayanan, "Normalizing flows for probabilistic modeling and inference," Journal of Machine Learning Research 22(57), 1–64 (2021).