Self-Supervised Learning for Time Series: Contrastive or Generative?

Xiang Zhang, Ziyu Liu, Azadeh Alavi, Minyi Li, Xiang Zhang 0012arXiv 2024 · DOI

Abstract

Self-supervised learning (SSL) has emerged as a powerful paradigm for leveraging unlabeled data in domains where annotations are costly, such as healthcare and finance. This paper presents a rigorous head-to-head comparison between two dominant SSL philosophies—contrastive learning (SimCLR) and generative learning (Masked Autoencoders, MAE)—specifically adapted for time series data. Our findings reveal that while generative models are computationally more efficient and superior in extremely low-label scenarios, contrastive models tend to achieve higher performance as the availability of labeled data increases.

Introduction

Deep learning's success is often predicated on the availability of large-scale labeled datasets. However, in specialized time series applications like ECG monitoring or financial forecasting, obtaining expert labels is expensive and time-consuming. SSL addresses this by pre-training models on unlabeled data to learn robust representations. Currently, the field is divided between contrastive methods, which learn by distinguishing between similar and dissimilar samples, and generative methods, which learn by reconstructing missing portions of the input. This study aims to provide a "fair" comparison to guide researchers in selecting the appropriate paradigm for specific time series challenges.

Methodology

The authors implemented and adapted two state-of-the-art frameworks for time series analysis:

  1. Contrastive Framework (SimCLR): This approach utilizes data augmentation (specifically Gaussian jittering) to create "positive" pairs. A 2-layer Transformer encoder is trained using the NT-Xent loss to pull representations of positive pairs together in latent space while pushing "negative" pairs apart.
  2. Generative Framework (MAE): Adapted from computer vision, this model partitions time series into patches and masks 75% of them. The encoder processes only the visible 25%, and a decoder attempts to reconstruct the original signal, forcing the model to learn the underlying data distribution.
Overview of the Contrastive (SimCLR) and Generative (MAE) frameworks for time series SSL.

To ensure comparability, both frameworks utilized similar Transformer-based backbones and identical hyperparameters where possible.

Experimental Results

The models were evaluated on two distinct datasets: Human Activity Recognition (HAR) from smartphone sensors and the MIT-BIH ECG dataset for heart arrhythmia classification.

The Impact of Label Scarcity

A key finding is that the optimal SSL method depends heavily on the "label ratio"—the percentage of labeled data available for fine-tuning. Generative models (MAE) proved to be "kings of scarcity," significantly outperforming SimCLR when labels were extremely limited (e.g., 1% of the dataset). On the HAR dataset, pre-trained MAE improved the F1 score by 5.53% over a non-pre-trained baseline at a 1% label ratio.

F1-Score performance of MAE vs. SimCLR across different label ratios, showing the crossover point.

The Tipping Point and Efficiency

As shown in the results, a "tipping point" exists. On the HAR dataset, MAE outperformed SimCLR at low label ratios (0.01 to 0.1). However, once the label ratio exceeded 0.5, SimCLR's performance began to surpass that of MAE.

Furthermore, MAE demonstrated superior computational efficiency. By avoiding the heavy pairwise distance calculations required for negative sampling in contrastive learning, MAE trained 25.6% faster than SimCLR.

Dataset Sensitivity

The relative performance was not universal across datasets. On the ECG dataset, SimCLR outperformed MAE even at the 1% label mark. This suggests that the periodic and relatively simple patterns of ECG signals may be easier to contrast than to reconstruct, highlighting the importance of matching the SSL paradigm to the data's inductive biases.

Conclusion

This comparative study highlights the trade-offs between contrastive and generative SSL for time series. Generative models like MAE offer a compelling choice for low-resource settings and high-efficiency requirements. In contrast, SimCLR remains a strong contender when more labeled data is available or when data augmentations can effectively capture the signal's essence. Future work should explore hybrid approaches that combine both losses and extend the evaluation to forecasting and anomaly detection tasks.

Summary updated

BibTeX
@misc{zhang2024self,
  author = {Xiang Zhang and Ziyu Liu and Azadeh Alavi and Minyi Li and Xiang Zhang},
  title = {{Self-Supervised Learning for Time Series: Contrastive or Generative?}},
  year = {2024},
  eprint = {2403.09809},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.09809},
}
Figure