Estimating High Order Gradients of the Data Distribution by Denoising

Chenlin Meng, Yang Song, Wenzhe Li, Stefano Ermon

Abstract: The first order derivative of a data density can be estimated efficiently by denoising score matching, and has become an important component in many applications, such as image generation and audio synthesis. Higher order derivatives provide additional local information about the data distribution and enable new applications. Although they can be estimated via automatic differentiation of a learned density model, this can amplify estimation errors and is expensive in high dimensional settings. To overcome these limitations, we propose a method to directly estimate high order derivatives (scores) of a data density from samples. We first show that denoising score matching can be interpreted as a particular case of Tweedie's formula. By leveraging Tweedie's formula on higher order moments, we generalize denoising score matching to estimate higher order derivatives. We demonstrate empirically that models trained with the proposed method can approximate second order derivatives more efficiently and accurately than via automatic differentiation. We show that our models can be used to quantify uncertainty in denoising and to improve the mixing speed of Langevin dynamics via Ozaki discretization for sampling synthetic data and natural images.

1. Introduction

Score-based generative modeling and denoising typically rely on Denoising Score Matching (DSM) to estimate the first-order score—the gradient of the log data density. While effective, first-order scores lack local curvature information. Higher-order derivatives, such as the second-order score (the Hessian of the log density), are valuable for accelerating sampling algorithms and quantifying uncertainty in denoising tasks.

Traditionally, second-order scores are obtained by applying automatic differentiation (auto-diff) to a pre-trained first-order score model. However, this approach is computationally expensive in high dimensions, scaling linearly with the data dimension $D$. Furthermore, auto-diff can amplify estimation errors, as a model optimized for first-order accuracy may not yield reliable higher-order derivatives. This paper proposes a method to learn higher-order scores directly from data, bypassing these limitations.

2. Methodology

The proposed approach generalizes Tweedie’s formula, which relates the first-order score of a noise-perturbed distribution to the posterior mean of the clean data.

2.1 Generalized Tweedie's Formula and $D_2SM$

The authors demonstrate that Tweedie's formula extends to higher-order moments. Specifically, the second-order posterior moment $E[xx^T | \tilde{x}]$ can be expressed through a combination of first- and second-order scores of the noisy distribution. By formulating a least-squares regression to match these moments, the authors derive the Second-Order Denoising Score Matching ($D_2SM$) objective. This allows a neural network to directly parameterize and learn the Hessian of the log density.

2.2 Efficient Parameterization and Variance Reduction

To handle high-dimensional data, the second-order score model is parameterized using a low-rank matrix plus a diagonal component, avoiding the $O(D^2)$ storage requirement of a full Hessian. Additionally, to combat high variance in the loss function at small noise scales ($\sigma \to 0$), an antithetic sampling technique ($D_2SM-VR$) is introduced, which uses correlated noise vectors to stabilize training.

Figure 2: Training loss stabilization via variance reduction (VR) and accuracy of estimated first-order and second-order scores compared to ground truth.

3. Experimental Evaluation

The method was evaluated on synthetic datasets (e.g., mixtures of logistics) and image datasets (MNIST, CIFAR-10).

3.1 Accuracy and Efficiency

Directly evaluating a learned second-order model is up to 500x faster than computing the Hessian via auto-diff through a U-Net on MNIST. On high-dimensional synthetic data, the $D_2SM$ method achieved significantly lower Mean Squared Error (MSE) against ground-truth Hessians compared to the auto-diff baseline.

3.2 Sampling and Uncertainty

Incorporating second-order scores into Langevin dynamics via Ozaki discretization significantly improves mixing speeds. As shown in Figure 3, models using second-order information produce higher-quality samples with fewer steps compared to standard first-order methods.

Figure 3: Qualitative comparison of sampling on synthetic ring and spiral datasets. Incorporating second-order scores leads to better alignment with the true data distribution.

Furthermore, the second-order score is mathematically equivalent to the conditional covariance matrix, providing a principled measure of denoising uncertainty. On CIFAR-10, this uncertainty correctly identifies object boundaries and high-frequency details as regions of higher variance.

4. Discussion and Conclusion

This work introduces a scalable and accurate framework for estimating higher-order scores directly from data. By leveraging a generalized Tweedie's formula, the proposed $D_2SM$ method offers substantial computational speedups and improved accuracy over automatic differentiation. While evaluations were focused on second-order scores and low-resolution images, the theoretical framework generalizes to any $k$-th order score. Future work includes scaling these techniques to high-resolution images and exploring applications in out-of-distribution detection and other data modalities.

Summary updated

Abstract

The first order derivative of a data density can be estimated efficiently by denoising score matching, and has become an important component in many applications, such as image generation and audio synthesis. Higher order derivatives provide additional local information about the data distribution and enable new applications. Although they can be estimated via automatic differentiation of a learned density model, this can amplify estimation errors and is expensive in high dimensional settings. To overcome these limitations, we propose a method to directly estimate high order derivatives (scores) of a data density from samples. We first show that denoising score matching can be interpreted as a particular case of Tweedie's formula. By leveraging Tweedie's formula on higher order moments, we generalize denoising score matching to estimate higher order derivatives. We demonstrate empirically that models trained with the proposed method can approximate second order derivatives more efficiently and accurately than via automatic differentiation. We show that our models can be used to quantify uncertainty in denoising and to improve the mixing speed of Langevin dynamics via Ozaki discretization for sampling synthetic data and natural images.
BibTeX
@inproceedings{meng2021estimating,
  author = {Chenlin Meng and Yang Song and Wenzhe Li and Stefano Ermon},
  title = {{Estimating High Order Gradients of the Data Distribution by Denoising}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=YTkQQrqSyE1},
}

Loading related content...

Figure