CSE-41XX
Course Curriculum

7. Phase Space Evolution, Liouville's Theorem & Continuous Flow Matching

From Hamiltonian Incompressibility and the Continuity Equation to Continuous Normalizing Flows, Flow Matching, and Optimal Transport

"The phase space is a strange and beautiful world where every point represents an entire universe in a specific microscopic state, and time evolution is nothing other than an incompressible fluid flow." — Ludwig Boltzmann & J. Willard Gibbs

In the previous chapters, we analyzed static equilibrium ensembles, free energy landscapes, and the stochastic dynamics of Brownian particles via the Langevin equation and the Fluctuation-Dissipation theorem. In this chapter, we take a foundational step: we investigate the exact deterministic laws governing how probability distributions evolve through continuous dynamical systems.

We begin in the classical realm of 19th-century statistical mechanics with Hamiltonian mechanics, the phase space probability density ρ(q,p,t)\rho(q, p, t), and Liouville's Theorem, which establishes the profound incompressibility of Hamiltonian phase space flows. We then bridge this classical physics to 21st-century deep learning. By relaxing the Hamiltonian constraint to general vector fields on Euclidean and Riemannian manifolds, we arrive at the General Probability Continuity Equation, the engine behind Continuous Normalizing Flows (CNFs), and Flow Matching (Lipman et al., 2023).

Finally, we establish the exact mathematical dictionary linking Stochastic Differential Equations (SDEs), Fokker-Planck Equations, Deterministic Probability Flow ODEs, and Optimal Transport Flow Matching.


1. Hamiltonian Mechanics and Phase Space Geometry

1.1 The Canonical Coordinates and Symplectic Structure

Consider a classical physical system with dd degrees of freedom. In Newtonian mechanics, the state is specified by positions qRdq \in \mathbb{R}^d and velocities q˙Rd\dot{q} \in \mathbb{R}^d. In Hamiltonian mechanics, the state is elevated to a point in a 2d2d-dimensional phase space ΓR2d\Gamma \cong \mathbb{R}^{2d}, parameterized by canonical generalized coordinates q=(q1,,qd)q = (q_1, \dots, q_d)^\top and their conjugate momenta p=(p1,,pd)p = (p_1, \dots, p_d)^\top.

The state vector is denoted by:

z=(qp)ΓR2dz = \begin{pmatrix} q \\ p \end{pmatrix} \in \Gamma \cong \mathbb{R}^{2d}

The total energy of the system is governed by the scalar Hamiltonian function H(q,p,t):R2d×RRH(q, p, t): \mathbb{R}^{2d} \times \mathbb{R} \to \mathbb{R}. For standard mechanical systems with kinetic energy T(p)T(p) and potential energy V(q)V(q):

H(q,p)=i=1dpi22mi+V(q1,,qd)H(q, p) = \sum_{i=1}^d \frac{p_i^2}{2m_i} + V(q_1, \dots, q_d)

The time evolution of the microstate z(t)z(t) is governed by Hamilton's Canonical Equations of Motion:

q˙i=Hpip˙i=Hqifor i{1,,d}\begin{aligned} \dot{q}_i &= \frac{\partial H}{\partial p_i} \\ \dot{p}_i &= -\frac{\partial H}{\partial q_i} \qquad \text{for } i \in \{1, \dots, d\} \end{aligned}

We can express these equations compactly using the canonical symplectic matrix JR2d×2dJ \in \mathbb{R}^{2d \times 2d}:

z˙=JzH(z)\dot{z} = J \nabla_z H(z)

where:

J=(0IdId0),J=J=J1,J2=I2dJ = \begin{pmatrix} 0 & I_d \\ -I_d & 0 \end{pmatrix}, \quad J^\top = -J = J^{-1}, \quad J^2 = -I_{2d}

Energy Conservation in Autonomous Systems

If the Hamiltonian does not explicitly depend on time (Ht=0\frac{\partial H}{\partial t} = 0), the total energy is strictly conserved along any trajectory:

dHdt=i=1d(Hqiq˙i+Hpip˙i)=i=1d(HqiHpiHpiHqi)=(zH)J(zH)=0\frac{dH}{dt} = \sum_{i=1}^d \left( \frac{\partial H}{\partial q_i} \dot{q}_i + \frac{\partial H}{\partial p_i} \dot{p}_i \right) = \sum_{i=1}^d \left( \frac{\partial H}{\partial q_i}\frac{\partial H}{\partial p_i} - \frac{\partial H}{\partial p_i}\frac{\partial H}{\partial q_i} \right) = (\nabla_z H)^\top J (\nabla_z H) = 0

This holds because JJ is skew-symmetric: vJv=0v^\top J v = 0 for any vector vR2dv \in \mathbb{R}^{2d}.


1.2 Phase Space Probability Density ρ(q,p,t)\rho(q, p, t)

In statistical mechanics, we almost never know the exact microscopic state z(0)z(0) of a system containing N1023N \sim 10^{23} particles. Instead, following Josiah Willard Gibbs, we define a statistical ensemble: a collection of an infinite number of virtual, non-interacting copies of the system, each evolving according to Hamilton's equations under identical macroscopic constraints.

We define the phase space probability density ρ(q,p,t)=ρ(z,t)\rho(q, p, t) = \rho(z, t) such that the probability dPdP of finding the system in an infinitesimal phase volume element d2dz=dqdp=i=1ddqidpid^{2d}z = dq \, dp = \prod_{i=1}^d dq_i \, dp_i at time tt is:

dP=ρ(q,p,t)dq1dqddp1dpd=ρ(z,t)d2dzdP = \rho(q, p, t) \, dq_1 \dots dq_d \, dp_1 \dots dp_d = \rho(z, t) \, d^{2d}z

The density is non-negative and normalized over the entire phase space Γ\Gamma:

ρ(z,t)0,Γρ(z,t)d2dz=1t0\rho(z, t) \ge 0, \quad \int_{\Gamma} \rho(z, t) \, d^{2d}z = 1 \quad \forall t \ge 0

2. Liouville's Theorem: Incompressibility of Phase Space

2.1 The Divergence-Free Nature of Hamiltonian Vector Fields

Consider the phase space velocity vector field v(z)R2dv(z) \in \mathbb{R}^{2d}:

v(z)=z˙=(q˙p˙)=(pHqH)v(z) = \dot{z} = \begin{pmatrix} \dot{q} \\ \dot{p} \end{pmatrix} = \begin{pmatrix} \nabla_p H \\ -\nabla_q H \end{pmatrix}

Let us compute the phase space divergence of this velocity field zv(z)\nabla_z \cdot v(z):

zv(z)=i=1dq˙iqi+i=1dp˙ipi=i=1dqi(Hpi)+i=1dpi(Hqi)=i=1d(2Hqipi2Hpiqi)\begin{aligned} \nabla_z \cdot v(z) &= \sum_{i=1}^d \frac{\partial \dot{q}_i}{\partial q_i} + \sum_{i=1}^d \frac{\partial \dot{p}_i}{\partial p_i} \\ &= \sum_{i=1}^d \frac{\partial}{\partial q_i} \left( \frac{\partial H}{\partial p_i} \right) + \sum_{i=1}^d \frac{\partial}{\partial p_i} \left( -\frac{\partial H}{\partial q_i} \right) \\ &= \sum_{i=1}^d \left( \frac{\partial^2 H}{\partial q_i \partial p_i} - \frac{\partial^2 H}{\partial p_i \partial q_i} \right) \end{aligned}

By Clairaut-Schwarz Theorem on the equality of mixed partial derivatives (assuming HC2H \in C^2):

