# Uncertainty-Aware Time Series Anomaly Detection
## 3 Proposed Approach
### Thresholding Mechanism
In this experiment, we want to test how they react to different levels of noise in the data. #### 4.1.1 Data

We prepare five different synthetic pairs of datasets, using the synthetic data generation tool gutenTAG [35], each consisting of a train and a test set. All of them follow the same basic data pattern of a sine function. Therefore, we introduce noise to the data by adding a controlled deviation to the existent base data [36]. This may correspond to more imprecise measurements often present in real-world data. Five different levels of noise are introduced, one for each pair of training and testing data. The different levels of noise are as follows: 0%, 1%, 10%, 30%, 50%. The two datasets of each pair are generated separately and are not identical to avoid testing on a perfectly learned training dataset (Table 3). We use a standard amplitude of 1 and 100 equally distributed points. A visualization is depicted in Figure 3. The data are available at [[https://github.com/p199671/LSTM-AE-UQ/tree/master/data](https://github.com/p199671/LSTM-AE-UQ/tree/master/data)]([https://github.com/p199671/LSTM-AE-UQ/tree/master/data](https://github.com/p199671/LSTM-AE-UQ/tree/master/data)) (accessed on 1 September 2024). Figure 3: Sine data for training and testing with different levels of noise. The declaration in percent relates to the whole value range of the base function, meaning 1% refers to an absolute value of 0.01 for a given value range of 1. These noise levels can be seen as real-world emulation where noise increasingly obscures true observations. #### 4.1.2 Model Training

We train the model (Table 4) for 250 epochs with a test on validation data every 10 th epoch. This is a performance improvement regarding the computation it takes for MC sampling. Additionally, we implement an early stopping mechanism to avoid overfitting. This terminates the training procedure after the third increased validation loss in a row. In the experiments, we refer to the small model as an architecture of 50-40-50 and to the big model as 100-80-100 which corresponds to a compression rate of 0.2. Further, the model is trained on a separate, clean training set, if not specified differently. We separate the training set into training and validation sets with a ratio of \(80:20\). The learning rate is set to a standard value of 0.001. For Bayesian posterior approximation, we set dropout between layers to 0.3 throughout all test cases and MC sampling size to 100. We use a batch size of 64 samples per batch to enhance performance. Additionally, the Adam optimizer is employed, and we utilize a modified loss function, detailed in Section 3.1. The parameters are based on the work of [7], whose similar model architecture makes these parameters a suitable choice, also enhancing comparability. #### 4.1.3 Results

Figures 4 and 5 show the results of the experiment for aleatoric and epistemic uncertainty accordingly. In this experiment, we tested two different model sizes and two window sizes. Each model is trained on data with a certain level of noise according to the legend, and evaluated on varying noise levels, indicated on the X-axis. The Y-axis shows the value of aleatoric/epistemic uncertainty taken as the median over the whole test results. \begin{table}
\begin{tabular}{c c} \hline
**Attribute** & **Value** \\ \hline epochs & 250 \\ \hline validation & every 10 th epoch \\ \hline early stopping & after 3 rd validation \\ \hline train/val ratio & \(80:20\) \\ \hline learning rate & 0.001 \\ \hline dropout rate & 0.3 \\ \hline batch size & 64 \\ \hline dropout sample size & 100 \\ \hline optimizer & Adam \\ \hline loss & modified mse \\ \hline \end{tabular}
\end{table} 
Table 4: Parameters for model training. \begin{table}
\begin{tabular}{c c} \hline
**Attribute** & **Value** \\ \hline Function & \(\sin(x)\) \\ \hline Amplitude & 1.0 \\ \hline Period & 100 points \\ \hline Length & 1000 points \\ \hline Noise & \(0\%,1\%,10\%,30\%,50\%\) \\ \hline \end{tabular}
\end{table} 
Table 3: Base sine specifications with noise levels.