HampelDetector<T>
Models & Types · AiDotNet.AnomalyDetection.Statistical
Detects anomalies using Hampel identifier (median-based outlier detection).
Inheritance: ModelBase<T, Matrix<T>, Vector<T>> → AnomalyDetectorBase<T> → HampelDetector<T>
For Beginners
The Hampel identifier is a robust outlier detection method that uses a sliding window to compute local median and MAD. It’s particularly effective for time series data where local context matters.
How It Works
The algorithm works by:
- For each point, compute median and MAD in a local window
- Compute the deviation from local median in MAD units
- Points exceeding the threshold are anomalies
When to use:
- Time series with local patterns
- When global statistics don’t capture local anomalies
- As a robust alternative to moving average methods
Industry Standard Defaults:
- Window size: 7 (3 on each side)
- Threshold: 3 MAD units
- Scale factor: 1.4826
- Contamination: 0.1 (10%)
Reference: Hampel, F.R. (1974). “The Influence Curve and its Role in Robust Estimation.”
Constructors
| Constructor | Summary |
|---|---|
HampelDetector(int windowSize, double threshold, double scaleFactor, double contamination, int randomSeed) |
Creates a new Hampel anomaly detector. |
Properties
| Property | Summary |
|---|---|
double ThresholdMAD { get; } |
Gets the threshold in MAD units. |
int WindowSize { get; } |
Gets the window size. |
Methods
| Method | Summary |
|---|---|
Vector<T> ScoreAnomalies(Matrix<T> X) |
|
void Fit(Matrix<T> X) |