2Hqipi=2Hpiqi    zv(z)0\frac{\partial^2 H}{\partial q_i \partial p_i} = \frac{\partial^2 H}{\partial p_i \partial q_i} \implies \nabla_z \cdot v(z) \equiv 0

Fundamental Theorem (Hamiltonian Incompressibility)

The phase space velocity field v(z)=JH(z)v(z) = J \nabla H(z) generated by any classical Hamiltonian system is strictly divergence-free (solenoidal):

zz˙=div(v)=0\nabla_z \cdot \dot{z} = \operatorname{div}(v) = 0

Phase space dynamics behave exactly like an incompressible fluid flow.


2.2 Geometric Conservation of Phase Space Volume

Let Φt:ΓΓ\Phi_t: \Gamma \to \Gamma be the Hamiltonian flow map that maps an initial condition z0z_0 to its state at time tt:

z(t)=Φt(z0)z(t) = \Phi_t(z_0)

Consider an arbitrary domain Ω0Γ\Omega_0 \subset \Gamma of initial conditions, which evolves under the flow into Ωt=Φt(Ω0)\Omega_t = \Phi_t(\Omega_0). The volume of this domain at time tt is:

Vol(Ωt)=Ωtd2dz=Ω0detM(t)d2dz0\operatorname{Vol}(\Omega_t) = \int_{\Omega_t} d^{2d}z = \int_{\Omega_0} |\det M(t)| \, d^{2d}z_0

where M(t)=z(t)z0=Φt(z0)z0R2d×2dM(t) = \frac{\partial z(t)}{\partial z_0} = \frac{\partial \Phi_t(z_0)}{\partial z_0} \in \mathbb{R}^{2d \times 2d} is the Jacobian matrix of the flow map.

To see how the Jacobian determinant evolves, we invoke Jacobi's Formula for matrix derivatives:

ddtdet(M(t))=det(M(t))Tr(M˙(t)M(t)1)\frac{d}{dt} \det(M(t)) = \det(M(t)) \operatorname{Tr}\left( \dot{M}(t) M(t)^{-1} \right)

Differentiating the equation of motion z˙(t)=v(z(t))\dot{z}(t) = v(z(t)) with respect to z0z_0:

M˙(t)=ddt(z(t)z0)=v(z(t))z(t)z(t)z0=[zv(z(t))]M(t)\dot{M}(t) = \frac{d}{dt} \left( \frac{\partial z(t)}{\partial z_0} \right) = \frac{\partial v(z(t))}{\partial z(t)} \frac{\partial z(t)}{\partial z_0} = \left[ \nabla_z v(z(t)) \right] M(t)

Multiplying by M(t)1M(t)^{-1} on the right:

M˙(t)M(t)1=zv(z(t))\dot{M}(t) M(t)^{-1} = \nabla_z v(z(t))

Taking the trace of both sides:

Tr(M˙(t)M(t)1)=Tr(zv(z(t)))=zv(z(t))\operatorname{Tr}\left( \dot{M}(t) M(t)^{-1} \right) = \operatorname{Tr}\left( \nabla_z v(z(t)) \right) = \nabla_z \cdot v(z(t))

Substituting this back into Jacobi's Formula:

ddtdet(M(t))=det(M(t))(zv(z(t)))\frac{d}{dt} \det(M(t)) = \det(M(t)) \left( \nabla_z \cdot v(z(t)) \right)

Since zv=0\nabla_z \cdot v = 0 for all Hamiltonian systems:

ddtdet(M(t))=0    det(M(t))=det(M(0))=det(I2d)=1\frac{d}{dt} \det(M(t)) = 0 \implies \det(M(t)) = \det(M(0)) = \det(I_{2d}) = 1

Phase Space Differential Volume Element \delta x \, \delta p on Canonical Coordinate Grid

Harmonic Oscillator Phase Space Trajectory and Volume-Preserving Orbits

Therefore, the phase space volume is strictly invariant under Hamiltonian time evolution:

Vol(Ωt)=Ω01d2dz0=Vol(Ω0)\operatorname{Vol}(\Omega_t) = \int_{\Omega_0} 1 \cdot d^{2d}z_0 = \operatorname{Vol}(\Omega_0)

2.3 The Liouville Equation & Poisson Brackets

Because no systems are created or destroyed, the total probability inside a co-moving volume Ωt\Omega_t is strictly conserved:

ddtΩtρ(z,t)d2dz=0\frac{d}{dt} \int_{\Omega_t} \rho(z, t) \, d^{2d}z = 0

Transforming the integral back to the fixed initial domain Ω0\Omega_0:

ddtΩ0ρ(Φt(z0),t)det(M(t))=1d2dz0=Ω0ddtρ(z(t),t)d2dz0=0\frac{d}{dt} \int_{\Omega_0} \rho(\Phi_t(z_0), t) \underbrace{\det(M(t))}_{= 1} \, d^{2d}z_0 = \int_{\Omega_0} \frac{d}{dt} \rho(z(t), t) \, d^{2d}z_0 = 0

Because this must hold for any arbitrary volume Ω0\Omega_0, the integrand must vanish identically:

ddtρ(z(t),t)=0(Total / Material Derivative)\frac{d}{dt} \rho(z(t), t) = 0 \quad \text{(Total / Material Derivative)}

Expanding the total time derivative using the multivariate chain rule:

dρdt=ρt+i=1d(ρqiq˙i+ρpip˙i)=ρt+zρz˙=0\frac{d\rho}{dt} = \frac{\partial \rho}{\partial t} + \sum_{i=1}^d \left( \frac{\partial \rho}{\partial q_i} \dot{q}_i + \frac{\partial \rho}{\partial p_i} \dot{p}_i \right) = \frac{\partial \rho}{\partial t} + \nabla_z \rho \cdot \dot{z} = 0

Substituting Hamilton's equations q˙i=Hpi\dot{q}_i = \frac{\partial H}{\partial p_i} and p˙i=Hqi\dot{p}_i = -\frac{\partial H}{\partial q_i}:

ρt+i=1d(ρqiHpiρpiHqi)=0\frac{\partial \rho}{\partial t} + \sum_{i=1}^d \left( \frac{\partial \rho}{\partial q_i} \frac{\partial H}{\partial p_i} - \frac{\partial \rho}{\partial p_i} \frac{\partial H}{\partial q_i} \right) = 0

We introduce the Poisson Bracket {,}\{\cdot, \cdot\} between two phase space observables A(q,p)A(q, p) and B(q,p)B(q, p):

{A,B}i=1d(AqiBpiApiBqi)\{ A, B \} \equiv \sum_{i=1}^d \left( \frac{\partial A}{\partial q_i} \frac{\partial B}{\partial p_i} - \frac{\partial A}{\partial p_i} \frac{\partial B}{\partial q_i} \right)

This yields the celebrated Classical Liouville Equation:

ρt={ρ,H}\frac{\partial \rho}{\partial t} = -\{ \rho, H \}

Alternatively, defining the Liouvillian Operator L^{,H}\hat{L} \equiv -\{ \cdot, H \}:

ρt=L^ρ    ρ(t)=eL^tρ(0)\frac{\partial \rho}{\partial t} = \hat{L} \rho \implies \rho(t) = e^{\hat{L} t} \rho(0)

