CoST: Contrastive Learning of Disentangled Seasonal-Trend Representations for Time Series Forecasting

Gerald Woo, Chenghao Liu, Doyen Sahoo, Akshat Kumar, Steven Hoi

TL;DR

CoST (Contrastive Seasonal-Trend) is a novel framework for time series forecasting that departs from traditional end-to-end training paradigms. Instead of mapping raw data directly to predictions, CoST first learns disentangled representations of trend and seasonal components using specialized contrastive learning tasks. This approach achieves a massive 21.3% improvement in Mean Squared Error (MSE) over previous state-of-the-art multivariate benchmarks.

The Problem with End-to-End Forecasting

Most modern deep learning models for time series forecasting—whether based on LSTMs, TCNs, or Transformers—are trained "end-to-end." While powerful, this direct mapping from raw data to prediction suffers from two major flaws:

  1. Overfitting to Noise: Models frequently capture spurious correlations from unpredictable noise rather than learning the underlying signal.
  2. Entanglement: Standard neural networks mix trend and seasonal information into a single, entangled feature vector. In real-world data, trends often shift while seasonality remains constant. An entangled model struggles to generalize in these scenarios because it cannot isolate which part of the underlying process changed.
Decomposition of a time series into seasonal and trend components.

The authors argue that for better generalization, time series should be viewed through a causal lens, separating invariant components (trend and seasonality) from random error.

The CoST Framework

The CoST framework addresses these issues by utilizing a backbone encoder followed by two specialized "disentanglers" designed to isolate specific temporal features.

The CoST framework architecture, detailing the overall pipeline and the specific Trend and Seasonal Feature Disentanglers.

1. Trend Feature Disentangler (TFD)

The TFD operates in the time domain. It employs a Mixture of Auto-Regressive Experts (using 1D causal convolutions with varying kernel sizes) to adaptively capture trends at different scales. It is trained using a time-domain contrastive loss inspired by MoCo. This loss encourages the model to identify the same underlying trend even under different noise "interventions" (data augmentations like scaling and jittering).

2. Seasonal Feature Disentangler (SFD)

The SFD operates in the frequency domain. It utilizes a learnable Fourier layer to capture periodic patterns. Instead of processing raw time steps, it applies a Discrete Fourier Transform (DFT), performs a linear transformation on the frequencies, and then applies an inverse DFT. It is trained with a novel frequency-domain contrastive loss that separately constrains the amplitude and phase of the signal, allowing the model to distinguish between different periodicities without requiring manually specified periods (e.g., "daily" or "weekly").

Once these disentangled representations are learned in a self-supervised manner, a simple ridge regressor is trained on top to perform the final forecast.

Key Insights and Results

  • State-of-the-Art Performance: Evaluated on high-profile benchmarks including ETT (Electricity Transformer Temperature), Electricity, Weather, and the M5 Walmart retail dataset, CoST outperformed existing methods like Informer, LogTrans, and TS2Vec. Most notably, it achieved a 21.3% average improvement in MSE on multivariate benchmarks.
  • The Power of Disentanglement: Separating trend and seasonality is a powerful inductive bias for deep learning. Visualizations demonstrate that CoST creates much tighter, more distinct clusters for different seasonal and trend patterns compared to previous representation learning methods.
  • Causal Robustness: By treating data augmentations (scaling, shifting, jittering) as "interventions" on the error variable, the model learns to extract features that are genuinely invariant to noise.
  • Backbone Agnostic: The framework is highly robust to the choice of base encoder. Whether paired with a Temporal Convolutional Network (TCN), LSTM, or Transformer, CoST consistently improves performance over standard training methods.

Limitations and Future Directions

While highly effective, CoST does introduce some computational overhead. The sequential computation of experts in the TFD mixture can be slower than simpler encoders, though parallelization can mitigate this. Additionally, the balance between trend and seasonal losses (controlled by a hyperparameter $\alpha$) may require tuning for datasets where one component heavily dominates the other.

Looking forward, the authors suggest extending this disentangled representation learning approach to other time series tasks beyond forecasting, such as classification and anomaly detection.

Summary updated

BibTeX
@inproceedings{woo2022cost,
  author = {Gerald Woo and Chenghao Liu and Doyen Sahoo and Akshat Kumar and Steven Hoi},
  title = {{CoST: Contrastive Learning of Disentangled Seasonal-Trend Representations for Time Series Forecasting}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=PilZY3omXV2},
}
Figure