Example 1.61 (Diffusion Model). Consider the forward OU process \[ \mathrm {d}x_t = -\tfrac {1}{2}x_t\,\mathrm {d}t + \mathrm {d}B_t, \quad x_0 \sim p_0. \] A direct computation gives \(x_t | x_0 \sim N(\alpha _t x_0,\, \sigma _t^2 I)\)
where \(\alpha _t = e^{-t/2}\) and \(\sigma _t^2 = 1 - e^{-t}\). As \(t \to \infty \), the distribution \(p_t\) converges exponentially to \(N(0, I)\) — structure is destroyed and replaced
by pure noise.
By the Fokker–Planck equation, the density \(p(x,t)\) satisfies \[ \frac {\partial p}{\partial t} = \nabla \cdot \left (\tfrac {1}{2}x\, p\right ) + \tfrac {1}{2}\Delta p = \tfrac {1}{2}\nabla \cdot \left (x\, p + \nabla p\right ). \]
Reverse SDE.
Anderson (1982) showed that for a general forward SDE \(\mathrm {d}x_t = f(x,t)\,\mathrm {d}t + g(t)\,\mathrm {d}B_t\), a reverse process is given by \[ \mathrm {d}\tilde {x}_t = \left [f(\tilde {x}_t, t) - g^2(t)\,\nabla _x \log p(\tilde {x}_t, t)\right ]\mathrm {d}t + g(t)\,\mathrm {d}\bar {B}_t, \quad t: T \to 0, \] where \(\bar {B}_t\) is a
backward Brownian motion.
Proof. The forward SDE \(\mathrm {d}x_t = f\,\mathrm {d}t + g\,\mathrm {d}B_t\) has Fokker–Planck equation \[ \frac {\partial p}{\partial t} = -\nabla \cdot (f\, p) + \tfrac {1}{2}g^2 \Delta p. \] Set \(s = T - t\) and \(q(x,s) = p(x, T-s)\). Since \(\partial q / \partial s = -\partial p / \partial t\), the density \(q\) must satisfy \[ \frac {\partial q}{\partial s} = \nabla \cdot (f\,p) - \tfrac {1}{2}g^2 \Delta p. \tag {$\star $} \] Now we
verify that the proposed reverse SDE, with drift \(h = -f + g^2 \nabla _x \log p\) and diffusion \(g\), reproduces \((\star )\). Its Fokker–Planck equation
in \(s\) reads \(\partial q / \partial s = -\nabla \cdot (h\,q) + \tfrac {1}{2}g^2 \Delta q\). Substituting \(q = p\) and using \(p\,\nabla \log p = \nabla p\): \begin{align*} -\nabla \cdot (h\,p) + \tfrac {1}{2}g^2 \Delta p &= \nabla \cdot (f\,p) - \underbrace {\nabla \cdot (g^2 \nabla p)}_{=\, g^2 \Delta p} + \tfrac {1}{2}g^2 \Delta p = \nabla \cdot (f\,p) - \tfrac {1}{2}g^2 \Delta p, \end{align*}
which matches \((\star )\). □
For our OU process, \(f(x,t) = -x/2\) and \(g = 1\), so the reverse SDE reads \[ \mathrm {d}\tilde {x}_t = \left [-\tfrac {1}{2}\tilde {x}_t - \nabla _x \log p(\tilde {x}_t, t)\right ]\mathrm {d}t + \mathrm {d}\bar {B}_t. \] If we knew the score function \(\nabla _x \log p(x,t)\), we could simulate
this backward from \(\tilde {x}_T \sim N(0,I)\) and recover samples from \(p_0\). The entire problem reduces to learning the
score.
Denoising score matching
We want to minimize \(L_t(\theta ) = \mathbb {E}_{x \sim p_t}\left [\|s_\theta (x,t) - \nabla _x \log p(x,t)\|^2\right ]\), but \(\nabla _x \log p(x,t)\) is unknown. The key trick is integration by parts. Expand the square and note
that the cross term satisfies \[ \int \langle s_\theta ,\, \nabla _x p\rangle \,\mathrm {d}x = -\int (\nabla \cdot s_\theta )\, p\,\mathrm {d}x. \] Now use \(p(x,t) = \int p_t(x|x_0)\,p_0(x_0)\,\mathrm {d}x_0\) and apply integration by parts again on the inner integral. After
recombining, we get \[ L_t(\theta ) = \mathbb {E}_{x_0 \sim p_0}\,\mathbb {E}_{x_t | x_0}\left [\|s_\theta (x_t, t) - \nabla _{x_t} \log p_t(x_t | x_0)\|^2\right ] + C, \] where \(C\) is independent of \(\theta \). The crucial point: the intractable marginal score \(\nabla \log p\) has been
replaced by the conditional score \(\nabla \log p_t(\cdot | x_0)\), which is explicitly computable. Since \(x_t | x_0 \sim N(\alpha _t x_0,\, \sigma _t^2 I)\), we have \(\nabla _{x_t} \log p_t(x_t|x_0) = -(x_t - \alpha _t x_0)/\sigma _t^2 = -\xi _t/\sigma _t\) where \(x_t = \alpha _t x_0 + \sigma _t \xi _t\) and \(\xi _t \sim N(0,I)\).
The final training objective is therefore \[ \min _\theta \; \mathbb {E}_t\,\mathbb {E}_{x_0}\,\mathbb {E}_{\xi _t}\left [\left \|s_\theta (\alpha _t x_0 + \sigma _t \xi _t,\, t) - \frac {\xi _t}{\sigma _t}\right \|^2\right ], \] which only requires samples from \(p_0\) and standard
Gaussians.