mahalanobis¶
- probly.method.mahalanobis(base: Predictor[In, Out], feature_nodes: FeatureNodes = None, input_preprocessing_eps: float = 0.0) MahalanobisPredictor[In, Out][source]¶
Turn a classifier into a Mahalanobis-distance OOD detector.
Based on [LLLS18]. The final linear head is stripped to expose penultimate features, class-conditional Gaussians with a tied covariance are fitted on those features (and, optionally, on extra intermediate layers), and the per-layer Mahalanobis confidence is combined into a single out-of-distribution score by logistic regression.
The returned predictor still needs its Gaussian parameters fitted after training via
fit_mahalanobis_heads(and, optionally,fit_combinerto calibrate the multi-layer weights on in- vs out-of-distribution data).- Parameters:
base – Base logit classifier to be transformed.
feature_nodes – Optional names of intermediate submodules (as returned by
named_modules) whose global-average-pooled outputs provide additional feature layers for the ensemble. WhenNoneonly the penultimate features are used, recovering the single-layer detector.input_preprocessing_eps – Magnitude of the FGSM-style input perturbation applied at inference to sharpen the in/out separation.
0disables preprocessing.
- Returns:
The transformed Mahalanobis predictor.