Federal learning-based electricity consumption anomaly detection method, system and device, and medium

By employing a federated learning-based dynamic adaptive anomaly detection framework (FedDAE), which combines a dual-channel temporal autoencoder and a dynamic weight aggregation mechanism on both the client and server sides, the heterogeneity and privacy protection issues of cross-regional electricity consumption data in smart grids are addressed, achieving both effectiveness and privacy protection in cross-regional anomaly detection.

CN121234243APending Publication Date: 2025-12-30HAINAN POWER GRID CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511053917.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-30
Publication Date
2025-12-30

AI Technical Summary

Technical Problem

In the cross-regional collaborative management of smart grids, there are issues of data heterogeneity and privacy protection requirements, which limit the generalization ability of traditional centralized training models. Furthermore, cross-regional electricity data sharing may lead to privacy leakage risks, and there is a lack of effective methods to combine data privacy protection with anomaly detection.

Method used

The FedDAE framework for dynamic adaptive anomaly detection employs federated learning. A dual-channel temporal autoencoder (Dual-AE) is constructed on the client side to extract electricity consumption features. A dynamic dual-weight federated aggregation mechanism is designed on the server side to dynamically adjust the aggregation weights to achieve collaborative mining and adaptive generalization of anomaly patterns across regions.

Benefits of technology

It enables the accurate detection of hidden anomalies such as electricity theft and equipment failure without sharing raw data, balancing privacy protection and heterogeneous data collaboration, and improving the model's generalization ability and detection efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121234243A_ABST
    Figure CN121234243A_ABST
Patent Text Reader

Abstract

The invention discloses a federated learning-based electricity consumption anomaly detection method, system and device, and a storage medium, and belongs to the technical field of electricity consumption data analysis, and the method comprises the steps: collecting local electricity consumption data, and carrying out the preprocessing; the client constructs a dual-channel auto-encoder to perform feature extraction and reconstruction on the preprocessed data, calculates an anomaly score based on a dynamic weighted fusion mechanism, judges anomaly and executes local model training; the clients upload parameters after local model training to the server, and the server calculates dynamic fusion weights of the clients, aggregates a global model and updates global feature distribution; and the server broadcasts the global model and the feature distribution parameters to each client. According to the method, hidden anomalies such as electricity stealing and equipment faults can be accurately captured, and collaborative mining and self-adaptive generalization of cross-regional abnormal modes can be realized under the condition that original data does not need to be shared.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electricity consumption data analysis technology, specifically to a method, system, device, and medium for detecting abnormal electricity consumption based on federated learning. Background Technology

[0002] Anomaly detection is a crucial link in the safe operation and efficient management of smart grids, and its importance is reflected in three aspects: Economic loss prevention: Timely identification of abnormal electricity consumption patterns (such as electricity theft and non-technical losses caused by equipment failure). According to the International Energy Agency, global economic losses due to electricity theft exceed US$96 billion annually. Safety risk early warning: By capturing abnormal signals such as sudden current changes and load imbalances, electrical fires, equipment damage, and regional power outages can be prevented, protecting users' lives and property and ensuring the stable operation of the power grid. Energy efficiency optimization support: Anomaly detection provides a data foundation for electricity consumption behavior analysis and energy dispatch, helping to achieve dynamic optimization of the distribution network, refined management of the power system, and green transformation. It has irreplaceable strategic value for building a reliable, low-carbon smart energy ecosystem.

[0003] In the cross-regional collaborative management of smart grids, electricity anomaly detection faces two core challenges: data heterogeneity and privacy protection requirements. On the one hand, due to the diversity of user structure (such as the difference in the proportion of residential areas and industrial parks), industry type (the different load characteristics of high-energy-consuming manufacturing and light industry), and climate conditions (the periodic impact of temperature on air conditioning load), different regions exhibit significant heterogeneity in electricity consumption patterns in terms of peak and off-peak distribution, fluctuation cycle patterns, and abnormal baseline thresholds. Traditional centralized training models are easily dominated by local features, thus limiting their generalization ability. On the other hand, electricity consumption data contains sensitive information about industrial and commercial operations (such as production cycles and energy intensity). Cross-regional plaintext transmission and sharing may lead to privacy leakage risks and even provide opportunities for cybercriminal groups to reverse engineer user profiles.

[0004] To address the aforementioned issues, this invention proposes a Federated Dynamic Adaptive Anomaly Detection Framework (FedDAE) to construct a solution that balances privacy protection and heterogeneous data collaboration. At the client level, an innovative dual-channel temporal autoencoder (Dual-AE) is designed: through a cascaded structure of dilated causal convolution and gated recurrent units (GRUs), electricity consumption time-series features are encoded from the perspectives of local fluctuations and long-term trends, respectively. A dynamically weighted anomaly scoring module (such as a sliding weighted fusion of reconstruction error and prediction bias) is introduced to accurately capture concealed anomalies such as electricity theft and equipment failure. At the server level, a dynamic dual-weighted federated aggregation mechanism is designed. Based on the client model performance and feature distribution alignment (MMD distance calculation), the aggregation weights are dynamically adjusted. Initially, knowledge transfer in high-precision regions is emphasized to accelerate convergence, while later, distribution similarity optimization is strengthened to suppress model bias. This enables collaborative mining and adaptive generalization of cross-regional anomaly patterns without sharing original data. Summary of the Invention

[0005] In view of the above-mentioned problems, the present invention is proposed.

[0006] Therefore, this invention aims to address the issue that the stability of electricity consumption data varies across different regions and the distribution of user structures. Some regions have a lower incidence of electricity consumption anomalies due to their homogeneous user structure, while others have a higher incidence due to their complex user distribution and diverse industrial structures. Furthermore, the electricity consumption data from different regions exhibits heterogeneity. As a result, the lack of an effective method to construct a robust model to achieve both data privacy protection and effective anomaly detection is a key problem that needs to be solved.

[0007] To address the aforementioned technical problems, this invention provides the following technical solution: a method for detecting abnormal electricity consumption based on federated learning, comprising,

[0008] The system collects and preprocesses local electricity consumption data; the client constructs a dual-channel autoencoder to extract and reconstruct features from the preprocessed data; the client calculates anomaly scores based on a dynamic weighted fusion mechanism, identifies anomalies, and performs local model training; the client uploads the parameters of the locally trained model to the server; the server calculates the dynamic fusion weights of all clients, aggregates the global model, and updates the global feature distribution; the server broadcasts the global model and feature distribution parameters to each client.

[0009] As a preferred embodiment of the federated learning-based power consumption anomaly detection method described in this invention, the preprocessing includes:

[0010] Local electricity consumption data is cleaned and missing data is filled in.

[0011] Local electricity consumption data is standardized and time-series features are extracted.

[0012] Generate temporal feature slices with context labels by associating them with the external environment.

[0013] As a preferred embodiment of the federated learning-based power consumption anomaly detection method described in this invention, the construction of the dual-channel autoencoder includes: constructing a client infrastructure, organizing the client's local power consumption data in the form of a sliding window, and normalizing the preprocessed data again.

[0014] The dual-channel autoencoder includes a first branch, a second branch, and a third stage;

[0015] Local temporal features are extracted using the first branch;

[0016] Global temporal features are extracted using the second branch;

[0017] In the third stage, the features output from the two branches are concatenated and then reconstructed through a fully connected layer to form the input sequence.

[0018] As a preferred embodiment of the federated learning-based electricity consumption anomaly detection method described in this invention, the anomaly score calculation includes calculating the mean square error between the input sequence and the reconstructed input sequence as the reconstruction error.

[0019] The hidden state of the branch is extracted using temporal features to predict the power at the next time step;

[0020] Calculate the mean absolute error between the predicted and actual values ​​within the sliding window;

[0021] The fusion weights of reconstruction error and mean absolute error are dynamically adjusted to generate a comprehensive anomaly score.

[0022] The beneficial effects of the preferred technical solution in the embodiments of the present invention are as follows: by calculating the reconstruction error, the morphological anomaly of the power consumption sequence (such as abnormal power consumption curve) is directly reflected, and the normal mode noise is filtered by the compression characteristics of the autoencoder; by calculating the prediction error, deviations in the timing pattern are captured, and this step has early warning value for latent anomalies; by dynamically adjusting the fusion weight, adaptive detection of sudden anomalies and gradual anomalies is realized.

[0023] As a preferred embodiment of the federated learning-based electricity consumption anomaly detection method described in this invention, the local model training includes: employing a multi-task loss function, jointly optimizing the reconstruction loss and the prediction loss, and introducing a weight decay regularization term.

[0024] An early stop mechanism is used to control the number of training rounds during the training process.

[0025] As a preferred embodiment of the federated learning-based electricity consumption anomaly detection method described in this invention, the parameters uploaded after local model training include the locally trained model parameters.

[0026] Anomaly detection performance metrics for the local validation set;

[0027] The mean and covariance matrix of the encoder output features.

[0028] As a preferred embodiment of the federated learning-based electricity consumption anomaly detection method described in this invention, the aggregated global model includes:

[0029] Calculate performance weights based on client performance metrics;

[0030] The kernel function measures the difference between the client feature distribution and the global distribution, generating distribution weights.

[0031] The ratio of the two types of weights is dynamically adjusted according to the training rounds, and the final fusion weights are calculated.

[0032] Update the global feature distribution statistics by weighting the client model parameters according to the fusion weights.

[0033] The beneficial effects of the preferred technical solution in the embodiments of the present invention are as follows: by using both performance weights (reflecting model accuracy) and distribution weights (kernel function to calculate KL divergence), the model performance is guaranteed while the data distribution matching degree is considered, thus solving the aggregation bias problem under non-independent and identically distributed data; the dynamic weight adjustment strategy balances the need to focus on performance in the early stage and on distribution convergence in the later stage; the feature statistics update mechanism realizes the dynamic calibration of the global distribution, enabling the model to adapt to the distribution shift of new clients.

[0034] Another objective of this invention is to provide a power consumption anomaly detection system based on federated learning.

[0035] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a power consumption anomaly detection system based on federated learning, comprising: a data processing module, a client processing module, and a server operation module;

[0036] The data processing module collects local electricity consumption data and performs preprocessing.

[0037] The client processing module constructs a dual-channel autoencoder to extract and reconstruct features from the preprocessed data. The client calculates anomaly scores based on a dynamic weighted fusion mechanism, determines anomalies, and performs local model training.

[0038] The server operation module allows clients to upload parameters from their local model training to the server. The server then calculates the dynamic fusion weights for each client, aggregates the global model, updates the global feature distribution, and broadcasts the global model and feature distribution parameters to each client.

[0039] The present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, characterized in that the processor executes the computer program to implement the steps of the described method for detecting abnormal electricity consumption based on federated learning.

[0040] The present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that, when the computer program is executed by a processor, it implements the steps of the power consumption anomaly detection method based on federated learning.

[0041] The beneficial effects of this invention are as follows: At the client-side level, this invention proposes an innovative design of a dual-channel temporal autoencoder (Dual-AE): by cascading dilated causal convolution with gated recurrent units (GRUs), the timing characteristics of electricity consumption are encoded from the perspectives of local fluctuations and long-term trends, respectively. Simultaneously, a dynamically weighted anomaly scoring module is introduced (e.g., sliding weighted fusion of reconstruction error and prediction bias), which can accurately capture hidden anomalies such as electricity theft and equipment malfunctions.

[0042] This invention employs a dynamic dual-weighted federated aggregation mechanism on the server side, dynamically adjusting aggregation weights based on the alignment between the client model's performance and feature distribution (calculated through MMD distance). Initially, the focus is on knowledge transfer in high-precision regions to accelerate model convergence; later, distribution similarity optimization is strengthened to suppress model bias. This enables collaborative mining and adaptive generalization of cross-regional anomaly patterns without sharing original data. Attached Figure Description

[0043] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0044] Figure 1 The above is a flowchart of an overall method for detecting abnormal electricity consumption based on federated learning, provided as an embodiment of the present invention. Detailed Implementation

[0045] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of the present invention.

[0046] Example 1, referring to Figure 1 This is one embodiment of the present invention, which provides a method for detecting abnormal electricity consumption based on federated learning, including:

[0047] S100: Collect local power consumption data and perform preprocessing.

[0048] S200: The client constructs a dual-channel autoencoder to extract and reconstruct features from the preprocessed data. The client calculates anomaly scores based on a dynamic weighted fusion mechanism, determines anomalies, and executes local model training.

[0049] S300: The client uploads the parameters of the local model after training to the server. The server calculates the dynamic fusion weights of all clients, aggregates the global model, and updates the global feature distribution.

[0050] The server broadcasts the global model and feature distribution parameters to each client.

[0051] It should be noted that the stability and user structure distribution of electricity consumption data vary in different regions. Some regions have a lower incidence of electricity consumption anomalies due to their simple user structure, while other regions have a higher incidence of electricity consumption anomalies due to their complex user distribution and diverse industrial structure. Furthermore, electricity consumption data from different regions exhibits heterogeneity. Therefore, the lack of effective methods to build robust models to achieve both data privacy protection and effective anomaly detection is a key issue in smart grid research.

