Skip to main content
Open In Colab What happens when particles move stochastically? Every diffusion model (DDPM, DDIM, score SDEs) has Brownian motion at its core. The discrete forward chain you saw in the DDPM tutorial, clusters dissolving into Gaussian noise, is a discrete variance-preserving process: each step shrinks the signal and adds fresh noise. Its continuous-time form is the Ornstein-Uhlenbeck (variance-preserving) SDE of the drift section below, driven by a Wiener process. Building intuition for the Wiener process makes the rest of the diffusion-model machinery click. In the probability transport chapter each particle followed a velocity field, and its path was smooth. A Brownian path has no velocity: it is continuous but nowhere differentiable. Its density still changes smoothly in time. The continuity equation of the transport chapter describes how a velocity field moves a density; Brownian motion adds a spreading term to that equation, and the result is the Fokker-Planck equation.

Math recap: the Wiener process

A standard Wiener process WtW_t on [0,T][0, T] is a continuous-time stochastic process satisfying:
  • W0=0W_0 = 0
  • Independent increments: for 0≤s<t0 \le s < t, Wt−Ws∼N(0,t−s)W_t - W_s \sim \mathcal{N}(0, t - s), independent of the path up to time ss
  • Continuous paths
A discrete-time approximation with step Δt\Delta t is the random walk Wt+Δt=Wt+Δt  ξ,ξ∼N(0,1)W_{t + \Delta t} = W_t + \sqrt{\Delta t}\; \xi, \quad \xi \sim \mathcal{N}(0, 1) Multiplied by a noise scale σ\sigma this gives Brownian motion with variance σ2t\sigma^2 t. Later sections write the noise scale as gg, the same quantity as σ\sigma here, and use the diffusion coefficient D=g2/2D = g^2/2 in the next two sections. The DDPM forward chain q(xt∣xt−1)=N(xt;1−βt xt−1,βtI)q(x_t \mid x_{t-1}) = \mathcal{N}(x_t; \sqrt{1-\beta_t}\, x_{t-1}, \beta_t I) is a variance-preserving discrete-time analogue: it adds Brownian-style noise and shrinks the signal each step so the marginal stays bounded.

Brownian motion in motion

Eight particles start at the origin and trace independent random walks. The trail behind each particle is its history: short trajectories stay near the origin on either side, and the cloud widens the longer the walk runs.

Eight Brownian trajectories

Eight particles released from the origin, each undergoing an independent random walk over 500 steps with σ=0.7\sigma = 0.7 and Δt=1/60\Delta t = 1/60. The colored end-dots mark each trajectory’s final position; the black dot at the origin marks the common start.
Output from cell 2

Snapshot grid of the Wiener process

200 fresh particles released from the origin, snapshotted at t=0,10,50,100,200,500t = 0, 10, 50, 100, 200, 500, the step indices the DDPM tutorial uses for its forward-noising visualization. These are Wiener snapshots at those indices, not DDPM marginals. The cloud spreads with variance proportional to tt, whereas the DDPM marginal variance saturates, as the drift section below shows.
Output from cell 4

Diffusion flux from unbiased steps

Put particles on a line with spacing Δx\Delta x. In each time step Δt\Delta t, every particle moves one site to the left or one site to the right, with probability one half each. The mean step is zero, so no particle prefers a direction. Now count the particles that cross the bond between site jj and site j+1j+1 in one step. Of the njn_j particles at site jj, about nj/2n_j/2 step right. Of the nj+1n_{j+1} particles at site j+1j+1, about nj+1/2n_{j+1}/2 step left. On average, the net number crossing from left to right is 12 (nj−nj+1).\tfrac{1}{2}\,(n_j - n_{j+1}). Where the density falls from left to right, nj>nj+1n_j > n_{j+1} and the net crossing is positive. Mass moves down the gradient even though every step is unbiased. To take the continuum limit, write nj=N p(xj) Δxn_j = N\,p(x_j)\,\Delta x for NN particles with density pp. For small Δx\Delta x the net crossing per step becomes −12 N Δx2 ∂xp-\tfrac{1}{2}\,N\,\Delta x^2\,\partial_x p. Each step has variance Δx2\Delta x^2. Brownian motion with noise scale gg (the σ\sigma above) has Δx2=g2Δt\Delta x^2 = g^2 \Delta t, so Δx2/(2Δt)=g2/2=D\Delta x^2 / (2\Delta t) = g^2/2 = D, and the net crossing per step is N (−D ∂xp) ΔtN\,(-D\,\partial_x p)\,\Delta t. The diffusion flux is therefore Fick’s law, Jdiff=−D ∂xp,D=g22.J_{\text{diff}} = -D\,\partial_x p, \qquad D = \frac{g^2}{2}. Take N=109N = 10^9 particles started from a smooth, decreasing profile (a logistic step on [−8,8][-8, 8]) with D=1D = 1 and Δx=0.1\Delta x = 0.1, so that Δt=Δx2/(2D)=0.005\Delta t = \Delta x^2 / (2D) = 0.005. Draw the random steps for every bond and compare the net crossing count with −D ∂xp Δt N-D\,\partial_x p\,\Delta t\,N.
Output from cell 7 At all three probe points the net crossing count matches Fick’s law to within a few percent. Along the whole profile in the figure, the net count follows −D ∂xp Δt-D\,\partial_x p\,\Delta t and goes to zero where the density is flat.