[!NOTE] Physical Interpretation of Liouville's Theorem

  1. Lagrangian Viewpoint (Co-moving observer): As an observer rides along a trajectory z(t)z(t) in phase space, the local probability density surrounding them never changes: dρ(z(t),t)dt=0\frac{d\rho(z(t), t)}{dt} = 0.
  2. Eulerian Viewpoint (Stationary observer): At a fixed coordinate zΓz \in \Gamma, the local density changes at a rate exactly balanced by the advective probability flux: ρt=zρv(z)={ρ,H}\frac{\partial \rho}{\partial t} = -\nabla_z \rho \cdot v(z) = -\{ \rho, H \}.
  3. Equilibrium Ensembles: A distribution is stationary (ρt=0\frac{\partial \rho}{\partial t} = 0) if and only if {ρ,H}=0\{\rho, H\} = 0. This is automatically satisfied whenever ρ(q,p)=f(H(q,p))\rho(q, p) = f(H(q, p)) depends on coordinates only through the conserved energy HH, yielding the Microcanonical Ensemble ρδ(HE)\rho \propto \delta(H - E) and Canonical Ensemble ρeβH\rho \propto e^{-\beta H}.

3. The General Probability Continuity Equation

In modern machine learning, statistics, and non-conservative physics, dynamics are not restricted to Hamiltonian vector fields. The vector field ut(x)Rdu_t(x) \in \mathbb{R}^d can have non-zero divergence (ut0\nabla \cdot u_t \neq 0), representing stretching, compression, and arbitrary smooth deformations of space.

3.1 Derivation from Mass Conservation

Let pt(x):RdR0p_t(x): \mathbb{R}^d \to \mathbb{R}_{\ge 0} be a time-dependent probability density over state space xRdx \in \mathbb{R}^d, transported by a velocity vector field ut(x):RdRdu_t(x): \mathbb{R}^d \to \mathbb{R}^d.

Consider an arbitrary, fixed control volume VRdV \subset \mathbb{R}^d with smooth boundary V\partial V and outward unit normal vector n(x)n(x).

The total probability mass inside VV at time tt is:

P(V,t)=Vpt(x)dxP(V, t) = \int_V p_t(x) \, dx

The rate of change of probability inside VV must equal the negative net probability flux exiting through the boundary V\partial V:

ddtVpt(x)dx=Vpt(x)ut(x)n(x)dA\frac{d}{dt} \int_V p_t(x) \, dx = - \oint_{\partial V} p_t(x) u_t(x) \cdot n(x) \, dA

Applying the Divergence Theorem (Gauss-Ostrogradsky Theorem) to the boundary integral:

Vpt(x)ut(x)n(x)dA=V(pt(x)ut(x))dx\oint_{\partial V} p_t(x) u_t(x) \cdot n(x) \, dA = \int_V \nabla \cdot \left( p_t(x) u_t(x) \right) \, dx

Since the control volume VV is stationary in time:

V[pt(x)t+(pt(x)ut(x))]dx=0\int_V \left[ \frac{\partial p_t(x)}{\partial t} + \nabla \cdot \left( p_t(x) u_t(x) \right) \right] dx = 0

Because this equality holds for every arbitrary volume VRdV \subset \mathbb{R}^d, the integrand must vanish everywhere:

pt(x)t+(pt(x)ut(x))=0\frac{\partial p_t(x)}{\partial t} + \nabla \cdot \left( p_t(x) u_t(x) \right) = 0

This is the General Eulerian Probability Continuity Equation (or advection equation for conserved probability mass).


3.2 Eulerian vs. Lagrangian Decomposition

We can expand the divergence term using the vector product rule (pu)=p(u)+up\nabla \cdot (p u) = p (\nabla \cdot u) + u \cdot \nabla p:

pt(x)t+ut(x)pt(x)+pt(x)(ut(x))=0\frac{\partial p_t(x)}{\partial t} + u_t(x) \cdot \nabla p_t(x) + p_t(x) \left( \nabla \cdot u_t(x) \right) = 0

Recognizing the material derivative along a flow trajectory x˙(t)=ut(x(t))\dot{x}(t) = u_t(x(t)):

ddtpt(x(t))=ptt+ptx˙(t)=ptt+ut(x)pt(x)\frac{d}{dt} p_t(x(t)) = \frac{\partial p_t}{\partial t} + \nabla p_t \cdot \dot{x}(t) = \frac{\partial p_t}{\partial t} + u_t(x) \cdot \nabla p_t(x)

Substituting this into the expanded continuity equation yields:

ddtpt(x(t))=pt(x(t))(ut(x(t)))\frac{d}{dt} p_t(x(t)) = - p_t(x(t)) \left( \nabla \cdot u_t(x(t)) \right)

Dividing both sides by pt(x(t))>0p_t(x(t)) > 0 and noting that ddtlogp=1pdpdt\frac{d}{dt} \log p = \frac{1}{p} \frac{dp}{dt}:

ddtlogpt(x(t))=ut(x(t))\frac{d}{dt} \log p_t(x(t)) = - \nabla \cdot u_t(x(t))

[!IMPORTANT] Comparison: Liouville vs. General Continuity Equation

PropertyClassical Hamiltonian System (Liouville)General Machine Learning Flow (CNF / Flow Matching)
State SpacePhase Space Γ=R2d\Gamma = \mathbb{R}^{2d} with (q,p)(q, p)Arbitrary Feature / Latent Space xRdx \in \mathbb{R}^d
Velocity Fieldv(z)=JH(z)v(z) = J \nabla H(z) (Symplectic gradient)ut(x)=vθ(x,t)u_t(x) = v_\theta(x, t) (Arbitrary Neural Network)
Divergencev(z)0\nabla \cdot v(z) \equiv 0 (Incompressible)ut(x)0\nabla \cdot u_t(x) \neq 0 (Compressible / Expansible)
Jacobian Determinantdet(M(t))=1\det(M(t)) = 1det(M(t))=exp(0tusds)\det(M(t)) = \exp\left( \int_0^t \nabla \cdot u_s \, ds \right)
Lagrangian Densitydρdt=0\frac{d\rho}{dt} = 0 (Constant along path)dlogptdt=ut(x(t))\frac{d \log p_t}{dt} = -\nabla \cdot u_t(x(t)) (Changes dynamically)
Continuity PDEρt+ρv=0\frac{\partial \rho}{\partial t} + \nabla \rho \cdot v = 0ptt+(ptut)=0\frac{\partial p_t}{\partial t} + \nabla \cdot (p_t u_t) = 0

4. Continuous Normalizing Flows (CNFs)

4.1 Pushforward Measures and Continuous Change of Variables

In generative modeling, our objective is to transform an easily sampleable base noise distribution p0(x0)=N(x0;0,Id)p_0(x_0) = \mathcal{N}(x_0; 0, I_d) into a complex, multi-modal target data distribution q(x1)pdata(x1)q(x_1) \approx p_{\mathrm{data}}(x_1).

Let ψt:RdRd\psi_t: \mathbb{R}^d \to \mathbb{R}^d be the continuous flow map generated by an Ordinary Differential Equation (ODE) parameterized by a neural network vθ(x,t)v_\theta(x, t):

dx(t)dt=vθ(x(t),t),x(0)=x0p0(x0)\frac{d x(t)}{dt} = v_\theta(x(t), t), \quad x(0) = x_0 \sim p_0(x_0)

The state at time tt is given by integrating the vector field:

x(t)=ψt(x0)=x0+0tvθ(x(s),s)dsx(t) = \psi_t(x_0) = x_0 + \int_0^t v_\theta(x(s), s) \, ds

The pushforward distribution pt=[ψt]p0p_t = [\psi_t]_\sharp p_0 satisfies the discrete change-of-variables formula:

