# Anomaly Detection and Early Warning Model for Latency in Private 5G Networks
## 3 Proposed Methods
### Anomaly Detection  
Traditional O&M methods is based on periodic inspection, assign work. Problems exist such as low efficiency and lack of timeliness of resource placement; thus, non-preventive O&M fails to meet the needs of private 5G network. The use of artificial intelligence and big data and other new technologies to achieve active, rapid, and accurate detection is a new trend in the development of O&M. As the autoencoder is trained as a neural network with unsupervised learning, it can reconstruct the original data by hidden features, and the reconstructed data are made closer to the original data by iterative training. If input data are anomaly, the distribution of reconstruction error is different. Based on this, we propose an autoencoder-based anomaly detection model (ConvAE-Latency) for anomaly detection of latency-sensitive scenarios in private 5G networks. The wireless data of base station are used for training, while probed latency is used for labeling to distinguish normal and abnormal samples. Significantly, only normal samples are used to train, and the results show the ConvAE-Latency model can reconstruct normal data well, while the abnormal samples are detected. The network architecture of the ConvAE-Latency model is shown in Figure 2. It consists of three parts: an encoder, decoder and latency classification network. For the encoder, two convolutional layers are used for dimensionality reduction because of the large dimensionality of the wireless parameters on the base station side, and the training algorithm for the ConvAE-Latency model is shown in Algorithm 1. The encoder maps an input vector \(\mathbf{x}\) to a hidden representation \(\mathbf{z}\) by a an affine mapping following a nonlinearity, as shown in Equation (1). Subsequently, the decoding process shown in Equation (2) also maps the potential spatial representation of the hidden layer back to the original input space as the reconstructed output through the nonlinear transformation. The reconstruction goal is given by Equation (3), the difference between the original input vector \(\mathbf{x}\) and the reconstruction output vector \(\mathbf{\hat{x}}\). Notably, the reconstruction-error distribution of abnormal samples should be as far away from the normal samples as possible:  
\[\mathbf{z} =k_{\theta}^{E}(\mathbf{W}_{E}\mathbf{x}+\mathbf{b}_{E}), \tag{1}\] \[\mathbf{\hat{x}} =k_{\sigma}^{E}(\mathbf{W}_{D}\mathbf{z}+\mathbf{b}_{D}),\] (2) \[E_{x} =\sum_{i=1}^{n}||\mathbf{x}_{i}-\mathbf{\hat{x}}_{i}||^{2}, \tag{3}\]  
where \(\mathbf{x}=[\mathbf{x}_{1},\mathbf{x}_{2},\cdots,\mathbf{x}_{n}]\), \(\mathbf{x}\in\mathbb{R}^{m}\), \(m\) represents the wireless parameter dimension, and \(n\) represents the number of samples. \(\mathbf{W}\) and \(\mathbf{b}\) are the weight matrix and bias vector of the neural network, respectively, and \(k\) denotes the nonlinear activation function. Figure 1: The framework of Intelligent Q&M. Considering latency as target indicators in this scenario, the correlation with the hidden features \(z\) needs to be enhanced. In addition to reconstructing input, dense networks are used to construct the latency classification network, which ensures that \(z\) is strongly correlated with the latency, using the binary cross-entropy loss function with the function set, as shown in Equation (4):  
\[L=\frac{1}{N}\sum_{i}L_{i}=\frac{1}{N}\sum_{i}-[y_{i}\log p_{i}+(1-y_{i})\log(1 -p_{i})], \tag{4}\]  
where \(y_{i}\) denotes the label of sample \(x_{i}\), that is, the positive class is 1, the negative class is 0, and 30 ms is used as the classification threshold. \(p_{i}\) denotes the probability that sample \(i\) is judged to positive class.