Skip to main content
Open In Colab This section repeats the steps of the score-based section on a two-dimensional mixture, with data at t=0t = 0. The forward process, the training loss and the two samplers are the ones derived there, now applied to vector fields. Here too the exact score is known, and every learned quantity is checked against it.

The target distribution

The data distribution p0p_0 is the 2D mixture of the DDPM and DDIM sections: three anisotropic Gaussians with equal weights πk=1/3\pi_k = 1/3, means μk\mu_k and covariances Σk\Sigma_k. Those sections draw 300 points from it. Here you draw 3000 points, for a reason that the training section makes concrete. The forward process is the Ornstein-Uhlenbeck process dXt=−Xt dt+2 dWtdX_t = -X_t\,dt + \sqrt{2}\,dW_t, applied to each coordinate. At each fixed tt, XtX_t has the distribution of atX0+bt εa_t X_0 + b_t\,\varepsilon with at=e−ta_t = e^{-t}, bt=1−e−2tb_t = \sqrt{1 - e^{-2t}} and ε∼N(0,I)\varepsilon \sim \mathcal{N}(0, I). A Gaussian component stays Gaussian under this map, so ptp_t is again a mixture, with means atμka_t \mu_k and covariances Σk,t=at2 Σk+bt2 I.\Sigma_{k,t} = a_t^2\,\Sigma_k + b_t^2\,I . The horizon is T=4T = 4 and the small-noise cutoff is tmin⁡=10−3t_{\min} = 10^{-3}, as in the score-based section.
Three panels of the two-dimensional density p_t at t = t_min, 0.5 and 2, drawn as gray shading. The first panel also shows a third of the 3000 data points in blue on three elongated clusters. As t grows, the clusters shrink toward the origin and widen into one round blob. The density ptp_t at t=tmin⁡t = t_{\min}, 0.50.5 and 22, with a third of the 3000 data points on the first panel. As tt grows the components shrink toward the origin and widen toward the identity covariance.

The exact mixture score

The score of ptp_t follows from the posterior average of the score-based section, with vectors and matrices in place of numbers. Each component of ptp_t has the score Σk,t−1(atμk−x)\Sigma_{k,t}^{-1}(a_t \mu_k - x), and the score of the mixture weights them by the responsibilities: st(x)=∑krk(x,t) Σk,t−1 (atμk−x).s_t(x) = \sum_k r_k(x, t)\,\Sigma_{k,t}^{-1}\,(a_t \mu_k - x) . Here rk(x,t)r_k(x, t) is the posterior probability of component kk given Xt=xX_t = x, the responsibility of the EM algorithm. This field is the ground truth for everything that follows. The responsibilities are computed from log densities with the log-sum-exp identity, so the field stays finite where ptp_t underflows. The check compares it with a central finite difference of log⁡pt\log p_t at every point of a grid over the plot box, at t=0.05t = 0.05, 0.50.5 and 22. The same responsibilities, averaged over a set of samples at tmin⁡t_{\min}, give the mass that the samples put on each component.
Two panels of the exact score at t = 0.1 and t = 1. Unit arrows colored by the log of the score magnitude point toward the nearest high-density region. The background blends one color per mixture component by responsibility, and black curves are level sets of log p_t. The exact score at t=0.1t = 0.1 and t=1t = 1. Arrows show direction only, colored by the log of the magnitude. The background color mixes one color per component in proportion to the responsibilities, and the black curves are level sets of log⁡pt\log p_t. Inside each colored region the field is close to the straight-line score of one component. Where the colors blend, the responsibilities hand the field from one component to the next. The score field ∇log⁡p0\nabla \log p_0 of the data distribution, the limit of the figures above as t→0t \to 0.

Learning the score field

