A collection of useful util functions
Project description
Anomaly Detection and Explanation
We develop deep learning model that detects and explain anomaly in multivariate time series data.
Our model is based on Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy (ICLR'22). We train and evaluate the model on DBSherlock dataset.
Anomaly Transformer
Anomaly transformer is a transformer-based model that detects anomaly in multivariate time series data. It is based on the assumption that the normal data is highly correlated, while the abnormal data is not. It uses a transformer encoder to learn the correlation between different time steps, and then uses a discriminator to distinguish the normal and abnormal data based on the learned correlation.
- An inherent distinguishable criterion as Association Discrepancy for detection.
- A new Anomaly-Attention mechanism to compute the association discrepancy.
- A minimax strategy to amplify the normal-abnormal distinguishability of the association discrepancy.
For more details, please refer to the paper.
Environment Setup
Start docker container using docker compose, and login to the container
docker compose up -d
Install python packages
pip install -r requirements.txt
Prepare Dataset
Download
Download DBSherlock dataset.
python scripts/dataset/download_datasets.py
Append --download_all
argument to download all datasets (i.e., SMD, SMAP, PSM, MSL, and DBSherlock).
python scripts/dataset/download_datasets.py --download_all
Preprocess data
Convert DBSherlock data (.mat file to .json file):
python src/data_factory/dbsherlock/convert.py \
--input dataset/dbsherlock/tpcc_16w.mat \
--out_dir dataset/dbsherlock/converted/ \
--prefix tpcc_16w
python src/data_factory/dbsherlock/convert.py \
--input dataset/dbsherlock/tpcc_500w.mat \
--out_dir dataset/dbsherlock/converted/ \
--prefix tpcc_500w
python src/data_factory/dbsherlock/convert.py \
--input dataset/dbsherlock/tpce_3000.mat \
--out_dir dataset/dbsherlock/converted/ \
--prefix tpce_3000
Convert DBSherlock data into train & validate data for Anomaly Transformer:
python src/data_factory/dbsherlock/process.py \
--input_path dataset/dbsherlock/converted/tpcc_16w_test.json \
--output_path dataset/dbsherlock/processed/tpcc_16w/
python src/data_factory/dbsherlock/process.py \
--input_path dataset/dbsherlock/converted/tpcc_500w_test.json \
--output_path dataset/dbsherlock/processed/tpcc_500w/
python src/data_factory/dbsherlock/process.py \
--input_path dataset/dbsherlock/converted/tpce_3000_test.json \
--output_path dataset/dbsherlock/processed/tpce_3000/
Train and Evaluate
We provide the experiment scripts under the folder ./scripts
. You can reproduce the experiment results with the below script:
bash ./scripts/experiment/DBS.sh
or you can run the below commands to train and evaluate the model step by step.
Training
Train the model on DBSherlock dataset:
python main.py \
--dataset EDA \
--dataset_path dataset/EDA/ \
--mode train
Evaluating
Evaluate the trained model on the test split of the same dataset:
python main.py \
--dataset EDA \
--dataset_path dataset/EDA/ \
--mode test
Inference
Perform inference on time series data with the trained model:
python main.py \
--dataset EDA \
--dataset_path dataset/EDA/ \
--mode infer
--output_path results/EDA/
Reference
This respository is based on Anomaly Transformer.
@inproceedings{
xu2022anomaly,
title={Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy},
author={Jiehui Xu and Haixu Wu and Jianmin Wang and Mingsheng Long},
booktitle={International Conference on Learning Representations},
year={2022},
url={https://openreview.net/forum?id=LzQQ89U1qm_}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dbanomtransformer-0.1.6.tar.gz
.
File metadata
- Download URL: dbanomtransformer-0.1.6.tar.gz
- Upload date:
- Size: 56.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 412a051b9cb4af4c002569bca2502791ef41f9c593924afbf4ea7b83c0edbe4a |
|
MD5 | 9389f8ec3d7143c4fb15075a23efa798 |
|
BLAKE2b-256 | cee0176183b35a6583bb78fdd7bb6c76eb7d949ea4007d8e94a00dd997637759 |
File details
Details for the file dbanomtransformer-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: dbanomtransformer-0.1.6-py3-none-any.whl
- Upload date:
- Size: 37.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a9dc227bafa81ea28de9660936bcf09f0d7de8b07f8e41a6f27da0b34c3431c |
|
MD5 | a5b4e4eba998a8ff1673f51bfd7328d8 |
|
BLAKE2b-256 | 86c250efc04139a67f2229fa17051c16d8417190c393bf304e0e6ab873140934 |