pt(x(t))=p0(x0)det(ψt(x0)x0)1p_t(x(t)) = p_0(x_0) \left| \det \left( \frac{\partial \psi_t(x_0)}{\partial x_0} \right) \right|^{-1}

Taking the logarithm:

logpt(x(t))=logp0(x0)logdet(ψt(x0)x0)\log p_t(x(t)) = \log p_0(x_0) - \log \left| \det \left( \frac{\partial \psi_t(x_0)}{\partial x_0} \right) \right|

Using our Lagrangian continuity result ddtlogpt(x(t))=vθ(x(t),t)\frac{d}{dt} \log p_t(x(t)) = -\nabla \cdot v_\theta(x(t), t), we integrate directly from t=0t=0 to t=1t=1:

logp1(x(1))=logp0(x(0))01vθ(x(t),t)dt\log p_1(x(1)) = \log p_0(x(0)) - \int_0^1 \nabla \cdot v_\theta(x(t), t) \, dt

4.2 Hutchinson's Trace Estimator for Scalable Divergence

The exact divergence vθ(x,t)=Tr(vθx)\nabla \cdot v_\theta(x, t) = \operatorname{Tr}\left( \frac{\partial v_\theta}{\partial x} \right) requires computing all dd diagonal elements of the Jacobian matrix vθxRd×d\frac{\partial v_\theta}{\partial x} \in \mathbb{R}^{d \times d}. For high-dimensional data (e.g., images with d=3×512×5127.8×105d = 3 \times 512 \times 512 \approx 7.8 \times 10^5), computing the full Jacobian requires dd backward passes of automatic differentiation, which is computationally prohibitive (O(d)\mathcal{O}(d) backward passes).

To solve this, Continuous Normalizing Flows (Chen et al., 2018; Grathwohl et al., 2019 - FFJORD) utilize Hutchinson's Stochastic Trace Estimator.

Let ϵRd\epsilon \in \mathbb{R}^d be a random noise vector drawn from a zero-mean distribution with covariance identity Cov(ϵ)=E[ϵϵ]=Id\operatorname{Cov}(\epsilon) = \mathbb{E}[\epsilon \epsilon^\top] = I_d (such as standard Gaussian N(0,Id)\mathcal{N}(0, I_d) or Rademacher distribution ϵi{1,+1}\epsilon_i \in \{-1, +1\} with equal probability).

For any square matrix ARd×dA \in \mathbb{R}^{d \times d}:

Eϵ[ϵAϵ]=Eϵ[Tr(ϵAϵ)]=Eϵ[Tr(Aϵϵ)]=Tr(AEϵ[ϵϵ])=Tr(AId)=Tr(A)\begin{aligned} \mathbb{E}_{\epsilon} \left[ \epsilon^\top A \epsilon \right] &= \mathbb{E}_{\epsilon} \left[ \operatorname{Tr}\left( \epsilon^\top A \epsilon \right) \right] = \mathbb{E}_{\epsilon} \left[ \operatorname{Tr}\left( A \epsilon \epsilon^\top \right) \right] \\ &= \operatorname{Tr}\left( A \mathbb{E}_{\epsilon} \left[ \epsilon \epsilon^\top \right] \right) = \operatorname{Tr}(A I_d) = \operatorname{Tr}(A) \end{aligned}

Setting A=vθxA = \frac{\partial v_\theta}{\partial x}:

vθ(x,t)=Tr(vθx)=EϵN(0,Id)[ϵ(vθ(x,t)x)ϵ]\nabla \cdot v_\theta(x, t) = \operatorname{Tr}\left( \frac{\partial v_\theta}{\partial x} \right) = \mathbb{E}_{\epsilon \sim \mathcal{N}(0, I_d)} \left[ \epsilon^\top \left( \frac{\partial v_\theta(x, t)}{\partial x} \right) \epsilon \right]

Computational Efficiency of Hutchinson's Estimator

The quantity ϵ(vθx)\epsilon^\top \left( \frac{\partial v_\theta}{\partial x} \right) is a Vector-Jacobian Product (VJP). It can be computed in a single backward pass of automatic differentiation:

ϵ(vθx)=x(ϵvθ(x,t))\epsilon^\top \left( \frac{\partial v_\theta}{\partial x} \right) = \nabla_x \left( \epsilon^\top v_\theta(x, t) \right)

Thus, we can compute an unbiased Monte Carlo estimate of vθ(x,t)\nabla \cdot v_\theta(x, t) with cost O(1)\mathcal{O}(1) backward passes instead of O(d)\mathcal{O}(d)!


5. Flow Matching: The Modern Paradigm (Lipman et al., 2023)

Despite the mathematical elegance of CNFs, training them via Maximum Likelihood requires numerically integrating the ODE x(t)x(t) and its divergence across the entire time interval t[0,1]t \in [0, 1] for every gradient step. This makes CNF training notoriously slow, unstable, and prone to error accumulation.

Flow Matching (Lipman et al., ICLR 2023; Albergo & Vanden-Eijnden, 2023; Liu et al., 2023) revolutionizes continuous generative modeling by providing a simulation-free objective. It enables training continuous normalizing flows with simple regression losses—completely bypassing numerical ODE integration during training.


5.1 The Target Probability Path and Intractable Flow Matching

Let q(x1)q(x_1) be the empirical data distribution, and p0(x0)=N(x0;0,I)p_0(x_0) = \mathcal{N}(x_0; 0, I) be the prior noise distribution.

We desire a time-dependent probability path pt(x)p_t(x) for t[0,1]t \in [0, 1] such that:

  • At t=0t = 0: p0(x)p_0(x) is the known noise distribution.
  • At t=1t = 1: p1(x)q(x1)p_1(x) \approx q(x_1) is the target data distribution.

If we knew the true marginal vector field ut(x)u_t(x) that generates pt(x)p_t(x) via the continuity equation:

pt(x)t+(pt(x)ut(x))=0\frac{\partial p_t(x)}{\partial t} + \nabla \cdot \left( p_t(x) u_t(x) \right) = 0

We could train a neural network vθ(x,t)v_\theta(x, t) via the ideal Flow Matching (FM) objective:

LFM(θ)=EtU[0,1],xpt(x)[vθ(x,t)ut(x)22]\mathcal{L}_{\mathrm{FM}}(\theta) = \mathbb{E}_{t \sim \mathcal{U}[0, 1], x \sim p_t(x)} \left[ \| v_\theta(x, t) - u_t(x) \|_2^2 \right]

The Intractability Bottleneck

In practice, pt(x)p_t(x) and ut(x)u_t(x) are completely intractable:

pt(x)=pt(xx1)q(x1)dx1,ut(x)=ut(xx1)pt(xx1)q(x1)pt(x)dx1p_t(x) = \int p_t(x | x_1) q(x_1) \, dx_1, \quad u_t(x) = \int u_t(x | x_1) \frac{p_t(x | x_1) q(x_1)}{p_t(x)} \, dx_1

We cannot compute ut(x)u_t(x) or sample directly from pt(x)p_t(x) without already knowing the generative solution!


5.2 Conditional Flow Matching (CFM)

Lipman et al. (2023) solved this impasse by introducing Conditional Flow Matching (CFM).

Instead of working with the intractable marginal path pt(x)p_t(x), we condition on individual data points x1q(x1)x_1 \sim q(x_1) (or pairs (x0,x1)(x_0, x_1)). We define simple, tractable conditional probability paths pt(xx1)p_t(x | x_1) and corresponding conditional vector fields ut(xx1)u_t(x | x_1) that satisfy the conditional continuity equation:

pt(xx1)t+(pt(xx1)ut(xx1))=0\frac{\partial p_t(x | x_1)}{\partial t} + \nabla \cdot \left( p_t(x | x_1) u_t(x | x_1) \right) = 0

The marginal quantities are related to the conditional quantities by marginalization:

pt(x)=pt(xx1)q(x1)dx1p_t(x) = \int p_t(x | x_1) q(x_1) \, dx_1 ut(x)=ut(xx1)pt(xx1)q(x1)pt(x)dx1u_t(x) = \int u_t(x | x_1) \frac{p_t(x | x_1) q(x_1)}{p_t(x)} \, dx_1

We now define the Conditional Flow Matching (CFM) objective:

LCFM(θ)=EtU[0,1],x1q(x1),xpt(xx1)[vθ(x,t)ut(xx1)22]\mathcal{L}_{\mathrm{CFM}}(\theta) = \mathbb{E}_{t \sim \mathcal{U}[0, 1], x_1 \sim q(x_1), x \sim p_t(x | x_1)} \left[ \| v_\theta(x, t) - u_t(x | x_1) \|_2^2 \right]

This objective is completely tractable and simulation-free: we sample x1q(x1)x_1 \sim q(x_1), sample tU[0,1]t \sim \mathcal{U}[0, 1], sample xpt(xx1)x \sim p_t(x | x_1), evaluate the closed-form conditional vector field ut(xx1)u_t(x | x_1), and compute a standard MSE loss!


5.3 Step-by-Step Proof of the CFM Theorem

We now present the complete, rigorous mathematical proof that optimizing the tractable LCFM(θ)\mathcal{L}_{\mathrm{CFM}}(\theta) is mathematically identical to optimizing the intractable LFM(θ)\mathcal{L}_{\mathrm{FM}}(\theta).

Theorem (Conditional Flow Matching Equivalence — Lipman et al., 2023)

Assuming pt(x)>0p_t(x) > 0 for all xRdx \in \mathbb{R}^d and t[0,1]t \in [0, 1], the gradients of the marginal Flow Matching loss and the Conditional Flow Matching loss with respect to the network parameters θ\theta are identical:

θLFM(θ)=θLCFM(θ)\nabla_\theta \mathcal{L}_{\mathrm{FM}}(\theta) = \nabla_\theta \mathcal{L}_{\mathrm{CFM}}(\theta)

Consequently, LCFM(θ)\mathcal{L}_{\mathrm{CFM}}(\theta) and LFM(θ)\mathcal{L}_{\mathrm{FM}}(\theta) share the exact same global and local parameter minima.

Proof:

Expand the squared Euclidean norm in the marginal Flow Matching loss LFM(θ)\mathcal{L}_{\mathrm{FM}}(\theta):

LFM(θ)=Et,xpt(x)[vθ(x,t)ut(x)22]=01dtRddxpt(x)(vθ(x,t)222vθ(x,t),ut(x)+ut(x)22)\begin{aligned} \mathcal{L}_{\mathrm{FM}}(\theta) &= \mathbb{E}_{t, x \sim p_t(x)} \left[ \| v_\theta(x, t) - u_t(x) \|_2^2 \right] \\ &= \int_0^1 dt \int_{\mathbb{R}^d} dx \, p_t(x) \left( \| v_\theta(x, t) \|_2^2 - 2 \langle v_\theta(x, t), u_t(x) \rangle + \| u_t(x) \|_2^2 \right) \end{aligned}

Since ut(x)22\| u_t(x) \|_2^2 does not depend on the network parameters θ\theta, taking the gradient with respect to θ\theta yields:

θLFM(θ)=01dtRddxpt(x)(θvθ(x,t)222θvθ(x,t),ut(x))\nabla_\theta \mathcal{L}_{\mathrm{FM}}(\theta) = \int_0^1 dt \int_{\mathbb{R}^d} dx \, p_t(x) \left( \nabla_\theta \| v_\theta(x, t) \|_2^2 - 2 \nabla_\theta \langle v_\theta(x, t), u_t(x) \rangle \right)

Now examine the cross-term Rdpt(x)vθ(x,t),ut(x)dx\int_{\mathbb{R}^d} p_t(x) \langle v_\theta(x, t), u_t(x) \rangle \, dx. Substitute the definition of the marginal vector field ut(x)=ut(xx1)pt(xx1)q(x1)pt(x)dx1u_t(x) = \int u_t(x | x_1) \frac{p_t(x | x_1) q(x_1)}{p_t(x)} \, dx_1:

Rdpt(x)vθ(x,t),ut(x)dx=Rdpt(x)vθ(x,t),Rdut(xx1)pt(xx1)q(x1)pt(x)dx1dx=RdRdq(x1)pt(xx1)vθ(x,t),ut(xx1)dxdx1=Ex1q(x1),xpt(xx1)[vθ(x,t),ut(xx1)]\begin{aligned} \int_{\mathbb{R}^d} p_t(x) \langle v_\theta(x, t), u_t(x) \rangle \, dx &= \int_{\mathbb{R}^d} p_t(x) \left\langle v_\theta(x, t), \int_{\mathbb{R}^d} u_t(x | x_1) \frac{p_t(x | x_1) q(x_1)}{p_t(x)} \, dx_1 \right\rangle dx \\ &= \int_{\mathbb{R}^d} \int_{\mathbb{R}^d} q(x_1) p_t(x | x_1) \langle v_\theta(x, t), u_t(x | x_1) \rangle \, dx \, dx_1 \\ &= \mathbb{E}_{x_1 \sim q(x_1), x \sim p_t(x | x_1)} \left[ \langle v_\theta(x, t), u_t(x | x_1) \rangle \right] \end{aligned}

Similarly, for the first term:

Rdpt(x)vθ(x,t)22dx=Rd(Rdpt(xx1)q(x1)dx1)vθ(x,t)22dx=RdRdq(x1)pt(xx1)vθ(x,t)22dxdx1=Ex1q(x1),xpt(xx1)[vθ(x,t)22]\begin{aligned} \int_{\mathbb{R}^d} p_t(x) \| v_\theta(x, t) \|_2^2 \, dx &= \int_{\mathbb{R}^d} \left( \int_{\mathbb{R}^d} p_t(x | x_1) q(x_1) \, dx_1 \right) \| v_\theta(x, t) \|_2^2 \, dx \\ &= \int_{\mathbb{R}^d} \int_{\mathbb{R}^d} q(x_1) p_t(x | x_1) \| v_\theta(x, t) \|_2^2 \, dx \, dx_1 \\ &= \mathbb{E}_{x_1 \sim q(x_1), x \sim p_t(x | x_1)} \left[ \| v_\theta(x, t) \|_2^2 \right] \end{aligned}

Now, write out the expansion of the Conditional Flow Matching loss LCFM(θ)\mathcal{L}_{\mathrm{CFM}}(\theta):

LCFM(θ)=Et,x1q(x1),xpt(xx1)[vθ(x,t)ut(xx1)22]=Et,x1,x[vθ(x,t)22]2Et,x1,x[vθ(x,t),ut(xx1)]+Et,x1,x[ut(xx1)22]\begin{aligned} \mathcal{L}_{\mathrm{CFM}}(\theta) &= \mathbb{E}_{t, x_1 \sim q(x_1), x \sim p_t(x | x_1)} \left[ \| v_\theta(x, t) - u_t(x | x_1) \|_2^2 \right] \\ &= \mathbb{E}_{t, x_1, x} \left[ \| v_\theta(x, t) \|_2^2 \right] - 2 \mathbb{E}_{t, x_1, x} \left[ \langle v_\theta(x, t), u_t(x | x_1) \rangle \right] + \mathbb{E}_{t, x_1, x} \left[ \| u_t(x | x_1) \|_2^2 \right] \end{aligned}

