# CGFL: A Robust Federated Learning Approach for Intrusion Detection Systems Based on Data Generation
## 3 Methods
### Data Generation Module
Let the data distribution generated by a generator be denoted as \(D_{G}\). The training objective for this generator is to minimize the Kullback-Leibler divergence:  
\[ \begin{split}\mathcal{L}_{KL(D_{G}\|P)}&=-\mathcal{ H}(D_{G})\\ &+E_{x\sim D_{G},\mathcal{H}(x)\geq\omega}[\log p_{M}(x)]\\ &-E_{x\sim D_{G},\mathcal{H}(x)<\omega,p_{N}(x)<\varphi_{1}}[\log p _{N}(x)]\\ &+E_{x\sim D_{G},\mathcal{H}(x)<\omega,p_{N}(x)\geq\theta_{2}}[ \log p_{N}(x)]\\ &+\lambda\left(\left\|E_{x\sim P}[f_{D}(G(x))]-E_{x\sim X_{G}}[f_{ D}(x)]\right\|^{2}\right)\end{split}  \tag{4}\]  
Here, \(\mathcal{H}\) is the entropy function, which can be approximated using the divergence term. Consequently, for a generator, the initial training samples \(x\), which are situated within  
Figure 5: Overview of the data generation module. the relevant target regions, and the freshly produced data \(x^{\prime}\) are chosen. The reconstruction loss and pairwise feature matching loss between these two data types are employed to guarantee the high quality and accuracy of the generated samples. This purpose may be articulated as follows:  
\[\mathcal{L}_{f}=\frac{1}{2}\Big{(}\parallel x-x^{\prime}\parallel_{2}^{2}+ \parallel f_{D}(x)-f_{D}(x^{\prime})\parallel_{2}^{2}+\parallel f_{\text{C}}( x)-f_{\text{C}}(x^{\prime})\parallel_{2}^{2}\Big{)} \tag{5}\]  
The variables \(f_{D}(x)\) and \(f_{\text{C}}(x)\) denote the intermediate layer features obtained from the discriminator network \(D\) and the classifier network \(C\), respectively. The comprehensive loss function of a generator is delineated as follows:  
\[\mathcal{L}_{\mathcal{G}}=\mathcal{L}_{KL(D_{\text{C}}\parallel P)}+\mathcal{ L}_{f} \tag{6}\]  
The article designates \(G_{B_{N}}\), \(G_{B_{O}}\), and \(G_{B_{M}}\) to represent the novel data generated by the three generator networks targeting \(B_{N}\), \(B_{O}\), and \(B_{M}\), respectively. This synthetic data, along with the training dataset \(D_{\text{train}}\) (comprising normal data \(D_{\text{normal}}\) and malicious data \(D_{\text{malicious}}\)), is provided as input to the discriminator. Similar to a conventional GAN, the generators produce new data that aligns with the target distribution while maintaining significant variability. The discriminator's objective is to classify all input data--both original and synthetic--into normal or malicious categories. This encourages the generators to create data that improves the classification accuracy of machine learning models. The loss function for the discriminator is defined as follows:  
\[\mathcal{L}_{D} =E_{x\sim D_{\text{normal}}}[log(\mathcal{D}(x))]+E_{x\sim D_{ \text{malicious}}}[log(1-\mathcal{D}(x))]\] \[+E_{x\sim G_{\text{MB}}}[log(1-\mathcal{D}(x))]+E_{x\sim G_{\text{ MO}}}[log(1-\mathcal{D}(x))] \tag{7}\] \[+E_{x\sim G_{\text{NB}}}[log(\mathcal{D}(x))].\]  
In the formula, \(\mathcal{D}(x)\) represents the anticipated probability for sample x, and \(\mathcal{D}(x)\in[0,1]\). If x is more likely to be malicious data, then \(\mathcal{D}(x)\) exhibits greater bias towards 1. Our GAN model is trained adversarially on the label-corrected raw data. Once the model converges, the synthetic data generated by the generator network is used as new training data. To address the issue of model collapse and improve the diversity of the generated data, the data augmentation module trains multiple independent GAN models. The loss function of the generators is further optimized using average feature matching and pairwise feature matching techniques. Finally, the synthetic data produced by all the models is combined into a unified set of new training data. Accurate detection can then be performed based on this enhanced training dataset and fully developed machine learning models.