Skip to content

Recurrent Neural Networks based Autoencoder for Time Series Anomaly Detection

License

Notifications You must be signed in to change notification settings

PyLink88/Recurrent-Autoencoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recurrent Neural Networks-based Autoencoders

A PyTorch implementation of LSTM-based Encoder-Decoder for Multi-sensor Anomaly Detection

Table of Contents:

Project Structure:

The project structure is based on the following Pytorch Project Template

├── agents
|  └── rnn_autoencoder.py # the main training agent for the recurrent NN-based AE
├── graphs
|  └── models
|  |  └── recurrent_autoencoder.py  # recurrent NN-based AE model definition
|  └── losses
|  |  └── MAELoss.py # contains the Mean Absolute Error (MAE) loss
|  |  └── MSELoss.py # contains the Mean Squared Error (MSE) loss
|  |  └── AUCLoss.py # under development (DO NOT USE!)
├── datasets  # contains all dataloaders for the project
|  └── ecg5000.py # dataloader for ECG5000 dataset
├── data
|  └── ECG5000  # contains all ECG time series
├── utils # utilities folder containing metrics, checkpoints and arg parsing (configs).
|  └── assets
|  └── checkpoints.py
|  └── config.py
|  └── metrics.py
|  └── create_config.py
|  └── data_preparation.py
├── notebooks # Folder where adding your notebook
├── experiments # Folder where saving the results of your experiments
├── main.py

Model

Encoder

alt text

In the encoder each vector of a time-window of length is fed into a recurrent unit to perform the following computation:

Decoder

alt text

In the decoder we reconstruct the time series in reverse order:

Data

Description

The ECG5000 dataset contains 5000 ElectroCardioGram (ECG) univariate time series of length . Each sequence corresponds to an heartbeat. Five classes are annotated, corresponding to the following labels: Normal (N), R-on-T Premature Ventricular Contraction (R-on-T PVC), Premature Ventricular Contraction (PVC), Supra-ventricular Premature or Ectopic Beat (SP or EB) and Unclassified Beat (UB). For each class we have the number of instances reported in the following Table:

Class #Instance
N 2919
R-on-T PVC 1767
PVC 194
SP or EB 96
UB 24

Since the main task here is anomaly detection rather than classification, all istances which do not belong to class N have been merged in unique class which will be referred to as Anomalous (AN).

Download and data partioning

You can directly download the ECG5000 dataset from here or by running the script utils/data_preparation.py. This script allows performing data partitioning as well, i.e., splitting your data in training, validation and test set. For more details, run the following: python utils/data_preparation.py -h

Requirements

Check requirements.txt.

Usage

  • Before running the project, you need to add your configuration into the folder configs/ as found here. To this aim, you can just modify the script utils/create_config.pyand then running the following python utils/create_config.py.
  • Finally to run the project: python main.py configs/config_rnn_ae.json

About

Recurrent Neural Networks based Autoencoder for Time Series Anomaly Detection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages