All Projects → ML4ITS → mtad-gat-pytorch

ML4ITS / mtad-gat-pytorch

Licence: MIT License
PyTorch implementation of MTAD-GAT (Multivariate Time-Series Anomaly Detection via Graph Attention Networks) by Zhao et. al (2020, https://arxiv.org/abs/2009.02040).

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to mtad-gat-pytorch

how attentive are gats
Code for the paper "How Attentive are Graph Attention Networks?" (ICLR'2022)
Stars: ✭ 200 (+135.29%)
Mutual labels:  attention, graph-attention-networks, graph-neural-networks
AC-VRNN
PyTorch code for CVIU paper "AC-VRNN: Attentive Conditional-VRNN for Multi-Future Trajectory Prediction"
Stars: ✭ 21 (-75.29%)
Mutual labels:  time-series, graph-attention-networks, graph-neural-networks
gnn-lspe
Source code for GNN-LSPE (Graph Neural Networks with Learnable Structural and Positional Representations), ICLR 2022
Stars: ✭ 165 (+94.12%)
Mutual labels:  attention, graph-neural-networks, gnn
BGCN
A Tensorflow implementation of "Bayesian Graph Convolutional Neural Networks" (AAAI 2019).
Stars: ✭ 129 (+51.76%)
Mutual labels:  graph-neural-networks, gnn
awesome-efficient-gnn
Code and resources on scalable and efficient Graph Neural Networks
Stars: ✭ 498 (+485.88%)
Mutual labels:  graph-neural-networks, gnn
msda
Library for multi-dimensional, multi-sensor, uni/multivariate time series data analysis, unsupervised feature selection, unsupervised deep anomaly detection, and prototype of explainable AI for anomaly detector
Stars: ✭ 80 (-5.88%)
Mutual labels:  time-series, anomaly-detection
Astgcn
⚠️[Deprecated] no longer maintained, please use the code in https://github.com/guoshnBJTU/ASTGCN-r-pytorch
Stars: ✭ 246 (+189.41%)
Mutual labels:  time-series, attention
stagin
STAGIN: Spatio-Temporal Attention Graph Isomorphism Network
Stars: ✭ 34 (-60%)
Mutual labels:  attention, gnn
GNN-Recommender-Systems
An index of recommendation algorithms that are based on Graph Neural Networks.
Stars: ✭ 505 (+494.12%)
Mutual labels:  graph-neural-networks, gnn
Meta-GDN AnomalyDetection
Implementation of TheWebConf 2021 -- Few-shot Network Anomaly Detection via Cross-network Meta-learning
Stars: ✭ 22 (-74.12%)
Mutual labels:  anomaly-detection, graph-neural-networks
awesome-time-series
Resources for working with time series and sequence data
Stars: ✭ 178 (+109.41%)
Mutual labels:  time-series, anomaly-detection
SelfGNN
A PyTorch implementation of "SelfGNN: Self-supervised Graph Neural Networks without explicit negative sampling" paper, which appeared in The International Workshop on Self-Supervised Learning for the Web (SSL'21) @ the Web Conference 2021 (WWW'21).
Stars: ✭ 24 (-71.76%)
Mutual labels:  graph-attention-networks, graph-neural-networks
Literatures-on-GNN-Acceleration
A reading list for deep graph learning acceleration.
Stars: ✭ 50 (-41.18%)
Mutual labels:  graph-neural-networks, gnn
gemnet pytorch
GemNet model in PyTorch, as proposed in "GemNet: Universal Directional Graph Neural Networks for Molecules" (NeurIPS 2021)
Stars: ✭ 80 (-5.88%)
Mutual labels:  graph-neural-networks, gnn
3DInfomax
Making self-supervised learning work on molecules by using their 3D geometry to pre-train GNNs. Implemented in DGL and Pytorch Geometric.
Stars: ✭ 107 (+25.88%)
Mutual labels:  graph-neural-networks, gnn
mvts-ano-eval
A repository for code accompanying the manuscript 'An Evaluation of Anomaly Detection and Diagnosis in Multivariate Time Series' (published at TNNLS)
Stars: ✭ 26 (-69.41%)
Mutual labels:  time-series, anomaly-detection
Lstm anomaly thesis
Anomaly detection for temporal data using LSTMs
Stars: ✭ 178 (+109.41%)
Mutual labels:  time-series, anomaly-detection
Taganomaly
Anomaly detection analysis and labeling tool, specifically for multiple time series (one time series per category)
Stars: ✭ 200 (+135.29%)
Mutual labels:  time-series, anomaly-detection
singular-spectrum-transformation
fast implementation of singular spectrum transformation (change point detection algorithm)
Stars: ✭ 41 (-51.76%)
Mutual labels:  time-series, anomaly-detection
CoVA-Web-Object-Detection
A Context-aware Visual Attention-based training pipeline for Object Detection from a Webpage screenshot!
Stars: ✭ 18 (-78.82%)
Mutual labels:  attention, graph-attention-networks

Our implementation of MTAD-GAT: Multivariate Time-series Anomaly Detection (MTAD) via Graph Attention Networks (GAT) by Zhao et al. (2020).

  • This repo includes a complete framework for multivariate anomaly detection, using a model that is heavily inspired by MTAD-GAT.
  • Our work does not serve to reproduce the original results in the paper.
  • 📧 For contact, feel free to use [email protected]

Key Notes

  • By default we use the recently proposed GATv2, but include the option to use the standard GAT
  • Instead of using a Variational Auto-Encoder (VAE) as the Reconstruction Model, we use a GRU-based decoder.
  • We provide implementations of the following thresholding methods, but their parameters should be customized to different datasets:
    • peaks-over-threshold (POT) as in the MTAD-GAT paper
    • thresholding method proposed by Hundman et. al.
    • brute-force method that searches through "all" possible thresholds and picks the one that gives highest F1 score
    • All methods are applied, and their respective results are outputted together for comparison.
  • Parts of our code should be credited to the following:
    • OmniAnomaly for preprocessing and evaluation methods and an implementation of POT
    • TelemAnom for plotting methods and thresholding method
    • pyGAT by Diego Antognini for inspiration on GAT-related methods
    • Their respective licences are included in licences.

Getting Started

To clone the repo:

git clone https://github.com/ML4ITS/mtad-gat-pytorch.git && cd mtad-gat-pytorch

Get data:

cd datasets && wget https://s3-us-west-2.amazonaws.com/telemanom/data.zip && unzip data.zip && rm data.zip &&
cd data && wget https://raw.githubusercontent.com/khundman/telemanom/master/labeled_anomalies.csv &&
rm -rf 2018-05-19_15.00.10 && cd .. && cd ..

This downloads the MSL and SMAP datasets. The SMD dataset is already in repo. We refer to TelemAnom and OmniAnomaly for detailed information regarding these three datasets.

Install dependencies (virtualenv is recommended):

pip install -r requirements.txt 

Preprocess the data:

python preprocess.py --dataset <dataset>

where <dataset> is one of MSL, SMAP or SMD.

To train:

 python train.py --dataset <dataset>

where <dataset> is one of msl, smap or smd (upper-case also works). If training on SMD, one should specify which machine using the --group argument.

You can change the default configuration by adding more arguments. All arguments can be found in args.py. Some examples:

  • Training machine-1-1 of SMD for 10 epochs, using a lookback (window size) of 150:
python train.py --dataset smd --group 1-1 --lookback 150 --epochs 10 
  • Training MSL for 10 epochs, using standard GAT instead of GATv2 (which is the default), and a validation split of 0.2:
python train.py --dataset msl --epochs 10 --use_gatv2 False --val_split 0.2

⚙️ Default configuration:

Default parameters can be found in args.py.

Data params:

--dataset='SMD' --group='1-1' --lookback=100 --normalize=True

Model params:

--kernel_size=7 --use_gatv2=True --feat_gat_embed_dim=None --time_gat_embed_dim=None
--gru_n_layers=1 --gru_hid_dim=150 --fc_n_layers=3 --fc_hid_dim=150 --recon_n_layers=1
--recon_hid_dim=150 --alpha=0.2

Train params:

--epochs=30 --val_split=0.1 --bs=256 --init_lr=1e-3 --shuffle_dataset=True --dropout=0.3
--use_cuda=True --print_every=1 --log_tensorboard=True

Anomaly Predictor params:

--save_scores=True --load_scores=False --gamma=1 --level=None --q=1e-3 --dynamic_pot=False
--use_mov_av=False

👀 Output and visualization results

Output are saved in output/<dataset>/<ID> (where the current datetime is used as ID) and include:

  • summary.txt: performance on test set (precision, recall, F1, etc.)
  • config.txt: the configuration used for model, training, etc.
  • train/test.pkl: saved forecasts, reconstructions, actual, thresholds, etc.
  • train/test_scores.npy: anomaly scores
  • train/validation_losses.png: plots of train and validation loss during training
  • model.pt model parameters of trained model

This repo includes example outputs for MSL, SMAP and SMD machine 1-1.

result_visualizer.ipynb provides a jupyter notebook for visualizing results. To launch notebook:

jupyter notebook result_visualizer.ipynb

Predicted anomalies are visualized using a blue rectangle.
Actual (true) anomalies are visualized using a red rectangle.
Thus, correctly predicted anomalies are visualized by a purple (blue + red) rectangle.
Some examples:

SMD test set (feature 0) SMD train set (feature 0)
drawing drawing

Example from SMAP test set: drawing

Example from MSL test set (note that one anomaly segment is not detected): drawing

🧬 Model Overview

drawing

Figure above adapted from Zhao et al. (2020)

  1. The raw input data is preprocessed, and then a 1-D convolution is applied in the temporal dimension in order to smooth the data and alleviate possible noise effects.
  2. The output of the 1-D convolution module is processed by two parallel graph attention layer, one feature-oriented and one time-oriented, in order to capture dependencies among features and timestamps, respectively.
  3. The output from the 1-D convolution module and the two GAT modules are concatenated and fed to a GRU layer, to capture longer sequential patterns.
  4. The output from the GRU layer are fed into a forecasting model and a reconstruction model, to get a prediction for the next timestamp, as well as a reconstruction of the input sequence.

📖 GAT layers

Below we visualize how the two GAT layers view the input as a complete graph.

Feature-Oriented GAT layer Time-Oriented GAT layer
drawing drawing

Left: The feature-oriented GAT layer views the input data as a complete graph where each node represents the values of one feature across all timestamps in the sliding window.

Right: The time-oriented GAT layer views the input data as a complete graph in which each node represents the values for all features at a specific timestamp.

📖 GATv2

Recently, Brody et al. (2021) proposed GATv2, a modified version of the standard GAT.

They argue that the original GAT can only compute a restricted kind of attention (which they refer to as static) where the ranking of attended nodes is unconditioned on the query node. That is, the ranking of attention weights is global for all nodes in the graph, a property which the authors claim to severely hinders the expressiveness of the GAT. In order to address this, they introduce a simple fix by modifying the order of operations, and propose GATv2, a dynamic attention variant that is strictly more expressive that GAT. We refer to the paper for further reading. The difference between GAT and GATv2 is depicted below:

drawing

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].