[0052] Therefore, to address the aforementioned problems, a Federated Dynamic Adaptive Anomaly Detection Framework (FedDAE) is proposed through steps S100-S300 to construct a solution that balances privacy protection and heterogeneous data collaboration. At the client level, it enables accurate detection of covert anomalies such as electricity theft and equipment malfunctions; at the server level, it achieves collaborative mining and adaptive generalization of cross-regional anomaly patterns without requiring the sharing of original data.

[0053] Example 2, refer to Figure 1 This is one embodiment of the present invention. Based on the above embodiment, a method for detecting abnormal electricity consumption based on federated learning is provided.

[0054] This invention proposes a Federated Dynamic Adaptive Anomaly Detection Framework (FedDAE) to construct a solution that balances privacy protection and heterogeneous data collaboration.

[0055] In this embodiment of the invention, step S100 involves collecting local electricity consumption data and performing preprocessing, including the following steps S101-S104:

[0056] In an embodiment of the present invention, S101, data cleaning of local electricity consumption data includes the following steps A1-A2:

[0057] A1. Eliminate instantaneous spike noise (such as ±10% sudden changes caused by sensor failure) based on the sliding window standard deviation method. Calculate the data standard deviation with a sliding window of 15 minutes.

[0058] A2. If the deviation of a data point exceeds the threshold (e.g., mean ± 3 times standard deviation), it is considered noise and is removed or corrected.

[0059] In an optional embodiment, data cleaning in S101 can be a sliding window median filtering method. A sliding window is defined for the local electricity consumption data, with the window size consistent with the embodiments of the present invention. The median of all data points is calculated within each window, and for each data point within the window, its absolute deviation from the median is calculated. If the deviation exceeds a preset threshold, it is considered noise and is removed or corrected.

[0060] In another optional embodiment, the data cleaning in S101 can be a sliding window Hampel filter. Also using a sliding window, the power consumption data sequence is covered. Within each window, the median and median absolute deviation of the data points are calculated. A dynamic threshold is set based on the median and median absolute deviation. If a data point exceeds the threshold, it is considered noise and is removed or corrected.

[0061] In an embodiment of the present invention, S102, data completion of missing data, includes the following steps B1-B2:

[0062] B1. Use the weighted interpolation method of adjacent time periods to fill in the missing data, and perform linear interpolation for the three hours before and after the missing data.

[0063] B2. For missing points, use weighted average interpolation based on time-proximity data to fill in the missing values;

[0064] In an optional embodiment, data completion for missing data in S102 can be performed using spline interpolation. This involves identifying missing points in the electricity consumption data, determining the missing time period, selecting data from neighboring time periods centered on the missing point, using a spline interpolation algorithm to fit the neighboring data points, generating a smooth and continuous curve, and then performing a fitting calculation to determine the missing point value.

[0065] In another optional embodiment, data completion for missing data in S102 can be performed using exponential smoothing based on time series forecasting, extracting preceding time period data, and using an exponential smoothing model to predict the value of the missing point based on the preceding data.

[0066] S103. Standardize the local electricity consumption data and extract time-series features;

[0067] Convert multi-source electricity meter data into a unified unit, and convert multi-source electricity meter data into standard units such as kW·h / kVA;

[0068] Specifically, data standardization and feature extraction are performed, and Min-Max normalization is carried out according to the user's historical electricity consumption to eliminate individual differences in electricity consumption scale.

[0069] S104. Generate temporal feature slices with context labels by associating with the external environment.

[0070] Specifically, statistical features such as load factor, peak-to-valley difference, and fluctuation coefficient are extracted from daily / weekly / monthly data and embedded with external labels such as temperature and holidays to assist in pattern recognition and context labeling.

[0071] Specifically, the initial screening of anomalies and data slicing are carried out, and threshold pre-filtering is performed by setting a power over-limit baseline according to the industry type (e.g., triggering a flag when the instantaneous power of a commercial user exceeds 120% of the contract capacity).

[0072] Time segments are generated in 15-minute increments to adapt to the input requirements of models such as LSTM / GRU by slicing time windows.

[0073] The system records operating conditions synchronously with equipment log data such as the status of the metering cabinet door and abnormal TA circuits.

