DConAD: A Differencing-based Contrastive Representation Learning Framework for Time Series Anomaly Detection

Wenxin Zhang, Xiaojian Lin, Wenjun Yu, Guangzhen Yao, Jingxing Zhong, Yu Li, Ruili Han, Sheng Xu, Hao Shi, Cuicui Luo2025 · DOI

TL;DR

This paper introduces DConAD, a novel framework for unsupervised time series anomaly detection. DConAD uses differencing to enhance Transformer models' ability to capture normal patterns and employs a KL divergence-based contrastive learning approach with only positive samples to avoid being misled by anomalies during training.

What Problem Does This Paper Address?

Detecting anomalies in time series data is crucial for many applications, from industrial process control to financial fraud detection. However, existing unsupervised methods struggle with several challenges: anomalies can appear in many different forms, they are often rare, and the sheer volume and complexity of modern time series data make it hard to capture robust patterns. Traditional methods like Transformers, while powerful, can be biased towards anomalies, and many unsupervised approaches rely on reconstruction or prediction, which are sensitive to the presence of unknown anomalies in the training data. This can lead to impure representations of normal behavior and hinder accurate anomaly detection.

Methods

DConAD tackles these issues with a multi-pronged approach:

  • Differencing for Enhanced Representation: The core idea is to generate "differential" time series data by calculating the difference between consecutive time points. This process helps to remove trends and seasonality, providing a complementary view of the data that can highlight subtle changes and reduce the impact of noise.
  • Transformer-based Spatiotemporal Learning: DConAD utilizes a Transformer architecture, enhanced with both time-oriented and relation-oriented components. The time-oriented part captures long-range temporal dependencies, while the relation-oriented part models correlations between different variables (features) in the time series. By encoding both the original and differential time series, the model aims to mitigate the Transformer's tendency to overemphasize anomalies.
  • Contrastive Learning with Positive Samples: Instead of relying on reconstruction or prediction, DConAD employs a contrastive learning strategy. It generates two "views" of the time series data (one from the original, one from the differential representation) and trains the model to make these views consistent. Crucially, it uses a novel KL divergence-based contrastive loss that only uses positive samples. This means it learns what "normal" looks like by comparing different representations of normal data, avoiding the pitfalls of learning from potentially anomalous data.
  • Stop-Gradient Strategy: To ensure stable training and prevent model collapse, DConAD incorporates a stop-gradient strategy. This technique is applied to one of the contrastive views, forcing the model to learn from the other view without allowing the gradients to flow back and potentially disrupt the learning process.

Datasets

DConAD was evaluated on five public datasets:

  • MSL (NASA)
  • SMAP (NASA)
  • PSM (eBay)
  • SMD (Server)
  • SWaT (Water)

These datasets represent diverse application domains and vary in dimensionality, size, and anomaly rates.

Key Insights and Ideas

  • Differencing as a "Denoiser": The paper highlights how differencing can act as a form of data augmentation that specifically helps to "denoise" the time series by focusing on changes rather than absolute values, thereby improving the Transformer's ability to learn normal patterns.
  • Positive-Sample Contrastive Learning is Sufficient: The authors demonstrate that a contrastive learning approach can be highly effective for anomaly detection even when only using positive (normal) samples, bypassing the need for complex reconstruction or prediction mechanisms that are vulnerable to anomalies.
  • Symmetrical KL Divergence is Key: The experiments show that using symmetrical KL divergence for measuring consistency between contrastive views is superior to asymmetrical KL divergence or Jensen-Shannon divergence, suggesting a specific mathematical property that benefits anomaly detection.
  • Stop-Gradient is Crucial for Stability: The ablation study clearly shows that the stop-gradient strategy is essential for achieving satisfactory performance, preventing significant drops in F1-score.

Key Results

DConAD consistently outperformed nine state-of-the-art baselines across the evaluated datasets, showing significant improvements in F1-score (ranging from 1.09% to 34.16% on various datasets). Ablation studies confirmed the effectiveness of the differencing module, the time-oriented and relation-oriented Transformer blocks, and the stop-gradient strategy. Sensitivity analysis indicated that while the number of layers has minor impact, the number of attention heads, hidden size, and window size are critical hyperparameters.

Limitations and Future Work

The authors acknowledge that DConAD's performance on the SMD dataset was suboptimal, potentially due to its lower anomaly rate, which might limit the capture of key abnormal characteristics. Future work will focus on exploring more computationally efficient algorithms to reduce training and inference time.

Summary updated

Abstract

Time series anomaly detection holds notable importance for risk identification and fault detection across diverse application domains. Unsupervised learning methods have become popular because they have no requirement for labels. However, due to the challenges posed by the multiplicity of abnormal patterns, the sparsity of anomalies, and the growth of data scale and complexity, these methods often fail to capture robust and representative dependencies within the time series for identifying anomalies. To enhance the ability of models to capture normal patterns of time series and avoid the retrogression of modeling ability triggered by the dependencies on high-quality prior knowledge, we propose a differencing-based contrastive representation learning framework for time series anomaly detection (DConAD). Specifically, DConAD generates differential data to provide additional information about time series and utilizes transformer-based architecture to capture spatiotemporal dependencies, which enhances the robustness of unbiased representation learning ability. Furthermore, DConAD implements a novel KL divergence-based contrastive learning paradigm that only uses positive samples to avoid deviation from reconstruction and deploys the stop-gradient strategy to compel convergence. Extensive experiments on five public datasets show the superiority and effectiveness of DConAD compared with nine baselines. The code is available at https://github.com/shaieesss/DConAD.
BibTeX
@misc{zhang2025dconad,
  author = {Wenxin Zhang and Xiaojian Lin and Wenjun Yu and Guangzhen Yao and Jingxing Zhong and Yu Li and Ruili Han and Sheng Xu and Hao Shi and Cuicui Luo},
  title = {{DConAD: A Differencing-based Contrastive Representation Learning Framework for Time Series Anomaly Detection}},
  year = {2025},
  doi = {10.1109/ijcnn64981.2025.11229301},
}
Figure