arXiv:2609.39843stat.MLSep 2026

Manuscript Offprint

arXiv:2609.39843

BayesNDE: Bayesian Generative Modeling for Neural Density Estimation

Chenglin Li, Qiao Liu

Abstract

Density estimation is a fundamental problem in statistics and machine learning. In this work, we introduce BayesNDE, a neural density estimator based on Bayesian generative modeling. BayesNDE learns a Bayesian generative model and evaluates its density without requiring invertible networks or Jacobian-determinant computation. For each observation, it infers a sample-specific latent posterior to construct an adaptive proposal that focuses computation on regions contributing most to its density. Bridge sampling then combines samples from this proposal with separate posterior samples to estimate the density. Experiments on nonlinear and multimodal synthetic datasets show improved estimation of density values and better recovery of the density structure compared to the state-of-the-art neural density estimators. Applications to real-world datasets further demonstrate improved anomaly detection. Together, these results highlight BayesNDE as a flexible and effective neural density estimator, demonstrating how posterior inference can turn generative models into tools for density estimation. The code and tutorials are available at https://github.com/liuq-lab/BayesNDE.

1 Introduction

Density estimation is a fundamental problem in statistics and machine learning. Given observations {xi}i=1N\{x_i\}_{i=1}^N drawn from an unknown distribution, the goal is to learn the underlying distribution p(x)p(x) and evaluate the density value at a new observation. Traditional density estimators such as kernel-based methods [Parzen, 1962] typically perform well only in low-dimensional settings. Density estimation has become increasingly challenging as modern data exhibit complex patterns, such as nonlinearity and high-dimensionality.

Deep neural networks provide powerful tools for modeling complex distributions, offering new advances to density estimation. There are two major types of neural density estimators: autoregressive models and normalizing flows. Autoregressive models obtain tractable

*Corresponding author: qiao.liu@yale.edu likelihoods through a sequential factorization of the joint density [Germain et al., 2015, Papamakarios et al., 2017], while normalizing flows construct invertible transformations whose Jacobian determinants can be efficiently evaluated [Dinh et al., 2017, Chen et al., 2018, 2019].

Despite their different formulations, both autoregressive density estimators and normalizing flows can be viewed within a general change-of-variables framework [Kingma et al., 2016]. Specifically, let z∼pZ(z)z \sim p_Z(z) and x=G(z)x = G(z), where G:Rp→RpG : \mathbb{R}^p \to \mathbb{R}^p is differentiable and invertible. The density of xx follows,

pX(x)=pZ(z)∣det⁡∂G(z)∂z⊤∣−1.(1)p_{X}(x)=p_{Z}(z)\left|\det\frac{\partial G(z)}{\partial z^{\top}}\right|^{-1}. \tag{1}

Within this change-of-variables formulation, exact density evaluation requires both invertible transformation and tractable Jacobian computation. It requires the latent and observed spaces to have the same dimension and constrains the neural architecture, which may potentially limit the expressiveness of the neural architecture.

Latent-variable generative models provide an alternative route to flexible distribution modeling. Given a latent variable z with prior pZ(z)p_{Z}(z) and the model pθ(x∣z)p_{\theta}(\boldsymbol{x} \mid \boldsymbol{z}), the marginal density is

pθ(x)=∫pθ(x∣z)pZ(z)dz.(2)p_{\theta}(\boldsymbol{x})=\int p_{\theta}(\boldsymbol{x}\mid\boldsymbol{z})p_{Z}(\boldsymbol{z})d\boldsymbol{z}. \tag{2}

The challenge is therefore shifted from Jacobian computation to integration over the latent space, which is generally intractable. Following this direction, Liu et al. [2021] proposed Roundtrip, which models observations around a learned low-dimensional manifold and evaluates pointwise densities using importance sampling or Laplacian approximation.

Although Roundtrip substantially relaxes the architectural constraints of flow-based density estimators, its importance proposal is centered at the encoder output, which provides a deterministic latent representation rather than a distributional characterization of the observation-specific posterior. The resulting proposal may therefore not fully capture posterior uncertainty, dependence, or multimodality, potentially reducing importance-sampling efficiency when proposal-posterior mismatch is substantial.

To overcome these limitations, we introduce BayesNDE, a neural density estimator based on Bayesian generative modeling. To our knowledge, BayesNDE is the first neural density-estimation framework to use sample-specific posterior-adaptive bridge sampling for pointwise density evaluation. We summarize our contributions as follows:

  • We introduce a new perspective for explicit neural density evaluation by estimating the marginal or conditional density of each observation through posterior-adaptive bridge sampling. This removes the need for dimension-preserving, invertible transformations and tractable Jacobian determinants.

  • BayesNDE uses observation-specific posterior samples to construct adaptive proposals and bridge sampling to estimate the resulting normalizing constants. We establish consistency of the estimator and characterize how posterior-proposal overlap determines its asymptotic efficiency.

  • BayesNDE achieves superior performance in a diverse of density estimation benchmarks, including nonlinear and multimodal simulation datasets, and real-world datasets. The downstream applications, such as outlier detection and Bayesian classification, further support the significance of our method.

References (32)