# Adaptive Seasonality Anomaly Detection Algorithm under Intricate KPI Profiles
## 3 Materials and Methods
### eBeats Clustering Algorithm
#### 3.2.1 Lightweight Distance Measurement Algorithm  
The choice of distance measurement algorithm has an important influence on the clustering algorithm [28]. In the previous literature, researchers have presented a variety of distance measurement algorithms, such as Move-Split-Merge [29], Spade [30], \(L_{p}\) norm [31] and so on. [PERSON] [32] evaluated nine distance measurement algorithms and corresponding derivative algorithms. Therefore, they discovered that Euclidean distance is more accurate than other distance measurement algorithms, and that DTW outperforms them. There is a significant variance in the direct use of Euclidean distance for distance measurement due to the offset of the KPI time series data. The offset phenomenon of KPI time series data is shown in Figure 6. In the picture, we use two color lines to represent two separated dates of KPI time series data. Furthermore, the peak values in the two pieces of KPI time series data shown in red rectangles are not perfectly aligned in time, indicating the offset phenomena of KPI time series data. DTW can handle the offset of KPI time series data, but the computation time will be very long because a large number of short sample intervals exist in intricate KPI time series data. Therefore, it is not appropriate to use the DTW algorithm directly under intricate KPI profiles. Figure 5: Sub-sequences segmentation of KPI time series data. To reduce time consumption of the clustering algorithm [33], we propose a lightweight distance measurement algorithm in \(ASAD\) to quantify the distance between KPI time series data sub-sequences. It can reduce the consuming time by extracting the primary information from a piece of KPI time series data and then utilizing the DTW method to estimate the distance. In short, there are three phases in this algorithm. Firstly, divide time series data into a set of data blocks. Secondly, modify each data block by using the discrete cosine transform, and the most important information is gathered in the upper left corner. Finally, extract the most significant data using a quantitative approach and matrix division. Following the above steps, we can extract the essential information and mask the offset of some KPI time series data to compress the sequence length. The specific algorithm flow is as follows. At first, divide the data by one window size (\(n\)) for a given period of time series data. For example \(n=8\), for the observed data of \(Y=\{y_{1},y_{2},y_{3},\ldots,y_{i}\}\), divide \(Y\) into \(8\times 8\) matrices. If the last matrix has less than \(8\times 8\) elements, fill it with 0. After completing the previous step, the data in each window can form a matrix \(M_{i}\),\(i\)=1,2,3..., \(\lceil\frac{len(Y)}{size}\rceil\), \(M_{i}\) can be expressed as  
\[M_{i}= \begin{bmatrix}y_{1+size\times(i-1)}&y_{2+size\times(i-1)}&\cdots&y_{8+ size\times(i-1)}\\ y_{9+size\times(i-1)}&y_{10+size\times(i-1)}&\cdots&y_{16+size\times(i-1)}\\ \vdots&\vdots&\ddots&\vdots\\ y_{57+size\times(i-1)}&y_{58+size\times(i-1)}&\cdots&y_{64+size\times(i-1)} \end{bmatrix}  \tag{8}\]  
Then, the discrete cosine transform is performed on the divided data block \(M_{i}\). \[D=UMU^{T} \tag{9}\]  
where \(U\) is a discrete cosine variable matrix. In our method, the discrete cosine variable matrix can be expressed as  
\[U_{ij}= \begin{cases}\dfrac{1}{2^{2}\sqrt{2}},i=1\\ \dfrac{1}{2}\cos[\dfrac{\pi}{16}(i-1)(2j-1)],i\
eq 1\end{cases}  \tag{10}\]  
Taking one of the matrices as an example, the data aggregation effect of \(M_{i}\) is shown in Figure 7. The color closest to white in the heat map represents a bigger absolute value of the data, whereas the color closest to black suggests a smaller absolute value of the data. The thermal data distribution of the original matrix is shown in Figure 7a. It can be seen that the original matrix's data distribution is not concentrated, and the four corners of the matrix have more data. The thermal distribution of the data after the discrete cosine transform  
Figure 6: Cycle offset diagram of KPI time series data.