Taking the gradient with respect to θ\theta:

θLCFM(θ)=θEt,x1,x[vθ(x,t)22]2θEt,x1,x[vθ(x,t),ut(xx1)]\nabla_\theta \mathcal{L}_{\mathrm{CFM}}(\theta) = \nabla_\theta \mathbb{E}_{t, x_1, x} \left[ \| v_\theta(x, t) \|_2^2 \right] - 2 \nabla_\theta \mathbb{E}_{t, x_1, x} \left[ \langle v_\theta(x, t), u_t(x | x_1) \rangle \right]

Matching terms with the gradient of LFM(θ)\mathcal{L}_{\mathrm{FM}}(\theta):

θLFM(θ)θLCFM(θ)\nabla_\theta \mathcal{L}_{\mathrm{FM}}(\theta) \equiv \nabla_\theta \mathcal{L}_{\mathrm{CFM}}(\theta)

Furthermore, subtracting the two loss functions:

LCFM(θ)LFM(θ)=Et,x1q(x1),xpt(xx1)[ut(xx1)22]Et,xpt(x)[ut(x)22]0\mathcal{L}_{\mathrm{CFM}}(\theta) - \mathcal{L}_{\mathrm{FM}}(\theta) = \mathbb{E}_{t, x_1 \sim q(x_1), x \sim p_t(x | x_1)} \left[ \| u_t(x | x_1) \|_2^2 \right] - \mathbb{E}_{t, x \sim p_t(x)} \left[ \| u_t(x) \|_2^2 \right] \ge 0

This difference is a non-negative constant independent of θ\theta. \blacksquare


5.4 Optimal Transport Paths and Straight-Line Trajectories

What is the optimal choice for the conditional probability path pt(xx1)p_t(x | x_1)?

Consider the Gaussian conditional path conditioned on both a noise sample x0p0(x0)=N(0,I)x_0 \sim p_0(x_0) = \mathcal{N}(0, I) and a data sample x1q(x1)x_1 \sim q(x_1):

ψt(x0,x1)=(1t)x0+tx1\psi_t(x_0, x_1) = (1 - t) x_0 + t x_1

The conditional vector field along this path is simply the time-derivative:

ut(xx0,x1)=ddtψt(x0,x1)=x1x0u_t(x | x_0, x_1) = \frac{d}{dt} \psi_t(x_0, x_1) = x_1 - x_0

In standard Conditional Flow Matching (Independent Coupling), x0N(0,I)x_0 \sim \mathcal{N}(0, I) and x1q(x1)x_1 \sim q(x_1) are sampled independently: q(x0,x1)=p0(x0)q(x1)q(x_0, x_1) = p_0(x_0) q(x_1).

In Optimal Transport Conditional Flow Matching (OT-CFM), we sample (x0,x1)(x_0, x_1) from the 2-Wasserstein optimal transport plan π(x0,x1)Π(p0,q)\pi(x_0, x_1) \in \Pi(p_0, q):

π=argminπΠ(p0,q)Rd×Rdx0x122dπ(x0,x1)\pi^* = \arg\min_{\pi \in \Pi(p_0, q)} \int_{\mathbb{R}^d \times \mathbb{R}^d} \| x_0 - x_1 \|_2^2 \, d\pi(x_0, x_1)

In practice, this is computed over mini-batches using the Hungarian algorithm or Earth Mover's Distance solver.

Flow Matching Coupling Paths: Independent vs Optimal Transport

[!TIP] Why Straight Paths Matter When the trajectories x(t)x(t) are straight lines (ut(x)=constu_t(x) = \text{const}), the velocity field does not change direction along the flow. This allows numerical ODE solvers (e.g., Euler or Heun) to take massive step sizes, generating high-fidelity images in as few as 1 to 4 evaluation steps, compared to 50–1000 steps required by traditional curved diffusion models!


6. SDEs vs. ODEs: Stochastic Diffusion vs. Probability Flow ODEs

We now unify stochastic physics (Brownian motion, Langevin dynamics) with deterministic probability flows.

6.1 The Fokker-Planck Equation for Itô SDEs

Consider a general forward Stochastic Differential Equation (SDE) in Rd\mathbb{R}^d:

dxt=f(xt,t)dt+g(t)dwtdx_t = f(x_t, t) \, dt + g(t) \, dw_t

where f(x,t)Rdf(x, t) \in \mathbb{R}^d is the drift coefficient, g(t)Rg(t) \in \mathbb{R} is the scalar diffusion coefficient, and wtw_t is standard dd-dimensional Brownian motion (dwtN(0,dtId)dw_t \sim \mathcal{N}(0, dt \, I_d)).

The time evolution of the marginal probability density pt(x)p_t(x) is governed by the Fokker-Planck Equation (Forward Kolmogorov Equation):

pt(x)t=(f(x,t)pt(x))+12g(t)22pt(x)\frac{\partial p_t(x)}{\partial t} = - \nabla \cdot \left( f(x, t) p_t(x) \right) + \frac{1}{2} g(t)^2 \nabla^2 p_t(x)

where 2pt(x)=i=1d2ptxi2=(pt(x))\nabla^2 p_t(x) = \sum_{i=1}^d \frac{\partial^2 p_t}{\partial x_i^2} = \nabla \cdot (\nabla p_t(x)) is the spatial Laplacian.


6.2 Exact Derivation of the Deterministic Probability Flow ODE

Let us rewrite the second-order diffusion term 2pt(x)\nabla^2 p_t(x) in terms of the Stein Score Function s(x,t)xlogpt(x)s(x, t) \equiv \nabla_x \log p_t(x):

pt(x)=pt(x)xlogpt(x)\nabla p_t(x) = p_t(x) \nabla_x \log p_t(x)

Taking the divergence of both sides:

2pt(x)=(pt(x))=(pt(x)xlogpt(x))\nabla^2 p_t(x) = \nabla \cdot \left( \nabla p_t(x) \right) = \nabla \cdot \left( p_t(x) \nabla_x \log p_t(x) \right)

Substitute this identity back into the Fokker-Planck Equation:

pt(x)t=(f(x,t)pt(x))+12g(t)2(pt(x)xlogpt(x))=[pt(x)(f(x,t)12g(t)2xlogpt(x))]\begin{aligned} \frac{\partial p_t(x)}{\partial t} &= - \nabla \cdot \left( f(x, t) p_t(x) \right) + \frac{1}{2} g(t)^2 \nabla \cdot \left( p_t(x) \nabla_x \log p_t(x) \right) \\ &= - \nabla \cdot \left[ p_t(x) \left( f(x, t) - \frac{1}{2} g(t)^2 \nabla_x \log p_t(x) \right) \right] \end{aligned}

Rearranging into the standard Continuity Equation form:

pt(x)t+(pt(x)vt(x))=0\frac{\partial p_t(x)}{\partial t} + \nabla \cdot \left( p_t(x) v_t(x) \right) = 0

where the deterministic velocity field vt(x)v_t(x) is defined as:

vt(x)f(x,t)12g(t)2xlogpt(x)v_t(x) \equiv f(x, t) - \frac{1}{2} g(t)^2 \nabla_x \log p_t(x)

The Song et al. (2021) Probability Flow ODE Theorem

