Unsupervised Representation Learning for Time Series with Temporal Neighborhood Coding

Sana Tonekaboni, Danny Eytan, Anna Goldenberg

TL;DR

Temporal Neighborhood Coding (TNC) is a new self-supervised framework designed to learn informative representations from complex, non-stationary time series data without requiring manual labels. By leveraging the statistical property of local stationarity and a debiased contrastive loss, TNC effectively captures underlying state transitions, outperforming existing unsupervised methods in clustering and classification tasks.

What Problem Does This Paper Address?

Modeling real-world time series data—like ECG signals from a hospital patient—is notoriously difficult. These signals are high-dimensional, frequently unlabeled, and "non-stationary," meaning their statistical properties (like mean or variance) change over time as the underlying state of the system changes.

Existing unsupervised methods often struggle with these dynamics. For instance, contrastive learning usually works by picking a "positive" sample near a reference point and "negative" samples from elsewhere. However, in time series, a distant "negative" sample might actually represent the same underlying state (e.g., a patient returning to a stable heart rhythm after an episode). Treating these as negatives introduces sampling bias, which confuses the model. TNC aims to solve this by intelligently defining temporal neighborhoods and accounting for potential bias in negative sampling.

Methods

The core of TNC is the idea of Temporal Neighborhoods. Instead of using fixed-length windows or random sampling, TNC defines a neighborhood $N_t$ around a window $W_t$ where the signal is relatively stationary.

  1. Automatic Neighborhood Discovery: The authors use the Augmented Dickey-Fuller (ADF) test, a statistical tool, to find the widest range around a window where the signal remains stationary. This allows the model to adaptively determine how far "local" extends for any given part of the signal.
  2. Debiased Contrastive Learning: TNC uses an encoder to map windows into a latent space and a discriminator to predict if two windows belong to the same neighborhood. To fix the sampling bias mentioned earlier, they borrow concepts from Positive-Unlabeled (PU) learning. They treat non-neighboring samples as "unlabeled" rather than strictly "negative," applying a weighting factor ($w$) to the loss function to account for the possibility that a distant sample might actually be similar to the reference.
Overview of the TNC framework components. The encoder learns to distinguish between neighborhood samples (a) and weighted non-neighboring samples (b).

Datasets

The authors evaluated TNC on three distinct types of data:

  • Simulated Data: A synthetic dataset generated using Hidden Markov Models (HMMs) and Gaussian Processes to create 4 distinct underlying states with complex transitions.
  • MIT-BIH Atrial Fibrillation: A real-world medical dataset containing long-term ECG recordings. This is particularly challenging due to extreme class imbalance and non-stationary heart rhythms.
  • UCI Human Activity Recognition (HAR): Data from smartphone sensors (accelerometers/gyroscopes) capturing activities like walking, sitting, and standing.

Key Insights and Ideas

  • Stationarity as a Proxy for State: The most clever insight is using local stationarity (via the ADF test) as a self-supervised signal. It assumes that if the statistical properties haven't changed, the underlying "state" likely hasn't changed either.
  • Handling the "Return to State" Problem: By using PU learning weights, TNC acknowledges that time series are often cyclical or repetitive. This prevents the model from being penalized when it recognizes that a patient’s heart rate at hour 1 is the same as at hour 10.
  • Encoder Agnosticism: TNC is a framework, not a specific architecture. It can work with Recurrent Neural Networks (RNNs) or Convolutional Neural Networks (CNNs) depending on the data's requirements (e.g., high-frequency ECG vs. lower-frequency sensor data).

Key Results

TNC consistently outperformed state-of-the-art baselines like Contrastive Predictive Coding (CPC) and Triplet Loss.

  • Clustering: In the latent space, TNC produced much cleaner clusters of underlying states. On simulated data, TNC achieved a Silhouette score of 0.71, compared to 0.51 for CPC and 0.61 for Triplet Loss.
  • Classification: When the learned representations were used to train a simple linear classifier, TNC performed nearly as well as fully supervised models. On the ECG dataset, TNC reached 77.79% accuracy, significantly higher than CPC (68.64%).
  • Trajectory Visualization: The model successfully captured state transitions. As seen in Figure 3, the 10-dimensional encoding shifts distinctly whenever the underlying simulated state changes.
T-SNE visualization showing that TNC (a) clusters latent states much more effectively than Triplet Loss (b) or CPC (c).
Trajectory of a signal encoding. The bottom panel shows how the 10-dimensional representation settles into distinct patterns for each of the 4 underlying states.

Limitations and Future Work

  • Computational Efficiency: The ADF test used to define neighborhoods is currently implemented in a way that doesn't support GPU acceleration. This makes the training process slower than simpler contrastive methods. The authors noted they are working on an optimized version.
  • Hyperparameter Sensitivity: While the neighborhood range is discovered automatically, the window size ($\delta$) and the PU learning weight ($w$) still require some manual tuning or prior domain knowledge.
  • Broadening Applications: The authors suggest that these general representations could be highly effective for other downstream tasks like anomaly detection, which they leave for future exploration.

Summary updated

BibTeX
@inproceedings{tonekaboni2021unsupervised,
  author = {Sana Tonekaboni and Danny Eytan and Anna Goldenberg},
  title = {{Unsupervised Representation Learning for Time Series with Temporal Neighborhood Coding}},
  booktitle = {International Conference on Learning Representations},
  year = {2021},
}
Figure