The network and the loss are those of the score-based section, with two outputs in place of one. The network predicts noise, εθ(x,t)\varepsilon_\theta(x, t), and returns the score sθ=−εθ/bts_\theta = -\varepsilon_\theta / b_t. With the weight λ(t)=bt2\lambda(t) = b_t^2 the loss is L(θ)=E bt2 ∥sθ(Xt,t)+ε/bt∥2=E ∥ε−εθ(Xt,t)∥2,\mathcal{L}(\theta) = \mathbb{E}\,b_t^2\,\bigl\lVert s_\theta(X_t, t) + \varepsilon / b_t \bigr\rVert^2 = \mathbb{E}\,\bigl\lVert \varepsilon - \varepsilon_\theta(X_t, t) \bigr\rVert^2 , with X0X_0 drawn from the 3000 data points and log⁡t\log t uniform on [log⁡tmin⁡,log⁡T][\log t_{\min}, \log T] (Vincent, 2011; Song et al., 2020). The table reports the weighted RMSE, the error averaged over samples of ptp_t, and the grid RMSE over the plot box. The relative weighted RMSE divides the weighted RMSE by that of the zero function, which is the root mean square of the exact score under ptp_t.
Three panels. Left and middle, at t = 0.1 and t = 1, wide blue arrows for the exact score and thin gray arrows for the learned score over gray level sets of log p_t; the two fields agree near the data. Right, a log-log plot of score RMSE against t for the weighted RMSE, the grid RMSE on the plot box, and the weighted RMSE of the zero function as a dashed gray reference. Left and middle, the exact score (blue, wide arrows) and the learned score (gray, thin arrows) at t=0.1t = 0.1 and t=1t = 1, both on one scale, over level sets of log⁡pt\log p_t. Right, the weighted and grid RMSE at 30 noise levels, with the weighted RMSE of the zero function for scale. The learned field matches the exact one where the data is. For tt between 0.1 and 1 the relative weighted RMSE stays between 0.07 and 0.12. It rises to 0.17 at t=0.01t = 0.01 and 0.48 at tmin⁡t_{\min}. The grid RMSE is 10 to 70 times the weighted RMSE, because most of the plot box lies far from all three components, where no training sample lands. As in one dimension, the loss counts errors only where noisy samples fall. The number of data points sets a floor on this accuracy. On a fixed data set the minimizer of the loss is the score of the scaled data points atxia_t x_i, each smoothed by a Gaussian of standard deviation btb_t, which is about 0.43 at t=0.1t = 0.1. At small noise this field pulls a point toward the nearest data points, not toward the center of its component. The pull averages out to the exact score only when the data points are dense. On the 300 points of the DDPM section the minimizer has a relative weighted RMSE of 0.91 at t=0.1t = 0.1. On the 3000 points used here it is 0.23, and the network reaches 0.12, because its smoothness keeps it from fitting each point separately. At t=0.5t = 0.5 and t=1t = 1 the minimizer on 3000 points is closer to the exact score than the network (0.04 and 0.02 against 0.10 and 0.07), so there the network’s own fitting error dominates.

Sampling in the reverse clock

