## 3 Materials and Methods
### Ensemble Detection Network
#### 3.4.2 Stacking Ensemble Detection Network  
The stacking ensemble detection network learns to train the base learner by reconstructing the data \(\bar{X}\). In this paper, CNN, LSTM, and LENET networks are used as the heterogeneous base learner of the network, and the classification judgment of traffic is made according to the reconstructed data \(\bar{X}\):  
\[\delta_{i} =f\left(\bar{X}\right)_{i}\in R^{N} \tag{12}\] \[\Delta =F\left(\bar{X}\right)\in R^{D_{o}\times k\times N} \tag{13}\]  
where \(f\left(\bar{X}\right)_{i}\) is the base learner, \(\delta_{i}\) is the outlier matrix obtained after the base learner \(f\left(\bar{X}\right)_{i}\) detection, and \(\Delta=[\delta_{0},\dots,\delta_{k}]\in R^{D_{o}\times k\times N}\) is composed of outliers obtained by the base learner. The learner can be any supervised classifier. In theory, heterogeneous base learners can make more robust coarse-grained detection. Diversity and heterogeneity among base learners can provide different perspectives for classification.  
In the second layer of the stacking ensemble detection network, we designed a fusion module to train the fusion module by using the long-term dependencies between samples captured by the self-attention mechanism and the prediction results of the base learner as a new dataset. Based on the embedded vector \(c_{i}\) and the outlier matrix \(\delta_{i}\), the stacking ensemble detection network performs a dot product operation on the embedded vector \(c_{i}\) and the outlier matrix \(\delta_{i}\) through a fusion module then obtains the final detection result through a fully connected layer:  
\[o_{i} =softmax\left(\sum_{j=0}^{k}\text{CF}\left(c_{ij},\delta_{ij} \right)\right) \tag{14}\] \[=softmax\left(\sum_{j=0}^{k}c_{ij}\delta_{ij}\right) \tag{15}\]  
where \(CF\left(c_{ij},\delta_{ij}\right)\) is the embedding fusion function, and \(o_{i}\) is the outlier vector obtained by the fusion function. We choose the dot product method to fuse the embedding vectors in our method. In theory, an excellent fusion method can effectively exploit the information in the embedding vector.  
We design a new loss function to fully consider the sharing of each base model to the model as a whole. The loss function of our method is calculated based on the cross-entropy loss function:  
\[L\big{(}\hat{Y},Y,\Delta\big{)}=W_{0}\times CE\big{(}\hat{Y},Y\big{)}+\sum_{t=1} ^{k}W_{t}\times CE(\delta_{t},Y)+log\Bigg{(}1+\prod_{t=1}^{k}CE(\delta_{t},Y) \Bigg{)}\]  
where \(CE\) is the cross-entropy loss function, \(W_{t}\) is the weight value with a sum of 1, \(Y\) is the label set, \(\hat{Y}\) is the outlier prediction made by the method in this paper, and \(\Delta\) is the outlier prediction value set made by the base learner set. \(W_{0}\times CE\big{(}\hat{Y},Y\big{)}\) is the cross entropy between the predicted value made by the method in this paper and the label set \(Y\). \(W_{t}\times CE(\delta_{t},Y)\) is the cross entropy between the predicted value of each base learner and the label set Y, which aims to fully consider the pre-detection results of the base learner during the training process. \(log\bigg{(}1+\prod_{t=1}^{k}CE(\delta_{t},Y)\bigg{)}\) is used as the regular term of the loss function to prevent the model from falling into an overfitting state. \(1+\prod\limits_{t=1}^{k}CE(\delta_{t},Y)\) guarantees that the function value is always greater than 1. \(W_{t}\) is used as a hyperparameter in the model training process to adjust the weight of the different items.