Home

Awesome

Time-Series Representation Learning via Temporal and Contextual Contrasting (TS-TCC) [Paper] [Cite]

by: Emadeldeen Eldele, Mohamed Ragab, Zhenghua Chen, Min Wu, Chee Keong Kwoh, Xiaoli Li and Cuntai Guan

This work is accepted for publication in the International Joint Conferences on Artificial Intelligence (IJCAI-21) (Acceptance Rate: 13.9%).

:boom::boom: Update: We extended our method to the semi-supervised settings (CA-TCC). Please refer to the manuscript Self-supervised Contrastive Representation Learning for Semi-supervised Time-Series Classification for more details. The code is also publicly available. :boom::boom:

:boom::boom: Update 2: The extension CA-TCC has been accepted in the IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI) :boom::boom:

Abstract

<p align="center"> <img src="misc/TS_TCC.png" width="400" class="center"> </p>

Learning decent representations from unlabeled time-series data with temporal dynamics is a very challenging task. In this paper, we propose an unsupervised <b>T</b>ime-<b>S</b>eries representation learning framework via <b>T</b>emporal and <b>C</b>ontextual <b>C</b>ontrasting (<b>TS-TCC</b>), to learn time-series representation from unlabeled data. First, the raw time-series data are transformed into two different yet correlated views by using weak and strong augmentations. Second, we propose a novel temporal contrasting module to learn <i>robust</i> temporal representations by designing a tough cross-view prediction task. Last, to further learn <i>discriminative</i> representations, we propose a contextual contrasting module built upon the contexts from the temporal contrasting module. It attempts to maximize the similarity among different contexts of the same sample while minimizing similarity among contexts of different samples. Experiments have been carried out on three real-world time-series datasets. The results manifest that training a linear classifier on top of the features learned by our proposed TS-TCC performs comparably with the supervised training. Additionally, our proposed TS-TCC shows high efficiency in few-labeled data and transfer learning scenarios.

Requirmenets:

Datasets

Download datasets

Update: You can now find the preprocessed datasets on this Dataverse

We used four public datasets in this study:

Preparing datasets

The data should be in a separate folder called "data" inside the project folder. Inside that folder, you should have a separate folders; one for each dataset. Each subfolder should have "train.pt", "val.pt" and "test.pt" files. The structure of data files should in dictionary form as follows: train.pt = {"samples": data, "labels: labels}, and similarly val.pt, and test.pt

The details of preprocessing is as follows:

1- Sleep-EDF dataset:

Create a folder named data_files in the path data_preprocessing/sleep-edf/. Download the dataset files and place them in this folder.

Run the script preprocess_sleep_edf.py to generate the numpy files ... you will find the numpy files of each PSG file in another folder named sleepEDF20_fpzcz (you can change these names from args). You will also find the data of each subject in the folder sleepEDF20_fpzcz_subjects (since each subject has two-night data)

Finally run the file generate_train_val_test.py to generate the files and it will automatically place them in the data/sleepEDF folder.

2- UCI HAR dataset

When you dowload the dataset and extract the zip file, you will find the data in a folder named UCI HAR Dataset ... place it in data_preprocessing/uci_har/ folder and run preprocess_har.py file.

3- Epilepsy and Fault diagnosis datasets:

download the data file in data_files folder and run the preprocessing scripts.

Configurations

The configuration files in the config_files folder should have the same name as the dataset folder name. For example, for HAR dataset, the data folder name is HAR and the configuration file is HAR_Configs.py. From these files, you can update the training parameters.

Training TS-TCC

You can select one of several training modes:

The code allows also setting a name for the experiment, and a name of separate runs in each experiment. It also allows the choice of a random seed value.

To use these options:

python main.py --experiment_description exp1 --run_description run_1 --seed 123 --training_mode random_init --selected_dataset HAR

Note that the name of the dataset should be the same name as inside the "data" folder, and the training modes should be the same as the ones above.

To train the model for the fine_tune and train_linear modes, you have to run self_supervised first.

Results

Citation

If you found this work useful for you, please consider citing it.

@inproceedings{ijcai2021-324,
  title     = {Time-Series Representation Learning via Temporal and Contextual Contrasting},
  author    = {Eldele, Emadeldeen and Ragab, Mohamed and Chen, Zhenghua and Wu, Min and Kwoh, Chee Keong and Li, Xiaoli and Guan, Cuntai},
  booktitle = {Proceedings of the Thirtieth International Joint Conference on Artificial Intelligence, {IJCAI-21}},
  pages     = {2352--2359},
  year      = {2021},
}
@article{emadeldeen2022catcc,
  title   = {Self-supervised Contrastive Representation Learning for Semi-supervised Time-Series Classification},
  author  = {Eldele, Emadeldeen and Ragab, Mohamed and Chen, Zhenghua and Wu, Min and Kwoh, Chee Keong and Li, Xiaoli and Guan, Cuntai},
  journal = {arXiv preprint arXiv:2208.06616},
  year    = {2022}
}

Contact

For any issues/questions regarding the paper or reproducing the results, please contact me.
Emadeldeen Eldele
School of Computer Science and Engineering (SCSE),
Nanyang Technological University (NTU), Singapore.
Email: emad0002{at}e.ntu.edu.sg