Get Start

Inspired by Jiang et al., I realized that any pattern-matching algorithm based on dynamic programming can theoretically be transformed into an equivalent or approximate recurrent neural network. This transformation could then be applied to tackle sample classification problems in scenarios like cold-start, interpretability, knowledge-driven tasks, and low-resource settings.

In the field of time series classification, the classic dynamic time warping algorithm is essentially a pattern-matching algorithm based on dynamic programming. This project provides a concrete implementation of transforming dynamic time warping into a neural network.

Requirements

  • arff2pandas 1.0.1
  • matplotlib 3.5.0
  • numpy 1.21.4
  • pandas 1.4.3
  • scipy 1.9.3
  • sklearn 0.0
  • torch 1.10.0+cu113
  • tqdm 4.61.2

Data

The UCR datasets can be downloaded here: UCR Time Series Classification Archive
You can download and extract the zip file, and replace the original data directory. The directory structure should be:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
.
├── LICENSE.md
├── README.md
├── datasets
│   ├── UCRArchive_2018
│   │   ├── ACSF1
│   │   │   ├── ACSF1_TEST.tsv
│   │   │   ├── ACSF1_TRAIN.tsv
│   │   │   └── README.md
│   │   ├── Adiac
│   │   │   ├── Adiac_TEST.tsv
│   │   │   ├── Adiac_TRAIN.tsv
│   │   │   └── README.md
│   │   ├── AllGestureWiimoteX
│   │   │   ├── AllGestureWiimoteX_TEST.tsv
│   │   │   ├── AllGestureWiimoteX_TRAIN.tsv
│   │   │   └── README.md
│   │   ...
│   └── process.py
├── main.py
├── main_imbalance.py
├── models
│   ├── DTW_RNN.py
│   └── handlers.py
├── results
│   └── prototypes
└── utils
├── evaluators.py
└── utils.py

Run

There are two main entry files:

1
2
main.py
main_inbalance.py

The main experimental results are generated by main.py, and the main_imbalance.py generates the results for imbalanced settings.

If you have downloaded UCR data and place them into the right location, run:

1
python main.py --dataset ECG5000 --lr 0.05 --batch_size 2000  --k_shot 10  --scaling_rate 0.5