AnomalyTransformerDetector<T>

Models & Types · AiDotNet.AnomalyDetection.TimeSeries

Implements Anomaly Transformer for time series anomaly detection.

Inheritance: ModelBase<T, Matrix<T>, Vector<T>> → AnomalyDetectorBase<T> → AnomalyTransformerDetector<T>

Implements: IGeneratedParameterRegistrar<T>

For Beginners

Anomaly Transformer uses the attention mechanism to detect anomalies. Normal points tend to have similar attention patterns to their neighbors, while anomalies show distinct attention patterns. It uses “Association Discrepancy” as the anomaly score.

How It Works

The algorithm works by:

  1. Encode time series using positional encoding
  2. Apply self-attention to learn temporal relationships
  3. Compute association discrepancy between prior and series associations
  4. High discrepancy indicates anomalies

When to use:

  • Long time series with complex patterns
  • When you need to capture long-range dependencies
  • Multivariate time series anomaly detection

Industry Standard Defaults:

  • Model dimensions: 64
  • Number of heads: 4
  • Sequence length: 100
  • Epochs: 10
  • Contamination: 0.1 (10%)

Reference: Xu, J., et al. (2022). “Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy.” ICLR.

Constructors

Constructor Summary
AnomalyTransformerDetector(int modelDim, int numHeads, int seqLength, int epochs, double learningRate, double contamination, int randomSeed) Creates a new Anomaly Transformer detector.

Properties

Property Summary
int ModelDim { get; } Gets the model dimensions.
int NumHeads { get; } Gets the number of attention heads.
int SeqLength { get; } Gets the sequence length.

Methods

Method Summary
Vector<T> ScoreAnomalies(Matrix<T> X)
void Fit(Matrix<T> X)