# SDN Anomalous Traffic Detection Based on Temporal Convolutional Network
## 3 Proposed Method
### Model Training and Optimization  
In the process of model training, the selection of appropriate loss functions and optimization algorithms is crucial. These elements directly affect the training efficiency, convergence speed, and generalization ability of the model. The loss function is used to measure the difference between the model's predicted output and the true label, while the optimization algorithm gradually reduces the loss function by adjusting the model's parameters so that the model continuously approaches the optimal solution on the training data. In order to ensure that the model can converge effectively during the training process and has strong generalization ability, this paper adopts the cross-entropy loss function and Adam optimization algorithm and introduces the dropout technique to reduce the overfitting phenomenon.  
The cross-entropy loss function is commonly used in classification tasks, and it can effectively measure the difference between the model output and the true label. Setting the true label as \(y\in\{0,1\}\) and the predicted value of the model as \(\hat{y}\in[0,\ 1]\), the cross-entropy loss function \(L\) can be expressed as:  
\[L=-\sum_{i=1}^{N}[y_{i}\log(\hat{y}_{i})+(1-y_{i})\log(1-\hat{y}_{i})] \tag{5}\]  
where \(N\) denotes the number of samples, \(y_{i}\) is the true label of the ith sample, and \(\hat{y}_{i}\) is the predicted probability of the model. This loss function pushes the model to output more accurate predictions by penalizing the model for larger errors in incorrect predictions.  
During the training process, the optimization algorithm is responsible for updating the model parameters through a back-propagation algorithm. The Adam (Adaptive Mo ment Estimation) optimization algorithm combines the advantages of the RMSprop and Momentum optimization algorithms, and it is able to adaptively adjust the learning rate to improve the training efficiency. Specifically, the Adam optimization algorithm uses first-order moments (mean) and second-order moments (variance) to calculate the adaptive learning rate for each parameter. [PERSON]'s update formula is as follows:  
\[m_{t}=\beta_{1}m_{t-1}+(1-\beta_{1})\
abla_{\theta}J(\theta) \tag{6}\]  
\[v_{t}=\beta_{2}v_{t-1}+(1-\beta_{2})\Big{(}\
abla_{\theta}J(\theta))^{2} \tag{7}\]  
\[\dot{m}_{t}=\frac{m_{t}}{1-\beta_{1}^{t}},\hat{\sigma}_{t}=\frac{v_{t}}{1- \beta_{2}^{t}} \tag{8}\]  
\[\theta_{t}=\theta_{t-1}-\frac{\alpha\dot{m}_{t}}{\sqrt{\hat{\sigma}_{t}}+\epsilon} \tag{9}\]  
where \(m_{t}\) and \(v_{t}\) denote the estimates of the first-order and second-order moments, respectively, \(\beta_{1}\) and \(\beta_{2}\) are the decay rates, \(\alpha\) is the learning rate, and \(\epsilon\) is a constant that prevents division-by-zero errors. By combining the information of the first-order moments and second-order moments, [PERSON] is able to better control the direction and magnitude of the gradient update, which enables the model parameters to converge quickly and stably during the training process.  
In order to prevent the model from overfitting during the training process, this paper introduces the dropout technique. Dropout is a regularization method that reduces the model's overdependence on some specific neurons by randomly discarding a portion of the neurons in the neural network during the training process, thus improving the model's generalization ability. Specifically, in each training iteration, dropout sets the output of some neurons to zero with probability \(p\), thus breaking the co-adaptation relationship between neurons. Usually, the application of dropout can effectively prevent overfitting and improve the robustness of the model.