Out-of-Distribution Representation Learning for Time Series Classification

Wang Lu, Jindong Wang, Xinwei Sun, Yiqiang Chen, Xing Xie

TL;DR

Time series data is notoriously non-stationary, making out-of-distribution (OOD) generalization difficult because distinct "sub-domains" are hidden and constantly changing. This paper introduces DIVERSIFY, an iterative framework that automatically uncovers these latent sub-domains via a min-max adversarial game and forces the model to learn domain-invariant features. By doing so, it achieves state-of-the-art performance across diverse time series classification tasks without requiring explicit domain labels during training.

What Problem Does This Paper Address?

Traditional domain generalization (DG) algorithms—mostly designed for computer vision—rely on explicit, static domain labels (e.g., distinguishing between "Photo," "Sketch," or "Cartoon" styles). In time series data, however, distributions shift dynamically across both time (temporal shifts) and different subjects or sensors (spatial shifts), meaning explicit domain labels are rarely available.

Naively treating a time series dataset as a single uniform distribution ignores these internal variations, leading to models that fail to generalize to unseen target distributions. The authors tackle the challenge of learning robust, out-of-distribution representations from time series data when the underlying sub-domains are completely unknown.

Figure 1: Illustration of DIVERSIFY: (a) Domain generalization for image data requires known domain labels. (b) Domain labels are unknown for time series. (c) If we treat the time series data as one single domain, the sub-domains are misclassified. Different colors and shapes correspond to different classes and domains. Axes represent data values. (d) Finally, our DIVERSIFY can effectively learn the latent distributions. X-axis represents data numbers while Y-axis represents values.

Methods

The authors propose DIVERSIFY, which operates via an iterative min-max adversarial game structured into four main steps:

  1. Pre-processing: The time series is segmented using a standard sliding window approach, treating each window as the basic unit of data.
  2. Fine-grained Feature Update: The model assigns joint "pseudo domain-class labels" to ensure the feature extractor retains both class-specific and domain-specific nuances.
  3. Latent Distribution Characterization (The Max Step): To find the "worst-case" distribution scenario, DIVERSIFY uses an adapted adversarial training mechanism combined with a self-supervised clustering strategy (nearest centroid) to automatically assign pseudo-domain labels to data segments. It maximizes the divergence between these discovered sub-domains to capture the full diversity of the data.
  4. Domain-Invariant Representation Learning (The Min Step): Using the newly assigned pseudo-domain labels, the framework applies a Gradient Reversal Layer (GRL) to minimize the distribution gap between these sub-domains, forcing the network to learn features that generalize across all of them.

Datasets

The method was evaluated across 7 distinct datasets spanning 4 real-world tasks:

  • Gesture Recognition: EMG for gestures dataset (36 subjects).
  • Speech Commands Recognition: Speech Commands dataset (over 35,000 samples across 10 words).
  • Wearable Stress & Affect Detection: WESAD dataset (physiological and motion data from 15 subjects).
  • Sensor-based Human Activity Recognition (HAR): DSADS, USC-HAD, UCI-HAR, and PAMAP datasets. These were evaluated across four challenging OOD configurations: cross-person, cross-position, cross-dataset, and one-person-to-another generalization.

Key Insights and Ideas

  • The Power of the "Worst-Case" Scenario: Instead of trying to find a clean, average distribution, DIVERSIFY intentionally drives the sub-domains apart during the characterization step. Maximizing this source-domain divergence theoretically expands the coverage of the training space, making it far more likely to encompass an unseen, out-of-distribution test domain.
  • Single Individuals Contain Multiple Domains: A fascinating finding from their analysis is that even data recorded from a single person performing the same activity over time exhibits distinct latent distributions. This underscores why traditional subject-level domain splits are insufficient for time series.
  • Fine-Grained Supervision is Critical: The ablation studies revealed that updating features using only domain labels or only class labels degrades performance. The feature extractor needs the combined pseudo domain-class labels to avoid becoming heavily biased toward one or the other.

Key Results

  • DIVERSIFY consistently outperformed 9 strong baselines (including ERM, DANN, Mixup, GroupDRO, and AdaRNN) across all benchmarks.
  • On the highly challenging EMG gesture dataset, DIVERSIFY achieved an average accuracy of 77.1%, outperforming the next best method (AdaRNN) by 1.3% and standard ERM by 9.7%.
  • On the massive WESAD dataset, it boosted performance by over 8% compared to other state-of-the-art methods.
  • In Human Activity Recognition (HAR), it beat the second-best baselines by 2.4% (cross-person), 1.4% (cross-position), 9.9% (cross-dataset), and 5.8% (one-person-to-another).
  • The framework proved robust across multiple architectures, showing substantial gains when paired with both standard CNNs and advanced Transformer backbones.

Limitations and Future Work

  • Hyperparameter Dependency: The number of latent sub-domains ($K$) must be predefined and tuned manually as a hyperparameter. Automating the discovery of the optimal $K$ remains an open challenge.
  • Lack of Semantic Interpretability: While the algorithm successfully clusters data into distinct latent distributions, it does not explain why those specific boundaries exist (e.g., whether a sub-domain corresponds to a specific physical fatigue level, sensor slippage, or environmental change).
  • Task Scope: The current framework is strictly evaluated on time series classification and has not yet been extended to time series forecasting or anomaly detection problems.

Summary updated

Abstract

Time series classification is an important problem in real world. Due to its non-stationary property that the distribution changes over time, it remains challenging to build models for generalization to unseen distributions. In this paper, we propose to view the time series classification problem from the distribution perspective. We argue that the temporal complexity attributes to the unknown latent distributions within. To this end, we propose DIVERSIFY to learn generalized representations for time series classification. DIVERSIFY takes an iterative process: it first obtains the worst-case distribution scenario via adversarial training, then matches the distributions of the obtained sub-domains. We also present some theoretical insights. We conduct experiments on gesture recognition, speech commands recognition, wearable stress and affect detection, and sensor-based human activity recognition with a total of seven datasets in different settings. Results demonstrate that DIVERSIFY significantly outperforms other baselines and effectively characterizes the latent distributions by qualitative and quantitative analysis. Code is available at: https://github.com/microsoft/robustlearn.
BibTeX
@inproceedings{lu2023out,
  author = {Wang Lu and Jindong Wang and Xinwei Sun and Yiqiang Chen and Xing Xie},
  title = {{Out-of-Distribution Representation Learning for Time Series Classification}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=gUZWOE42l6Q},
}
Figure