The target distribution
The data distribution is the 2D mixture of the DDPM and DDIM sections: three anisotropic Gaussians with equal weights , means and covariances . 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 , applied to each coordinate. At each fixed , has the distribution of with , and . A Gaussian component stays Gaussian under this map, so is again a mixture, with means and covariances The horizon is and the small-noise cutoff is , as in the score-based section.Code
Code
The exact mixture score
The score of follows from the posterior average of the score-based section, with vectors and matrices in place of numbers. Each component of has the score , and the score of the mixture weights them by the responsibilities: Here is the posterior probability of component given , 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 underflows. The check compares it with a central finite difference of at every point of a grid over the plot box, at , and . The same responsibilities, averaged over a set of samples at , give the mass that the samples put on each component.Code
Code
Code
Code
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, , and returns the score . With the weight the loss is with drawn from the 3000 data points and uniform on (Vincent, 2011; Song et al., 2020). The table reports the weighted RMSE, the error averaged over samples of , 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 .Code
Code
Code
Code
Sampling in the reverse clock
The samplers are those of the score-based section. In the reverse clock , with , the reverse SDE (Anderson, 1982) and the reverse probability flow ODE (Song et al., 2020). Both run from to in 500 steps, evenly spaced in , 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 and uses the exact score, so it measures integration error. Run D starts from and uses the learned score: it is the practical model. Run B starts from 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 between the projections, and averages over directions. Here it uses 64 random directions, and the projection of onto a direction is an exact one-dimensional Gaussian mixture. The sliced distance is a different quantity from the two-dimensional , 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.Code
Code
Code
Code
Numerical checks
Two reference values put the sliced distances in context. The sampling floor is the sliced distance of 10000 exact samples of , over five independent draws. The cost of the cutoff is the sliced distance between and , computed from the exact projected CDFs without sampling.Code
Code
Code
Code
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.

