Mathematics foundation¶
Initial version: 2026-02-21 · First published: 2026-02-24 · Last content update: 2026-10-29
All discussions are in the Euclidean setting unless stated otherwise: \(x\in\mathbb{R}^D\), \(t\in[0,1]\). Where a general terminal time \(T\) is used, assume \(0<T<\infty\). The goal is to pin down the minimum deterministic/stochastic differential-equation facts needed for flow models and diffusion models.
Notation. \(X_t\) is a random state and \(x(t)\) a deterministic trajectory. \(\mu_t\) denotes a probability law; \(p_t\) denotes its Lebesgue density when one exists. A density is not required for a pushforward of measures. We write the ODE field as \(u(t,x)\); numerical examples use the argument order \(v(x,t):=u(t,x)\). For SDEs, \(b(t,x)\) and \(f(x,t)\) denote drifts in their stated argument orders; \(\sigma(t,x)\) or \(G(x,t)\) is a matrix diffusion coefficient, and \(g(t)\) its scalar isotropic special case. The diffusion matrix is \(a=\sigma\sigma^\top\). Spatial derivatives always act on \(x\); \(\nabla_x u\) means the vector-field Jacobian with entries \(\partial_{x_j}u_i\).
Chapter 1 — Differential equations: first-order ODEs and SDEs¶
1.1 Foundations of ordinary differential equations¶
Let \(u:[0,1]\times\mathbb{R}^D\to\mathbb{R}^D\) be a time-dependent vector field. Consider the initial value problem (IVP)
A standard sufficient condition for (global) existence and uniqueness on \([0,1]\) is:
- \(u(t,x)\) is measurable in \(t\) and continuous in \(x\);
- there is a nonnegative \(L\in L^1([0,1])\) such that \(\lVert u(t,x)-u(t,y)\rVert\le L(t)\lVert x-y\rVert\) for all \(x,y\in\mathbb{R}^D\) and almost every \(t\); and
- \(\lVert u(t,0)\rVert\le a(t)\) for a nonnegative \(a\in L^1([0,1])\), which gives the integrable growth bound \(\lVert u(t,x)\rVert\le a(t)+L(t)\lVert x\rVert\).
Under these Carathéodory conditions, solutions are absolutely continuous and satisfy the ODE almost everywhere. Joint continuity of \(u\) in \((t,x)\) gives the usual classical solution.
We write the solution as \(x(t;x_0)\) and define the flow map
One immediate consequence of uniqueness (hence of the Lipschitz-type assumptions above) is non-intersection at the same time: if two solutions \(x_1(\cdot),x_2(\cdot)\) satisfy \(x_1(t_\ast)=x_2(t_\ast)\) at some time \(t_\ast\), then they must coincide for all \(t\) in their common interval of existence. (Proof sketch: treat \((t_\ast,x_1(t_\ast))\) as a new initial condition and apply uniqueness both forward and backward on the common interval.) Paths may pass through the same spatial location at different times; this does not contradict uniqueness.
1.1.1 Integrating factors and variation of constants¶
This subsection is mainly about how to solve first-order ODEs in the cases where closed forms exist, and how to rewrite them into a form that is more structured (and numerically stable) when they do not.
Baseline. For a general nonlinear ODE \(\dot x=u(t,x)\), a closed form is usually unavailable; the “solution operator” is the flow map \(\psi_t\). In special cases, \(\psi_t\) can be written explicitly.
(A) Linear scalar ODE (homogeneous). Consider
where \(L:[0,1]\to\mathbb{R}\) is continuous. Then for any \(0\le s\le t\le 1\),
This motivates the exponential (integration) factor
which accumulates the time-dependent linear effect.
(B) Linear scalar ODE (inhomogeneous): integrating factor. For
define \(E(s\to t)\) as above. Then the closed-form solution is
This is the standard integrating-factor method.
(C) Semilinear ODE: variation of constants / Duhamel formula. More generally, consider a semilinear ODE
where \(x(t)\in\mathbb{R}^D\), \(L(t)\in\mathbb{R}\) (equivalently \(L(t)I\) acting on \(\mathbb{R}^D\)), and \(N:\mathbb{R}^D\times[0,1]\to\mathbb{R}^D\). Multiplying by \(E(s\to t)^{-1}\) and applying the product rule yields
Integrating from \(s\) to \(t\) gives the integral form (Duhamel / variation-of-constants formula)
This separates the evolution into a closed-form linear propagation and a nonlinear residual. Exponential integrators discretize only the integral term while handling the linear propagation exactly, often improving stability when the linear part is stiff.
Remark (matrix-valued linear part). If the linear part is \(L(t)\in\mathbb{R}^{D\times D}\), the same integral formula holds with \(E(s\to t)\) defined as the fundamental matrix solving \(\frac{d}{dt}E(s\to t)=L(t)E(s\to t)\), \(E(s\to s)=I\). One cannot generally replace this fundamental matrix by \(\exp\!\big(\int_s^t L(\tau)\,d\tau\big)\). Pairwise commutation of \(L(t)\) at different times (including constant \(L\)) is a sufficient condition for that exponential formula.
What is “closed form” here (and when do we still need numerics)? For a generic nonlinear first-order ODE, a closed-form solution is not available. Case (A) is fully explicit. Case (B) is explicit up to quadrature: if the integral \(\int_s^t E(\tau\to t)r(\tau)\,d\tau\) can be evaluated analytically then we obtain a closed form; otherwise we still compute that integral numerically. Case (C) provides an exact integral representation, but since \(N\) depends on the unknown trajectory \(x(\tau)\), it is generally an implicit integral equation and still requires numerical approximation (e.g., time stepping, Picard iteration, or exponential integrators).
Diffeomorphism concerns regularity and invertibility, not linearity. A sufficient setting is the global existence assumptions of Section 1.1 together with joint continuity of \(u\) and \(D_xu\), and \(C^1\) dependence on \(x\). The resulting flow maps are \(C^1\) diffeomorphisms, with inverse obtained by solving backward. With only local hypotheses, this statement applies between domains where the forward and backward solutions exist; it does not give a global map on all of \(\mathbb R^D\). Nonlinear fields can satisfy these assumptions just as linear ones can.
1.1.2 Numerical solvers for ODEs (time discretization)¶
Closed-form solutions are rare for nonlinear, time-dependent ODEs, so we typically approximate trajectories numerically. A useful starting point is the integral form of the ODE
namely
Numerical solvers discretize time and approximate this integral by evaluating the vector field \(v\) at selected points.
Discretization. Choose grid points \(0=t_0<t_1<\dots<t_N=T\) with step sizes \(h_n:=t_{n+1}-t_n\), and maintain states \(x_n\approx x(t_n)\).
Order of accuracy (one line). A method is called order-\(p\) if, for a sufficiently smooth solution and a uniform step size \(h\), its global error at \(T\) scales as \(O(h^p)\) as \(h\to 0\). A one-step defect of order \(O(h^{p+1})\) yields this global order under the required stability and regularity assumptions.
Euler (explicit). The simplest one-step method uses the current slope:
It is first-order accurate: local truncation error \(O(h_n^2)\) and global error \(O(\max_n h_n)\) under standard regularity assumptions.
Heun (improved Euler / explicit trapezoid). A second-order predictor–corrector:
It has local error \(O(h_n^3)\) and global error \(O((\max_n h_n)^2)\).
Runge–Kutta (RK4). A standard fourth-order method based on four slopes:
RK4 is a common accuracy–cost tradeoff when vector-field evaluations are not too expensive.
Semilinear structure and exponential integrators. If \(v(x,t)=L(t)x+N(x,t)\) (Section 1.1.1), then
and exponential integrators approximate only the integral term while handling the linear propagation \(E(\cdot\to\cdot)\) analytically. This can substantially improve stability when the linear part is stiff.
Reverse-time integration (ODE). Solving backward from a terminal condition \(x(T)=x_T\) is straightforward: integrate on a decreasing grid \(t_0=T>t_1>\dots>t_N=0\). With Euler and constant step \(h>0\),
For ODEs, this is just a reparameterization of time; in diffusion models, reverse-time ODE integration is used for sampling (e.g., probability flow ODEs).
Remark (stability and stiffness). For stiff dynamics, explicit methods may require very small step sizes for stability; implicit methods or structure-exploiting solvers (e.g., exponential integrators, diffusion-specific solvers) can be preferable.
Minimal code (Euler / Heun / RK4). Below is a tiny reference implementation for the scalar ODE \( \dot x=v(x,t) \). The same structure applies to \(x\in\mathbb{R}^D\) by letting x be a NumPy/PyTorch array/tensor and having v(x,t) return the same shape.
from typing import Callable, Literal, Tuple, List
Method = Literal["euler", "heun", "rk4"]
def solve_ode(
v: Callable[[float, float], float],
x0: float,
t0: float,
t1: float,
n_steps: int,
method: Method = "euler",
) -> Tuple[List[float], List[float]]:
"""
Solve dx/dt = v(x,t) on [t0,t1] with a chosen explicit solver.
- method: "euler" | "heun" | "rk4"
"""
if n_steps <= 0:
raise ValueError("n_steps must be positive")
h = (t1 - t0) / n_steps
t = t0
x = x0
ts = [t]
xs = [x]
for _ in range(n_steps):
if method == "euler":
x = x + h * v(x, t)
elif method == "heun":
k1 = v(x, t)
x_pred = x + h * k1
k2 = v(x_pred, t + h)
x = x + (h / 2.0) * (k1 + k2)
elif method == "rk4":
k1 = v(x, t)
k2 = v(x + 0.5 * h * k1, t + 0.5 * h)
k3 = v(x + 0.5 * h * k2, t + 0.5 * h)
k4 = v(x + h * k3, t + h)
x = x + (h / 6.0) * (k1 + 2.0 * k2 + 2.0 * k3 + k4)
else:
raise ValueError(f"unknown method: {method}")
t = t + h
ts.append(t)
xs.append(x)
return ts, xs
1.2 Random initial condition (random IVP)¶
Fix a probability space \((\Omega,\mathcal{F},\mathbb{P})\). Let \(\mathbf{X}_0:\Omega\to\mathbb{R}^D\) be an \(\mathcal{F}\)-measurable random variable with law \(\mu_0:=\mathcal{L}(\mathbf{X}_0)\). Define
and denote \(\mu_t:=\mathcal{L}(\mathbf{X}_t)\). This is still a deterministic ODE; randomness enters only through \(\mathbf{X}_0\).
1.3 Push-forward of measures and test-function identity¶
For each \(t\), the law evolves by push-forward:
Equivalently, for any bounded measurable \(\varphi:\mathbb{R}^D\to\mathbb{R}\),
1.4 Foundations of stochastic differential equations¶
This section provides an intuition-first bridge from ODEs to SDEs. Chapter 2 then states the Itô SDE and the associated density evolution (Fokker–Planck).
1.4.1 From ODEs to SDEs (discretization intuition)¶
Start from a deterministic ODE in \(\mathbb{R}^D\):
Euler time stepping with step size \(\Delta t\) gives
To define stochastic dynamics, add a random perturbation at each time step:
The \(\sqrt{\Delta t}\) scaling is crucial: it is the scaling (up to constants) for which the cumulative randomness remains \(O(1)\) over \(O(1)\) time, rather than vanishing (\(\Delta t\)) or exploding (\(1\)).
In the continuous-time limit, this leads to an Itô SDE
where \(W_t\in\mathbb{R}^D\) is a standard Brownian motion (Wiener process) characterized by:
- \(W_0=0\) a.s.;
- independent increments: \(W_t-W_s\) is independent of \(\sigma(W_u:u\le s)\) for \(0\le s<t\);
- Gaussian increments: \(W_t-W_s\sim \mathcal{N}(0,(t-s)I_D)\);
- sample paths are a.s. continuous but nowhere classically differentiable.
The notation \(dW_t:=W_{t+dt}-W_t\) is a convenient shorthand for these increments and should not be interpreted as a classical differential. Informally, one writes
meaning that over a short interval of length \(dt\), the increment behaves like a zero-mean Gaussian with covariance \(dt\,I_D\).
1.4.2 How to read an Itô SDE: integral form and Itô integration intuition¶
An SDE should be understood through its integral formulation. For example, the Itô SDE
means that for each \(t\in[0,T]\),
where the first integral is an ordinary time integral (Lebesgue; Riemann when its integrand is continuous) and the second is an Itô stochastic integral.
We do not build the Itô integral rigorously here; instead, keep the following intuition in mind. For a partition \(0=t_0<t_1<\dots<t_N=t\), the Itô integral can be viewed (informally) as a limit of left-point Riemann sums:
For continuous deterministic \(g\) on a compact interval, these sums converge in mean square (and hence in probability). General square-integrable adapted integrands are defined by approximation with adapted step processes, not by arbitrary point samples. For the deterministic time-only integrand shown here, Itô and Stratonovich integrals coincide under the usual regularity assumptions. Their distinction matters for state-dependent integrands: left-point adapted evaluation gives the Itô integral, whereas Stratonovich uses a symmetric convention and generally induces a drift correction.
Because Brownian sample paths are a.s. continuous but nowhere classically differentiable, expressions like \(dW_t/dt\) do not exist in the usual sense, and classical “integrate both sides” reasoning does not apply directly. The differential notation \(dX_t\), \(dt\), \(dW_t\) is therefore shorthand for increments and must be interpreted through the integral equation above.
Comparison with ODEs. For an ODE \(\dot x(t)=f(x(t),t)\), the integral form
is justified by the fundamental theorem of calculus (differentiability recovers the function from its derivative). For SDEs, one cannot recover a classical time derivative because \(W_t\) is not differentiable and stochastic integrals do not obey the classical chain rule. Instead, the correct replacement is Itô’s formula (Itô’s lemma), which we will use later when connecting SDEs to density evolution and reverse-time constructions in diffusion models.
Minimal code (Euler–Maruyama / Milstein). The most common time stepping for Itô SDEs is Euler–Maruyama. Below is a small reference implementation for
where \(W_t\in\mathbb{R}^m\) and \(G(x,t)\in\mathbb{R}^{D\times m}\). Milstein is included only for the scalar case \(D=m=1\).
from typing import Callable, Literal, Tuple, Optional
import numpy as np
SdeMethod = Literal["euler_maruyama", "milstein_scalar"]
def solve_sde(
f: Callable[[np.ndarray, float], np.ndarray],
G: Callable[[np.ndarray, float], np.ndarray],
x0,
t0: float,
t1: float,
n_steps: int,
*,
method: SdeMethod = "euler_maruyama",
rng: Optional[np.random.Generator] = None,
dgdx_scalar: Optional[Callable[[float, float], float]] = None,
) -> Tuple[np.ndarray, np.ndarray]:
"""
Solve the Itô SDE: dX = f(X,t) dt + G(X,t) dW, with W in R^m.
- f(x,t): (D,) -> (D,)
- G(x,t): (D,) -> (D,m)
- x0: float or array-like of shape (D,)
- method:
- "euler_maruyama": works for any (D,m)
- "milstein_scalar": only for D=m=1; requires dgdx_scalar(x,t)=d/dx g(x,t)
where G(x,t) = [[g(x,t)]].
"""
if n_steps <= 0:
raise ValueError("n_steps must be positive")
if t1 <= t0:
raise ValueError("require t1 > t0 for this forward-time solver")
rng = np.random.default_rng() if rng is None else rng
x = np.asarray(x0, dtype=float)
if x.ndim == 0:
x = x.reshape((1,))
if x.ndim != 1 or x.size == 0:
raise ValueError("x0 must be a scalar or a nonempty vector of shape (D,)")
t = float(t0)
h = (t1 - t0) / n_steps
ts = np.empty(n_steps + 1, dtype=float)
xs = np.empty((n_steps + 1,) + x.shape, dtype=float)
ts[0] = t
xs[0] = x
for n in range(n_steps):
drift = np.asarray(f(x, t), dtype=float)
if drift.shape != x.shape:
raise ValueError("f(x,t) must return shape (D,)")
diffusion = np.asarray(G(x, t), dtype=float)
if diffusion.ndim != 2:
raise ValueError("G(x,t) must return a 2D array of shape (D,m)")
D, m = diffusion.shape
if m < 1:
raise ValueError("Brownian dimension m must be positive")
if D != x.shape[0]:
raise ValueError("G(x,t) first dimension must match x dimension D")
dW = rng.standard_normal(size=(m,)) * np.sqrt(h) # N(0, h I_m)
if method == "euler_maruyama":
x = x + h * drift + diffusion @ dW
elif method == "milstein_scalar":
if not (D == 1 and m == 1 and x.shape == (1,)):
raise ValueError("milstein_scalar requires D=m=1 and scalar state")
if dgdx_scalar is None:
raise ValueError("milstein_scalar requires dgdx_scalar")
g = float(diffusion[0, 0])
gp = float(dgdx_scalar(float(x[0]), t))
x = x + h * drift + diffusion @ dW + 0.5 * g * gp * (dW[0] ** 2 - h)
else:
raise ValueError(f"unknown method: {method}")
t = t + h
ts[n + 1] = t
xs[n + 1] = x
return ts, xs
Chapter 2 — Density evolution: from change of variables to Fokker–Planck¶
This chapter summarizes the two canonical density-evolution PDEs:
- deterministic transport (ODE) \(\Rightarrow\) continuity equation;
- stochastic diffusion (Itô SDE) \(\Rightarrow\) Fokker–Planck equation.
2.1 Change of variables: deterministic maps and stochastic evolution¶

