Distributed power grid safety detection model determination method and device, and medium
By employing local Transformer model training and pseudo-label generation in distributed power grids, the problems of high communication costs and low training accuracy are solved, achieving efficient and secure power grid safety detection and improving the model's real-time performance and reliability.
Patent Information
- Application Number
- CN202510998755.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2025-10-31
AI Technical Summary
Traditional centralized security detection methods in power systems suffer from high communication costs, low training accuracy, and high data transmission risks, especially in distributed power grids where they struggle to meet real-time requirements.
A distributed power grid safety detection model is adopted. The Transformer model is trained locally on the client side. Using preset global parameters and local labeled data, if the detection accuracy reaches the threshold, the training samples and model parameters are uploaded to the control cloud platform to update the global parameters. The global model is optimized by combining pseudo-label generation and dynamic weighted aggregation algorithms.
It reduces communication volume, improves training accuracy and model real-time performance, enhances system reliability and efficiency, makes full use of unlabeled data, and protects data privacy.
Smart Images

Figure CN120879545A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of power grids, and in particular to a method, apparatus and medium for determining a distributed power grid security detection model. Background Technology
[0002] With the rapid development of new power systems, the large-scale grid connection of distributed power sources has brought greater flexibility and complexity to power system regulation, while also introducing significant security challenges.
[0003] Traditional centralized security detection methods require uploading terminal data from each client to the control cloud platform for global model training. The transmission of massive amounts of data increases communication costs, leads to network congestion, and makes it difficult to meet real-time requirements. Furthermore, the transmission of raw data increases the risk of sensitive information leakage. In addition, in real-world scenarios, most of the data generated by the various clients of the power IoT is unlabeled, affecting the global model training results.
[0004] Therefore, how to reduce the communication cost of global model training and improve training accuracy is a technical problem that urgently needs to be solved by people in this field. Summary of the Invention
[0005] The purpose of this application is to provide a method, device, and medium for determining a distributed power grid security detection model, thereby solving the problems of high communication costs and low training accuracy in global model training.
[0006] To address the aforementioned technical problems, this application provides a method for determining a distributed power grid security detection model, applicable to various clients of a distributed power system, including:
[0007] Receive preset global parameters sent by the control cloud platform;
[0008] Train a local Transformer model based on the preset global parameters and locally stored labeled data;
[0009] If the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, the number of training samples, the client's global model parameters, and the detection accuracy are sent to the control cloud platform so that the control cloud platform can update the preset global parameters according to the data sent by each client and obtain the updated global parameters for the current round.
[0010] Receive updated global parameters sent by the control cloud platform, and update the trained local Transformer model according to the updated global parameters.
[0011] As an optional approach, the above-mentioned method for determining the distributed power grid security detection model includes updating the training of the local Transformer model based on the updated global parameters, comprising:
[0012] Based on the updated global parameters, the unlabeled data is predicted using the local Transformer model to obtain the category probability distribution;
[0013] If the maximum value of the category probability distribution is greater than the preset probability value, then the predicted value of the unlabeled data is used as the corresponding pseudo label to generate pseudo labeled data.
[0014] Train a local Transformer model based on the labeled data and the pseudo-labeled data;
[0015] Then return to the step of sending the number of training samples, client global model parameters, and detection accuracy to the control cloud platform if the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, until the number of prediction training rounds is completed, and the last updated global parameters are used as the global parameter result of the global model.
[0016] As an optional approach, the method for determining the distributed power grid security detection model described above, including determining whether the detection accuracy of the trained local Transformer model is greater than a preset accuracy value, includes:
[0017] Construct a confusion matrix based on the training samples and training results;
[0018] The detection accuracy is obtained based on the confusion matrix.
[0019] Determine whether the detection accuracy is greater than a preset accuracy value;
[0020] If so, then the detection accuracy of the local Transformer model after training is determined to be greater than the preset accuracy value.
[0021] As an optional solution, in the above-mentioned method for determining the distributed power grid security detection model, the control cloud platform updates the preset global parameters based on the data sent by each client to obtain the updated global parameters for the current round, including:
[0022] The contribution rate of each client is obtained based on the number of training samples for each client and the first formula.
[0023] The first formula is: ;
[0024] In the formula, the subscript r represents the r-th round of training, and the subscript c represents the c-th client. This represents the contribution rate of the c-th client in the r-th training round. This represents the number of training samples for the c-th client in the r-th round of training. This represents the set of clients participating in the r-th round of training;
[0025] The weight of each client is obtained based on the detection accuracy of each client and the second formula;
[0026] The second formula is: ;
[0027] In the formula, e represents the natural constant. This represents the weights of the c-th client in the r-th round of training. This represents the detection accuracy of the c-th client in the r-th round of training;
[0028] The updated global parameters for the current round are obtained based on the contribution rate, weight, local model parameters, and the third formula of each client.
[0029] The third formula is: ;
[0030] In the formula, This indicates the update of global parameters in the r-th training round. This represents the local model parameters of the c-th client during the r-th round of training.
[0031] As an optional approach, in the above-mentioned method for determining the distributed power grid security detection model, if the maximum value of the category probability distribution is greater than a preset probability value, the predicted value of the unlabeled data is used as the corresponding pseudo-label. After generating pseudo-labeled data, the method further includes:
[0032] Obtain the first total loss for unlabeled samples;
[0033] Obtain the second total loss for the labeled samples;
[0034] The joint loss is obtained based on the first total loss and the second total loss;
[0035] Update the local Transformer model based on the joint loss.
[0036] As an optional approach, in the above-mentioned method for determining the distributed power grid security detection model, obtaining the first total loss of unlabeled samples includes:
[0037] The cross-entropy loss is obtained based on the number of unlabeled samples, the predicted probability of unlabeled samples by the local Transformer model, and the fourth formula.
[0038] The fourth formula is: ;
[0039] In the formula, The cross-entropy loss represents the loss for unlabeled samples, where N represents the total number of samples, C represents the number of classes, and j represents the sample ID; y jc As an indicator variable, if the j-th sample belongs to class C, then yjc =1, otherwise y jc =0; p ic It is the probability that the local Transformer model predicts the j-th sample as class C, and log() represents the logarithmic function;
[0040] Based on the global model and the local Transformer model, the output prediction distribution of pseudo-labeled unlabeled samples, the total number of unlabeled samples, and the fifth formula, the KL divergence loss is obtained.
[0041] The fifth formula is: ;
[0042] In the formula, Let m represent the total number of unlabeled samples, and i represent the ID of the unlabeled sample that passed the screening. This represents the i-th unlabeled sample that passed the screening. and These represent the global model and the local Transformer model's handling of pseudo-labeled unlabeled samples, respectively. The output prediction distribution;
[0043] The information entropy regularization term is obtained from the sixth formula;
[0044] The sixth formula is: ;
[0045] In the formula, This represents the information entropy regularization term;
[0046] The first total loss for unlabeled samples is obtained by summing the cross-entropy loss, the KL divergence loss, and the information entropy regularization term.
[0047] As an optional approach, in the above-mentioned method for determining the distributed power grid security detection model, obtaining the second total loss of the labeled samples includes:
[0048] The cross-entropy loss of the labeled samples is obtained according to the seventh formula and used as the second total loss;
[0049] The seventh formula is: ;
[0050] In the formula, y represents the cross-entropy loss of the labeled samples, where n represents the total number of labeled samples and y represents the true label of the labeled samples; The predicted output for labeled samples.
[0051] To address the aforementioned technical problems, this application also provides a method for determining a distributed power grid security detection model, applied to a control cloud platform for distributed power systems, comprising:
[0052] Retrieve preset global parameters and send them to each client;
[0053] Receive the number of training samples, client global model parameters, and detection accuracy sent by each client when the detection accuracy of the local Transformer model is greater than the preset accuracy value;
[0054] The preset global parameters are updated based on the number of training samples, client-side global model parameters, and detection accuracy to obtain the updated global parameters for the current round.
[0055] The updated global parameters are sent to each client so that the client can update and train its local Transformer model based on the updated global parameters.
[0056] To address the aforementioned technical problems, this application also provides a distributed power grid security detection model determination device, applied to various clients of a distributed power system, comprising:
[0057] The receiving module is used to receive preset global parameters sent by the control cloud platform;
[0058] The training module is used to train a local Transformer model based on the preset global parameters and locally stored labeled data.
[0059] The filtering module is used to send the number of training samples, client global model parameters, and detection accuracy to the control cloud platform if the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, so that the control cloud platform can update the preset global parameters according to the data sent by each client to obtain the updated global parameters for the current round.
[0060] The update module is used to receive updated global parameters sent by the control cloud platform and update the trained local Transformer model according to the updated global parameters.
[0061] To address the aforementioned technical problems, this application also provides a distributed power grid security detection model determination device, applied to a control cloud platform for distributed power systems, comprising:
[0062] The sending module is used to obtain preset global parameters and send them to each client;
[0063] The aggregation module is used to receive the number of training samples, client global model parameters, and detection accuracy sent by each client when the detection accuracy of the local Transformer model is greater than a preset accuracy value.
[0064] The control module is used to update the preset global parameters based on the number of training samples, the client global model parameters, and the detection accuracy to obtain the updated global parameters for the current round.
[0065] The feedback module is used to send the updated global parameters to each of the clients, so that the clients can update and train their local Transformer models based on the updated global parameters.
[0066] To address the aforementioned technical problems, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the above-described method for determining a distributed power grid security detection model.
[0067] The distributed power grid security detection model determination method provided in this application involves the client obtaining initial global model parameters from the control cloud platform during training. This serves as the starting point for local training. The client uses limited local labeled data and preset global parameters to train the local model. If the detection accuracy of the trained local model exceeds a preset threshold, the client sends the number of training samples, the client's global model parameters, and the detection accuracy to the control cloud platform. The control cloud platform then updates the global parameters based on feedback data from each client. The client receives the updated global parameters from the control cloud platform and further optimizes the local model. Since only encrypted model parameters, such as global model parameters and client-side global model parameters, need to be transmitted, there is no need to upload large amounts of raw data, significantly reducing communication volume. Each client only sends data to the control cloud platform when the detection accuracy exceeds a preset accuracy value, reducing unnecessary communication. The control cloud platform updates the preset global parameters based on the number of training samples, model parameters, and detection accuracy sent by each client, further improving the training accuracy of the global model and providing feedback to improve the training accuracy of the local model, thereby enhancing model training efficiency and the system's real-time performance and reliability.
[0068] In addition, this application also provides an apparatus and medium that correspond to the above-mentioned method for determining the distributed power grid security detection model, and have the same effect. Attached Figure Description
[0069] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0070] Figure 1 This application provides a flowchart of a method for determining a distributed power grid security detection model.
[0071] Figure 2 This is a distributed power cluster grid-connected control system architecture;
[0072] Figure 3 This is a schematic diagram of a distributed power grid security detection architecture provided in an embodiment of this application;
[0073] Figure 4 A flowchart illustrating another method for determining a distributed power grid security detection model provided in this application embodiment;
[0074] Figure 5 A structural diagram of a distributed power grid security detection model determination device provided in an embodiment of this application;
[0075] Figure 6 This is a structural diagram of another distributed power grid security detection model determination device provided in an embodiment of this application. Detailed Implementation
[0076] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0077] The core of this application is to provide a method, device, and medium for determining a distributed power grid security detection model.
[0078] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0079] To address the aforementioned issues, this application provides a method for determining a distributed power grid security detection model, applicable to various clients of a distributed power system, such as... Figure 1 As shown, it includes:
[0080] S11: Receive preset global parameters sent by the control cloud platform;
[0081] S12: Train the local Transformer model based on preset global parameters and locally stored labeled data;
[0082] S13: If the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, the number of training samples, the client's global model parameters, and the detection accuracy are sent to the control cloud platform so that the control cloud platform can update the preset global parameters according to the data sent by each client and obtain the updated global parameters for the current round.
[0083] S14: Receive updated global parameters sent by the control cloud platform, and update the local Transformer model based on the updated global parameters.
[0084] This embodiment is applicable to all clients of a distributed power system, especially in the power Internet of Things environment, where client devices need to perform data processing and model training locally, while collaborating with the control cloud platform to complete the global model update.
[0085] Client devices may include intelligent terminals of distributed power sources that collect power system operation data (such as voltage, current, power, etc.) and safety-related log data (such as access records, alarm information, etc.).
[0086] Federated machine learning (FL), also known as federated learning, joint learning, or consortium learning, allows multiple participants (usually devices or servers) to collaboratively train a shared machine learning model while maintaining data privacy and locality. In federated learning, data does not need to be transferred to a central server, thus reducing the risk of data leakage. Participants independently train their models using their own data and then send model updates (such as gradients or model parameters) to a central server. The central server collects all model updates from all participants and uses an algorithm to aggregate these updates into a global model. The aggregated global model updates are then sent back to the participants, who use these updates to improve their own models.
[0087] Figure 2 This is a distributed power cluster grid-connected control system architecture, such as Figure 2 As shown, this system can be divided into a multi-level physical structure consisting of a control cloud platform layer, a distributed power cluster layer, and a distributed power unit layer. In this embodiment, the client refers to... Figure 2 The cloud-edge computing of intelligent terminals in the system specifically achieves data processing and computing through the edge computing unit of the intelligent terminal.
[0088] In step S11, receiving the preset global parameters sent by the control cloud platform refers to the client obtaining the initial model parameters from the control cloud platform. The preset global parameters are fundamental in the federated learning framework for initializing the local model, ensuring that all clients start training from the same point. Specifically, these parameters may be information such as the weights and biases of the Transformer model, broadcast from the control cloud platform to each client via encrypted communication.
[0089] The control cloud platform is the central node in federated learning, responsible for coordinating the updates and distribution of the global model. It receives model parameter updates from each client and generates new global parameters through aggregation algorithms.
[0090] The local Transformer model configured on each client can be specifically configured as needed. Specifically, to adapt to the low computing power requirements of terminal devices, a lightweight model needs to be built. The cloud platform will broadcast the parameter set used for model configuration on each client to all client nodes participating in training. Before receiving the preset global parameters sent by the cloud platform, the following steps are also included:
[0091] Receive the initial parameter set of the improved Transformer model sent by the control cloud platform;
[0092] Configure the local Transformer model based on the initial parameter set.
[0093] The improved Transformer model removes the traditional decoder and replaces it with a two-layer perceptron (MLP) (128 → 64 neurons), reducing the model parameter size from 12.5MB to 3.2MB, thus adapting to the computing power constraints of edge devices. Furthermore, residual connections and a global average pooling layer are embedded in the encoder. For voltage phase sequence data, the multi-head attention mechanism (8 heads) can capture temporal dependencies of up to 512 steps, improving the detection accuracy of spoofed data injection (FDIA) attacks by 12.8% compared to the Long Short-Term Memory (LSTM) model. A dual-stream input structure is also designed, where information-side data (logs, access records) and physical-side data (current amplitude, harmonic distortion rate) are extracted for features by independent encoders, and then fused through a cross-attention mechanism to achieve dual-side threat correlation analysis.
[0094] All clients start training with the same initial parameters, which helps reduce the variability in model convergence and improves the overall efficiency of federated learning.
[0095] In step S12, the client trains the model using global parameters received from the control cloud platform and locally stored labeled data (such as power system operation data and safety tags). Local Transformer model training can be achieved using the Adam optimizer (an optimization algorithm for deep learning model training), employing the cross-entropy loss function to measure the difference between the model's predictions and the true labels. In this step, local training enables the model to learn and adapt to local data features, while the Transformer model's multi-head attention mechanism captures the temporal characteristics of the power data, improving the model's ability to detect threats such as fake data injection attacks.
[0096] The tagged data stored on the client side refers to power system operation data with security labels. For example, normal operation data is tagged as "normal," while data subjected to spoofed data injection attacks is tagged as "attack." This data is used for supervised learning to help the model learn how to distinguish between normal and abnormal states.
[0097] The client uses the Adam optimizer to train the local model. The learner rate can be set to 0.01, and the batch size to 64. During training, the model iterates multiple times (e.g., 5 times) on the labeled data, calculates the cross-entropy loss function, and updates the model parameters through backpropagation.
[0098] In step S13, after completing local training, the client evaluates the model's detection accuracy. If the detection accuracy exceeds a preset threshold (e.g., 80% or 60%), the client's model training is considered effective, and the relevant data is sent to the control cloud platform. This data includes the number of training samples, the global parameters of the local model, and the detection accuracy metrics. The accuracy threshold filtering mechanism can select high-quality client model parameters, reducing the impact of invalid communication and noisy data on global model updates.
[0099] Preset accuracy values are typically set based on the actual application scenario and requirements. For example, if the security requirements of the power Internet of Things are high, the preset accuracy value can be set to 80% or higher.
[0100] The number of training samples is the total number of samples used by the client for training, used to calculate the client's contribution to the global model. The client-side global model parameters are the weights and biases of the locally trained model, used for updating the global model. Detection accuracy is the detection accuracy metric of the client model, used to evaluate the quality of the client model.
[0101] In step S14, the client receives the updated global model parameters from the control cloud platform based on the data uploaded by each client. The control cloud platform calculates the aggregation weights using a dynamic weighted aggregation algorithm, combining the client's sample size and detection accuracy, and updates the global model parameters. After receiving the updated global parameters, the client uses them as new initial parameters to continue training its local model. This process achieves collaborative optimization between the global and local models, ensuring continuous iteration and improvement of the model in a distributed environment.
[0102] The distributed power grid security detection model determination method provided in this application involves the client obtaining initial global model parameters from the control cloud platform during training. This serves as the starting point for local training. The client uses limited local labeled data and preset global parameters to train its local model. If the detection accuracy of the trained local model exceeds a preset threshold, the client sends the number of training samples, the client's global model parameters, and the detection accuracy to the control cloud platform. The control cloud platform then updates the global parameters based on feedback data from each client. The client receives the updated global parameters from the control cloud platform and further optimizes its local model. Since only encrypted model parameters, such as global model parameters and client-side global model parameters, need to be transmitted, there is no need to upload large amounts of raw data, significantly reducing communication volume. Each client only sends data to the control cloud platform when the detection accuracy exceeds a preset accuracy value, reducing unnecessary communication. The control cloud platform updates the preset global parameters based on the number of training samples, model parameters, and detection accuracy sent by each client. Through a dynamic weighted aggregation algorithm, the global model can better integrate the model parameters from each client, achieving collaborative optimization between the global model and the local model, thus improving model training efficiency and the system's real-time performance and reliability.
[0103] In existing solutions, federated learning protects data privacy through distributed training, but it still suffers from limitations such as reliance on labeled data, low reliability of pseudo-labels, and high communication overhead. Most federated learning methods assume that the client has sufficient labeled data, but labeling costs are high in real-world power scenarios. However, unlabeled data typically accounts for over 90% of the data in the power Internet of Things (IoT). To fully utilize unlabeled data, this application provides a specific solution that updates the training of the local Transformer model based on updated global parameters, including:
[0104] Based on updating global parameters, the local Transformer model is used to predict unlabeled data and obtain the category probability distribution;
[0105] If the maximum value of the category probability distribution is greater than the preset probability value, the predicted value of the unlabeled data will be used as the corresponding pseudo label to generate pseudo labeled data.
[0106] Train a local Transformer model based on labeled and pseudo-labeled data;
[0107] Then, if the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, the number of training samples, the client's global model parameters, and the detection accuracy are sent to the control cloud platform. This process continues until the number of prediction training rounds is completed, and the last updated global parameters are used as the global parameter result of the global model.
[0108] In the local Transformer model, updated global parameters received from the control cloud platform are used to predict unlabeled data stored locally, obtaining the class probability distribution for each sample. The updated global parameters incorporate model knowledge from multiple clients, enabling better capture of the global characteristics of distributed data. Initializing the local model with these parameters improves the model's predictive ability for unlabeled data.
[0109] The model outputs a probability distribution for each unlabeled sample. , representing the confidence level that a sample belongs to each category. The maximum value of the probability distribution is obtained. ,like If the value is less than the threshold of 0.8, it is discarded; if If the predicted value is greater than the threshold, the predicted value is set as a pseudo-label for the unlabeled sample. For example, if the model predicts that a sample is in an attack state with a probability of 0.9 (greater than the preset probability value of 0.8), then the sample is labeled as an attack state.
[0110] By incorporating these unlabeled and labeled samples into local model training, the amount of samples available for training is increased, thus improving the model's training performance. By setting a threshold, predictions with relatively high confidence are selected, preventing low-confidence predictions from interfering with model training.
[0111] It should be noted that after each model training, if the accuracy screening conditions of the local Transformer model's detection accuracy are met, the number of training samples uploaded, the client's global model parameters, and the detection accuracy are all uploaded based on the data from the current training round. After receiving the updated global parameters sent by the control cloud platform, the pseudo-labels need to be recalculated for each full iteration. This is to prevent the errors caused by samples with incorrect pseudo-labels from propagating continuously during iterative training.
[0112] Training with both labeled and pseudo-labeled data allows for full utilization of limited labeled data and a large amount of unlabeled data, improving the model's generalization ability and detection accuracy. This process is repeated until the predetermined number of training rounds is completed. Finally, the last update of the global parameters is used as the final result of the global model. Through multiple iterations and dynamic updates of the global parameters, the model can be gradually optimized, improving overall performance. The global model can better integrate the features of distributed data, ultimately converging to a model with better performance.
[0113] This embodiment significantly improves the model's generalization ability and detection accuracy by introducing pseudo-label generation and joint training mechanisms, making full use of unlabeled data. Simultaneously, through a dynamic weighted aggregation algorithm and multiple iterative optimizations, the performance of the global model is continuously improved.
[0114] Figure 3This is a schematic diagram of a distributed power grid security detection architecture provided in an embodiment of this application, such as... Figure 3 As shown, each client trains its local Transformer model based on the labeled data. Clients that pass the accuracy screening send their training data to the cloud control platform. The cloud control platform performs overall analysis and updates the global parameters, then distributes the updated global parameters back to each client. Each client then predicts the unlabeled data based on the updated global parameters, and only a portion of the unlabeled samples are pseudo-labeled to participate in the local Transformer model's update training. After each training iteration, clients that meet the requirements upload their data to the cloud control platform for global parameter updates, which are then fed back to the client.
[0115] Determining whether the detection accuracy of the local Transformer model after training exceeds a preset accuracy value is a crucial step in the entire semi-supervised federated learning process. This process not only determines whether the client model can participate in the global model update but also directly impacts the overall efficiency and model performance of federated learning. Specifically, determining whether the detection accuracy of the local Transformer model after training exceeds a preset accuracy value includes:
[0116] Construct a confusion matrix based on the training samples and training results;
[0117] The detection accuracy is obtained from the confusion matrix;
[0118] Determine whether the detection accuracy is greater than the preset accuracy value;
[0119] If so, then the detection accuracy of the local Transformer model after training is determined to be greater than the preset accuracy value.
[0120] After the local model is trained, its performance is evaluated using a local test dataset. A confusion matrix is constructed by comparing the model's predictions with the true labels.
[0121] A confusion matrix is a table used in machine learning to evaluate the performance of classification models. It compares the model's predictions with the actual results, mainly including four cases: 1. True Positive (TP): The model predicts correctly, and the actual result is also correct; 2. False Positive (FP): The model predicts incorrectly, and the actual result is also incorrect (false positive); 3. False Negative (FN): The model predicts incorrectly, and the actual result is correct (false negative); 4. True Negative (TN): The model predicts correctly, and the actual result is also incorrect.
[0122] Detection accuracy, or precision, is calculated as (TP+TN) / (TP+TN+FP+FN). The higher the precision, the better the overall predictive ability of the model.
[0123] By setting preset precision values, high-quality client-side model parameters are selected, avoiding the negative impact of low-quality models on global model updates. High-quality client-side model parameters help the global model better learn the characteristics of distributed data, improving its performance. Through multiple iterations and dynamic updates of global parameters, the model can be gradually optimized, eventually converging to a globally performing model.
[0124] According to the above embodiments, specifically, the control cloud platform updates the preset global parameters based on the data sent by each client to obtain the updated global parameters for the current round, including:
[0125] The contribution rate of each client is obtained based on the number of training samples for each client and the first formula.
[0126] The first formula is: ;
[0127] In the formula, the subscript r represents the r-th round of training, and the subscript c represents the c-th client. This represents the contribution rate of the c-th client in the r-th training round. This represents the number of training samples for the c-th client in the r-th round of training. This represents the set of clients participating in the r-th round of training;
[0128] The weight of each client is obtained based on the detection accuracy of each client and the second formula;
[0129] The second formula is: ;
[0130] In the formula, e represents the natural constant. This represents the weights of the c-th client in the r-th round of training. This represents the detection accuracy of the c-th client in the r-th round of training;
[0131] The updated global parameters for the current round are obtained based on the contribution rate, weight, local model parameters, and the third formula of each client.
[0132] The third formula is: ;
[0133] In the formula, This indicates the update of global parameters in the r-th training round. This represents the local model parameters of the c-th client during the r-th round of training.
[0134] The cloud-based control platform calculates the contribution rate of each client using the first formula, based on the number of training samples for each client. The contribution rate reflects the magnitude of each client's contribution to the global model, ensuring that clients with larger sample sizes have a greater impact on the global model's updates. In each training round, the contribution rate is dynamically calculated based on the client's sample size, adapting to the data distribution across different clients.
[0135] The cloud-based control platform calculates the weight of each client using a second formula based on the detection accuracy of each client. The weight reflects the performance of the client's model; clients with higher detection accuracy have a greater impact on the global model update. A normalization (Softmax) function is used to ensure a more reasonable distribution of weights, preventing a single client's excessively high detection accuracy from dominating the global model update.
[0136] Based on the contribution rate, weight, and local model parameters of each client, the updated global parameters for the current round are calculated using the third formula. When updating the global parameters, the sample size and detection accuracy of each client are comprehensively considered to ensure that the global model can better integrate the features of the distributed data.
[0137] Through the steps described above, the cloud control platform can effectively update global parameters. This process considers not only the sample size of each client (through contribution rate) but also the performance of the client model (through weights), ensuring that the global model can fully leverage the strengths of each client, gradually optimizing and improving overall performance. This method significantly improves the performance and efficiency of security threat detection models in distributed power control scenarios while protecting data privacy.
[0138] According to the above embodiment, specifically, if the maximum value of the category probability distribution is greater than the preset probability value, the predicted value of the unlabeled data is used as the corresponding pseudo-label. After generating pseudo-labeled data, the process further includes:
[0139] Obtain the first total loss for unlabeled samples;
[0140] Obtain the second total loss for the labeled samples;
[0141] The joint loss is obtained based on the first total loss and the second total loss;
[0142] Update the local Transformer model based on the joint loss.
[0143] After generating pseudo-labeled data, the total loss for unlabeled samples is calculated, called the first total loss. The total loss for labeled samples is calculated, called the second total loss. The first total loss for unlabeled samples and the second total loss for labeled samples are combined to obtain the joint loss. The joint loss considers the losses of both labeled and unlabeled samples, which can comprehensively optimize the model's performance and improve its generalization ability. The model can be optimized based on the joint loss in each iteration, gradually adapting to the characteristics of the local data.
[0144] Specifically, the first total loss for unlabeled samples is obtained, including:
[0145] The cross-entropy loss is obtained based on the number of unlabeled samples, the predicted probability of unlabeled samples by the local Transformer model, and the fourth formula.
[0146] The fourth formula is: ;
[0147] In the formula, The cross-entropy loss represents the loss for unlabeled samples, where N represents the total number of samples, C represents the number of classes, and j represents the sample ID; y jc As an indicator variable, if the j-th sample belongs to class C, then y jc =1, otherwise y jc =0; p ic It is the probability that the local Transformer model predicts the j-th sample as class C, and log() represents the logarithmic function;
[0148] Based on the global model and the local Transformer model, the output prediction distribution of pseudo-labeled unlabeled samples, the total number of unlabeled samples, and the fifth formula, the KL divergence loss is obtained.
[0149] The fifth formula is: ;
[0150] In the formula, Let represent the KL divergence loss, m represent the total number of unlabeled samples, and i represent the ID of the unlabeled sample that passed the screening. Indicates the number that passed the screening. One unlabeled sample; and These represent the global model and the local Transformer model's handling of pseudo-labeled unlabeled samples, respectively. The output prediction distribution is given by ln(), which represents the natural logarithm operation.
[0151] The information entropy regularization term is obtained from the sixth formula;
[0152] The sixth formula is: ;
[0153] In the formula, This represents the information entropy regularization term.
[0154] The first total loss for unlabeled samples is obtained by summing the cross-entropy loss, KL divergence loss, and information entropy regularization term.
[0155] For each unlabeled sample, calculate the cross-entropy loss between its predicted value and the pseudo-label. The cross-entropy loss measures the difference between the model's prediction and the pseudo-label, guiding the model to learn the features of the unlabeled data.
[0156] The relative entropy (Kullback-Leibler Divergence, KLD), also known as KL divergence, is calculated based on the output prediction distributions of the global model and the local Transformer model for pseudo-labeled unlabeled samples. KL divergence is used to measure the difference in predictions between the client model and the global model on unlabeled data, forcing the local model to align with the global model's prediction distribution and suppressing client overfitting.
[0157] Information entropy represents the complexity of a probability distribution. The more complex and disordered a distribution is, the greater its information entropy. As a measure of the complexity of a probability distribution, the core function of information entropy is to balance model complexity and generalization ability, avoid overfitting, and optimize model performance by introducing information entropy as a regularization term.
[0158] After screening, the first total loss of unlabeled samples It consists of three parts.
[0159] The first total loss is expressed as: .
[0160] According to the above embodiments, specifically, obtaining the second total loss of the labeled samples includes:
[0161] The cross-entropy loss of the labeled samples is obtained according to the seventh formula and used as the second total loss;
[0162] The seventh formula is: ;
[0163] In the formula, y represents the cross-entropy loss of the labeled samples, where n represents the total number of labeled samples and y represents the true label of the labeled samples; The predicted output for labeled samples.
[0164] Cross-entropy loss is a common method for measuring the difference between a model's predicted output and the true label. The second total loss for labeled samples directly reflects how well the model fits the labeled data. By minimizing this loss, the model can learn the features of the labeled data, thereby improving its ability to detect known threats.
[0165] The combined loss is: L represents the joint loss. This function is used to update the local model. The model's joint loss function combines the loss from unlabeled samples and the loss from labeled samples to update the local model.
[0166] In semi-supervised learning, the loss for labeled samples and the loss for unlabeled samples are optimized together. The loss for labeled samples ensures that the model can learn the features of the known data, while the loss for unlabeled samples helps the model utilize more data to improve its generalization ability.
[0167] This application also provides another method for determining a distributed power grid security detection model, applied to a control cloud platform for distributed power systems, such as... Figure 4 As shown, it includes:
[0168] S21: Obtain preset global parameters and send them to each client;
[0169] S22: Receive the number of training samples, client global model parameters, and detection accuracy sent by each client when the detection accuracy of the local Transformer model is greater than the preset accuracy value;
[0170] S23: Update the preset global parameters based on the number of training samples, client-side global model parameters, and detection accuracy to obtain the updated global parameters for the current round;
[0171] S24: Send the updated global parameters to each client so that the client can update and train its local Transformer model based on the updated global parameters.
[0172] This embodiment provides a method for determining a distributed power grid safety detection model in a control cloud platform applied to a distributed power system. The control cloud platform initializes global model parameters and broadcasts these parameters to all participating clients. The control cloud platform receives data sent by each client when the detection accuracy of their local Transformer model exceeds a preset accuracy value. This data includes the number of training samples, the client's global model parameters, and the detection accuracy. Based on the number of training samples, the client's global model parameters, and the detection accuracy of each client, the control cloud platform updates the global model parameters using a dynamic weighted aggregation algorithm, obtaining the updated global parameters for the current round. The control cloud platform then broadcasts the updated global parameters back to each client for them to continue updating and training their local models. Since only encrypted model parameters, such as global model parameters and client-side global model parameters, need to be transmitted, there is no need to upload a large amount of raw data, which greatly reduces the amount of communication. Each client only needs to send data to the control cloud platform when the detection accuracy is greater than the preset accuracy value, reducing unnecessary communication. The control cloud platform updates the preset global parameters based on the number of training samples, model parameters, and detection accuracy sent by each client. Through a dynamic weighted aggregation algorithm, the global model can better integrate the model parameters of each client, realize the collaborative optimization of the global model and the local model, and improve the model training efficiency and the real-time performance and reliability of the system.
[0173] In the above embodiments, the method for determining the distributed power grid security detection model has been described in detail. This application also provides embodiments corresponding to the device for determining the distributed power grid security detection model. It should be noted that this application describes the embodiments of the device from two perspectives: one is based on functional modules, and the other is based on hardware.
[0174] From the perspective of functional modules Figure 5 A structural diagram of a distributed power grid security detection model determination device provided in an embodiment of this application is shown below. Figure 5 As shown, a distributed power grid security detection model determination device is applied to various clients of a distributed power system, including:
[0175] Receiver module 11 is used to receive preset global parameters sent by the control cloud platform;
[0176] Training module 12 is used to train a local Transformer model based on preset global parameters and locally stored labeled data;
[0177] The filtering module 13 is used to send the number of training samples, client global model parameters, and detection accuracy to the control cloud platform if the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, so that the control cloud platform can update the preset global parameters according to the data sent by each client and obtain the updated global parameters for the current round.
[0178] The update module 14 is used to receive the updated global parameters sent by the control cloud platform and update the trained local Transformer model according to the updated global parameters.
[0179] Figure 6 A structural diagram of a distributed power grid security detection model determination device provided in an embodiment of this application is shown below. Figure 6 As shown, a distributed power grid security detection model determination device is applied to the control cloud platform of a distributed power system, comprising:
[0180] Sending module 21 is used to obtain preset global parameters and send them to each client;
[0181] The aggregation module 22 is used to receive the number of training samples, client global model parameters, and detection accuracy sent by each client when the detection accuracy of the local Transformer model is greater than a preset accuracy value.
[0182] The control module 23 is used to update the preset global parameters based on the number of training samples, client global model parameters, and detection accuracy to obtain the updated global parameters for the current round.
[0183] Feedback module 24 is used to send updated global parameters to each client so that the client can update and train its local Transformer model based on the updated global parameters.
[0184] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.
[0185] Finally, this application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps described in the above embodiment of the distributed power grid security detection model determination method.
[0186] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0187] The computer-readable storage medium provided in this embodiment stores a computer program thereon. When the processor executes the program, it can implement the following method: a method for determining a distributed power grid security detection model.
[0188] The above provides a detailed description of the distributed power grid security detection model determination method, apparatus, and medium provided in this application. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
[0189] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A method for determining a distributed power grid security detection model, applied to each client of a distributed power system, characterized in that, include: Receive preset global parameters sent by the control cloud platform; Train a local Transformer model based on the preset global parameters and locally stored labeled data; If the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, the number of training samples, the client's global model parameters, and the detection accuracy are sent to the control cloud platform so that the control cloud platform can update the preset global parameters according to the data sent by each client and obtain the updated global parameters for the current round. Receive updated global parameters sent by the control cloud platform, and update the trained local Transformer model according to the updated global parameters.
2. The method for determining the distributed power grid security detection model according to claim 1, characterized in that, Updating the training of the local Transformer model based on the updated global parameters includes: Based on the updated global parameters, the unlabeled data is predicted using the local Transformer model to obtain the category probability distribution; If the maximum value of the category probability distribution is greater than the preset probability value, then the predicted value of the unlabeled data is used as the corresponding pseudo label to generate pseudo labeled data. Train a local Transformer model based on the labeled data and the pseudo-labeled data; Then return to the step of sending the number of training samples, client global model parameters, and detection accuracy to the control cloud platform if the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, until the number of prediction training rounds is completed, and the last updated global parameters are used as the global parameter result of the global model.
3. The method for determining the distributed power grid security detection model according to claim 1, characterized in that, Determine whether the detection accuracy of the local Transformer model after training is greater than a preset accuracy value, including: Construct a confusion matrix based on the training samples and training results; The detection accuracy is obtained based on the confusion matrix. Determine whether the detection accuracy is greater than a preset accuracy value; If so, then the detection accuracy of the local Transformer model after training is determined to be greater than the preset accuracy value.
4. The method for determining the distributed power grid security detection model according to claim 1, characterized in that, The control cloud platform updates the preset global parameters based on the data sent by each client to obtain the updated global parameters for the current round, including: The contribution rate of each client is obtained based on the number of training samples for each client and the first formula. The first formula is: ; In the formula, the subscript r represents the r-th round of training, and the subscript c represents the c-th client. This represents the contribution rate of the c-th client in the r-th training round. This represents the number of training samples for the c-th client in the r-th round of training. This represents the set of clients participating in the r-th round of training; The weight of each client is obtained based on the detection accuracy of each client and the second formula; The second formula is: ; In the formula, e represents the natural constant. This represents the weights of the c-th client in the r-th round of training. This represents the detection accuracy of the c-th client in the r-th round of training; The updated global parameters for the current round are obtained based on the contribution rate, weight, local model parameters, and the third formula of each client. The third formula is: ; In the formula, This indicates the update of global parameters in the r-th training round. This represents the local model parameters of the c-th client during the r-th round of training.
5. The method for determining the distributed power grid security detection model according to claim 2, characterized in that, If the maximum value of the category probability distribution is greater than the preset probability value, then the predicted value of the unlabeled data is used as the corresponding pseudo-label. After generating pseudo-labeled data, the following steps are also included: Obtain the first total loss for unlabeled samples; Obtain the second total loss for the labeled samples; The joint loss is obtained based on the first total loss and the second total loss; Update the local Transformer model based on the joint loss.
6. The method for determining the distributed power grid security detection model according to claim 5, characterized in that, Obtain the first total loss for unlabeled samples, including: The cross-entropy loss is obtained based on the number of unlabeled samples, the predicted probability of unlabeled samples by the local Transformer model, and the fourth formula. The fourth formula is: ; In the formula, The cross-entropy loss represents the loss for unlabeled samples, where N represents the total number of samples, C represents the number of classes, and j represents the sample ID; y jc As an indicator variable, if the j-th sample belongs to class C, then y jc =1, otherwise y jc =0; p ic It is the probability that the local Transformer model predicts the j-th sample as class C, and log() represents the logarithmic function; Based on the global model and the local Transformer model, the output prediction distribution of pseudo-labeled unlabeled samples, the total number of unlabeled samples, and the fifth formula, the KL divergence loss is obtained. The fifth formula is: ; In the formula, Let m represent the total number of unlabeled samples, and i represent the ID of the unlabeled sample that passed the screening. This represents the i-th unlabeled sample that passed the screening. and These represent the global model and the local Transformer model's handling of pseudo-labeled unlabeled samples, respectively. The output prediction distribution; The information entropy regularization term is obtained from the sixth formula; The sixth formula is: ; In the formula, This represents the information entropy regularization term; The first total loss for unlabeled samples is obtained by summing the cross-entropy loss, the KL divergence loss, and the information entropy regularization term.
7. The method for determining the distributed power grid security detection model according to claim 5, characterized in that, Obtain the second total loss for the labeled samples, including: The cross-entropy loss of the labeled samples is obtained according to the seventh formula and used as the second total loss; The seventh formula is: ; In the formula, y represents the cross-entropy loss of the labeled samples, where n represents the total number of labeled samples and y represents the true label of the labeled samples; The predicted output for labeled samples.
8. A method for determining a distributed power grid security detection model, applied to a control cloud platform for distributed power systems, characterized in that, include: Retrieve preset global parameters and send them to each client; Receive the number of training samples, client global model parameters, and detection accuracy sent by each client when the detection accuracy of the local Transformer model is greater than the preset accuracy value; The preset global parameters are updated based on the number of training samples, client-side global model parameters, and detection accuracy to obtain the updated global parameters for the current round. The updated global parameters are sent to each client so that the client can update and train its local Transformer model based on the updated global parameters.
9. A distributed power grid security detection model determination device, applied to each client of a distributed power system, characterized in that, include: The receiving module is used to receive preset global parameters sent by the control cloud platform; The training module is used to train a local Transformer model based on the preset global parameters and locally stored labeled data. The filtering module is used to send the number of training samples, client global model parameters, and detection accuracy to the control cloud platform if the detection accuracy of the local Transformer model after training is greater than the preset accuracy value, so that the control cloud platform can update the preset global parameters according to the data sent by each client to obtain the updated global parameters for the current round. The update module is used to receive updated global parameters sent by the control cloud platform and update the trained local Transformer model according to the updated global parameters.
10. A distributed power grid security detection model determination device, applied to a control cloud platform for distributed power systems, characterized in that, include: The sending module is used to obtain preset global parameters and send them to each client; The aggregation module is used to receive the number of training samples, client global model parameters, and detection accuracy sent by each client when the detection accuracy of the local Transformer model is greater than a preset accuracy value. The control module is used to update the preset global parameters based on the number of training samples, the client global model parameters, and the detection accuracy to obtain the updated global parameters for the current round. The feedback module is used to send the updated global parameters to each of the clients, so that the clients can update and train their local Transformer models based on the updated global parameters.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the distributed power grid security detection model determination method as described in any one of claims 1 to 8.