Expand description
Anomaly / outlier detection — folded into the statistics foundation (it is just
statistics with a decision rule). Univariate detectors (z-score, robust modified
z-score, Tukey fences, Grubbs’ test) plus a multivariate Mahalanobis gate. Each
reuses the existing descriptive / robust / distribution primitives and follows the
module’s Option idiom (None on degenerate input — empty, zero spread).
Mission note: outliers are flagged as candidates for human attention, never auto-acted-on — a deviation is a signal, not a verdict.
Structs§
- Grubbs
Result - The result of Grubbs’ test for a single outlier.
Functions§
- grubbs_
test - Grubbs’ test for the single most extreme value (assumes approximate normality).
alphais the significance level (e.g. 0.05). Reuses the Student-t quantile for the critical value.Noneif fewer than 3 points or zero spread. - iqr_
outliers - Indices outside the Tukey fences.
- is_
multivariate_ outlier - Multivariate outlier gate: a point is flagged when its squared Mahalanobis distance
exceeds the χ²(d) upper-
alphaquantile (the standardd-dimensional rule).Noneon a dimension mismatch. - mahalanobis_
sq - Squared Mahalanobis distance
(x − μ)ᵀ Σ⁻¹ (x − μ). The caller supplies the inverse covarianceinv_cov(row-majord×d, obtained from the linear-algebra substrate) — this keeps the metric self-contained.Noneon a dimension mismatch. - modified_
z_ score_ outliers - Robust outliers via the modified z-score (Iglewicz–Hoaglin):
0.6745 · (x − median) / MAD. Resistant to the very outliers it detects — the mean and SD are not. Flags indices exceedingthreshold(3.5 is the standard choice). - tukey_
fences - Tukey fences
[Q1 − k·IQR, Q3 + k·IQR](k = 1.5mild,3.0extreme).Noneif fewer than 4 points. - z_
score_ outliers - Indices whose standard score
|x − μ| / σexceedsthreshold(e.g. 3.0).Noneif there are fewer than 2 points or the spread is zero.