A Bayesian Nonparametric Perspective on Mahalanobis Distance for Out of Distribution Detection
Randolph W. Linderman, Yiran Chen, Scott W. Linderman
TL;DR
This work links Bayesian nonparametric Dirichlet process mixture models to the Relative Mahalanobis Distance score for out-of-distribution detection, showing that RMDS approximates the inlier probability under a Gaussian DPMM with tied covariances. It then extends this link by introducing hierarchical Gaussian DPMMs that allow class-specific covariances to be learned with shared statistical strength, via full, diagonal, and coupled diagonal covariance models. The authors derive EM algorithms to fit hyperparameters and provide closed-form predictive densities (including Student's t forms) to compute OOD scores. Empirical results on synthetic data and the OpenOOD benchmark demonstrate that hierarchical DPMMs improve OOD detection, especially when per-class covariance structures differ and data per class are limited, while highlighting limitations of the full covariance model in high dimensions and the practical utility of diagonal variants.
Abstract
Bayesian nonparametric methods are naturally suited to the problem of out-of-distribution (OOD) detection. However, these techniques have largely been eschewed in favor of simpler methods based on distances between pre-trained or learned embeddings of data points. Here we show a formal relationship between Bayesian nonparametric models and the relative Mahalanobis distance score (RMDS), a commonly used method for OOD detection. Building on this connection, we propose Bayesian nonparametric mixture models with hierarchical priors that generalize the RMDS. We evaluate these models on the OpenOOD detection benchmark and show that Bayesian nonparametric methods can improve upon existing OOD methods, especially in regimes where training classes differ in their covariance structure and where there are relatively few data points per class.
