Unsupervised Representation Learning for Time Series with Temporal Neighborhood Coding

Sana Tonekaboni, Danny Eytan, Anna Goldenberg

Introduction

In fields like medicine and wearable technology, time series data—such as heart rate, blood pressure, or physical movement—is abundant but rarely labeled. A patient might transition from a "stable" to a "critical" state, but clinicians cannot realistically label every second of that transition. This lack of annotations makes supervised learning incredibly difficult.

While unsupervised representation learning offers a potential solution, most existing methods struggle with non-stationarity—the reality that the statistical properties of a signal change over time as the underlying "state" shifts. Furthermore, common contrastive learning techniques suffer from sampling bias. They typically assume that any sample far away in time is a "negative" (i.e., fundamentally different). However, in real-world scenarios, a patient might return to a previous stable state hours later.

Temporal Neighborhood Coding (TNC) is a novel self-supervised framework designed to solve these issues. By dynamically defining local neighborhoods and accounting for recurring states, TNC captures the underlying dynamics of complex data better than existing state-of-the-art methods.

Methodology

The TNC framework introduces two primary innovations to handle non-stationary time series:

  1. Statistical Neighborhood Discovery: Instead of relying on a fixed, arbitrary window to define "similar" samples, TNC utilizes the Augmented Dickey-Fuller (ADF) test. This statistical tool determines the temporal range around a specific point where the signal remains stationary. If the signal is stationary, TNC assumes it belongs to the same underlying state, forming a dynamic "neighborhood."
  2. Debiased Contrastive Objective: TNC trains a discriminator to distinguish between windows within the same neighborhood and those outside of it. To correct the sampling bias—where a distant "negative" sample might actually represent a recurring positive state—the authors incorporate Positive Unlabeled (PU) Learning. This approach adds a weight ($w$) to the loss function, treating distant samples as a mixture of true negatives and potential hidden positives.
TNC architecture illustrating neighborhood sampling and debiased non-neighborhood sampling.

The architecture is highly flexible; it can be implemented using Recurrent Neural Networks (RNNs) for low-frequency data or Convolutional Neural Networks (CNNs) for high-frequency waveforms.

Key Insights

  • Stationarity as a Proxy for State: The core insight of TNC is using stationarity to define the boundaries of a representation. If the generative process of the signal hasn't changed statistically, the learned representation shouldn't either.
  • Handling Recurrence: By acknowledging that time series often return to previous states (e.g., a heart rate returning to normal after exercise), TNC abandons the flawed "further is more different" assumption that limits other contrastive methods like Contrastive Predictive Coding (CPC).
  • Encoding Trajectories: TNC goes beyond merely clustering points; it maps the progression of a signal. The learned representations exhibit clear trajectories that shift precisely when the underlying state changes, such as the onset of a medical artifact or a shift in physical activity.

Experiments and Key Results

The framework was rigorously evaluated across three distinct datasets: a simulated dataset with four hidden states, the MIT-BIH Atrial Fibrillation (ECG) dataset, and a Human Activity Recognition (HAR) dataset.

TNC consistently outperformed state-of-the-art baselines like CPC and Triplet Loss (T-Loss) across both clustering and classification tasks:

  • Classification Accuracy: On the simulated dataset, TNC achieved 97.5% accuracy, significantly outperforming CPC (70.2%) and T-Loss (76.6%).
  • Clinical Performance: On the highly imbalanced real-world ECG dataset, TNC achieved an Area Under the Precision-Recall Curve (AUPRC) of 0.55, beating the next best unsupervised method (0.47) and approaching the performance of fully supervised models (0.67).
  • Clustering Quality: Using the Silhouette score (where higher is better), TNC scored 0.71 on simulated data, while CPC and T-Loss trailed at 0.51 and 0.61, respectively.
Comparison of learned representations using TNC, Triplet Loss, and CPC.

Limitations and Future Work

While highly effective, the authors identify a few areas for future improvement:

  • Computational Efficiency: The ADF test used to define neighborhoods is currently implemented via a CPU-based library (statsmodels). Because it is not yet optimized for GPUs, it creates a bottleneck during the training process.
  • Hyperparameter Sensitivity: Although the neighborhood range is determined automatically, the base window size ($\delta$) still requires domain knowledge to set appropriately (e.g., knowing that 7 seconds of an ECG is sufficient to identify a rhythm).
  • Broader Applications: The authors suggest that TNC's robust, general representations could be highly effective for downstream anomaly detection, a critical task in both industrial maintenance and medical monitoring.

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