For any Itô SDE of the form dxt=f(xt,t)dt+g(t)dwtdx_t = f(x_t, t) dt + g(t) dw_t, there exists an associated deterministic ODE, termed the Probability Flow ODE:

dxtdt=f(xt,t)12g(t)2xlogpt(xt)\frac{dx_t}{dt} = f(x_t, t) - \frac{1}{2} g(t)^2 \nabla_x \log p_t(x_t)

whose trajectories share the exact same marginal probability density pt(x)p_t(x) for all t[0,1]t \in [0, 1] as the stochastic SDE!

This equivalence reveals that Score-based Diffusion Models and Continuous Normalizing Flows are two sides of the same coin:

  1. Diffusion models learn the spatial gradient of the log-density xlogpt(x)\nabla_x \log p_t(x) (the score).
  2. Flow Matching models directly learn the velocity field vt(x)v_t(x) that integrates the continuity equation.

7. The Grand Synthesis: Physics vs. Deep Learning Dictionary

The following table summarizes the exact mathematical and conceptual correspondences between Classical Hamiltonian Statistical Mechanics, Stochastic Non-Equilibrium Thermodynamics, and Modern Continuous Generative Modeling.

ConceptClassical Statistical MechanicsStochastic Thermodynamics (SDEs)Modern Continuous Flows (Flow Matching)
State VariablePhase point z=(q,p)R2dz = (q, p) \in \mathbb{R}^{2d}Particle position xRdx \in \mathbb{R}^dFeature / Latent vector xRdx \in \mathbb{R}^d
Governing LawHamilton's Equations: z˙=JH\dot{z} = J \nabla HItô SDE: dxt=fdt+gdwtdx_t = f dt + g dw_tNeural ODE: x˙=vθ(x,t)\dot{x} = v_\theta(x, t)
Density EvolutionLiouville Eq: tρ={ρ,H}\partial_t \rho = -\{\rho, H\}Fokker-Planck: tp=(fp)+g222p\partial_t p = -\nabla(fp) + \frac{g^2}{2}\nabla^2 pContinuity Eq: tpt+(ptvt)=0\partial_t p_t + \nabla \cdot (p_t v_t) = 0
Volume Evolutionz˙0\nabla \cdot \dot{z} \equiv 0 (Incompressible)Stochastic spreading (Entropy production)vθ0\nabla \cdot v_\theta \neq 0 (Compressible / Expansible)
Jacobian Detdet(M(t))=1\det(M(t)) = 1Undefined for stochastic pathsdet(M(t))=exp(0tvθds)\det(M(t)) = \exp\left(\int_0^t \nabla \cdot v_\theta \, ds\right)
Lagrangian Densitydρdt=0\frac{d\rho}{dt} = 0 (Conserved along flow)Fluctuates stochasticallydlogptdt=vθ(x(t),t)\frac{d\log p_t}{dt} = -\nabla \cdot v_\theta(x(t), t)
Training PrincipleConserved phase volumeDenoising Score MatchingConditional Flow Matching (LCFM\mathcal{L}_{\mathrm{CFM}})
Sampling ModeSymplectic integration (Verlet)Langevin / Euler-Maruyama SDEAdaptive ODE (Dormand-Prince / Euler)

8. Practical Implementation: Flow Matching in PyTorch

Below is a complete, minimal, and fully runnable implementation of Optimal Transport Conditional Flow Matching (OT-CFM) in PyTorch, including Hutchinson trace estimation for log-likelihood evaluation.

import torch
import torch.nn as nn
import torch.optim as optim

class TimeMLP(nn.Module):
    """Time-dependent Vector Field v_theta(x, t)"""
    def __init__(self, dim=2, hidden_dim=128):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(dim + 1, hidden_dim),
            nn.SiLU(),
            nn.Linear(hidden_dim, hidden_dim),
            nn.SiLU(),
            nn.Linear(hidden_dim, hidden_dim),
            nn.SiLU(),
            nn.Linear(hidden_dim, dim)
        )
        
    def forward(self, x, t):
        # x: [B, dim], t: [B, 1]
        t_input = t if t.dim() == 2 else t.unsqueeze(-1)
        tx = torch.cat([x, t_input], dim=-1)
        return self.net(tx)

class ConditionalFlowMatcher:
    """Optimal Transport / Linear Conditional Flow Matcher"""
    def __init__(self, sigma_min=1e-4):
        self.sigma_min = sigma_min

    def compute_loss(self, model, x_1):
        """
        x_1: Target data batch [B, dim]
        """
        B, dim = x_1.shape
        x_0 = torch.randn_like(x_1) # Base distribution p_0 ~ N(0, I)
        t = torch.rand(B, 1, device=x_1.device) # t ~ Uniform[0, 1]
        
        # Affine interpolation path: psi_t(x_0, x_1) = (1 - (1 - sigma_min)*t) * x_0 + t * x_1
        # Target vector field: u_t(x|x_0, x_1) = x_1 - (1 - sigma_min) * x_0
        psi_t = (1.0 - (1.0 - self.sigma_min) * t) * x_0 + t * x_1
        u_t = x_1 - (1.0 - self.sigma_min) * x_0
        
        # Neural network prediction
        v_pred = model(psi_t, t)
        
        # CFM Regression Loss
        loss = torch.mean((v_pred - u_t) ** 2)
        return loss

    @torch.no_grad()
    def sample_ode(self, model, num_samples, dim, steps=50, device='cpu'):
        """Euler ODE Integrator: dx = v_theta(x, t) dt from t=0 to 1"""
        x = torch.randn(num_samples, dim, device=device)
        dt = 1.0 / steps
        
        for step in range(steps):
            t_val = step * dt
            t_tensor = torch.full((num_samples, 1), t_val, device=device)
            v = model(x, t_tensor)
            x = x + v * dt # Euler step
            
        return x

def hutchinson_divergence(model, x, t, num_probes=1):
    """
    Computes unbiased estimate of div(v_theta) = Tr(dv/dx) using Hutchinson's estimator
    """
    x.requires_grad_(True)
    v = model(x, t)
    div = torch.zeros(x.shape[0], device=x.device)
    
    for _ in range(num_probes):
        # Rademacher noise eps in {-1, +1}
        eps = torch.randint(0, 2, x.shape, device=x.device).float() * 2.0 - 1.0
        # Vector-Jacobian Product (VJP)
        vjp = torch.autograd.grad(v, x, grad_outputs=eps, create_graph=True)[0]
        div += torch.sum(vjp * eps, dim=-1)
        
    return div / num_probes

9. Modern Frontiers (2024–2026)

The principles of Liouville's theorem and continuous flow matching form the bedrock of the most recent breakthroughs in foundation generative models:

Rectified Flow & Reflow (Liu et al.)

Iteratively straightening learned flow trajectories by recursive coupling distillation, enabling single-step neural image synthesis.

Riemannian Flow Matching (Chen & Lipman, 2024)

Extending the continuity equation and vector fields to curved manifolds (SO(3), SE(3), Tori) for protein folding and robotics.

Discrete Flow Matching & LLaDA (2024-2025)

Generalizing flow equations to discrete state spaces and categorical vocabularies for non-autoregressive language modeling.

Flow Matching with Large Multimodal Diffusion (2024-2026)

Modern text-to-image and text-to-video architectures (e.g. Stable Diffusion 3, Flux) replacing traditional DDPM with OT-CFM.


10. Exercises and Derivations

Exercise 1: Incompressibility of 1D Harmonic Oscillator Flow