Adding a drift

A drift adds a second way to move mass. The stochastic differential equation dXt=f(Xt) dt+g dWtdX_t = f(X_t)\,dt + g\,dW_t moves each particle by f dtf\,dt on average, on top of the random part. The drift carries density with the local velocity ff, so it adds the flux Jdrift=f pJ_{\text{drift}} = f\,p. The total flux is the sum of the two terms, J=f p−D ∂xp.J = f\,p - D\,\partial_x p. The next section turns this flux into an equation for ptp_t. First, the drift acting on paths. The running example uses f(x)=−xf(x) = -x and g=2g = \sqrt{2}, so D=1D = 1. This is the Ornstein-Uhlenbeck process. Started from a point x0x_0, its position at time tt is Gaussian with mean x0 e−tx_0\,e^{-t} and variance 1−e−2t1 - e^{-2t}. The mean decays to zero and the variance rises to 1, which is the variance of N(0,1)\mathcal{N}(0, 1). The position XtX_t has the same distribution as e−tx0+1−e−2t Ze^{-t} x_0 + \sqrt{1 - e^{-2t}}\,Z with Z∼N(0,1)Z \sim \mathcal{N}(0, 1) at each fixed tt. This holds at each fixed tt separately: reusing a single ZZ for every tt would not give Ornstein-Uhlenbeck paths. Paths are built step by step from the exact transition Xt+h=e−h Xt+1−e−2h Z.X_{t+h} = e^{-h}\,X_t + \sqrt{1 - e^{-2h}}\,Z. Simulate 20000 paths from x0=2x_0 = 2 and compare the sample mean and variance at four times with the exact values.
Output from cell 10 The paths start at x0=2x_0 = 2 and scatter around a mean that decays like e−te^{-t}. The spread widens at first, like Brownian motion, and then stops growing because the drift pulls paths back toward zero. By t=4t = 4 the sample variance is close to 1 and the mean is close to 0.

Connection back to diffusion

Continuous-time diffusion frames the forward process as the SDE dxt=f(xt,t) dt+g(t) dWtdx_t = f(x_t, t)\, dt + g(t)\, dW_t where WtW_t is exactly the Brownian motion above. The variance-preserving SDE used by DDPM picks f(xt,t)=−12β(t) xtf(x_t, t) = -\tfrac{1}{2}\beta(t)\, x_t and g(t)=β(t)g(t) = \sqrt{\beta(t)}, so the variance stays bounded. Only the transition q(xt∣x0)q(x_t \mid x_0) is Gaussian. The marginal ptp_t remains a mixture at every finite tt and approaches a Gaussian only as tt grows. The discrete chain of the DDPM tutorial is the exact Ornstein-Uhlenbeck transition of the drift section, not an Euler-Maruyama approximation of it. A DDPM step 1−βk Xk−1+βk ϵk\sqrt{1-\beta_k}\, X_{k-1} + \sqrt{\beta_k}\, \epsilon_k equals e−hkXk−1+1−e−2hk ϵke^{-h_k} X_{k-1} + \sqrt{1 - e^{-2h_k}}\, \epsilon_k with hk=−12log⁡(1−βk)h_k = -\tfrac{1}{2}\log(1 - \beta_k). Step kk therefore sits at Ornstein-Uhlenbeck time tk=−12log⁡αˉkt_k = -\tfrac{1}{2}\log \bar\alpha_k, where αˉk=∏j≤k(1−βj)\bar\alpha_k = \prod_{j \le k} (1 - \beta_j). The forward process is Brownian motion plus a drift. The reverse direction uses the score. The network ϵθ\epsilon_\theta estimates E[ϵ∣xk]\mathbb{E}[\epsilon \mid x_k], and the score at step kk is ∂xlog⁡ptk(xk)=−E[ϵ∣xk]/bk\partial_x \log p_{t_k}(x_k) = -\mathbb{E}[\epsilon \mid x_k] / b_k with bk=1−αˉkb_k = \sqrt{1 - \bar\alpha_k}. This bkb_k equals the Ornstein-Uhlenbeck bt=1−e−2tb_t = \sqrt{1 - e^{-2t}} at t=tkt = t_k. The reverse-time drift follows from this score, and deterministic DDIM is the probability flow ODE limit. The two sections above give the total flux J=f p−D ∂xpJ = f\,p - D\,\partial_x p with D=g2/2D = g^2/2: a drift term that carries density and a diffusion term that spreads it. The next section, Fokker-Planck and the probability flow ODE, uses conservation of mass to turn JJ into the Fokker-Planck equation.

References

  1. Anderson. Reverse-time diffusion equation models. Stochastic Processes Appl. 1982.
  2. Song et al. Score-Based Generative Modeling through Stochastic Differential Equations. ICLR 2021. arxiv.org/abs/2011.13456
  3. Karatzas & Shreve. Brownian Motion and Stochastic Calculus. Springer 1991. (textbook)

Found an error on this page? Report an issue.