Combining Statistical Depth and Fermat Distance for Uncertainty Quantification

Hai-Vy Nguyen, Fabrice Gamboa, Reda Chhaibi, Sixin Zhang, Serge Gratton, Thierry Giaccone

Deep neural networks are notoriously overconfident. When presented with an input that looks nothing like their training data—known as Out-of-Distribution (OOD) data—they often assign it a high-probability label instead of admitting uncertainty. Researchers have developed a novel, "plug-and-play" method for detecting OOD data by combining a geometric concept called Lens Depth with Fermat Distance. This approach requires zero retraining, makes no assumptions about the shape of the data, and provides a reliable uncertainty score for neural networks already in production.

The Problem with Existing Solutions

Existing solutions to this uncertainty quantification problem usually fall into two camps:

  1. Intrusive methods: These require retraining the model with special loss functions or using "Deep Ensembles," which are computationally expensive to train and deploy.
  2. Statistical methods: These often assume the data in the model's feature space follows a specific distribution, like a Gaussian (bell curve).

The problem is that in the high-dimensional "feature space" of a neural network, data clusters are rarely simple bell curves. They can be curved, elongated, or manifold-shaped. When these rigid distributional assumptions fail, the resulting uncertainty scores become unreliable.

A Non-Intrusive, Geometric Approach

The authors propose a non-parametric method that works directly on the features extracted by a pre-trained model. Because it is applied at test time to the output of the penultimate layer, it has zero impact on the original model's classification accuracy. You get uncertainty quantification "for free" without degrading performance.

Diagram illustrating the proposed non-intrusive pipeline where extracted features are scored using Lens Depth and Fermat distance.

The method relies on two key mathematical tools:

  • Lens Depth (LD): Imagine two random points in your dataset. Draw a circle (or ball) around each, with the radius being the distance between them. The "Lens" is the area where these two balls overlap. A point is considered "deep" (or central) if it frequently falls into these overlapping lenses.
  • Fermat Distance: Standard Euclidean distance ignores the "shape" of the data. Fermat distance, however, calculates the distance between points by following paths through high-density regions of the dataset. It effectively "hugs" the manifold of the data.

The authors modified the standard Fermat distance to ensure that as a point moves further away from the known data, its depth score correctly drops to zero. To handle the computational cost—which scales quadratically with the number of training points—they use a K-means strategy. Instead of comparing a new point to every single training example, they compare it to a representative set of centroids, significantly speeding up the process.

Geometry Over Distribution

The biggest insight from this work is that you don't need to know the formula for a distribution to measure how central a point is. By using Fermat distance, the algorithm learns the geometry of the feature space on the fly.

Side-by-side comparison on the two-moons dataset showing a standard distance metric failing (left) while the proposed method tightly captures the data manifold (right).

The paper demonstrates that even in simple cases, like the "two-moons" dataset, standard Gaussian Discriminant Analysis (GDA) fails completely because it tries to fit an ellipse over a crescent shape. In contrast, Lens Depth combined with Fermat distance captures the crescent perfectly.

Key Results

The method was evaluated on several standard benchmarks, including toy datasets, image benchmarks (like FashionMNIST vs. MNIST, and CIFAR-10 vs. SVHN), and hold-one-out scenarios.

  • Superior OOD Detection: On the FashionMNIST (In-Distribution) vs. MNIST (OOD) benchmark, the proposed method achieved an AUROC of 0.971, significantly outperforming the Gaussian-based Mahalanobis distance (0.942) and the popular DUQ method (0.955).
  • Competitive with Ensembles: In many CIFAR-10 tests, this single-model method performed competitively with—and sometimes better than—Deep Ensembles, which require training and running five separate neural networks.
  • Consistency: The authors showed that a model's accuracy on remaining data increases as you reject samples with low Lens Depth, proving it is a reliable proxy for how "easy" a sample is for the model to classify.

Limitations and Future Work

While highly effective, the method has some limitations. Even with the K-means optimization, calculating Lens Depth is more computationally intensive than simple distance metrics, scaling at $O(C \cdot n^2)$ (where $C$ is the number of classes and $n$ is the number of representative points). Additionally, while largely hyperparameter-free, it relies on a parameter $\alpha$ for the Fermat distance. Future work will look for even more efficient algorithms to calculate Lens Depth and mathematically investigate the impact of the $\alpha$ parameter on different manifold geometries.

Summary updated

BibTeX
@inproceedings{nguyen2024combining,
  author = {Hai-Vy Nguyen and Fabrice Gamboa and Reda Chhaibi and Sixin Zhang and Serge Gratton and Thierry Giaccone},
  title = {{Combining Statistical Depth and Fermat Distance for Uncertainty Quantification}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=xeXRhTUmcf},
}
Figure