Problem: A one-dimensional harmonic oscillator has Hamiltonian H(q,p)=p22m+12kq2H(q, p) = \frac{p^2}{2m} + \frac{1}{2} k q^2.

  1. Write Hamilton's equations for this system.
  2. Solve the equations analytically for q(t)q(t) and p(t)p(t) given initial conditions (q0,p0)(q_0, p_0).
  3. Compute the Jacobian matrix M(t)=(q(t),p(t))(q0,p0)M(t) = \frac{\partial (q(t), p(t))}{\partial (q_0, p_0)} and show directly that det(M(t))=1\det(M(t)) = 1 for all tt.

Solution:

  1. Hamilton's equations are: q˙=Hp=pm,p˙=Hq=kq\dot{q} = \frac{\partial H}{\partial p} = \frac{p}{m}, \quad \dot{p} = -\frac{\partial H}{\partial q} = -k q
  2. Let ω=km\omega = \sqrt{\frac{k}{m}}. Differentiating q˙\dot{q}: q¨=p˙m=kmq=ω2q\ddot{q} = \frac{\dot{p}}{m} = -\frac{k}{m} q = -\omega^2 q. The general solutions are: q(t)=q0cos(ωt)+p0mωsin(ωt)p(t)=p0cos(ωt)mωq0sin(ωt)\begin{aligned} q(t) &= q_0 \cos(\omega t) + \frac{p_0}{m \omega} \sin(\omega t) \\ p(t) &= p_0 \cos(\omega t) - m \omega q_0 \sin(\omega t) \end{aligned}
  3. The Jacobian matrix is: M(t)=(q(t)q0q(t)p0p(t)q0p(t)p0)=(cos(ωt)1mωsin(ωt)mωsin(ωt)cos(ωt))M(t) = \begin{pmatrix} \frac{\partial q(t)}{\partial q_0} & \frac{\partial q(t)}{\partial p_0} \\ \frac{\partial p(t)}{\partial q_0} & \frac{\partial p(t)}{\partial p_0} \end{pmatrix} = \begin{pmatrix} \cos(\omega t) & \frac{1}{m \omega} \sin(\omega t) \\ -m \omega \sin(\omega t) & \cos(\omega t) \end{pmatrix} Computing the determinant: det(M(t))=(cos(ωt))(cos(ωt))(1mωsin(ωt))(mωsin(ωt))=cos2(ωt)+sin2(ωt)1\det(M(t)) = (\cos(\omega t))(\cos(\omega t)) - \left( \frac{1}{m \omega} \sin(\omega t) \right) (-m \omega \sin(\omega t)) = \cos^2(\omega t) + \sin^2(\omega t) \equiv 1 This proves exact volume preservation det(M(t))=1\det(M(t)) = 1. \blacksquare

Exercise 2: CFM Loss Gradient for General Exponential Paths

Problem: Consider a general Gaussian conditional probability path:

pt(xx1)=N(x;μt(x1),σt2Id)p_t(x | x_1) = \mathcal{N}(x; \mu_t(x_1), \sigma_t^2 I_d)

with conditional flow ψt(x0,x1)=μt(x1)+σtx0\psi_t(x_0, x_1) = \mu_t(x_1) + \sigma_t x_0 where x0N(0,Id)x_0 \sim \mathcal{N}(0, I_d).

  1. Derive the conditional vector field ut(xx1)u_t(x | x_1) as a function of xx and x1x_1.
  2. Prove that this vector field satisfies the conditional continuity equation ptt+(ptut)=0\frac{\partial p_t}{\partial t} + \nabla \cdot (p_t u_t) = 0.

Solution:

  1. Differentiating ψt(x0,x1)\psi_t(x_0, x_1) with respect to tt: ddtψt(x0,x1)=μ˙t(x1)+σ˙tx0\frac{d}{dt} \psi_t(x_0, x_1) = \dot{\mu}_t(x_1) + \dot{\sigma}_t x_0 Inverting the flow map for x0x_0: x0=xμt(x1)σtx_0 = \frac{x - \mu_t(x_1)}{\sigma_t}. Substituting this into the velocity expression gives: ut(xx1)=μ˙t(x1)+σ˙tσt(xμt(x1))u_t(x | x_1) = \dot{\mu}_t(x_1) + \frac{\dot{\sigma}_t}{\sigma_t} \left( x - \mu_t(x_1) \right)
  2. Let pt(xx1)=(2πσt2)d/2exp(xμt(x1)222σt2)p_t(x | x_1) = (2\pi \sigma_t^2)^{-d/2} \exp\left( -\frac{\| x - \mu_t(x_1) \|_2^2}{2\sigma_t^2} \right). Compute the time derivative of logpt\log p_t: logptt=dσ˙tσt+σ˙tσt3xμt2+1σt2(xμt)μ˙t\frac{\partial \log p_t}{\partial t} = -\frac{d \dot{\sigma}_t}{\sigma_t} + \frac{\dot{\sigma}_t}{\sigma_t^3} \| x - \mu_t \|^2 + \frac{1}{\sigma_t^2} (x - \mu_t)^\top \dot{\mu}_t Compute the spatial gradient: logpt=xμtσt2\nabla \log p_t = -\frac{x - \mu_t}{\sigma_t^2} Compute the divergence of utu_t: ut=i=1dxi(μ˙t,i+σ˙tσt(xiμt,i))=dσ˙tσt\nabla \cdot u_t = \sum_{i=1}^d \frac{\partial}{\partial x_i} \left( \dot{\mu}_{t,i} + \frac{\dot{\sigma}_t}{\sigma_t} (x_i - \mu_{t,i}) \right) = d \frac{\dot{\sigma}_t}{\sigma_t} Now evaluate the left side of the continuity equation in logarithmic form: logptt+utlogpt+ut=[dσ˙tσt+σ˙tσt3xμt2+μ˙t(xμt)σt2]+(μ˙t+σ˙tσt(xμt))(xμtσt2)+dσ˙tσt=dσ˙tσt+σ˙tσt3xμt2+μ˙t(xμt)σt2μ˙t(xμt)σt2σ˙tσt3xμt2+dσ˙tσt=0\begin{aligned} \frac{\partial \log p_t}{\partial t} + u_t \cdot \nabla \log p_t + \nabla \cdot u_t &= \left[ -d \frac{\dot{\sigma}_t}{\sigma_t} + \frac{\dot{\sigma}_t}{\sigma_t^3} \|x-\mu_t\|^2 + \frac{\dot{\mu}_t \cdot (x-\mu_t)}{\sigma_t^2} \right] \\ &\quad + \left( \dot{\mu}_t + \frac{\dot{\sigma}_t}{\sigma_t}(x-\mu_t) \right) \cdot \left( -\frac{x-\mu_t}{\sigma_t^2} \right) + d \frac{\dot{\sigma}_t}{\sigma_t} \\ &= -d \frac{\dot{\sigma}_t}{\sigma_t} + \frac{\dot{\sigma}_t}{\sigma_t^3} \|x-\mu_t\|^2 + \frac{\dot{\mu}_t \cdot (x-\mu_t)}{\sigma_t^2} \\ &\quad - \frac{\dot{\mu}_t \cdot (x-\mu_t)}{\sigma_t^2} - \frac{\dot{\sigma}_t}{\sigma_t^3} \|x-\mu_t\|^2 + d \frac{\dot{\sigma}_t}{\sigma_t} \\ &= 0 \end{aligned} Multiplying by pt(xx1)p_t(x | x_1) yields ptt+(ptut)=0\frac{\partial p_t}{\partial t} + \nabla \cdot (p_t u_t) = 0. \blacksquare

On this page