# Anomaly Detection and Early Warning Model for Latency in Private 5G Networks
## 3 Proposed Methods
### Abnormal Early Warning  
#### 3.3.1 Network Architecture  
In the previous section, we proposed the ConvAE-Latency model, which can effectively shorten the O&M troubleshooting time, compared with manual experience-based O&M methods. However, it only detects the current network status. To further enhance the intelligence of O&M in private 5G networks, abnormal early warning is expected. The possible abnormality is predicted before the network faults occur, so staff can prepare preventive measures as well as maintenance in advance to avoid or reduce the loss caused by the network faults. LSTM has a memory function in the time dimension, which is often used in prediction schemes based on historical messages. Therefore, based on the ConvAE-Latency model, this study proposes a transfer-learning-based abnormal early warning model (LstmAE-TL), as shown in Figure 4. The model is divided into two parts: the LSTM-based prediction network and ConvAE-Latency model. The specific structure is described as follows. Figure 3: Implementation process of the ConvAE-Latency model. The first part of the proposed model consists of a three-layer LSTM network and dense networks; input data are the same as that for the ConvAE-Latency model. It is noteworthy that the input data need to be obtained by a sliding window algorithm. The output of the first part is the prediction of the wireless data \(\hat{\mathbf{w}}\) for the next period. The reconstructed function is given by Equation (5). Subsequently, \(\hat{\mathbf{w}}\) is fed into the previously trained ConvAE-Latency model to predict whether there is high latency, which is the final output. However, the ConvAE-Latency model is frozen and not trained here in order to fit the real situation better because inaccurate prediction will affect its judgment. It is worth noting that the latency fitting module of ConvAE-Latency is not used. The training algorithm for the LstmAE-TL is shown in Algorithm 3:  
\[E_{w}=\sum_{i=1}^{n}||\mathbf{w}_{i}-\hat{\mathbf{w}}_{i}||^{2}, \tag{5}\]  
where \(\mathbf{w}=(\mathbf{w}_{t_{1}},\mathbf{w}_{t_{2}},\cdots,\mathbf{w}_{t_{5}}),\mathbf{w}\in\mathbb{ R}^{m\times n}\), \(m\) represents the wireless parameter dimension, and \(n\) represents the number of samples. ```
0: Normal dataset \(\mathbf{w}_{normal}\), anomaly dataset \(\mathbf{w}_{anomal}\)
0: Prediction network \(h_{\xi}\)
1: Pre-training ConvAE-Latency model obtained from Algorithm 1;
2:\(\xi\leftarrow\) Initialization parameters;
3:repeat
4:\(\mathbf{E}_{\mathbf{w}}=\sum_{i=1}^{n}||\mathbf{w}_{i}-h_{\xi}(\mathbf{w}_{i})||^{2}\) Calculate predict error by only \(\mathbf{w}_{normal}\);
5:\(\mathbf{E}_{\mathbf{x}}=\sum_{i=1}^{n}||\,h_{\xi}(\mathbf{w}_{i})-g_{\sigma}(f_{\theta}(h _{\xi}(\mathbf{w}_{i})))||^{2}\) Calculate reconstruction error of the predict result of \(\mathbf{w}_{normal}\) by ConvAE-Latency model;
6:\(\xi\leftarrow\) Update parameters according to combination of \(\mathbf{E}_{\mathbf{w}}\) and \(\mathbf{E}_{\mathbf{x}}\);
7:until Convergence of parameters \(\xi\)
8: Freeze part of parameters in \(\xi\);
9:repeat
10:\(\mathbf{E}_{\mathbf{w}}=\sum_{i=1}^{n}||\mathbf{w}_{i}-h_{\xi}(\mathbf{w}_{i})||^{2}\) Calculate predict error by mix \(\mathbf{w}_{anomaly}\) and part of \(\mathbf{w}_{normal}\);
11:\(\xi\leftarrow\) Update parameters according to combination of \(\mathbf{E}_{\mathbf{w}}\);
12:until Convergence of parameters \(\xi\)
```  
**Algorithm 3** The LstmAE-TL model training algorithm  
As shown in Algorithm 4 and Figure 5, the implementation process of the LstmAE-TL model is as follows:  
Figure 4: Network architecture of the LstmAE-TL model.