Skip to content

Implementation of Anomaly Detection for Time Series Using VAE-LSTM Hybrid Model in PyTorch

License

Notifications You must be signed in to change notification settings

thatgeeman/ts_vae-lstm

Repository files navigation

TS VAE-LSTM

Implementation of the paper Anomaly Detection for Time Series Using VAE-LSTM Hybrid Model

This is a work in progress.

TODO

  • Separate training from notebooks
  • Fix github-actions
    • Page deployment
    • CI tests
    • precommit
  • Build complete AD pipeline
  • include fine-grained threshold with quantile for within window detection.
  • use a squared term if the absolute element-wise error falls below delta and a delta-scaled L1 term otherwise (Huber)
  • Use dotenv .env to manage paths
  • Plot has a shift of 21 due to remainder -> todo

Installation

pip install ts_vae_lstm

Results from NYC Traffic dataset

At time $t$, past $k$ window(s) of length $p=48$ are taken. The VAE-LSTM reconstructs the past windows and if the true time series deviates from the reconstructed time series, the $k^{th}$ window is marked as an “anomalous window”.

VAE-LSTM is trained on a time series without anomalies so any deviation beyond the 90th quantile of reconstruction error (L2 norm) is considered an anomaly.

In the figure (sample_data/result_granular.png), blue lines represent the unseen data. Orange lines correspond to the reconstructed data. Red dashed lines are the true labels in the unseen set. Green window is the region where anomaly was predicted. Green line is the first time anomaly was flagged in the window.

Misc

Env variables

BASEDIR='<your-base-path>/ts_vae-lstm'
MODELDIR=${BASEDIR}/models
VAE_MODEL=${MODELDIR}/<best-vae-model>.pth
LSTM_MODEL=${MODELDIR}/<best-lstm-model>.pth

CUDA setup

Download the driver and cuda version compiled for the driver.

sudo mhwd -i pci video-nvidia-470xx
sudo pacman -U https://archive.archlinux.org/packages/c/cuda/cuda-11.4.2-1-x86_64.pkg.tar.zst

About

Implementation of Anomaly Detection for Time Series Using VAE-LSTM Hybrid Model in PyTorch

Topics

Resources

License

Stars

Watchers

Forks