[0074] In this embodiment of the invention, in S200, the client constructs a dual-channel autoencoder to extract and reconstruct features from the preprocessed data. The client calculates anomaly scores based on a dynamic weighted fusion mechanism, determines anomalies, and performs local model training, including the following steps S201-S206:

[0075] S201. The client input layer is as follows: the client's local power consumption data is organized in the form of a sliding window with a window length of T = 96 (15-minute granularity, covering 24 hours). The feature dimensions are power, voltage, and current channels.

[0076] S202. Employ segmented normalization for each user's historical data x. norm Calculate the mean μ user and standard deviation σ user :

[0077]

[0078] Where, x norm These are the normalized data; in this invention, μ is 0 and σ is 1.

[0079] S203. Constructing a dual-channel self-encoder includes building a client infrastructure, organizing the client's local power consumption data in the form of a sliding window, and normalizing the preprocessed data again.

[0080] The dual-channel autoencoder includes a first branch, a second branch, and a third stage;

[0081] The first branch is the dilated causal convolution branch, which extracts local temporal features through causal convolution with an increasing dilation factor.

[0082] Specifically, the structure of the dilated causal convolution branch is configured as a stack of 3 dilated causal convolutions with dilation factors of d = {1, 2, 4}, a kernel size of k = 3, and 64 channels C, expressed as:

[0083]

[0084] Where l is the layer index, d is the inflation factor, and x (l-1) The output of the previous layer is H, where H is the feature, ReLU is the activation function, and W is the function of the previous layer. (l) (i) The i-th weight parameter of the l-th convolutional kernel, where x is the input sequence, b (l) td×i represents the bias learning parameters of the l-th layer, i is the variable index, and td×i is the extraction position.

[0085] The second branch is the temporal feature extraction branch, which extracts global temporal features through a bidirectional recurrent neural network;

[0086] Specifically, the temporal feature extraction branch structure is configured as a bidirectional GRU layer with H=64 hidden units, and the output is the hidden state at the last time step, expressed as:

[0087] h GRU c GRU =GRU(x norm W GRU )

[0088] Among them, h GRU c GRU It is the hidden state of the feature network at the last moment, x norm W represents the normalized input. GRU This represents the set of weight parameters for the GRU.

[0089] The third stage is the feature fusion stage, which concatenates the features output from the two branches and reconstructs the input sequence through a fully connected layer.

[0090] Specifically, spatiotemporal feature splicing combines the local features h of the DCC branch. dcc Global features h of GRU branches GRU The spliced ​​feature h is obtained by splicing. fuse :

[0091] h fuse =Concat(h dcc [:,-1,:],h GRU )

[0092] Here, `Concat` is a concatenation function that joins the vectors at the positions of the first and second parameters, where `h` represents all elements in the current dimension. GRU The hidden state at the last moment of the GRU branch output.

[0093] Dimensionality Reduction and Reconstruction: Generating Reconstruction Sequences through Fully Connected Layers

[0094]

[0095] Among them, W dec W is the weight matrix of another fully connected layer. fuse Both are weight matrices of fully connected layers, b fuse The bias vector of the fully connected layer, b dec This is the bias vector for the reconstruction layer.

[0096] S204. Calculate the mean square error (MSE) of the input sequence and the reconstructed input sequence as the reconstruction error: Calculate the MSE of the input and the reconstructed output.

[0097]

[0098] Where T is the length of the time series, e recon It is a reconstruction error.

[0099] The hidden states of branches are extracted using temporal features to predict the power at the next time step. The mean absolute error (MAE) between the predicted and actual values ​​within the sliding window is calculated. In other words, the hidden states of the GRU are used to predict the power at the next time step, and the MAE between the predicted and actual values ​​within the sliding window is calculated.

[0100]

[0101] Among them, e pred The prediction error is represented by t, where t is the index of the time step, and W is the value of W. pred The weights used for prediction, h GRU,t Let be the hidden state in the GRU branch at time step t;

[0102] The fusion weights of the two types of errors are dynamically adjusted based on the recent error distribution to generate a comprehensive anomaly score. Specifically, the sliding window statistics are as follows: based on the error distribution of the most recent W=100 samples, the weight α is dynamically calculated.

[0103]

[0104] Where σ recon and σ pred These are the standard deviations of the reconstruction error and the prediction error, respectively, μ. pred This represents the mean of the prediction error.

[0105] Anomaly scoring fusion:

