xpectra.ood
Out-of-distribution scoring and abstention.
Convention: every scorer returns a 1-D array where HIGHER = more OOD.
Functions
|
|
|
|
|
Shuffle contiguous wavenumber blocks: destroys band structure, keeps the overall intensity distribution. |
Classes
|
Predict a class when the OOD score is below tau, otherwise abstain. |
|
Negative log-sum-exp of logits (log-proba fallback for CV-calibrated models). |
|
Normalized Shannon entropy of the predictive distribution. |
|
Distance to the k-th nearest training sample in PCA space. |
|
Min per-class Mahalanobis distance in PCA space (shared LW covariance). |
1 - max predicted probability. |
|
Min spectral angle to the class-mean spectra (norm route only). |
- class xpectra.ood.Entropy[source]
Bases:
OODScorerNormalized Shannon entropy of the predictive distribution.
- class xpectra.ood.Energy[source]
Bases:
OODScorerNegative log-sum-exp of logits (log-proba fallback for CV-calibrated models).
- class xpectra.ood.Mahalanobis(n_components=20, random_state=42)[source]
Bases:
OODScorerMin per-class Mahalanobis distance in PCA space (shared LW covariance).
- class xpectra.ood.KNNDistance(k=5, n_components=20, random_state=42)[source]
Bases:
OODScorerDistance to the k-th nearest training sample in PCA space.
- class xpectra.ood.SpectralAngleScorer[source]
Bases:
OODScorerMin spectral angle to the class-mean spectra (norm route only).
- class xpectra.ood.AbstainingClassifier(model, scorer)[source]
Bases:
objectPredict a class when the OOD score is below tau, otherwise abstain.
- Parameters:
scorer (OODScorer)
- ABSTAIN = 'ABSTAIN'
- fit_tau(X_val, target_coverage=0.9)[source]
Set tau so that target_coverage of X_val falls below it.
X_val must be a HELD-OUT labeled set that neither the model nor the scorer was trained on — calibrating on in-sample data yields optimistic scores and a threshold too tight to hit the target coverage on new data.
- Parameters:
- Return type: