Official PyTorch implementation of "Self-Supervised Spatial-Temporal Normality Learning for Time Series Anomaly Detection".
Time Series Anomaly Detection (TSAD) finds widespread applications across various domains such as financial markets, industrial production, and healthcare. Its primary objective is to learn the normal patterns of time series data, thereby identifying deviations in test samples. Most existing TSAD methods focus on modeling data from the temporal dimension, while ignoring the semantic information in the spatial dimension. To address this issue, we introduce a novel approach, called Spatial-Temporal Normality learning (STEN). STEN is composed of a sequence Order prediction-based Temporal Normality learning (OTN) module that captures the temporal correlations within sequences, and a Distance prediction-based Spatial Normality learning (DSN) module that learns the relative spatial relations between sequences in a feature space. By synthesizing these two modules, STEN learns expressive spatial-temporal representations for the normal patterns hidden in the time series data. Extensive experiments on five popular TSAD benchmarks show that STEN substantially outperforms state-of-the-art competing methods.
- python >= 3.8
- torch >= 1.11.0
- torchvision >= 0.14.0
- scipy >= 1.5.1
- scikit_learn >= 0.20.0
- numpy >= 1.19
- tqdm >= 4.62.3
we provide a requirements.txt
in our repository.
Single NVIDIA GeForce RTX 3090
- Download data. You can obtain all benchmarks from Google Cloud. All the datasets are well pre-processed.
The dataset folder structure should look like:
data/
dataset1/
...
dataset2/
...
...
- Train and evaluate. To run the model in the paper, run this command:
python main.py --model STEN --runs $runs --data $data
We also provide the experiment scripts of all benchmarks under the folder ./scripts
. You can reproduce the experiment results as follows:
bash ./scripts/PSM.sh
bash ./scripts/MSL.sh
bash ./scripts/SMAP.sh
bash ./scripts/Epilepsy.sh
bash ./scripts/DSADS.sh
We appreciate the following github repos a lot for their valuable code:
https://github.com/xuhongzuo/DeepOD
https://github.com/ahstat/affiliation-metrics-py
https://github.com/DAMO-DI-ML/KDD2023-DCdetector/tree/main
@article{chen2024self,
title={Self-Supervised Spatial-Temporal Normality Learning for Time Series Anomaly Detection},
author={Chen, Yutong and Xu, Hongzuo and Pang, Guansong and Qiao, Hezhe and Zhou, Yuan and Shang, Mingsheng},
journal={arXiv preprint arXiv:2406.19770},
year={2024}
}