# SimCDL: A Simple Framework for Contrastive Dictionary Learning
## 5 Experiments
### Anomaly Detection  
Dictionary learning can also be applied to _anomaly detection_ tasks. A straightforward approach for _outlier detection_ is to calculate the representation error as follows:  
\[\mathbf{E}=\mathbf{Y}-\mathbf{D}\mathbf{X} \tag{23}\]  
Anomalous signals are those that usually produce poor representations. The anomaly score of signal \(i\) is simply the norm \(\|\mathbf{e}_{i}\|\) of the \(i\)-th column of \(\mathbf{E}\). A higher error norm indicates a greater likelihood that the signal is an outlier. The core assumption is that similar signals are better captured by the dictionary created by solving the DL problem. In this section, we present some experiments regarding anomaly detection applications. We conducted investigations in the spirit of the Python Outlier Detection (PyOD) toolbox [25]. More precisely, we used the Anomaly Detection Benchmark (ADBench) [26] to run experiments for anomaly detection tasks using dictionary learning. ADBench is currently the most comprehensive anomaly detection benchmark; it contains 30 anomaly detection algorithms and 57 datasets from different domains, including healthcare (e.g., disease diagnosis), audio and language processing (e.g., speech recognition), image processing (e.g., object identification), finance (e.g., financial fraud detection), etc. In addition to the original datasets, this benchmark provides support for generating four types of anomalies: _local_, _global_, _dependency_, and _cluster_. As stressed in [26], no method obtains good results for all types. During our experiments, we concluded that dictionary learning is a good competitor regarding the _dependency_ anomalies. Out of the 57 available datasets, we selected 30 for testing, ensuring a diverse range of data types with varying dimensions and anomaly ratios. To align with the sparse representation framework, all chosen datasets have signals with more than three features. For all our tests, we used undersampled dictionaries that were half the size of the data. This reduction ensures that, during the learning process, the dictionary atoms capture the overall structure and key features of the representation. Additionally, the sparsity constraint \(s\) was set to 2. This configuration facilitates a compact representation that effectively disregards abnormal or outlier samples. All the dictionaries were trained for 10 iterations. In Table 5, we summarize the ROC AUC (Receiver Operating Characteristic Area Under Curve) results obtained on the 30 testing datasets. With AK-SVD [4], we denote the results obtained using a random initialization. On the other hand, AK-SVD* denotes the same method, but with the benefits of a SimCDL initialization. The initialization was obtained using a batch size of 64, with 40 dictionary optimization steps and a sparsity constraint of 2. The problem of anomaly detection was solved in an unsupervised manner. The datasets were split into training test sets with a 70-30 ratio. During the training phase, both normal and abnormal samples were used to update the dictionary. However, due to the relatively small number of anomalies, the dictionary is expected to predominantly capture the representation of the normal samples. The ROC AUC values reported in Table 5 are obtained by averaging 5 independent runs and are computed for the test sets. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Dataset** & **Origin** & **Rotate*** & **Cutout*** & **Gaussian Noise*** & **Gaussian Blur*** & *** \\ \hline YaleB & 94.35 & 94.39 & 94.39 & 94.36 & 94.37 & **94.50** \\ AR & **93.07** & 93.00 & 92.57 & 92.85 & 92.85 & 92.57 \\ CMU PIE & 90.60 & 90.71 & **90.94** & 90.74 & 90.80 & 90.55 \\
15 Scene & 94.17 & **94.22** & 94.17 & 93.83 & 93.99 & 94.04 \\ Caltech101 & 72.18 & 72.22 & 72.27 & **72.31** & 72.22 & 72.30 \\ UCF50 & 60.14 & 60.13 & 60.07 & **60.16** & 60.12 & 60.08 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Ablation study: classification accuracy. The best result for each dataset is in bold.