The samplers are those of the score-based section. In the reverse clock u=T−tu = T - t, with Yu=XT−uY_u = X_{T-u}, dYu=(Yu+2 sT−u(Yu)) du+2 dWu,dYudu=Yu+sT−u(Yu),\begin{aligned} dY_u &= \bigl(Y_u + 2\,s_{T-u}(Y_u)\bigr)\,du + \sqrt{2}\,dW_u , \\ \frac{dY_u}{du} &= Y_u + s_{T-u}(Y_u) , \end{aligned} the reverse SDE (Anderson, 1982) and the reverse probability flow ODE (Song et al., 2020). Both run from u=0u = 0 to u=T−tmin⁡u = T - t_{\min} in 500 steps, evenly spaced in log⁡t\log t, with Euler-Maruyama for the SDE and Heun’s method for the ODE. Three runs separate the sources of error. Run A starts from exact samples of pTp_T and uses the exact score, so it measures integration error. Run D starts from N(0,I)\mathcal{N}(0, I) and uses the learned score: it is the practical model. Run B starts from N(0,I)\mathcal{N}(0, I) with the exact score, which isolates the prior gap. Run D is repeated with networks trained from seeds 1 and 2. The distance to the target is the sliced Wasserstein distance. It projects both distributions onto a direction, computes the one-dimensional W1W_1 between the projections, and averages over directions. Here it uses 64 random directions, and the projection of ptmin⁡p_{t_{\min}} onto a direction is an exact one-dimensional Gaussian mixture. The sliced distance is a different quantity from the two-dimensional W1W_1, so the two are not compared. Mass per component is reported next to it, because a sampler can reach all three components with the wrong weights.
Three scatter plots of 3000 points each: exact samples of p_t_min in blue, run D of the reverse SDE in green, and run D of the probability flow ODE in orange. All three show the same three clusters, and the ODE panel has more points between the clusters and in the tails. 3000 exact samples of ptmin⁡p_{t_{\min}} (left) and 3000 samples of run D from each sampler, which starts from N(0,I)\mathcal{N}(0, I) and uses the learned score. The ODE samples include more points between the components and in the tails than the other two panels. Run A sets the baseline. Both samplers reach a sliced distance close to the sampling floor of 0.032±0.0090.032 \pm 0.009 from the numerical checks below: 0.033 for the ODE and 0.037 for the SDE. Halving the step size leaves the ODE value unchanged to three decimals and moves the SDE value to 0.027, a change within the sampling noise, since the refined SDE run draws new noise. Integration error is small next to everything else in the table. With the learned score the reverse SDE stays close to the floor. Run D gives 0.043, 0.060 and 0.048 for the three training seeds, and the mass per component stays within 0.005 of πk\pi_k in every seed. The probability flow ODE shows a prior gap that the SDE removes. Started from N(0,I)\mathcal{N}(0, I) with the exact score in run B, the ODE reaches 0.168 and puts 0.363 of the mass on the component at the origin, where the SDE reaches 0.041. The means of this mixture lie farther from the origin than those of the one-dimensional mixture, so at the same horizon pTp_T differs more from N(0,I)\mathcal{N}(0, I). The ODE adds no noise, so a particle that starts on the wrong side of the boundary between two components ends in the wrong one. The SDE adds noise at every step, which moves particles between components while the noise is large and corrects the start. With the learned score, run D of the ODE gives 0.171, 0.126 and 0.081 for the three seeds, with the mass per component off by up to 0.032. Two of the three seeds land below run B. The starting draws also differ between seeds, but a new draw changes the distance by about the 0.009 spread of the sampling floor, so most of the spread comes from the networks. The errors of the learned score are about as large as the prior gap, and in some seeds they partly offset it. Three seeds are too few to say how the two errors combine on average.

Numerical checks

Two reference values put the sliced distances in context. The sampling floor is the sliced distance of 10000 exact samples of ptmin⁡p_{t_{\min}}, over five independent draws. The cost of the cutoff is the sliced distance between p0p_0 and ptmin⁡p_{t_{\min}}, computed from the exact projected CDFs without sampling.
The sliced distance between p0p_0 and ptmin⁡p_{t_{\min}} is 0.0032, a tenth of the sampling floor of 0.032±0.0090.032 \pm 0.009. The cutoff therefore accounts for little of the distances in the table. The samplers still target ptmin⁡p_{t_{\min}}, and they reach p0p_0 only up to this distance.

Further reading

The score-based section derives every step used here and runs the full set of diagnostics in one dimension. Song and Ermon trained a score network on a variance-exploding process and sampled with annealed Langevin dynamics (Song & Ermon, 2019). The score matching objective without noise is due to Hyvärinen (Hyvärinen, 2005).

PyTorch reference

References

  • Anderson, B. (1982). Reverse-time diffusion equation models. Stoch. Process. Their Appl. DOI
  • Hyvärinen, A. (2005). Estimation of non-normalized statistical models by score matching. Journal of Machine Learning Research. Link
  • Song, Y., Sohl-Dickstein, J., Kingma, D., Kumar, A., Ermon, S., et al. (2020). Score-based generative modeling through stochastic differential equations. arXiv [cs.LG]. DOI
  • Song, Y., Ermon, S. (2019). Generative modeling by estimating gradients of the data distribution. arXiv [cs.LG]. DOI
  • Vincent, P. (2011). A connection between score matching and denoising autoencoders. Neural Comput. DOI

Found an error on this page? Report an issue.