# CL-TAD: A Contrastive-Learning-Based Method for Time Series Anomaly Detection
## 4 Experiments and Discussions
### Experiment Results and Comparison  
To gain insight into how the proposed method forms the representations of samples, the distribution of representations was visualized for some examples from the ECG and 2D-Gesture datasets. This was done for both pre-training and post-training, as depicted in Figures 13 and 14. To ensure understandable visualization, we employed the PCA technique to project these representations into a two-dimensional space. From the figures to show post-training results, it is clear that the positive samples cluster closely together while the negative samples are dispersed further away. This observation shows that our proposed method can generate meaningful representations. Table 3 presents the experimental outcomes achieved by our proposed method on the benchmark datasets. We employed performance metrics such as precision, recall, and \(F_{1}\) score for the evaluation. For datasets that are split into several sub-datasets, we have provided an in-depth performance breakdown for each sub-dataset in Tables A1-A3 located in Appendix B. For datasets such as ECG, UCR, and SMD, which are divided into multiple sub-datasets, the \(F_{1}\) scores were averaged across all the sub-datasets to give a consolidated score. To further show the effectiveness of our proposed method, we have compared its \(F_{1}\) score performance with that of several state-of-the-art methods, as presented in Table 4, for the identical benchmark datasets. We made comparisons with the following methods: MAD-GAN [32], DAGMM [22], MSCRED [36], CAE-M [28], OmniAnomaly [30], TranAD [43], GDN [29], MTAD-GAT [38], and USAD [39]. The numbers in bold indicate the top-performing results for each benchmark dataset. Each compared method has achieved its best performance by using its curated optimal hyperparameters. We have utilized superscripts to indicate the source from which each performance score was derived: (1) refers to the model's original paper, (2) is sourced from [21], (3) from [42], (4) from [43], and (5) represents the performance scores that we obtained running the datasets through the \begin{table}
\begin{tabular}{c c} \hline \hline
**Hyperparameter** & **Set Value** \\ \hline Window size & 16 \\ Mask value & 0. \\ Batch size & 256 \\ Initial lr & 0.001 \\ lr scheduling & Consine annealing lr \\ Optimizer & Adam \\ tau (\(\tau\)) & 0.05 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Training parameters. Figure 13: Representation distributions before and after training for the 2D-Gesture dataset. **Left**: Pre-training; **Right**: Post-training. models using codes available from the developers' GitHub repositories [62; 63; 64]. Scores that carry a (6) superscript represent performances derived from evaluating the entire dataset. As seen in Table 4, our proposed method outperformed others in five out of the nine benchmark datasets. It exhibited superior performance over both univariate datasets. When examining multivariate datasets, our method took the lead in the 2D-Gesture, SMD, and MSL datasets. For the UCR dataset, which comprises four sub-datasets, detailed results of our method can be found in Table A1 in Appendix B. The ECG dataset consists of six sub-datasets and the performances on these sub-datasets are available in Table A2 in Appendix B. Regarding the SMD dataset, all the performance scores in Table 4 were evaluated on the sub-dataset'machine1-1' of the SMD dataset. For the performance of our method on the entire SMD dataset, refer to Table A3 in Appendix B. For the MSL dataset, the performance was evaluated on its sub-dataset 'C-1'. Finally, for the SWaT dataset, there are two versions  
Figure 14: Representation distributions before and after training for two sub-time series within the ECG benchmark. **Left**: Pre-training; **Right**: Post-training.