Abstract
Density estimation is a cornerstone of unsupervised learning, yet classical methods like Kernel Density Estimation (KDE) and K-Nearest Neighbors (KNN) often force a trade-off between smoothness and local adaptivity. This paper introduces VB-KNN-KDE, a hybrid framework that unifies these approaches using a Bayesian formulation and variational inference. By assigning locally adaptive kernels to every observation and leveraging sparse computations, the model scales to millions of data points. Experimental results on synthetic and high-dimensional tabular datasets demonstrate that VB-KNN-KDE provides superior density estimates, often outperforming complex neural density estimators.
Introduction
Researchers typically choose between two imperfect classical tools for density estimation: KDE, which provides a valid smooth density but suffers from rigidity due to fixed bandwidths, and KNN, which is inherently adaptive but produces "jagged" estimates that lack mathematical validity outside the infinite-data limit. Furthermore, both methods scale poorly, with standard KDE requiring $O(N^2)$ computations, making them unsuitable for modern large-scale datasets.
This paper addresses these limitations by proposing a model that "thinks global" by maintaining a valid total density while "adapting local" by allowing each data point to define its own neighborhood geometry.
Methods: The VB-KNN-KDE Framework
The core innovation of the paper is the unification of KDE and KNN within a Bayesian framework. In standard KDE, a global bandwidth parameter often fails to capture varying densities across the feature space. Conversely, KNN provides local adaptivity but lacks a smooth, continuous density function.
Locally Adaptive Kernels
VB-KNN-KDE addresses this by assigning a unique precision matrix (the inverse of the covariance) to each data point's kernel. These matrices are treated as latent variables following a Wishart distribution. By optimizing these variables, the model effectively "learns" the local geometry—stretching kernels along data manifolds and shrinking them in dense regions. The shape and orientation of these kernels are initialized based on the covariance of the $K$-nearest neighbors.
Scalable Variational Inference
To handle massive datasets, the authors utilize Variational Bayes (VB) to optimize the Evidence Lower Bound (ELBO). Scaling is achieved through two key innovations:
- Sparsity: Recognizing that a point's density is primarily influenced by its immediate neighbors, the model enforces a sparsity cutoff (e.g., $10^{-7}$), ignoring distant points.
- Batching: Using batched GPU optimization, memory requirements are reduced from $O(N^2)$ to approximately $O(N \log N)$, enabling inference on datasets with over a million samples.
Experimental Results
The model was evaluated on synthetic 2D datasets and five real-world tabular benchmarks (POWER, GAS, HEPMASS, MINIBOONE, and BSDS300) ranging from 6 to 63 dimensions.
Qualitative Performance
On synthetic data such as "2spirals" and "checkerboard," VB-KNN-KDE successfully recovers sharp, smooth boundaries. While standard KDE tends to blur edges and KNN creates noisy artifacts, the proposed method captures complex, non-linear shapes with high fidelity. The Bayesian adaptation allows the model to refine the initial KNN-based priors into a more accurate representation of the underlying density.
Quantitative Benchmarks
In real-world tabular data experiments, VB-KNN-KDE consistently outperformed conventional non-neural methods. Notably, it surpassed sophisticated neural density estimators like Masked Autoregressive Flow (MAF) and FFJORD on the GAS and BSDS300 datasets. This suggests that for certain tabular data, local geometric adaptivity is more critical than deep architectural complexity.
Discussion and Limitations
The "classical-plus" approach of VB-KNN-KDE demonstrates that local adaptivity can rival deep learning in specific domains. However, the model faces a dimensionality bottleneck; Cholesky decompositions scale $O(D^3)$ with the number of dimensions ($D$), making preprocessing steps like PCA necessary for extremely high-dimensional data like images. Additionally, the model's performance is somewhat dependent on the initial Euclidean KNN search used to define priors.
Future work includes exploring "Leave-K-out" cross-validation to further reduce bias and investigating Wishart processes to model the distribution of kernels more dynamically.
Reference: Olsen, K. F., Lindrup, R. M. H., & Mørup, M. (2024). Think Global, Adapt Local: Learning Locally Adaptive K-Nearest Neighbor Kernel Density Estimators. Proceedings of the 27th International Conference on Artificial Intelligence and Statistics (AISTATS).
Summary updated