Federal domain generalization abnormal traffic detection method based on dynamic feature alignment
Through the federated domain generalization method of dynamic feature alignment, combined with the automatic encoder and classifier, the feature representation consistency is optimized, which solves the problem of poor generalization of the model in federated learning, and realizes efficient detection on known and unknown domains.
Patent Information
- Application Number
- CN202510532807.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-08-08
AI Technical Summary
Traditional intrusion detection systems lack generalization capabilities in cross-domain environments and unknown threats. Due to data visibility constraints in federated learning, traditional domain generalization technology is difficult to directly scale, resulting in poor generalization of the model on unknown domains.
The federated domain generalized anomaly traffic detection method based on dynamic feature alignment is adopted, and the feature alignment loss term weight is dynamically adjusted through the server, combined with the automatic encoder and classifier, the feature representation consistency of the global model on different domains is optimized, and the feature similarity is measured using the Gaussian kernel function, and the feature alignment loss weight is iteratively adjusted.
It realizes good generalization of the global model in known domains and unknown domains, improves the detection performance of the model in unknown domains, and maintains the detection effect on the known domains.
Smart Images

Figure CN120455054A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of intrusion detection and machine learning, and in particular relates to a federal domain generalized abnormal traffic detection method based on dynamic feature alignment. Background Art
[0002] With the rapid development of the internet, network security has become a growing concern. As cyberattack methods continue to evolve, traditional intrusion detection systems (IDS) often suffer from insufficient generalization and domain drift when facing cross-domain environments and unknown threats. Domain drift refers to the difference in distribution between the source domain during training and the target domain during testing in machine learning. This leads to poor model robustness and generalization to the target domain. Federated intrusion detection, on the other hand, involves cross-island scenarios. Cross-island federated intrusion detection involves a relatively limited number of participants. Within the federated learning training framework, the heterogeneity of the real-world network environments between participating clients leads to certain differences in local data distribution. To ensure that the trained global model generalizes across network environments when deployed, domain drift between the limited source domain and the unknown target domain must be addressed. This is closely related to the federated domain generalization problem. Traditional domain generalization techniques often rely on directly accessing data from multiple source domains and improving model generalization through methods such as domain alignment and data augmentation. However, due to the constraints of federated learning on data visibility between different clients, traditional domain generalization techniques are difficult to directly extend to the federated learning domain. Current research on federated domain generalization primarily relies on federated domain alignment or data augmentation. This approach mitigates the impact of domain drift and improves the model's generalization to unknown domains by aligning domains and adjusting the data representation on each client. Federated domain alignment often relies on adding loss terms related to features in different domains during the local training phase. The local training phase aims to fit the data distribution on the local client while minimizing the differences in data representation with other domains. However, the impact of these two objectives on model performance varies at different stages of training. Summary of the Invention
[0003] The purpose of this invention is to propose a generalized abnormal traffic detection method for federated domains based on dynamic feature alignment, so as to ensure that the global model can effectively fit the data distribution on each domain while showing high generalization on unknown domains.
[0004] To achieve the above objectives, the technical solution of the present invention is: a generalized abnormal traffic detection method for federated domains based on dynamic feature alignment, comprising the following steps:
[0005] Step S1: The server initializes the global model and feature alignment loss weight α and sends it to N clients, each of which has a local dataset.
[0006] Step S2: The client performs local training based on the received global model parameters and feature alignment loss weight α.
[0007] Step S3: After local training is completed, the client uploads the updated local model parameters to the server. The server collects the model parameters of all clients and sends them to all clients. The client uses the model parameters of other clients to predict local data, obtains the prediction difference, and sends it to the server.
[0008] Step S4: The server combines the model prediction differences to obtain the difference divergence HΔH, which measures the performance difference of the model in different domains. The server summarizes the difference divergence between client I and all other clients HC I , where I∈[1,N];
[0009] Step S5: The server calculates the HC of each client in the current communication round. I Update the feature alignment loss weights of the local training phase in the next round of communication Where r represents the current communication round;
[0010] Step S6: The server generates new global model parameters by weighted average aggregation based on the model parameters of all clients collected in step S3, and sends the updated global model parameters to each client;
[0011] Step S7: A converged global model is obtained by repeating steps S2 to S6 for multiple communication cycles.
[0012] Preferably, in the training phase, each client constitutes a source domain, and there are N source domains D = {D1, D 2, …,D N}, each source domain D n There are paired labels and samples (x i ,y i ), the goal is to obtain the prediction model f:X→Y through training, so that the model can be used in the target domain D T In order to minimize the generalization error on , each client uses the combined loss function L to optimize the local model during local training:
[0013] L=L BCE +L REC +α·L SIM
[0014] Among them L BCE is the cross entropy loss, L REC is the reconstruction loss, L SIM is the feature alignment loss term.
[0015] Preferably, the local model includes an autoencoder and a classifier, wherein the autoencoder includes a feature extraction layer and a decoding layer, and the classifier includes a feature extraction layer and a classification layer. The autoencoder and the classifier share the feature extraction layer to learn the data representation of the current domain; the feature extraction layer is used to extract representative feature representations from the input data, the decoding layer reconstructs data based on the output of the feature extraction layer, and the classification layer determines whether the data is an attack based on the output of the feature extraction layer; the step S2 is specifically as follows:
[0016] Step S2.1: The original data is passed through the autoencoder AE during the forward propagation process of local training to obtain the reconstructed data x' = AE(x), and the prediction result is obtained by the classifier. The output reconstructed data x' and the original data are compared to calculate the mean square error MSE as the reconstruction loss L. REC :
[0017] L REC =γ·MSE(AE(x),x)
[0018] Where γ is a hyperparameter that controls the weight of the reconstruction loss;
[0019] Calculate the cross entropy loss L between the predicted result and the label of the original data BCE :
[0020] L BCE =-[y·log(f l (x))+(1-y)·log(1-f l (x))]
[0021] Among them, y represents the label corresponding to the original data x, f l (x) represents the prediction result;
[0022] Step S2.2, the feature alignment loss term is calculated by the client through the local feature extraction layer enco l With the global feature extraction layer enco g The differences between feature representations of the same sample encourage the model to learn domain-invariant features to improve the generalization and robustness of the global model. The specific implementation method is as follows:
[0023] During the forward propagation process, the Gaussian kernel function is used to measure the data representation of the local feature extraction layer and the global feature extraction layer to obtain the similarity as the feature alignment loss term:
[0024]
[0025] Where σ = (1-e / Epoch)·C, where C is a constant. The closer the number of iterations e of local training is to the total number of iterations Epoch, the smaller σ is.
[0026] Preferably, step S3 is specifically as follows:
[0027] S3.1 After the client uploads the local model parameters, the server collects the classifiers of all clients, including the feature extraction layer and classification layer, and sends the classifiers of all clients back to each client;
[0028] S3.2 Each client uses the classifier of other clients to predict the local data, then calculates the difference with the prediction result of the local model, and then uploads it to the server.
[0029] Preferably, step S4 is specifically as follows: the server combines the prediction difference results of the client model in different domains to obtain HΔH:
[0030]
[0031] Where Γ is the indicator function; f I (x i ) represents the prediction model f of client I I For client I local sample x i The prediction result, f J (x i ) represents the prediction model f of client J J For client I local sample x i The prediction result, f I (x j ) represents the prediction model f of client I I For client J local sample x j The prediction result, f J (x j ) represents the prediction model f of client J J For client J local sample x j The prediction result; n' represents the client I constitutes the source domain D I The number of samples in; m represents the client J that constitutes the source domain D J The number of samples in the medium;
[0032] And sum HΔH of client I and all other K clients to get HC I :
[0033]
[0034] Where I∈[1,N].
[0035] Preferably, the feature alignment loss weight in step S5 is calculated as follows:
[0036]
[0037] in represents the weight of the feature alignment loss term in the local training phase of the next round of communication of client I, β is a hyperparameter, The weight of the feature alignment loss term gradually increases with the communication round, r represents the current communication round, Round represents the total communication round, HC J represents the sum of the divergences between client J and all other K clients.
[0038] Compared with the prior art, the present invention has the following beneficial effects:
[0039] The present invention dynamically adjusts the weight of the feature alignment loss term through iteration during the federated learning process, and ultimately obtains a global model with good generalization performance in both known and unknown domains. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A schematic diagram of a method flow chart of an embodiment of the present invention;
[0041] Figure 2 Schematic diagram of effectiveness analysis of joint training of auto-encoders according to an embodiment of the present invention;
[0042] Figure 3 2 is a schematic diagram of effectiveness analysis of dynamic loss weights according to an embodiment of the present invention;
[0043] Figure 4 Schematic diagram of comparative analysis between the embodiment of the present invention and an advanced solution;
[0044] Figure 5 3 is a schematic diagram of comparative analysis between the autoencoder and non-autoencoder solutions according to an embodiment of the present invention. DETAILED DESCRIPTION
[0045] The following is combined with Figure 1-5 , the technical solution of the present invention is described in detail.
[0046] The present invention proposes a generalized abnormal traffic detection method for federated domains based on dynamic feature alignment, comprising the following steps:
[0047] Step S1: The server initializes the global model and feature alignment loss weight α and sends it to N clients. Each client has a local dataset, where α is initialized to
[0048] Step S2: The client performs local training based on the received global model parameters and feature alignment loss weight α.
[0049] Step S3: After local training is completed, the client uploads the updated local model parameters to the server. The server collects the model parameters of all clients and sends them to all clients. The client uses the model parameters of other clients to predict local data, obtains the prediction difference, and sends it to the server.
[0050] Step S4: The server combines the model prediction differences to obtain the difference divergence HΔH, which measures the performance difference of the model in different domains. The server summarizes the difference divergence between client I and all other clients HC I , where I∈[1,N];
[0051] Step S5: The server calculates the HC of each client in the current communication round. I Update the feature alignment loss weights of the local training phase in the next round of communication Where r represents the current communication round;
[0052] Step S6: The server generates new global model parameters by weighted average aggregation based on the model parameters of all clients collected in step S3, and sends the updated global model parameters to each client;
[0053] Step S7: A converged global model is obtained by repeating steps S2 to S6 for multiple communication cycles.
[0054] In this embodiment, during the training phase, each client constitutes a source domain, and there are N source domains D = {D1, D 2, …,D N}, each source domain D n There are paired labels and samples (x i' ,y i' ), the goal is to obtain the prediction model f:X→Y through training, so that the model can be used in the target domain D T In order to minimize the generalization error on , each client uses the combined loss function L to optimize the local model during local training:
[0055] L=L BCE +L REC +α·L SIM
[0056] Among them L BCE is the cross entropy loss, L REC is the reconstruction loss, L SIM is the feature alignment loss term.
[0057] In this embodiment, the local model includes an autoencoder and a classifier. The autoencoder includes a feature extraction layer and a decoding layer, and the classifier includes a feature extraction layer and a classification layer. The autoencoder and the classifier share the feature extraction layer to learn the data representation of the current domain. The feature extraction layer is used to extract representative feature representations from the input data and learn the data representation of the current domain. The decoding layer reconstructs data based on the output of the feature extraction layer. The classification layer determines whether the data is an attack based on the output of the feature extraction layer. Step S2 is specifically as follows:
[0058] Step S2.1: The original data is passed through the autoencoder AE during the forward propagation process of local training to obtain the reconstructed data x' = AE(x), and the prediction result is obtained by the classifier. The output reconstructed data x' and the original data are compared to calculate the mean square error MSE as the reconstruction loss L. REC :
[0059] L REC =γ·MSE(AE(x),x)
[0060] Where γ is a hyperparameter that controls the reconstruction loss weight and is set to 0.5;
[0061] Calculate the cross entropy loss L between the predicted result and the label of the original data BCE :
[0062] L BCE =-[y·log(f l (x))+(1-y)·log(1-f l (x))]
[0063] Among them, y represents the label corresponding to the original data x, f l (x) represents the prediction result;
[0064] Step S2.2, the feature alignment loss term is calculated by the client through the local feature extraction layer enco l With the global feature extraction layer enco g The differences between feature representations of the same sample encourage the model to learn domain-invariant features to improve the generalization and robustness of the global model. The specific implementation method is as follows:
[0065] During the forward propagation process, the Gaussian kernel function is used to measure the data representation of the local feature extraction layer and the global feature extraction layer to obtain the similarity as the feature alignment loss term:
[0066]
[0067] Where σ = (1-e / Epoch)·C, C is a constant of 10, Epoch is set to 20, and the closer the number of iterations e of local training is to the total number of iterations Epoch, the smaller σ is.
[0068] In this embodiment, step S3 is specifically as follows:
[0069] S3.1 After the client uploads the local model parameters, the server collects the classifiers of all clients, including the feature extraction layer and classification layer, and sends the classifiers of all clients back to each client;
[0070] S3.2 Each client uses the classifier of other clients to predict the local data, then calculates the difference with the prediction result of the local model, and then uploads it to the server.
[0071] In this embodiment, step S4 is specifically as follows: the server combines the prediction difference results of the client model in different domains to obtain HΔH:
[0072]
[0073] Where Γ is the indicator function; f I (x i ) represents the prediction model f of client I I For client I local sample x i The prediction result, f J (x i ) represents the prediction model f of client J J For client I local sample x i The prediction result, f I (x j ) represents the prediction model f of client I I For client J local sample x j The prediction result, f J (x j ) represents the prediction model f of client J J For client J local sample x j The prediction result; n' represents the client I constitutes the source domain D I The number of samples in; m represents the client J that constitutes the source domain D J The number of samples in the medium;
[0074] And sum HΔH of client I and all other K clients to get HC I :
[0075]
[0076] Where I∈[1,N].
[0077] HΔH divergence is used to determine the similarity between domains by evaluating the prediction differences between classifiers trained on the source and target domains respectively. The performance of the client model on other domains is evaluated by calculating the sum of the HΔH divergences between the client and other clients. This is used to adjust the weight α of the feature alignment loss term in the client's local training phase in different communication rounds. When the HC is larger, α is also larger, thereby improving the impact of feature alignment. When the HC is smaller, the model focuses more on the classification effect.
[0078] In this embodiment, step S5 evaluates the performance of the client model on other domains by calculating the sum of the HΔH divergences HC between the client and other clients, thereby adjusting the weight α of the feature alignment loss term in different communication rounds. When HC is larger, α is also larger, thereby improving the impact of feature alignment. When HC is smaller, the model focuses more on the classification effect.
[0079] The weight of the feature alignment loss term in step S5 is calculated as follows:
[0080]
[0081] in represents the weight of the feature alignment loss term in the local training phase of the next round of communication of client I. β is a hyperparameter and is set to 0.1. The weight of the feature alignment loss term gradually increases with the communication round, r represents the current communication round, Round represents the total communication round, set to 20, HC J represents the sum of the divergences between client J and all other K clients.
[0082] This example preprocesses the Netflow-formatted raw traffic from the publicly available CIC-IDS2017, UNSW-NB15, ToN-IoT, and BoT-IoT datasets, uniformly following the following settings: the four sub-datasets are treated as four different domains, each corresponding to a client. One domain is set as an unknown domain, and the other three domains are trained as known domains. Other specific settings include 20 communication rounds for federated learning and 10 rounds for local training, with a learning rate of 1e-4. The classification model is a fully connected neural network with three layers, each with input and output dimensions of (42, 36,), (36, 18), and (18, 2). The first two layers serve as feature extraction layers, while the autoencoder consists of the first two layers of the classification model and two decoding layers. The input and output dimensions of each decoding layer are (18, 36) and (36, 42).
[0083] This example simulates the above method steps using Netflow-formatted raw traffic from four datasets: CIC-IDS2017, UNSW-NB15, ToN-IoT, and BoT-IoT. This data is then recaptured to generate unified 42-dimensional data. Because the four datasets originate from different sources and the traffic generation environments vary significantly, they are well suited for simulating federated domain generalization scenarios. Figure 2 From the effectiveness analysis of the joint training of autoencoders, it can be seen that the scheme without using autoencoders performs better than the scheme with autoencoders on known domains in some experimental groups. However, the performance on unknown domains is significantly lower than that of the scheme with autoencoders. It can be seen that the addition of autoencoders makes the extracted features more universal, thereby improving the performance on unknown domains and making the performance on known domains more balanced. Figure 3 This is an effectiveness analysis of dynamic loss weights, comparing the performance of the proposed scheme using dynamic feature loss weights with that without using them. The loss weights of the scheme without dynamic loss weights are calculated as follows: After adjustment, it can be seen that dynamically adjusting the loss weight of the feature alignment item according to the generalization differences between each client effectively improves the performance of the model in known and unknown domains. Figure 4 This figure compares the domain generalization performance of the present invention with that of baseline and advanced solutions. As can be seen from the figure, the various solutions exhibit varying performance advantages and disadvantages across different experimental groups. In Experimental Group 1, FedAVG achieved the best performance on the known domain, while FedDG achieved the best performance on the unknown domain. In Experimental Group 2, the present invention outperformed other solutions by more than 10 percentage points in most metrics across both the known and unknown domains, but FedDG led the present invention by 2.94 percentage points in precision on the known domain. In Experimental Group 3, FedProx and FedDG achieved the best performance on the known and unknown domains, respectively, while the present invention outperformed FedProx in recall on the known domain by 1.9 percentage points. In Experimental Group 4, FedProx and the present invention achieved the best performance on the known and unknown domains, respectively. The average results show that the present invention's overall performance outperforms other solutions on both the known and unknown domains. Specifically, on known domains, the precision of the proposed method is 3.45 percentage points lower than FedProx, while its recall is 5.34 to 16.16 percentage points higher than other methods, and its F1 score is 5.07 to 15.41 percentage points higher than other methods. On unknown domains, the precision of the proposed method is 12.11 to 20.83 percentage points higher than other methods, while its recall is 0.3 percentage points lower than FedDG, and its F1 score is 5.92 to 44.24 percentage points higher than other methods. Figure 5This is a comparative analysis of the autoencoder and non-autoencoder solutions of the present invention. As can be seen from the figure, FedDG and FedAVG in Experimental Groups 1 and 3 outperform other solutions in various metrics. In Experimental Groups 2 and 4, the present invention outperforms other solutions in most metrics. On average, the accuracy of the present invention on known domains is 4.16 percentage points lower than that of FedAVG, while all other metrics are superior to those of other solutions. In summary, the proposed solution outperforms state-of-the-art solutions in generalization across both known and unknown domains, effectively extending anomaly detection to the generalized domain of federated domains while maintaining balanced performance across both known and unknown domains.
[0084] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any other manner. Any person skilled in the art may utilize the above-disclosed technical content to modify or modify the present invention into equivalent embodiments. However, any simple modifications, equivalent variations, and modifications to the above embodiments that do not depart from the technical content of the present invention and are based on the technical essence of the present invention remain within the scope of protection of the present invention.
Claims
1. A generalized abnormal traffic detection method for federated domains based on dynamic feature alignment, characterized by: The following steps are involved: Step S1: The server initializes the global model and feature alignment loss weight α and sends it to N clients, each of which has a local dataset. Step S2: The client performs local training based on the received global model parameters and feature alignment loss weight α. Step S3: After local training is completed, the client uploads the updated local model parameters to the server. The server collects the model parameters of all clients and sends them to all clients. The client uses the model parameters of other clients to predict local data, obtains the prediction difference, and sends it to the server. Step S4: The server combines the model prediction differences to obtain the difference divergence HΔH, which measures the performance difference of the model in different domains. The server summarizes the difference divergence between client I and all other clients HC I , where I∈[1,N]; Step S5: The server calculates the HC of each client in the current communication round. I Update the feature alignment loss weights of the local training phase in the next round of communication Where r represents the current communication round; Step S6: The server generates new global model parameters by weighted average aggregation based on the model parameters of all clients collected in step S3, and sends the updated global model parameters to each client; Step S7: A converged global model is obtained by repeating steps S2 to S6 for multiple communication cycles.
2. The method for detecting generalized abnormal traffic in a federated domain based on dynamic feature alignment according to claim 1, characterized in that: In the training phase, each client constitutes a source domain, and there are N source domains D = {D1, D2, ..., D N }, each source domain D n There are pairs of labels and samples (x i ,y i ), the goal is to obtain the prediction model f:X→Y through training, so that the model can be used in the target domain D T Minimize the generalization error on ; Each client uses the combined loss function L to optimize the local model during local training: L=L BCE +L REC +α·L SIM Among them L BCE is the cross entropy loss, L REC is the reconstruction loss, L SIM is the feature alignment loss term.
3. The method for detecting generalized abnormal traffic in federated domains based on dynamic feature alignment according to claim 1, characterized in that: The local model includes an autoencoder and a classifier. The autoencoder includes a feature extraction layer and a decoding layer, and the classifier includes a feature extraction layer and a classification layer. The autoencoder and the classifier share the feature extraction layer to learn the data representation of the current domain. The feature extraction layer is used to extract representative feature representations from the input data. The decoding layer reconstructs data based on the output of the feature extraction layer. The classification layer determines whether the data is an attack based on the output of the feature extraction layer. Step S2 is specifically as follows: Step S2.1: The original data x is passed through the autoencoder AE during the forward propagation process of local training to obtain the reconstructed data x' = AE(x), and the prediction result is obtained by the classifier. The output reconstructed data x' and the original data are compared to calculate the mean square error MSE as the reconstruction loss L. REC : THE REG =γ·MSE(AE(x),x) Where γ is a hyperparameter that controls the weight of the reconstruction loss; Calculate the cross entropy loss L between the predicted result and the label of the original data BCE : L BCE =-[y·log(f l (x))+(1-y)·log(1-f l (x))] Among them, y represents the label corresponding to the original data x, f l (x) represents the prediction result; Step S2.2, the feature alignment loss term is calculated by the client through the local feature extraction layer enco l With the global feature extraction layer enco g The differences between feature representations of the same sample encourage the model to learn domain-invariant features to improve the generalization and robustness of the global model. The specific implementation method is as follows: During the forward propagation process, the Gaussian kernel function is used to measure the data representation of the local feature extraction layer and the global feature extraction layer to obtain the similarity as the feature alignment loss term: Where σ = (1-e / Epoch)·C, where C is a constant. The closer the number of iterations e of local training is to the total number of iterations Epoch, the smaller σ is.
4. The method for detecting generalized abnormal traffic in federated domains based on dynamic feature alignment according to claim 1, characterized in that: Step S3 is specifically as follows: S3.1 After the client uploads the local model parameters, the server collects the classifiers of all clients, including the feature extraction layer and classification layer, and sends the classifiers of all clients back to each client; S3.2 Each client uses the classifier of other clients to predict the local data, then calculates the difference with the prediction result of the local model, and then uploads it to the server.
5. The method for detecting generalized abnormal traffic in federated domains based on dynamic feature alignment according to claim 1, characterized in that: Step S4 is as follows: the server combines the prediction difference results of the client model in different domains to obtain HΔH: Where Γ is the indicator function; f I (x i ) represents the prediction model f of client I I For client I local sample x i The prediction result, f J (x i ) represents the prediction model f of client J J For client I local sample x i The prediction result, f I (x j ) represents the prediction model f of client I I For client J local sample x j The prediction result, f J (x j ) represents the prediction model f of client J J For client J local sample x j The prediction result; n' represents the client I constitutes the source domain D I The number of samples in; m represents the client J that constitutes the source domain D J The number of samples in the medium; And sum HΔH of client I and all other K clients to get HC I : Where I∈[1,N].
6. The method for detecting generalized abnormal traffic in federated domains based on dynamic feature alignment according to claim 1, characterized in that: The weight of the feature alignment loss term in step S5 is calculated as follows: in represents the weight of the feature alignment loss term in the local training phase of the next round of communication of client I, β is a hyperparameter, The weight of the feature alignment loss term gradually increases with the communication round, r represents the current communication round, Round represents the total communication round, HC J represents the sum of the divergences between client J and all other K clients.
Citation Information
Cited By
Primary base alignment guided personalized soft mask aggregation federal segmentation system and method
CN121366127A