[0106] s t =α·e recon,t +(1-α)·e pred,t

[0107] Among them, s t For the comprehensive anomaly score at time step t, e recon,t The reconstruction error at time step t is obtained from the reconstruction branch described above; e pred,t The prediction error at time step t is obtained from the prediction branch;

[0108] When s t >μ s +3σ s When judged as abnormal (μ) s σ s (This refers to the historical score mean and standard deviation).

[0109] S205. A multi-task loss function is adopted to jointly optimize the reconstruction loss and the prediction loss, and a weight decay regularization term is introduced. The joint optimization objective is:

[0110] L=λL recon +(1-λ)L pred +η||W|| 2

[0111] Where L is the total loss function of the joint optimization objective, and λ is the weight of the reconstruction loss. recon Reconstruction loss, L pred To predict the loss, η is the weight decay coefficient (regularization coefficient), ||W|| 2 It is the squared L2 norm of all weight parameters in the model (i.e., the weight decay term).

[0112] Where λ = 0.7, η = 1e -4 Each sub-loss is defined as:

[0113]

[0114] S206. Using federated local training parameters and the RAdam optimizer, the initial learning rate lr = 3e -4 Weight decay 1e -5 Local batch size B = 32, maximum number of training rounds E local =20, adopting an early stopping mechanism, training is terminated when the validation set loss does not decrease for 5 consecutive rounds.

[0115] In summary, at the client level, this invention innovatively designs a dual-channel time-series autoencoder (Dual-AE): through a cascaded structure of dilated causal convolution and gated recurrent units (GRU), it encodes the time-series characteristics of electricity consumption from the perspectives of local fluctuations and long-term trends, respectively. Furthermore, it introduces a dynamically weighted anomaly scoring module (such as sliding weighted fusion of reconstruction error and prediction deviation) to achieve accurate capture of hidden anomalies such as electricity theft and equipment failure.

[0116] In this embodiment of the invention, in step S300, the client uploads the parameters of the locally trained model to the server; the server calculates the dynamic fusion weights of each client, aggregates the global model, and updates the global feature distribution; the server broadcasts the global model and feature distribution parameters to each client, including the following steps S301-S303:

[0117] In an embodiment of the present invention, S301, the client uploads the parameters of the locally trained model to the server. The information that the client needs to upload to the server in each round of federated training is as follows:

[0118] Information 1: The model parameters are the weights θ of the locally trained dual-channel autoencoder. k .

[0119] Information 2: Verification performance metrics, namely the F1-score on the local validation set. k This is used to measure the model's ability to identify anomalous samples.

[0120] Information 3: Feature distribution statistics, i.e., the temporal feature matrix H output by the encoder. k mean μ k Covariance Σ k , used to calculate distribution alignment.

[0121] In an optional embodiment, the parameters trained on the local model can be uploaded only, such as the weight parameters of the last fully connected layer in the dual-channel autoencoder, to reduce communication overhead; the F1-score of the local validation set can be retained, but precision and recall can be added as auxiliary indicators; the mean and median of the feature matrix output by the encoder can be uploaded to reduce computational complexity; however, this is only suitable for situations with a single scenario.

[0122] In another alternative embodiment, the parameters trained on the local model can also be uploaded in a hierarchical manner, prioritizing the upload of the convolution kernel parameters of the dilated causal convolution branch, and uploading the temporal branch parameters every two rounds; a weighted F1 score is used instead, with the validation set loss value attached; only the sliding window mean of the feature matrix is ​​uploaded; however, this is only suitable for environments with strictly limited communication resources.

[0123] S302. Calculate the relative contribution weight based on the client-side verification F1-score:

[0124]

[0125] Where β is a temperature coefficient (default β = 2), used to amplify the weight differences of high-precision clients; The performance weight of the kth client, f k This is the F1 score of the kth client.

[0126] The similarity between the client-side feature distribution and the global distribution is measured using the maximum mean difference (MMD).

[0127] Global statistic estimation:

[0128]

[0129] Where, μ g The global mean vector is the mean μ of all clients. i The average of the covariances Σg is the global covariance matrix, which is the average of the covariances Σi of all clients, and N is the number of clients.

[0130] This is the temporal feature matrix H. k mean μ k Covariance Σ k Ball average

[0131] MMD distance calculation uses the kernel function K (Gaussian kernel) to calculate the difference between the client and the global distribution:

[0132]

