This repository provides the implementation of the Deep Contrastive One-Class Time Series Anomaly Detection method, called COCA bellow.
The implementation uses the Merlion and the Tsaug libraries.
The accumulation of time-series data and the absence of labels make time-series Anomaly Detection (AD) a selfsupervised deep learning task. Single-normality-assumptionbased methods, which reveal only a certain aspect of the whole normality, are incapable of tasks involved with a large number of anomalies. Specifically, Contrastive Learning (CL) methods distance negative pairs, many of which consist of both normal samples, thus reducing the AD performance. Existing multi-normality-assumption-based methods are usually two-staged, firstly pre-training through certain tasks whose target may differ from AD, limiting their performance. To overcome the shortcomings, a deep Contrastive One-Class Anomaly detection method of time series (COCA) is proposed by authors, following the normality assumptions of CL and one-class classification. It treats the origin and reconstructed representations as the positive pair of negative-samples-free CL, namely “sequence contrast”. Next, invariance terms and variance terms compose a contrastive one-class loss function in which the loss of the assumptions is optimized by invariance terms simultaneously and the “hypersphere collapse” is prevented by variance terms. In addition, extensive experiments on two real-world time-series datasets show the superior performance of the proposed method achieves state-of-the-art.
Link to arXiv version here
This code is based on Python 3.8
, all requires are written in requirements.txt
. Additionally, we should install saleforce-merlion v1.1.1
and ts_dataset
as Merlion suggested.
git clone https://github.com/salesforce/Merlion.git
cd Merlion
pip install salesforce-merlion==1.1.1
pip install -e Merlion/ts_datasets/
pip install -r requirements.txt
The COCA repository already includes the merlion's data loading package ts_datasets
.
Please unzip the data/iops_competition/phase2.zip
before running the program.
This directory contains experiment parameters for all models on IOpsCompetition, UCR datasets.
Source code of OCSVM, DeepSVDD, CPC, TS-TCC and COCA models.
Directory where the experiment results and checkpoint are saved.
python coca.py --selected_dataset UCR --device cuda --seed 2
python coca.py --selected_dataset IOpsCompetition --device cuda --seed 2
# COCA Variants
python coca_no_aug.py --selected_dataset IOpsCompetition --device cuda --seed 1
python coca_no_cl.py --selected_dataset IOpsCompetition --device cuda --seed 1
python coca_no_oc.py --selected_dataset IOpsCompetition --device cuda --seed 1
python coca_no_var.py --selected_dataset IOpsCompetition --device cuda --seed 1
python coca_no_view.py --selected_dataset IOpsCompetition --device cuda --seed 1
# Baseline training
# model_name: IsolationForest, RandomCutForest, SpectralResidual, LSTMED, DAGMM, CPC, OCSVM, DeepSVDD
python baseline.py --dataset UCR --model <model_name> --debug
# TS_TCC_AD training
python ts_tcc_main.py --training_mode self_supervised --selected_dataset IOpsCompetition --device cuda --seed 5
python ts_tcc_main.py --training_mode anomaly_detection --selected_dataset IOpsCompetition --device cuda --seed 5
This implementation is based on Deep-SVDD-PyTorch, Contrastive-Predictive-Coding-PyTorch, TS-TCC, and affiliation-metrics