# CL-TAD: A Contrastive-Learning-Based Method for Time Series Anomaly Detection
## 1 Introduction  
Anomaly detection in time series data has been a significant research topic for a number of applications such as intrusion detection in cybersecurity [1], fraud detection in finance [2], and damage detection in manufacturing [3]. Anomalies in time series data can be classified into point-wise and segment-wise anomalies [4]. Point-wise anomalies refer to unexpected events that occur at individual time points, typically having extreme values compared to the rest of the time points, or relatively deviated values from their neighboring points. In contrast, segment-wise anomalies typically are anomalous subsequences. The time series anomaly detection task is to identify where a given time series (a sequence of real values) \(X=(x_{0},x_{1},x_{2},\ \ldots,x_{i},\ \ldots,x_{T-1})\), where \(T\) is the length of \(X\), contains any anomalous events. This is commonly carried out by producing an output label sequence \(Y=(y_{0},y_{1},y_{2},\ \ldots,y_{i},\ \ldots y_{T-1})\), where \(y_{i}\in\{0,1\}\) indicates whether its corresponding value \(x_{i}\) is anomalous or not. Various methods have been developed for the task, which can be categorized into five approaches: statistical [5; 6; 7; 8; 9], signal analysis (SA) [10; 11; 12], system-modeling-based [13], machine learning (ML) [14; 15; 16; 17; 18; 19], and deep learning (DL) [20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43]. The statistical approach involves the creation of a statistical model by calculating distributions and measures such as mean, variance, median, quantile, and others. The SA-based approach utilizestime-frequency domain analysis techniques like the Fourier transform, to identify anomalies. The system-modeling-based approach constructs a mathematical model such as a Bayesian dynamic linear model [13] that simulates the latent process to produce the time series of interest. The ML-based approach constructs a trained model for anomaly detection using unlabeled and/or labeled data. The DL-based approach, which has recently gained significant attention, makes use of DL models for anomaly detection, and has found widespread adoption, achieving numerous successes across diverse application domains. Despite the successes of DL models in various applications, the performance of DL-based anomaly methods in the time series domain has not yet been as convincing as expected. To date, DL-based anomaly methods still suffer from the data scarcity problem caused by rare anomalous events and rare labeled data. Instead of using supervised learning techniques based on labeled data, the DL-based anomaly methods usually employ one of three unsupervised or self-supervised techniques: forecasting-based, reconstruction-based, or one-class classifier techniques. Forecasting-based techniques involve forecasting the value for the next time point from the preceding data. Any significant deviation between the predicted and actual value suggests an anomaly. Reconstruction-based techniques build a model to reconstruct the output similar to its input; discrepancies between the model's output and the actual data can indicate anomalies. One-class classifier techniques construct a classifier model for only normal data and leverage this model to determine if a given value of interest belongs to the normal class or not, thus enabling anomaly detection. Contrastive learning on unlabeled data has emerged as an effective technique for learning representations useful to downstream tasks. The learning technique has shown potential in anomaly detection task for time series data [44; 45; 46], especially when available training data does not include anomaly events. The performance of contrastive learning is strongly affected by the approach used to generate positive and negative samples from available unlabeled data. In time series data anomaly detection, it is also challenging to find out an appropriate sample generation method.