[0133] Where K represents the kernel function (using a Gaussian kernel function), n represents the number of samples, and MMD k h represents the MMD distance for the k-th client. A smaller value indicates a more similar client feature distribution to the global distribution. i h j H represents the feature samples from the i-th and j-th clients, derived from the temporal feature matrix H local to the client. k The i and j rows, where i and j are variable indices; Represents a global virtual sample, n gThis indicates the number of global virtual samples.

[0134] Normalized weights

[0135]

[0136] Where γ is the scaling factor (default γ = 5), the smaller the MMD, the greater the weight.

[0137] Adjust the weight ratio of the two classes according to the training round t:

[0138] λ(t)=λ max -(λ max -λ min )·(t / T max )

[0139] Where λ(t) is a time-dependent mixing parameter used to adjust the ratio of the two classes of weights at training epoch t. max Let λ(t) be the maximum value, and λ min Let λ(t) be the minimum value. max =0.8, λ min =0.2, T max Total number of training rounds;

[0140] Calculate the final fusion weights:

[0141]

[0142] Among them, w (k) The final aggregate weight for client k. For client k, use performance-based weights;

[0143] In an embodiment of the present invention, S303, which aggregates the global model and updates the global feature distribution, includes the following steps C1-C2:

[0144] C1. Parameter Collection: Receives {θ} uploaded by each client. k ,f k ,μ k ,Σ k};

[0145] C2. Weight Calculation: Calculate the weight of all clients. and

[0146] C3. Calculate the fusion weight w based on the current round t. (k) ;

[0147] C4. Model Aggregation:

[0148]

[0149] in, For the updated global model parameters, For client k, the local model parameters in round n;

[0150] C5. Update the global feature distribution statistic: adjust μ g , Σ g Broadcast to all clients for use as feature alignment regularization terms in the next round of local training:

[0151] L arg =KL(N(μ) k ,Σ k ) / / N(μ g ,Σ g ))

[0152] Among them, L arg The loss is the feature alignment regularization loss, and KL is the Kullback-Leibler divergence.

[0153] In an optional embodiment, the aggregation of the global model in S303 can be a dynamic weighted aggregation of hierarchical contributions. The server receives model parameters, validation set accuracy, and feature statistics uploaded by each client. Based on the accuracy, the clients are divided into three groups: high, medium, and low, and each group is assigned a basic weight. The cosine similarity between the client feature distribution and the global distribution is calculated. For clients with similarity below a threshold, the weights are multiplied by a penalty coefficient of 0.9. After normalizing the weights of clients in the same group, the model parameters are averaged according to the weights. The aggregated model and the mean / variance of global features are then broadcast to the clients. However, this method is only suitable for scenarios where client performance differences are significant and the distribution is relatively stable. It is weak in fine-grained weight allocation and distribution alignment.

[0154] In another optional embodiment, the aggregation of the global model in S303 can also be a progressive aggregation based on a sliding window. The server receives the client's model parameters and the loss reduction rate of the most recent 5 rounds of local training, calculates the sliding window average of the client's loss reduction rate, assigns linearly increasing weights to clients with a reduction rate higher than the average, and keeps the rest at 1.0. The historical weights are smoothed by a sliding weighted average, and the aggregation model and the median of global features are broadcast to reduce the impact of outliers. However, this is only suitable for slowly changing power consumption patterns, but may not be sufficient for dynamic anomaly detection tasks.

[0155] In summary, this invention proposes a Federated Dynamic Adaptive Anomaly Detection Framework (FedDAE) to construct a solution that balances privacy protection and heterogeneous data collaboration. On the server side, a dynamic dual-weighted federated aggregation mechanism is designed, dynamically adjusting the aggregation weights based on client model performance and feature distribution alignment (MMD distance calculation). Initially, it emphasizes knowledge transfer in high-precision regions to accelerate convergence, and later strengthens distribution similarity optimization to suppress model bias. Thus, it achieves collaborative mining and adaptive generalization of cross-regional anomaly patterns without sharing original data.

[0156] Example 3 is an embodiment of the present invention, which provides a power consumption anomaly detection system based on federated learning, including: a data processing module, a client processing module, and a server running module;

[0157] The data processing module collects local electricity consumption data and performs preprocessing.

[0158] The client-side processing module constructs a dual-channel autoencoder to extract and reconstruct features from the preprocessed data. The client calculates anomaly scores based on a dynamic weighted fusion mechanism, identifies anomalies, and performs local model training.