This section starts from a single deterministic update \(x_1=\Psi(x_0)\) and tracks how densities transform under smooth bijections. Composing many such updates leads to the Jacobian-determinant bookkeeping used in normalizing flows. Taking a continuous-time limit recovers the continuity equation; adding Brownian noise upgrades it to the Fokker–Planck equation (Section 2.2).
2.1.1 Single deterministic map¶
Let \(\Psi:\mathbb{R}^D\to\mathbb{R}^D\) be a \(C^1\) bijection with \(C^1\) inverse (a diffeomorphism). If \(X_0\sim p_0\) and \(X_1:=\Psi(X_0)\), then \(X_1\sim p_1\) where the density is given by the change-of-variable formula
Equivalently, writing \(x_1=\Psi(x_0)\),
Interpretation: \(\left|\det\nabla\Psi\right|\) is the local volume change, and the density compensates to conserve probability mass.
At the measure level, this is exactly a push-forward:
meaning \(\mu_1(A)=\mu_0(\Psi^{-1}(A))\) for any Borel set \(A\subseteq\mathbb{R}^D\). The density formula above is the Lebesgue-density version of \(\mu_1=\Psi_\#\mu_0\).
As a special case, if \(\Psi(x)=Ax\) with \(A\in\mathbb{R}^{D\times D}\) invertible, then
2.1.2 Composing multiple bijections (discrete normalizing flows)¶
Consider a sequence of diffeomorphisms \(\Psi_1,\dots,\Psi_L\) and states \(x_k=\Psi_k(x_{k-1})\). If \(X_0\sim p_0\), define \(X_k:=\Psi_k(X_{k-1})\) and let \(p_k\) be the density of \(X_k\). Mass conservation at each step implies
Recursing yields the overall Jacobian product
and, wherever the densities are positive, in log form,
This is the core likelihood bookkeeping identity for (discrete) normalizing flows.
2.1.3 Continuous-time limit \(\Rightarrow\) continuity equation¶
Let \(u(t,x)\) be a time-dependent velocity field and consider the ODE \(\dot x(t)=u(t,x(t))\). A standard way to connect maps to flows is to take small steps
so the Jacobian factor becomes \(\det(I+\Delta t\,\nabla_x u(t,x))\). In the limit \(\Delta t\to 0\), the density \(p_t\) (when it exists and is smooth enough) evolves according to the continuity equation
Where \(p_t>0\) and the field and density are differentiable, along trajectories \(X_t\) solving the ODE an equivalent form is
Regularity of \(u\) \(\Rightarrow\) an invertible flow map. Under standard ODE well-posedness assumptions (e.g., \(u(t,\cdot)\) locally Lipschitz in \(x\) and sufficiently regular in \(t\)), for each initial condition \(x_0\) there is a unique trajectory \(t\mapsto x(t;x_0)\). This defines the time-\(t\) flow map
Uniqueness implies non-intersection of trajectories, and in particular makes \(\psi_t\) (locally) invertible on its domain of existence: the inverse is given by running the same ODE backward in time, i.e., \(\psi_t^{-1}=\psi_{t\to 0}\) whenever both flows are well-defined. With the additional joint regularity of \(u,D_xu\) specified in Section 1.1.1, the maps are \(C^1\) diffeomorphisms between their domains of existence.
Derivation sketch (via change of variables). For this Taylor argument assume a positive, sufficiently smooth density and a sufficiently smooth field. Use the short-time exact flow expansion:
Then
and hence
using \(\det(I+\Delta t A)=1+\Delta t\,\mathrm{tr}(A)+O(\Delta t^2)\) and \(\nabla\!\cdot u=\mathrm{tr}(\nabla_x u)\). Applying the change-of-variable formula to the update gives
On the other hand, a Taylor expansion yields
Matching \(O(\Delta t)\) terms and rewriting via the product rule recovers (40) (and the trajectory form above).
At the measure level, the ODE flow map \(\psi_t\) (when well-defined) pushes the initial law forward:
When \(\mu_t(dx)=p_t(x)\,dx\) exists, the continuity equation (40) is the density-level expression of \(\mu_t=(\psi_t)_\#\mu_0\).
2.1.4 ODE vs SDE: push-forward map vs stochastic evolution¶
For an Itô SDE, sample paths satisfy
and, for genuinely stochastic dynamics, \(X_t\) depends on the Brownian path as well as \(X_0\). Its transition kernel is generally not a Dirac mass, so a deterministic function of the initial state alone does not represent these sample paths. This does not rule out a different deterministic flow with the same one-time marginals: the probability-flow ODE in Section 2.2 is precisely such a construction when its assumptions hold. Marginal equality and equality of stochastic trajectories are different claims.
For deterministic coefficients and a well-posed Markov SDE, the law evolves via a two-time transition kernel \(P_{s,t}\), with \(0\le s\le t\le1\). Below write \(P_t:=P_{0,t}\) for evolution from the fixed initial time. For time-dependent coefficients this is a transition family, not generally a one-parameter semigroup; semigroup notation applies in the time-homogeneous case. In a notation that mirrors the push-forward \(\#\), it is common to view \(P_t\) as inducing a push-forward operator on measures (the adjoint of \(P_t\) acting on test functions).
Kernel \(\Rightarrow\) measure push-forward. Let \(P_t(x,\cdot)\) be a probability measure on \(\mathbb{R}^D\) for each \(x\), and write \(P_t(x,A)\) for its mass on a Borel set \(A\). Define the induced operator \(P_t^\ast\) on measures by
Then the law evolution is simply
Many notes also write this as \(\mu_t=\mu_0 P_t\) (right action) or, informally, \(\mu_t=(P_t)_\#\mu_0\) to emphasize “push-forward by a stochastic mechanism”. The safest (unambiguous) notation is \(P_t^\ast \mu_0\).
Dual (test-function) form. The same evolution can be written as
for bounded measurable \(\varphi\). This is exactly the “kernel vs measure” adjoint relationship: \(P_t\) acts on functions, \(P_t^\ast\) acts on measures.
Deterministic maps as a special case. If \(P_t\) comes from a deterministic map \(\psi_t\), then
So the usual push-forward \((\psi_t)_\#\) is recovered by taking a Dirac transition kernel.
When a density \(p_t\) exists, this kernel-level evolution is described by the Fokker–Planck equation (Section 2.2), which differs from the continuity equation by a second-order diffusion term.
Velocity-first vs density-first. These are choices of what to specify, not synonyms for Eulerian and Lagrangian descriptions. Either design can be examined through trajectories or densities. There is an important asymmetry:
- Velocity-first: specifying \(u(t,\cdot)\) (under well-posedness assumptions) determines the flow map \(\psi_t\), hence determines the pushed-forward laws \(\mu_t=(\psi_t)_\#\mu_0\) and (when densities exist) a unique density evolution via (40).
- Density-first: specifying only a density path \(t\mapsto p_t\) generally does not determine a unique velocity field. Indeed, if a vector field \(w_t(x)\) satisfies
then both \(u_t\) and \(u_t+w_t\) produce the same right-hand side in (40), hence the same density evolution. When both fields also admit well-posed flows and the transport equation has the required uniqueness, a single density path can therefore correspond to different particle flows. The boundary conditions must be respected by the added flux as well.
Realizability requires both compatibility and well-posedness. A proposed density path and velocity must satisfy the continuity equation with the correct initial law and boundary behavior. To conclude that this density is the pushforward by a unique ODE flow, we additionally need a well-posed ODE and uniqueness of the corresponding transport equation in the solution class. Under the regularity assumptions above these statements agree. For rough velocities, a weak PDE solution alone need not provide a unique deterministic flow; continuity-equation compatibility must not be used as an unqualified definition of such a flow.
Conditioning. Let \(Z\) have probability law \(\pi\), and use an initial law \(\mu_0\) independent of \(Z\). For each fixed \(z\), assume a well-posed conditional flow \(\psi_t(\cdot;z)\). Then
The density statements require absolute continuity and the stated regularity. The marginal density is
This notation also covers discrete conditions. If the initial state depends on \(Z\), replace \(\mu_0\) by the conditional law \(\mu_0^z\); a shared initial law cannot then be assumed.
2.1.5 Path-first (density-first) vs velocity-first: where diffusion and flow matching fit¶
In modern generative modeling, it is useful to separate two design patterns:
- Path-first / density-first: first specify (explicitly or implicitly) a probability path \((\mu_t)_{t\in[0,1]}\) or a forward corruption mechanism that induces \(\mu_t\), and then learn dynamics that are consistent with that path.
- Velocity-first: first specify a parameterized dynamics family (e.g., a flow map or vector field \(u_\theta\)), and then fit it to data using an objective; the induced path \(\mu_t\) is whatever that dynamics produces.
Flow-based generative modeling can be understood as a Lagrangian particle system whose Eulerian density evolution satisfies the continuity equation (in a suitable weak sense, and as a pointwise PDE under additional regularity), expressing pure transport and conservation of probability mass. This is a useful intuition for why, in a velocity-first viewpoint, we do not “impose (40) as a constraint”: once we specify the particle dynamics \(\dot X_t=u(t,X_t)\) and define \(\mu_t=(\psi_t)_\#\mu_0\), (40) follows as the density-level statement of mass conservation. By contrast, in a path-first/density-first viewpoint, (40) acts as a compatibility condition between a prescribed \(p_t\) and a velocity field \(u\).
Here “first” refers to what is treated as the design input in modeling/derivation/training (what you specify up front), not what is “known during sampling”. In both paradigms, once dynamics are learned, sampling proceeds by integrating an ODE/SDE.
“Design input” means something you choose to specify that defines the modeling problem; “known” means something that is already given at a particular stage of an algorithm/derivation (often as an output of a previous stage).
Diffusion models and flow matching are typically path-first:
- Diffusion models: choose a forward noising SDE, or a compatible schedule within a specified SDE family, which defines a tractable forward path that “thickens” the data distribution. Training then learns a reverse-time object (often the score) that makes sampling possible.
- Flow matching / CFM: choose a probability path via a coupling + interpolation (e.g., endpoint pairing and \(\gamma_t(x_0,x_1)\)), then learn a velocity field that generates (or matches) that path.
In this path-first viewpoint, the continuity equation (40) plays the role of a consistency condition: a velocity field \(u\) generates a density path \(p_t\) only if \(p_t\) and \(u\) satisfy (40). In practice we rarely “solve (40) for \(u\)” directly because \(p_t\) is not available in closed form; instead, conditional regression supplies computable labels whose population-optimal field has the required consistency under the stated assumptions. Finite optimization and approximation do not inherit an exact guarantee.
At sampling time, these ODE/SDE models evaluate their learned fields and integrate the specified dynamics; there is no need to solve a density PDE at every sampling step. For an SDE, the drift alone is insufficient: its diffusion coefficient and random increments also enter the update.
2.2 Stochastic dynamics: Itô SDE¶
Work on a filtered probability space satisfying the usual completeness and right-continuity conditions. Let \(\mathbf X_0\) be measurable at time zero and let \(\mathbf W_t\) be an \(m\)-dimensional Brownian motion relative to that filtration (future increments are independent of present information). Solutions and stochastic integrands are adapted. One standard sufficient condition for a unique non-explosive strong solution on a finite interval is global spatial Lipschitz continuity and linear growth of the coefficients, uniformly in time, with measurable time dependence and a square-integrable initial state. These are sufficient assumptions, not necessary ones. They do not by themselves guarantee a smooth density. Consider the Itô SDE
where \(b:[0,1]\times\mathbb{R}^D\to\mathbb{R}^D\) is the drift and \(\sigma:[0,1]\times\mathbb{R}^D\to\mathbb{R}^{D\times m}\) is the diffusion coefficient. Define the diffusion matrix
Assume \(\mu_t(dx)=p_t(x)\,dx\) exists and \(b,\sigma\) are regular enough. Then \(p_t\) satisfies the Fokker–Planck (forward Kolmogorov) equation
Special cases:
- Pure transport (\(\sigma\equiv 0\)): the second-order term vanishes and we recover the continuity equation.
- Isotropic diffusion (\(a(t,x)=\beta(t)I\)): the second-order term becomes \(\frac{1}{2}\beta(t)\Delta p_t\).
In the diffusion-model setting, a common special case is
i.e., \(\sigma(t,x)=g(t)I\). Then
Where the density is positive and differentiable, using \(\nabla p_t=p_t\nabla\log p_t\), this can be rewritten in a divergence (mass conservation) form:
The drift transports probability, while the Laplacian accounts for stochastic spreading. Appendix B derives this equation using Itô's formula. The divergence rewriting identifies the probability-flow velocity
Under the additional ODE/PDE well-posedness and uniqueness conditions, this deterministic field reproduces the SDE's one-time marginals from the same initial law, not its Brownian trajectories. For the reverse SDE, use increasing generation time \(r=T-t\), and initialize \(Y_0\) with the forward terminal law \(p_T\). Under the time-reversal regularity assumptions,
The second line is the reversed probability-flow ODE. The score coefficient differs by a factor of two, so simply dropping the reverse-SDE noise does not give this ODE. These formulas assume scalar, spatially constant diffusion; state-dependent diffusion needs additional terms. Approximate scores or guidance modifications do not automatically retain the exact marginal correspondence. See Song et al. and the guidance discussion.
2.3 Understanding the continuity equation¶
The continuity equation is a conservation law for a density. In our context, it describes conservation of probability mass under deterministic transport.
2.3.1 A fixed region and its probability flux¶
For a three-dimensional illustration of the same conservation mathematics, take a small fixed box (control volume) whose lower corner is \(\xi=(x,y,z)\in\mathbb{R}^3\), with side lengths \(\Delta x,\Delta y,\Delta z\). Let \(p(\xi,t)\) be the density of a conserved quantity (mass or probability). The total amount inside the box is approximately
For a conserved quantity with no sources or sinks, changes occur through flux across the boundary. For generative models these are data-space probabilities, not a claim that data obey physical fluid laws. Let \(j(\xi,t)\in\mathbb{R}^3\) be the flux vector (amount crossing unit area per unit time). The net outflux in the \(x\)-direction is approximately
and similarly for the other directions. To leading order for a smooth flux, summing the three directions gives
Conservation says “rate of change inside = minus net outflux”, hence
Divide by the box volume and take the side lengths to zero to obtain the local form
For deterministic particle transport with velocity field \(u(t,x)\), the natural flux is \(j=p\,u\). Plugging this into the conservation law gives the continuity equation
which is exactly (40) in Section 2.1.3.
Correction (2026-10-14). The earlier face-difference and total-outflux expressions had the sign of net influx, while the final continuity equation had the correct sign. Outflux is the right-face contribution minus the left-face contribution; accumulation is its negative. For example, positive divergence gives net outward flow and decreases the amount in a fixed box.
2.3.2 Derivation from a global conservation law (divergence theorem)¶
Let \(p(x,t)\) be a density on \(\mathbb{R}^D\), \(u(t,x)\) a velocity field, and \(V\subset\mathbb{R}^D\) an arbitrary control volume with a sufficiently regular boundary \(\partial V\) and outward unit normal \(n\). The total mass in \(V\) is
so its time derivative is the accumulation rate \(\frac{d}{dt}\int_V p\,dx\). The outward flux through the boundary is
Conservation requires
Using the divergence theorem,
so
For differentiable density and flux the divergence-theorem argument gives a pointwise equation (or an almost-everywhere identity with suitable integrability). For nonsmooth fields one instead uses the distributional test-function formulation. The resulting equation is
Appendix A — Integrating factor derivation (scalar linear ODE)¶
This appendix spells out the algebra behind the integrating-factor identity used in Section 1.1.1.
A.1 Problem¶
Let \(L:[0,1]\to\mathbb{R}\) and \(r:[0,1]\to\mathbb{R}\) be continuous. Consider the inhomogeneous linear ODE
Fix \(0\le s\le t\le 1\) and assume \(x(\cdot)\) is differentiable.
A.2 Step 1: define the integration factor and its derivative¶
Define
By the chain rule and the fundamental theorem of calculus,
A.3 Step 2: product rule (the key identity)¶
Using the product rule,
Substituting \(\frac{d}{dt}E^{-1}(s\to t)=-L(t)E^{-1}(s\to t)\) gives
If \(\dot x(t)=L(t)x(t)+r(t)\), then \(\dot x(t)-L(t)x(t)=r(t)\), hence
A.4 Step 3: integrate from \(s\) to \(t\)¶
Integrate both sides from \(s\) to \(t\) (use \(\tau\) as the integration variable):
By the fundamental theorem of calculus, the left-hand side is
Since \(E^{-1}(s\to s)=\exp(0)=1\), we obtain
A.5 Step 4: solve for \(x(t)\) (the closed-form formula)¶
Multiply both sides by \(E(s\to t)\):
Finally, note that
so the solution can be written as
Appendix B — Derivation of the Fokker–Planck equation (isotropic diffusion)¶
This appendix derives the Fokker–Planck equation for the diffusion-model-style SDE
where \(X_t\in\mathbb{R}^D\), \(W_t\) is a standard \(D\)-dimensional Brownian motion, \(f:\mathbb{R}^D\times[0,T]\to\mathbb{R}^D\), and \(g:[0,T]\to[0,\infty)\). We assume enough regularity (existence of a smooth density \(p_t\) and sufficient decay at infinity) to justify exchanging derivatives/integrals and integrating by parts.
B.0 Notation and assumptions (what we use implicitly)¶
- Write \(X_t=(X_t^{(1)},\dots,X_t^{(D)})\) and \(W_t=(W_t^{(1)},\dots,W_t^{(D)})\).
- \(\nabla\varphi=(\partial_{x_1}\varphi,\dots,\partial_{x_D}\varphi)\), \(\Delta\varphi=\sum_{i=1}^D \partial_{x_i x_i}\varphi\), and \(\nabla\!\cdot F=\sum_{i=1}^D \partial_{x_i}F_i\).
- The quadratic covariation of Brownian motion satisfies
Consequently, since \(dX_t^{(i)}=\cdots + g(t)\,dW_t^{(i)}\),
B.1 From Itô’s formula to the generator identity (weak form)¶
Let \(\varphi\in C_c^\infty(\mathbb{R}^D)\) be a smooth test function with compact support. Define the (time-dependent) Itô generator
Step 1 (Itô’s formula, written component-wise). Since \(X_t\) solves \(dX_t=f(X_t,t)\,dt+g(t)\,dW_t\), Itô’s formula says
Substitute \(dX_t^{(i)}=f_i(X_t,t)\,dt+g(t)\,dW_t^{(i)}\) and \(d\langle X^{(i)},X^{(j)}\rangle_t=g(t)^2\delta_{ij}\,dt\):
Recognizing the dot products, this is exactly
Step 2 (integrate and take expectations). Integrate from \(0\) to \(t\):
Taking expectations and using that the Itô stochastic integral is a martingale with zero mean (under standard square-integrability conditions),
This is the weak evolution equation: it characterizes the time derivative of \(\mathbb{E}[\varphi(X_t)]\) for every test function \(\varphi\).
B.2 Convert the generator identity into a PDE for \(p_t\)¶
If \(X_t\) has density \(p_t\), then
Plugging into (97) gives
Step 1 (drift term: one integration by parts). Write the drift term coordinate-wise:
Integrate by parts in \(x_i\) (boundary terms vanish due to compact support/decay):
Summing over \(i\) yields
Step 2 (diffusion term: two integrations by parts). Since \(g(t)\) does not depend on \(x\), we can factor it out. Using that the Laplacian is formally self-adjoint under these boundary conditions,
One way to see this is coordinate-wise: for each \(i\),
then sum over \(i=1,\dots,D\). Therefore,
Since this holds for all \(\varphi\in C_c^\infty(\mathbb{R}^D)\), we conclude the Fokker–Planck equation (in the weak sense, and pointwise under additional regularity):
B.3 Divergence form and the score¶
The Fokker–Planck equation can be rewritten so that the right-hand side is a single divergence \(-\nabla\!\cdot(\text{flux})\), making the “mass conservation” structure explicit.
Step 1 (write diffusion as divergence of a flux). Since \(g(t)\) is independent of \(x\),
In the last equality we used \(\nabla p_t=p_t\nabla\log p_t\), valid wherever \(p_t>0\). At zeros of the density, retain the flux \(\nabla p_t\); a pointwise score need not be defined there.
Step 2 (combine drift flux and diffusion flux). Substituting into (106) yields the pure-divergence form
which matches the common “drift minus diffusion-times-score” decomposition.
Remark (general diffusion matrix). For a general Itô SDE \(dX_t=b\,dt+\sigma\,dW_t\) with \(a=\sigma\sigma^\top\), the diffusion term becomes \(\frac12\sum_{ij}\partial_{x_i}\partial_{x_j}(a_{ij}p_t)\). The isotropic case above corresponds to \(a(t,x)=g(t)^2 I\).
References¶
- Chieh-Hsin Lai, Yang Song, Dongjun Kim, Yuki Mitsufuji and Stefano Ermon. The Principles of Diffusion Models. 2025; revised 2026. Background on the relationship between diffusion and flow formulations.
- Yang Song et al. Score-Based Generative Modeling through Stochastic Differential Equations. ICLR 2021. Reverse-time SDEs and probability-flow ODEs.
- Related notes: Diffusion models intro, Flow matching, Comparison and code, and Guidance.