# Adaptive Seasonality Anomaly Detection Algorithm under Intricate KPI Profiles
## 3 Materials and Methods
### Scaling Auto-Period Seasonal Length Detection Algorithm
#### 3.1.2 Seasonal Length Detection  
_ASAD_ detects the seasonal length by using Auto-Period method, with the scaled seasonal components serving as the input to the seasonal length detection algorithm. The _ASAD_ algorithm treats the scaled seasonal component as new time series data and uses the Auto-Period technique to calculate the scaled seasonal component's period, or seasonal length. Then the flow of Auto-Period algorithm is described in the following statements. Firstly, this method could search a period diagram for one candidate period. Therefore, the candidate period can be recorded without verification if the second derivative of auto-correlation function's candidate period point is smaller than zero. Furthermore, the Auto-Period algorithm ranks all recorded candidate periods by power percentage. Finally, one candidate period with the highest power is regarded as the seasonal component's period.  
Specifically, through sampling and transformation of the seasonal component data \(S^{\prime}\), the Auto-Period algorithm obtains the set of all powers \(PO_{all}\) through the periodogram and main power set \(PO_{main}\). The calculation method of \(PO_{main}\) is shown in Equation (2).  
\[PO_{main}=\{po_{i}|po_{i}\in PO_{all}\wedge po_{i}>\xi_{po}\} \tag{2}\]  
where \(PO_{all}\) is the set of all powers obtained by the periodogram, \(po_{i}\) is \(i\)th element in the set of all powers and \(\xi_{po}\) is the power threshold.  
The frequency corresponding to the main power set \(PO_{main}\) can generate the candidate period set \(PE_{candidate}\). The auto-correlation function generated by the seasonal component data \(S^{\prime}\) is denoted as \(ACF(x)\). The verification of candidate periods is limited by the following Equation (3).  
\[\forall x\in(a,b),\frac{\partial^{2}ACF(x)}{\partial x^{2}}<0 \tag{3}\]  
where \(a\) is the left limit of the region, \(b\) is the right limit of the region and \(ACF(x)\) is the auto-correlation function generated by the seasonal component data \(S^{\prime}\).  
Figure 3: Seasonal components scaling.  
Among them, the calculation methods of a and b are as follows.  
\[a=\frac{1}{2}(\mathit{period}_{i}+\frac{N\times\mathit{period}_{i}}{N+\mathit{ period}_{i}})-1 \tag{4}\]  
\[b=\frac{1}{2}(\mathit{period}_{i}+\frac{N\times\mathit{period}_{i}}{N-\mathit{ period}_{i}})+1 \tag{5}\]  
where \(\mathit{period}_{i}\) is the \(i\)th element in the candidate period set generated by the main power set, that is \(\mathit{period}_{i}\in PE_{candidate}\), and \(N\) is the size of the seasonal component data \(S^{\prime}\).  
Generally, as in Equation (3), let \(L_{a}^{b}\) be the auto-correlation function \(ACF(x),x\in[a,b]\). Within the range of linear regression, the approximation error of linear regression is recorded as \(\xi(L_{a}^{b})\). At this time, as long as the linear regression satisfies upper convexity, the period verification of the candidate period is passed. Additionally, the verified candidate period is corrected to obtain the final period, that is  
\[\mathit{period}=\mathit{argmax}(\xi(L_{a}^{x})+\xi(L_{x+1}^{b})) \tag{6}\]  
where \(x\) is the candidate period.  
The period fitted by the Auto-Period algorithm is shown in Figure 4. The horizontal axis is the index of the seasonal component in KPI time series data after multi-point sampling, and the vertical axis is the value of the seasonal component. The blue line is the seasonal component of the KPI time series data, and the orange line is the waveform generated by the Auto-Period algorithm according to the estimated period. As can be seen from the red markings, peaks and troughs of the actual seasonal component and Auto-Period algorithm are approximately aligned.