[0159] The server runs the module. The client uploads the parameters of the local model after training to the server. The server calculates the dynamic fusion weights of each client, aggregates the global model and updates the global feature distribution. The server then broadcasts the global model and feature distribution parameters to each client.

[0160] This embodiment also provides an electronic device applicable to a federated learning-based power consumption anomaly detection method, comprising: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the federated learning-based power consumption anomaly detection method proposed in the above embodiment.

[0161] This embodiment also provides a storage medium storing a computer program that, when executed by a processor, implements a federated learning-based power consumption anomaly detection method as proposed in the above embodiments.

[0162] The storage medium proposed in this embodiment and the method for detecting abnormal power consumption based on federated learning proposed in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.

[0163] Based on the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.

[0164] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A power consumption anomaly detection method based on federated learning, characterized in that: The method comprises the following steps: Collecting local power consumption data and preprocessing; The client constructs a double-channel autoencoder to extract and reconstruct features from the preprocessed data, calculates an anomaly score based on a dynamic weighted fusion mechanism, determines the anomaly, and performs local model training; The client uploads the parameters of the trained local model to the server, the server calculates the dynamic fusion weight of all clients, aggregates the global model, and updates the global feature distribution; The server broadcasts the global model and the global feature distribution parameters to each client.

2. The power consumption anomaly detection method based on federated learning according to claim 1, wherein: The preprocessing comprises: Data cleaning and data completion for missing data on the local power consumption data; Data standardization and time series feature extraction on the local power consumption data; Generating time series feature slices with context labels by associating external environments. 3.The power consumption anomaly detection method based on federated learning of claim 2, wherein: The double-channel autoencoder comprises a client infrastructure, the client local power consumption data is organized in a sliding window form, and the preprocessed data is normalized again; The double-channel autoencoder comprises a first branch, a second branch, and a third stage; Local time series features are extracted through the first branch; Global time series features are extracted through the second branch; The features output by the two branches are spliced and reconstructed through a fully connected layer to input the sequence. 4.The power consumption anomaly detection method based on federated learning of claim 3, wherein: The calculation of the anomaly score comprises: The mean square error between the input sequence and the reconstructed input sequence is calculated as the reconstruction error; The hidden state of the time series feature extraction branch is used to predict the next time power; The average absolute error between the predicted value and the actual value in the sliding window is calculated; 5. The power consumption anomaly detection method based on federated learning according to claim 4, wherein: The fusion weight of the reconstruction error and the average absolute error is dynamically adjusted to generate a comprehensive anomaly score. The local model training comprises:

6. The electricity consumption anomaly detection method based on federated learning according to claim 5, wherein: A multi-task loss function is used to jointly optimize the reconstruction loss and the prediction loss, and a weight decay regularization term is introduced; An early stopping mechanism is used to control the training rounds during the training process. The uploaded parameters of the trained local model comprise:

7. The power consumption anomaly detection method based on federated learning according to claim 6, wherein: The model parameters after local training; The anomaly detection performance indicators of the local validation set; The mean and covariance matrix of the encoder output features. The aggregation of the global model comprises: Performance weights are calculated based on the performance indicators of the clients; 8. A power consumption anomaly detection system based on federated learning, applying a power consumption anomaly detection method based on federated learning according to any one of claims 1-7, characterized in that, Distribution weights are generated by measuring the difference between the client feature distribution and the global distribution through a kernel function; The proportion of the two types of weights is dynamically adjusted according to the training rounds to calculate the final fusion weight; The global feature distribution statistics are updated by weighted averaging the client model parameters according to the fusion weight. The method comprises the following steps: A data processing module, a client processing module, and a server running module; 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The data processing module collects local power consumption data and preprocesses it; The client processing module constructs a double-channel autoencoder to extract and reconstruct features from the preprocessed data, calculates an anomaly score based on a dynamic weighted fusion mechanism, determines the anomaly, and performs local model training; The server running module uploads the parameters of the trained local model to the server, the server calculates the dynamic fusion weight of all clients, aggregates the global model, and updates the global feature distribution, and the server broadcasts the global model and the feature distribution parameters to each client. The processor executes the computer program to realize the steps of the power consumption anomaly detection method based on federated learning in any one of claims 1 to 7.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by a processor, implements the steps of the federated learning-based power consumption anomaly detection method of any one of claims 1 to 7.