Power consumption data anomaly detection method and device based on Bayesian memory module enhancement
By introducing a Bayesian memory module enhancement method into the detection of anomalies in electricity consumption data, a feature extraction framework constrained by the joint reconstruction-regression task is constructed, which solves the problems of insufficient robustness and generalization ability in the existing technology and achieves efficient anomaly detection in complex scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-27
- Publication Date
- 2026-03-13
AI Technical Summary
Existing methods for detecting anomalies in electricity consumption data struggle to effectively capture the contextual dependencies and complex nonlinear relationships of time series data when faced with complex and ever-changing real-world scenarios. Furthermore, they are unable to learn long-term dependencies that extend beyond the time window size, resulting in poor robustness and generalization ability. In particular, the model suffers from severe unexpected generalization problems when contaminated data is present.
We employ a Bayesian memory module-based enhancement method to construct a feature extraction framework constrained by the reconstruction-regression joint task by inserting positional information within and between windows. By combining the reconstruction autoencoder and the Bayesian memory module, we suppress the influence of contaminated data, extract temporal features, and perform multi-objective optimization.
The model's robustness and generalization ability to electricity consumption data have been improved, enabling it to accurately extract normal patterns and long-term dependencies in time series data, effectively suppress interference from polluting data, and achieve more efficient anomaly detection.
Smart Images

Figure CN121659145A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electricity consumption data anomaly detection technology, and more specifically, to a method and apparatus for electricity consumption data anomaly detection based on Bayesian memory module enhancement. Background Technology
[0002] Electricity data is a key indicator for understanding the energy industry and macroeconomic operations, playing a central role in economic situation assessment and policy effectiveness evaluation. Currently, the company's electricity information collection system has achieved full access to smart meters of all electricity users within its operating area. These smart terminals, distributed at the user end, can collect electricity consumption and data at a fine-grained time level, such as daily or hourly. As the company's sole source of user electricity information, this system has accumulated a massive electricity user database over the long term, providing crucial support for precise analysis of user energy consumption characteristics, real-time monitoring of grid operation status, and serving national-level electricity data research. However, facing the demands of processing massive amounts of electricity data, coupled with the stringent timeliness requirements in specialized scenarios, current anomaly screening still primarily relies on fixed threshold judgments set by experts based on experience, and has not yet developed an intelligent identification solution with strong anti-interference capabilities and sensitive anomaly response.
[0003] In electricity consumption time series data, anomalies are often sparsely distributed and mixed within a large amount of normal data, making accurate labeling difficult. Therefore, unsupervised methods are currently the primary approach for anomaly detection. While classic unsupervised anomaly detection methods have been applied to electricity consumption data anomaly detection, they neglect the temporal structure of time series data, failing to capture the contextual dependencies and complex nonlinear relationships within the time series. Recently, deep learning-based time series anomaly detection methods have been proposed and have demonstrated high anomaly detection capabilities. Deep learning-based time series anomaly detection methods can be broadly categorized into reconstruction-based and prediction-based methods. However, due to the inherent randomness and unpredictability of time series data, accurate prediction of future values becomes impossible when the prediction period is too long. Therefore, current mainstream deep learning-based anomaly detection methods primarily focus on reconstruction-based methods.
[0004] Reconstruction-based methods heavily rely on the assumption that training data contains only normal data, using the larger reconstruction error of outlier data compared to normal data to identify positive anomalies. However, due to the susceptibility of electricity data collection to interference, training data may be corrupted by unknown outliers or noise, rendering the normality assumptions of current mainstream reconstruction-based anomaly detection methods inapplicable in the real world. While existing electricity data time series anomaly detection methods suppress the impact of contaminated data on model learning through model-level or data-level methods, typically by storing representative normal pattern vectors for anomaly detection or data reconstruction, these methods often exhibit poor robustness and generalization ability in complex and variable real-world scenarios. Existing methods often use fixed, rigid vector forms to represent the "normal" state, ignoring the inherent uncertainty and dynamic changes inherent in normal patterns. In practical applications, especially in complex industrial systems or environmental monitoring scenarios, the collected time series data (such as sensor signals) usually exhibit reasonable fluctuations within a certain range. These fluctuations are not anomalies but natural changes caused by various factors during system operation. Traditional methods model normal patterns using fixed vectors, which is essentially a dimensionality reduction and simplification of the dynamic characteristics of time series, making it difficult to fully characterize the multimodal distribution and potential changing trends of normal states.
[0005] Furthermore, most existing time series anomaly detection methods typically extract features within a fixed-length time window, failing to learn long-term dependencies that extend beyond the window size. This limitation restricts the model's extraction of contextual features and anomaly detection to a single fixed-length time period, preventing the extraction of complete contextual information (such as long-distance dependencies beyond the segment length and semantic consistency between adjacent segments), thus impacting anomaly detection performance. While simply increasing the segment length or storing previous window information sequentially are possible solutions, they are usually impractical due to resource constraints. Explicitly extracting dependencies between consecutive windows involves setting an additional cache matrix (memory module) to cache information from previous time windows and requires sequential window input. Larger caches are typically used for better results, leading to additional space consumption. Sequential input also presents problems such as unidirectional gradient updates, slow convergence, and potential overfitting of the latter half of the data.
[0006] The normality assumption of current mainstream reconstruction-based anomaly detection methods does not always apply in the real world. When the training data is contaminated, reconstruction-based anomaly detection methods face the problem of unexpected generalization of anomalies by the model, leading to a lack of distinction between positive and negative anomalies, thus affecting anomaly detection performance. Existing anomaly detection methods for handling contaminated training datasets mainly focus on contamination suppression at the model and training levels. Although these methods suppress the model's learning from contaminated data to some extent and improve model robustness, the following issues still limit further performance improvements:
[0007] 1) Existing time series anomaly detection methods typically extract features within a fixed-length time window, which fails to learn long-term dependencies that extend beyond the time window size.
[0008] 2) Existing model-level methods for suppressing contamination using memory modules typically achieve anomaly detection or data reconstruction by storing representative normal pattern vectors. However, these methods often exhibit poor robustness and generalization ability when faced with complex and ever-changing real-world scenarios. Summary of the Invention
[0009] To address the above problems, this invention proposes a method for detecting abnormal power consumption data based on a Bayesian memory module, comprising:
[0010] For the raw electricity consumption data, position information within and between windows is inserted to obtain sample data;
[0011] Based on the Bayesian memory module, a feature extraction framework constrained by the joint reconstruction-regression task is constructed according to the sample data.
[0012] An anomaly detection method for electricity consumption data is developed based on a feature extraction framework constrained by a joint reconstruction-regression task.
[0013] Optional, inter-window position information insertion includes:
[0014] For the time-series data X in the original electricity consumption data, a data normalization method is used to perform global encoding on the time-series data X, wherein the global position encoding PE at the pos position is... G for:
[0015]
[0016] PE G (pos,2i+1)=cos(pos / 10000 2i / F )
[0017] Where i represents the dimension index of the location encoding, and F represents the number of features in the time series;
[0018] Add the global code and the time series data X together so that the data contains absolute location information;
[0019] A fixed-length sample W is obtained through a sliding window. LW ={W L1 W L2 ,…,W Lt}, and in the process, obtain the position label of each window;
[0020] RevIN is used to normalize the data within the window, resulting in the normalized time window W′. LW ={W′ L1 ,W′ L2 ,…,W′ Lt The formula is as follows:
[0021]
[0022] Wherein, μ(W i LW ) represents the mean of time values within the i-th time window, σ(W) i LW ) represents the variance of time values within the i-th time window, and γ and β represent the learnable affine transformation parameters.
[0023] Optional, in-window position information insertion, including:
[0024] After obtaining the normalized window, the window-normalized data is used to inject the window's position information, including:
[0025] Calculation window The Fast Fourier Transform (DFT) is used to obtain the spectrum of this time window. Given a sequence x[n] containing n time points, the DFT maps it to a complex sequence in the frequency domain using the following formula:
[0026]
[0027] Where X[k] represents the transformed frequency domain representation, j represents the imaginary unit, and n and k represent the indices in the time domain and frequency domain, respectively;
[0028] The formula for calculating X[k] represents multiplying each sample in the original signal sequence x[n] by the corresponding complex exponential basis. Summing all products yields a specific frequency component X[k] in the frequency domain. The k frequencies with the highest power are extracted based on their amplitudes at different frequencies. The frequencies with the highest and lowest power are then selected as the base wavelength λ. max and λ min The wavelength parameters covering the main frequency range are generated by setting a geometric sequence. The calculation formula is as follows:
[0029]
[0030] Where i represents the dimension index of the location encoding, F represents the number of features in the time series, and λ i This represents the wavelength corresponding to the i-th position index;
[0031] The position code within the window is generated using wavelength parameters through sine and cosine functions, calculated as follows:
[0032]
[0033] Among them, PE W The window position code representing the pos position;
[0034] The window-normalized data and the timestamp encoding are summed to obtain samples for location information and feature extraction. The calculation formula is as follows:
[0035]
[0036] Where α represents the learnable weight parameter, and ⊙ represents the Hadamard product;
[0037] After completing the insertion of position information within and between windows, the raw data was processed to obtain two sets of time window data with the same window length, one set W G Normalization is performed using global statistical features, for a set of samples Normalization is performed using statistical features within the window, and includes positional information within and between windows.
[0038] Optionally, a feature extraction framework constrained by the joint reconstruction-regression task can be constructed, including:
[0039] Window normalization, window reconstruction, and addition of regression tasks.
[0040] Optional, window normalization and window reconstruction, including:
[0041] For samples after location information insertion A reconstructed autoencoder based on a location memory module is used to extract the temporal features and location information stored therein while suppressing the impact of contaminated data on model training.
[0042] Sample An encoder consisting of stacked GRU layers extracts the temporal features and location information of the samples to obtain the latent variable z. P The calculation formula is as follows:
[0043]
[0044] Set the location memory module to store the latent variable z. P ;
[0045] The location memory matrix is a learnable matrix. H represents the size of the memory matrix, K represents the feature dimension of each typical pattern in the memory matrix, and m j This represents the j-th memory feature in the memory module;
[0046] The time-domain latent variable z i Treating query q as a key, the position memory matrix is used as the key, and the similarity Sim(q,m) between it and the feature vector in each memory matrix is calculated. j The calculation formula is as follows:
[0047]
[0048] Where T represents the transpose of the matrix;
[0049] The obtained similarity matrix is normalized to obtain the global memory score matrix, and the memory matrix is weighted by the score matrix to obtain the reconstructed latent variables. The calculation formula is as follows:
[0050]
[0051] The momentum update method updates the memory items in the display update memory. The momentum encoder adopts a non-linear mapping structure, and the calculation formula is as follows:
[0052]
[0053] in, It is the feature encoded by the momentum encoder, W M1 W M2 and b M1 b M2 These represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively. Indicates the momentum coefficient;
[0054] The latent variables are fed into the decoder and the original input is reconstructed through denormalization. And the reconstruction loss L of the normalized window is calculated. G The calculation formula is as follows:
[0055]
[0056] Wherein, μ(W L ) represents the mean of the time window, σ(W) L ) represents the variance of the time window, and N represents the number of samples.
[0057] Optional, window normalization and window reconstruction, including:
[0058] For globally normalized sample W G The reconstructed autoencoder based on the Bayesian feature memory module, by fully integrating global-window position information and temporal features, accurately extracts normal temporal patterns while suppressing the influence of contaminated data, and obtains the query code z for querying position information. q The formula is as follows:
[0059] z G =GRUs(embadding(W G ))
[0060] z q =W2(ReLU(W1(z) G )+b1))+b2
[0061] Where W1, W2 and b1, b2 represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively;
[0062] The query code is used as the query of the location memory module. Its relevance is calculated with the memory vector in the location memory bank, and the query vector is reconstructed by a weighted combination of the memory vectors.
[0063] The query code is input into the Bayesian feature memory module, which makes the feature memory vector no longer a fixed single pattern by Bayesianizing the memory vector.
[0064] The feature memory matrix M is represented using different Gaussian distributions. P =[μ F ,σ F The distribution of memory vectors in [ ], where, I represents the size of the memory matrix, d model This represents the feature dimension of each typical pattern in the memory matrix;
[0065] For query code z q Calculate its Mahalanobis distance to the feature memory matrix. and similarity weight w i The calculation formula is as follows:
[0066]
[0067] Among them, Var(z) q The variance of the input features. Let represent the mean and variance of the i-th memory term. This represents the i-th memory item in the feature memory matrix;
[0068] The weighted mean and weighted variance are calculated using the following formulas:
[0069]
[0070] A resampling strategy is used to sample the reconstructed latent variables, and a weighted sum is used to obtain the final reconstructed query vector. The calculation formula is as follows:
[0071]
[0072] Where, N s Indicates the number of resampling attempts;
[0073] A gating mechanism is set up to merge the two reconstructed query vectors, and the calculation formula is as follows:
[0074]
[0075] Where η represents the learnable weight parameters;
[0076] The fused latent variables are fed into the decoder to reconstruct the original input. The calculation formula is as follows:
[0077]
[0078] Optional, add regression tasks, including:
[0079] The labels of the time window are normalized and used as the final predicted labels. i ;
[0080] The windows and their corresponding labels are randomly shuffled and then fed into the model for learning. A mapping layer based on a non-linear activation function is set up to encode and regress the position labels of the time windows. The window normalization process is constrained by the MSE loss relative to the true location labels, making the model focus more on uncovering dependencies between windows. The loss calculation for the regression process is as follows:
[0081]
[0082] A positional contrast learning loss was designed to maximize the alignment between target similarity and feature similarity, and the calculation formula is as follows:
[0083] pos_sim i,j =|l i -l j |(i,j=1,…,B)
[0084]
[0085] Where B represents the size of the training batch, fea_sim represents the similarity between query features, and pos_sim represents the similarity between labels.
[0086] Optional feature extraction frameworks constrained by the joint reconstruction-regression task include: contamination suppression and multi-objective optimization, including:
[0087] The loss adjustment strategy uses the difference between window-normalized reconstructed samples and globally normalized reconstructed samples as the loss adjustment weight. A weight difference mapper is designed to further amplify the weight difference between normal data and potentially contaminated data. The final reconstruction loss L of the model is:
[0088]
[0089] Where N represents the number of training samples, μ represents the loss weight. Dif denoted by , where τ represents the mean of the difference between the two paths, τ represents the temperature parameter, and ⊙ represents the Hadamard product operation.
[0090] A multi-objective loss optimization module based on uncertainty weighting is used to set a learnable variance parameter. This dynamically adjusts the magnitude of each loss term. For any loss term, the adjusted loss is... The calculation formula is as follows:
[0091]
[0092] The total loss of the entire model is:
[0093]
[0094] Optional anomaly detection includes:
[0095] Based on the dual-path reconstruction difference loss adjustment framework, a comprehensive anomaly score AS is set to determine whether an anomaly occurs at a time point. The calculation formula is as follows:
[0096]
[0097] The larger the AS value, the more likely an anomaly has occurred at that point in time.
[0098] After obtaining the abnormal scores of the test set data, the final detection result is obtained by using the optimal threshold method. Samples with abnormal scores greater than the threshold are classified as abnormal samples, and samples with abnormal scores less than or equal to the threshold are classified as normal samples.
[0099] Furthermore, this invention also proposes a power consumption data anomaly detection device based on Bayesian memory module enhancement, comprising:
[0100] The window unit is used to insert position information within and between windows into the original electricity consumption data to obtain sample data;
[0101] The reconstruction unit is used to construct a feature extraction framework constrained by the joint reconstruction-regression task based on sample data, using the Bayesian memory module.
[0102] Anomaly detection unit is used to perform anomaly detection on electricity consumption data based on a feature extraction framework constrained by a joint reconstruction-regression task.
[0103] Optional, inter-window position information insertion includes:
[0104] For the time-series data X in the original electricity consumption data, a data normalization method is used to perform global encoding on the time-series data X, wherein the global position encoding PE at the pos position is... G for:
[0105]
[0106] PE G (pos,2i+1)=cos(pos / 10000 2i / F )
[0107] Where i represents the dimension index of the location encoding, and F represents the number of features in the time series;
[0108] Add the global code and the time series data X together so that the data contains absolute location information;
[0109] A fixed-length sample W is obtained through a sliding window. LW ={W L1 W L2 ,…,W Lt}, and in the process, obtain the position label of each window;
[0110] RevIN is used to normalize the data within the window, resulting in the normalized time window W′. LW ={W′ L1 ,W′ L2 ,…,W′ Lt The formula is as follows:
[0111]
[0112] Wherein, μ(W i LW ) represents the mean of time values within the i-th time window, σ(W) i LW ) represents the variance of time values within the i-th time window, and γ and β represent the learnable affine transformation parameters.
[0113] Optional, in-window position information insertion, including:
[0114] After obtaining the normalized window, the window-normalized data is used to inject the window's position information, including:
[0115] Calculation window The Fast Fourier Transform (DFT) is used to obtain the spectrum of this time window. Given a sequence x[n] containing n time points, the DFT maps it to a complex sequence in the frequency domain using the following formula:
[0116]
[0117] Where X[k] represents the transformed frequency domain representation, j represents the imaginary unit, and n and k represent the indices in the time domain and frequency domain, respectively;
[0118] The formula for calculating X[k] represents multiplying each sample in the original signal sequence x[n] by the corresponding complex exponential basis. Summing all products yields a specific frequency component X[k] in the frequency domain. The k frequencies with the highest power are extracted based on their amplitudes at different frequencies. The frequencies with the highest and lowest power are then selected as the base wavelength λ. max and λ min The wavelength parameters covering the main frequency range are generated by setting a geometric sequence. The calculation formula is as follows:
[0119]
[0120] Where i represents the dimension index of the position encoding, λ i This represents the wavelength corresponding to the i-th position index;
[0121] The position code within the window is generated using wavelength parameters through sine and cosine functions, calculated as follows:
[0122]
[0123] Among them, PE W The window position code representing the pos position;
[0124] The window-normalized data and the timestamp encoding are summed to obtain samples for location information and feature extraction. The calculation formula is as follows:
[0125]
[0126] Where α represents the learnable weight parameter, and ⊙ represents the Hadamard product;
[0127] After completing the insertion of position information within and between windows, the raw data was processed to obtain two sets of time window data with the same window length, one set W G Normalization is performed using global statistical features, for a set of samples Normalization is performed using statistical features within the window, and includes positional information within and between windows.
[0128] Optionally, a feature extraction framework constrained by the joint reconstruction-regression task can be constructed, including:
[0129] Window normalization, window reconstruction, and addition of regression tasks.
[0130] Optional, window normalization and window reconstruction, including:
[0131] For samples after location information insertion A reconstructed autoencoder based on a location memory module is used to extract the temporal features and location information stored therein while suppressing the impact of contaminated data on model training.
[0132] Sample An encoder consisting of stacked GRU layers extracts the temporal features and location information of the samples to obtain the latent variable z. P The calculation formula is as follows:
[0133]
[0134] Set the location memory module to store the latent variable z. P ;
[0135] The location memory matrix is a learnable matrix. H represents the size of the memory matrix, K represents the feature dimension of each typical pattern in the memory matrix, and m j This represents the j-th memory feature in the memory module;
[0136] The time-domain latent variable z i Treating query q as a key, the position memory matrix is used as the key, and the similarity Sim(q,m) between it and the feature vector in each memory matrix is calculated. j The calculation formula is as follows:
[0137]
[0138] Where T represents the transpose of the matrix;
[0139] The obtained similarity matrix is normalized to obtain the global memory score matrix, and the memory matrix is weighted by the score matrix to obtain the reconstructed latent variables. The calculation formula is as follows:
[0140]
[0141] The momentum update method updates the memory items in the display update memory. The momentum encoder adopts a non-linear mapping structure, and the calculation formula is as follows:
[0142]
[0143] in, It is the feature encoded by the momentum encoder, W M1 W M2 and b M1 b M2 These represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively. Indicates the momentum coefficient;
[0144] The latent variables are fed into the decoder and the original input is reconstructed through denormalization. And the reconstruction loss L of the normalized window is calculated. G The calculation formula is as follows:
[0145]
[0146] Wherein, μ(W L ) represents the mean of the time window, σ(W) L ) represents the variance of the time window, and N represents the number of samples.
[0147] Optional, window normalization and window reconstruction, including:
[0148] For globally normalized sample W G The reconstructed autoencoder based on the Bayesian feature memory module, by fully integrating global-window position information and temporal features, accurately extracts normal temporal patterns while suppressing the influence of contaminated data, and obtains the query code z for querying position information. q The formula is as follows:
[0149] z G =GRUs(embadding(W G ))
[0150] z q =W2(ReLU(W1(z) G )+b1))+b2
[0151] Where W1, W2 and b1, b2 represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively;
[0152] The query code is used as the query of the location memory module. Its relevance is calculated with the memory vector in the location memory bank, and the query vector is reconstructed by a weighted combination of the memory vectors.
[0153] The query code is input into the Bayesian feature memory module, which makes the feature memory vector no longer a fixed single pattern by Bayesianizing the memory vector.
[0154] The feature memory matrix M is represented using different Gaussian distributions. P =[μ F ,σ F The distribution of memory vectors in [ ], where, I represents the size of the memory matrix, d model This represents the feature dimension of each typical pattern in the memory matrix;
[0155] For query code z q Calculate its Mahalanobis distance to the feature memory matrix. and similarity weight w i The calculation formula is as follows:
[0156]
[0157] Among them, Var(z) q The variance of the input features. Let represent the mean and variance of the i-th memory term. This represents the i-th memory item in the feature memory matrix;
[0158] The weighted mean and weighted variance are calculated using the following formulas:
[0159]
[0160] A resampling strategy is used to sample the reconstructed latent variables, and a weighted sum is used to obtain the final reconstructed query vector. The calculation formula is as follows:
[0161]
[0162] Where, N s Indicates the number of resampling attempts;
[0163] A gating mechanism is set up to merge the two reconstructed query vectors, and the calculation formula is as follows:
[0164]
[0165] Where η represents the learnable weight parameters;
[0166] The fused latent variables are fed into the decoder to reconstruct the original input. The calculation formula is as follows:
[0167]
[0168] Optional, add regression tasks, including:
[0169] The labels of the time window are normalized and used as the final predicted labels. i ;
[0170] The windows and their corresponding labels are randomly shuffled and then fed into the model for learning. A mapping layer based on a non-linear activation function is set up to encode and regress the position labels of the time windows. The window normalization process is constrained by the MSE loss relative to the true location labels, making the model focus more on uncovering dependencies between windows. The loss calculation for the regression process is as follows:
[0171]
[0172] A positional contrast learning loss was designed to maximize the alignment between target similarity and feature similarity, and the calculation formula is as follows:
[0173] pos_sim i,j =|l i -l j |(i,j=1,…,B)
[0174]
[0175] Where B represents the size of the training batch, fea_sim represents the similarity between query features, and pos_sim represents the similarity between labels.
[0176] Optional feature extraction frameworks constrained by the joint reconstruction-regression task include: contamination suppression and multi-objective optimization, including:
[0177] The loss adjustment strategy uses the difference between window-normalized reconstructed samples and globally normalized reconstructed samples as the loss adjustment weight. A weight difference mapper is designed to further amplify the weight difference between normal data and potentially contaminated data. The final reconstruction loss L of the model is:
[0178]
[0179] Where N represents the number of training samples, μ represents the loss weight. Dif denoted by , where τ represents the mean of the difference between the two paths, τ represents the temperature parameter, and ⊙ represents the Hadamard product operation.
[0180] A multi-objective loss optimization module based on uncertainty weighting is used to set a learnable variance parameter. This dynamically adjusts the magnitude of each loss term. For any loss term, the adjusted loss is... The calculation formula is as follows:
[0181]
[0182] The total loss of the entire model is:
[0183]
[0184] Optional anomaly detection includes:
[0185] Based on the dual-path reconstruction difference loss adjustment framework, a comprehensive anomaly score AS is set to determine whether an anomaly occurs at a time point. The calculation formula is as follows:
[0186]
[0187] The larger the AS value, the more likely an anomaly has occurred at that point in time.
[0188] After obtaining the abnormal scores of the test set data, the final detection result is obtained by using the optimal threshold method. Samples with abnormal scores greater than the threshold are classified as abnormal samples, and samples with abnormal scores less than or equal to the threshold are classified as normal samples.
[0189] In another aspect, the present invention also provides a computing device, comprising: one or more processors;
[0190] A processor is used to execute one or more programs;
[0191] When the one or more programs are executed by the one or more processors, the method described above is implemented.
[0192] In another aspect, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed, implements the method described above.
[0193] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0194] This invention proposes an anomaly detection method for electricity consumption data based on Bayesian memory modules. The method includes: inserting positional information within and between windows into the original electricity consumption data to obtain sample data; constructing a feature extraction framework constrained by a reconstruction-regression joint task based on the sample data using a Bayesian memory module; and performing anomaly detection on the electricity consumption data based on the feature extraction framework constrained by the reconstruction-regression joint task. This invention introduces different Gaussian distributions to model the uncertainty of complex normal patterns and combines a reparameterized sampling strategy to generate robust time-series patterns, effectively suppressing interference from contaminated data while enhancing the model's adaptability to fluctuations in input features. Attached Figure Description
[0195] Figure 1This is a flowchart of the method of the present invention;
[0196] Figure 2 This is a schematic diagram of the method of the present invention;
[0197] Figure 3 This is a flowchart illustrating the global encoding and location tagging process of the method of the present invention;
[0198] Figure 4 This is a schematic diagram of the location memory module and the Bayesian feature memory module of the method of the present invention;
[0199] Figure 5 This is a structural diagram of the device of the present invention. Detailed Implementation
[0200] Exemplary embodiments of the invention will now be described with reference to the accompanying drawings. However, the invention may be embodied in many different forms and is not limited to the embodiments described herein. These embodiments are provided to fully and completely disclose the invention and to fully convey its scope to those skilled in the art. The terminology used in the exemplary embodiments illustrated in the drawings is not intended to limit the invention. In the drawings, the same units / elements are referred to by the same reference numerals.
[0201] Unless otherwise stated, the terms used herein (including technical terms) have their common meaning as understood by one of ordinary skill in the art. Furthermore, it is understood that terms defined in commonly used dictionaries should be understood to have a meaning consistent with the context of their relevant field, and not to be interpreted as having an idealized or overly formal meaning.
[0202] Example 1:
[0203] This invention proposes a method for detecting abnormal power consumption data based on Bayesian memory modules, such as... Figure 1 As shown, it includes:
[0204] Step 1: For the original electricity consumption data, perform position information insertion within and between windows to obtain sample data;
[0205] Step 2: Based on the Bayesian memory module, construct a feature extraction framework constrained by the joint reconstruction-regression task according to the sample data;
[0206] Step 3: Perform anomaly detection on electricity consumption data based on the feature extraction framework constrained by the joint reconstruction-regression task.
[0207] This invention proposes a Bayesian memory module-enhanced electricity data anomaly detection method (BMECD), which mainly consists of three parts: position information injection for adding information within and between windows, timestamp and temporal feature extraction, and contamination suppression and multi-task loss optimization. Figure 2 As shown, the positional information injection part within and between windows, compared to traditional time series anomaly detection methods, explicitly incorporates the positional information of the time window in the time series during feature extraction, serving as the basis for subsequent position memory modules and position label regression tasks. In the timestamp and temporal feature extraction module, the position memory module and Bayesian feature memory module are mainly used to explicitly store the global-local positional information and typical normal patterns of the time series, helping the model accurately extract the temporal patterns of the time series while suppressing the impact of contaminated data on model training. In this module, for window correlation extraction and robust anomaly detection, this invention also designs a joint reconstruction-regression task, achieving better anomaly detection results through task constraints. Due to the multiple task losses designed, this invention specifically designs a multi-objective loss optimization module based on uncertainty weighting to ensure the stability of model training. Furthermore, a training-level contamination suppression method based on loss weight adjustment is introduced. Through joint adjustment with the model-level methods of the memory module, the impact of contaminated data on model training is effectively suppressed, achieving robust and accurate anomaly detection.
[0208] Insertion of position information within and between windows:
[0209] Insertion of inter-window position information, including:
[0210] For the collected time-series data X, this invention first designs two different data normalization methods to match the location information injection process. One method is consistent with the usual approach: calculating the mean and variance of the overall training data to perform z-score normalization on the training data, and then applying the normalized data... By dividing the window into different segments, we obtain different samples W that can be used to extract temporal patterns. GW ={W G1 W G2 ,…,W Gi ,…,W Gt},in T represents the number of time points in the time window, and F represents the number of features in the time series. The normalization process is shown in the following formula:
[0211]
[0212] Where μ represents the mean of the time series and τ represents the variance of the time series.
[0213] Considering the need to inject positional information between and within windows, this invention relates to an alternative method for normalizing data within a window. Firstly, for the entire training data, this invention uses a traditional triangular encoding method to globally encode the entire time series, with the global position encoding PE at position pos. Gfor:
[0214]
[0215] PE G (pos,2i+1)=cos(pos / 10000 2i / F )
[0216] Here, i represents the dimension index of the location encoding. The global encoding and the original time series data are then added together to include absolute location information in the data. Finally, a fixed-length sample W is obtained through a sliding window. LW ={W L1 W L2 ,…,W Lt}, and in the process, obtain the position label of each window (i.e., which window it is in the entire sequence). Then, we use RevIN to normalize the data within the window, obtaining the window-normalized time window W′. LW ={W′ L1 ,W′ L2 ,…,W′ Lt The specific process formula is as follows:
[0217]
[0218]
[0219] Wherein, μ(W i LW ) represents the mean of time values within the i-th time window, σ(W) i LW ) represents the variance of time values within the i-th time window, and γ and β are learnable affine transformation parameters.
[0220] Insertion of position information within the window, including:
[0221] After obtaining the normalized window, this invention injects the windowed data with positional information within the window. Because time series in NLP are shorter and have fewer dimensions, existing cosine and sine absolute position encoding methods are not very suitable for time series. When using traditional triangular encoding to encode the time window, low-frequency dimensional position differences become too small. This is because in traditional triangular encoding, when the wavelength is much larger than the sequence length, the encoding differences between low-frequency dimensional positions are significant. This will lead to a loss of distinguishability, causing similarity between location codes and thus affecting the accuracy of location coding. As shown in the following formula:
[0222]
[0223] Here, Δpos represents the positional difference between time points. Therefore, to avoid this situation, this invention designs a frequency-domain wavelength selection-based encoding method to encode time points within each window. First, the window size is calculated... The Fast Fourier Transform (DFT) is used to obtain the spectrum of this time window. Given a sequence x[n] containing n time points, the DFT maps it to a complex sequence in the frequency domain using the following method:
[0224]
[0225] Where X[k] represents the transformed frequency domain representation, j represents the imaginary unit, and n and k represent the indices in the time and frequency domains, respectively. This formula represents multiplying each sample in the original signal sequence x[n] by the corresponding complex exponential basis. Then, sum all these products to obtain a specific frequency component X[k] in the frequency domain. Next, extract the k frequencies with the highest power based on their amplitudes at different frequencies. Then, select the maximum and minimum frequencies from these as the basis numbers λmax and λmin for the wavelengths. Finally, generate wavelength parameters covering the dominant frequency range by setting a geometric progression.
[0226]
[0227] Where i represents the dimension index of the position encoding, λ i This represents the wavelength corresponding to the i-th position index. These wavelengths are then used to generate the position code within the window using sine and cosine functions.
[0228] The specific encoding process is as follows:
[0229]
[0230] Among them, PE W This represents the window position encoding at position pos. For each window, this invention uses a learnable parameter gating mechanism to weight and merge the intra-window encoding and inter-window encoding results, which is then used as the timestamp encoding for this window, such as... Figure 3 As shown. Then, the window-normalized data and the timestamp encoding are summed to obtain samples used for location information and feature extraction. The specific formula is shown below:
[0231]
[0232] Where α represents the learnable weight parameter, and ⊙ represents the Hadamard product. After completing the insertion operations for positional information within and between windows, this invention processes the original data to obtain two sets of time window data with the same window length, one set W G Normalization is performed using global statistical features, for a set of samples Normalization is performed using statistical features within the window, and includes positional information within and between windows.
[0233] Reconstruction-Regression Joint Feature Extraction Framework:
[0234] To accurately extract intra- and inter-window temporal dependencies in time series data while suppressing the influence of contaminated training data on the model, this invention designs a joint reconstruction-regression feature extraction framework to extract time series features, such as... Figure 4 As shown. First, the main framework is divided into two tasks: reconstruction and regression. The reconstruction task uses an encoding and decoding process to reconstruct the globally normalized data and the window-normalized data. The regression task uses a mapping model to map the samples with inter-window and intra-window positional information to the positional labels of the window in the entire time series. In this process, the temporal dependencies between windows are explicitly learned.
[0235] Window normalization and window reconstruction, including:
[0236] For samples after location information insertion This invention designs a reconstructed autoencoder based on a location memory module to suppress the impact of contaminated data on model training while extracting the temporal features and location information stored therein. The samples first pass through an encoder consisting of stacked GRU layers to extract the temporal features and location information of the samples, thereby obtaining the latent variable z. P :
[0237]
[0238] The present invention then designs a location memory module to store this information. The location memory matrix is a learnable matrix. H represents the size of the memory matrix, K represents the feature dimension of each typical pattern in the memory matrix, and m j This represents the j-th memory feature in the memory module. This invention uses the time-domain latent variable z... i Treating query q as a key, the position memory matrix is used as the key, and the similarity S between it and the feature vector in each memory matrix is calculated. im (q,m j ):
[0239]
[0240] Where T represents the transpose of the matrix. The obtained similarity matrix is then normalized to obtain the global memory score matrix, and the reconstructed latent variables are obtained by weighting the memory matrix with the score matrix.
[0241]
[0242] Unlike traditional memory modules, this invention designs a momentum update method to update the memory items in the display update memory bank, ensuring the continuity of the memory item mapping. The momentum encoder adopts a non-linear mapping structure, as detailed below:
[0243]
[0244] in It is the feature encoded by the momentum encoder, W M1 W M2 and b M1 ,b M2 These represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively. This represents the momentum coefficient. The invention then feeds the latent variables into the decoder and reconstructs the original input through inverse normalization. And the reconstruction loss L of the normalized window is calculated. G :
[0245]
[0246] Where μ(W) L ) represents the mean of the time window, σ(W) L ) represents the variance of the time window, and N represents the number of samples.
[0247] Window normalization and window reconstruction, including:
[0248] For globally normalized sample W G This invention designs a reconstruction autoencoder based on a Bayesian feature memory module. By fully integrating global-window position information and temporal features, it accurately extracts normal temporal patterns while suppressing the influence of contaminated data, thereby improving the model's anomaly detection capability. First, similar to window-normalized sample reconstruction, the latent variable z is obtained through an encoder consisting of stacked GRU layers. G However, unlike other methods, a latent variable encoder is designed here to further encode the extracted latent variables, obtaining the query code z used to query location information. q .
[0249] z G =GRUs(embadding(W G ))
[0250] z q =W2(ReLU(W1(z) G )+b1))+b2
[0251] Where W1, W2 and b1, b2 represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively. This invention uses the query encoding as the query for the location memory module, calculates its correlation with the memory vectors in the location memory bank, and reconstructs this query vector using a weighted combination of the memory vectors. This invention believes that such a reconstructed vector contains location information from both global and window encoding. Then, this invention further inputs the query encoding into the Bayesian feature memory module, which, by Bayesianizing the memory vectors, makes the feature memory vectors no longer a fixed single pattern, thus enhancing the robustness of the memory module.
[0252] The biggest difference between the Bayesian feature memory module and the traditional memory module is that the memory vector is Bayesianized. This invention uses different Gaussian distributions to represent the feature memory matrix M. P =[μ F ,σ F The distribution of memory vectors in [ ], where I represents the size of the memory matrix, d model This represents the feature dimension of each typical pattern in the memory matrix. For the query encoding z... q This invention calculates its Mahalanobis distance to the feature memory matrix. and similarity weight w i :
[0253]
[0254] Var(z) q The variance of the input features. Let represent the mean and variance of the i-th memory term. This represents the i-th memory entry in the feature memory matrix. The present invention then calculates the weighted mean and weighted variance:
[0255]
[0256] To avoid the problem of non-differentiability caused by directly sampling from the distribution of latent variables, this invention employs a resampling strategy to sample the reconstructed latent variables and obtains the final reconstructed query vector through weighted summation. The specific formula is as follows:
[0257]
[0258] Where N s This indicates the number of resampling operations. After obtaining the query vector reconstructed by the location memory module and the query vector reconstructed by the Bayesian feature memory module, this invention designs a gating mechanism to fuse these two reconstructed query vectors. The specific formula is as follows:
[0259]
[0260] Here, η represents the learnable weight parameters. The present invention then feeds the fused latent variables into the decoder to reconstruct the original input.
[0261]
[0262] The regression tasks include:
[0263] To more clearly extract the temporal dependencies between windows, this invention, in addition to the aforementioned location information injection, incorporates a window position label regression task. Firstly, when dividing samples into sliding window segments, this invention explicitly stores the absolute position label of each window sample, indicating which window it is within the entire time series. Figure 3 As shown. Then, this invention normalizes the labels of all time windows to obtain the final predicted label l. i Then, this invention randomly shuffles the window and its corresponding label and feeds it into the model for learning. This invention designs a mapping layer based on a non-linear activation function to encode and regress the position label of the time window. The window normalization process is constrained by the MSE loss relative to the true location labels, making the model more focused on uncovering dependencies between windows. The loss calculation for the regression process is as follows:
[0264]
[0265] Furthermore, to shorten the distance between sample pairs with similar positional labels and widen the distance between negative sample pairs with significantly different positional labels, this invention also designs a positional contrast learning loss by maximizing the alignment between target similarity and feature similarity.
[0266] pos_sim i,j =|l i -l j |(i,j=1,…,B)
[0267]
[0268] Where B represents the size of the training batch, fea_sim represents the similarity between query features, and pos_sim represents the similarity between labels.
[0269] Pollution suppression and multi-objective optimization:
[0270] To suppress contaminated data in the training data at the training level, this invention designs a loss adjustment strategy that uses the difference between window-normalized reconstructed samples and globally normalized reconstructed samples as the loss adjustment weight. Furthermore, a weight difference mapper is designed to further amplify the weight difference between normal data and potentially contaminated data. The final reconstruction loss L of the model is:
[0271]
[0272] Where N represents the number of training samples, μ represents the loss weight. Dif denoted by , where τ represents the mean of the difference between the two paths, τ represents the temperature parameter, and ⊙ represents the Hadamard product operation.
[0273] This invention incorporates multiple reconstruction and regression tasks, resulting in multiple losses. To balance the differences among these losses and ensure more stable model training, this invention designs a multi-objective loss optimization module based on uncertainty weighting. A learnable variance parameter is set. This dynamically adjusts the magnitude of each loss term. For any loss term, the adjusted loss is...
[0274]
[0275] The total loss of the entire model is:
[0276]
[0277] Anomaly detection:
[0278] For multivariate time series anomaly detection tasks, the goal is to determine whether anomalies have occurred at each time point in the time series. However, due to the difficulty in obtaining labeled data, it is impossible to directly predict whether anomalies have occurred at each time point in the test data. Current mainstream methods use reconstruction-based unsupervised methods to replace direct prediction of anomaly labels for anomaly detection. This invention, based on a dual-path reconstruction differential loss adjustment framework, designs a comprehensive anomaly score (AS) to determine whether anomalies have occurred at a time point.
[0279]
[0280] The larger the AS (Abnormal Score), the more likely an anomaly occurred at that time point. After obtaining the anomaly score of the test set data, this invention uses an optimal threshold method to obtain the final detection result, classifying samples with anomaly scores greater than the threshold as anomalous samples and samples with anomaly scores less than or equal to the threshold as normal samples.
[0281] The technical solution of this invention proposes a Bayesian memory module-based method to enhance cross-window dependency learning, enabling accurate and robust extraction of normal patterns from time series. First, a global window dual-position encoding mechanism is proposed, where position memory vectors store cross-window context, and supervised regression of position labels explicitly learns long-term dependencies and local dynamics. This model enhances temporal representation and generalization ability by integrating global and local positional information to jointly reconstruct features. Furthermore, a Bayesian memory module is designed to probabilistically represent normal pattern features. By introducing different Gaussian distributions to model the uncertainty of complex normal patterns and combining this with a reparameterized sampling strategy, robust time series patterns are generated. This effectively suppresses interference from contaminated data while enhancing the model's adaptability to fluctuations in input features.
[0282] This patent first compares BMECD with 13 more advanced models on 5 authoritative real-world datasets and actual electricity consumption datasets that represent the diversity of time series data distributions, and confirms the effectiveness and advancement of the proposed multi-dimensional time series electricity consumption data anomaly detection method.
[0283] Evaluation indicators:
[0284] AUC-ROC was selected as the evaluation metric to assess the performance of the proposed method and the baseline. AUC-ROC is a commonly used metric in anomaly detection, representing the area under the receiver operating characteristic curve (ROC) at different thresholds, with FPR (False Positive Rate) and TPR (True Positive Rate) as the x and y axes. AUC-ROC directly reflects the anomaly detection performance of the algorithm, excluding the influence of the threshold. Its range is from 0 to 1; a perfect algorithm has an AUC-ROC value of 1, while a random guessing model has an AUC value close to 0.5. The formulas for calculating TPR and FPR are shown below.
[0285]
[0286] Wherein, TP (True Postive) and FP (False Postive) are the number of true and false postive time points detected, respectively, and TN (True Negative) and FN (False Negative) are the number of true and false normal time points detected, respectively.
[0287] Comparison method:
[0288] This invention compares the proposed method with 11 multivariate time series anomaly detection methods, including traditional machine learning methods: LOF, Isolation Forest (IF); prediction-based methods: GDN, GTA; and reconstruction methods: MSCRED, USAD, TranAD, AT, RAE, DiffAD, and TSMAE.
[0289] Implementation details:
[0290] A sliding time window approach was used to divide the training and testing time window sets. The reconstruction window length for both training and testing was 16. During training, the step size of the sliding time window was 1, and during testing, the step size was 16. BMECD was implemented using PyTorch, and all experiments were run on a server equipped with an Intel(R) Core(TM) i9-10900X CPU 3.70GHz and an NVIDIA GeForce RTX 4090. It was trained using the Adam optimizer with a learning rate of 1e-4 and employed an early stopping strategy; if the loss on the validation set did not decrease after 6 consecutive epochs, early stopping was triggered.
[0291] Introduction to the public dataset:
[0292] Five real-world datasets from three application areas were used. The datasets consist of monitoring data from multiple complex physical devices or large facilities. Specific information for each dataset is shown in Table 1.
[0293] Table 1
[0294]
[0295] Evaluation of results from public datasets:
[0296] The results of the proposed method and various comparative methods under the AUC metric are shown in Table 2. Bold text in the table indicates the highest average AUC and the best ranking. The adversarial time-frequency domain contamination filtering and two-stage loss correction multivariate electricity consumption data time series anomaly detection method proposed in this invention is represented by BMECD in the table. The results in the table show that, under the AUC metric, BMECD achieved two best results and one second-best result across all five public datasets, with a significantly higher average score than other baseline methods and the best average ranking, indicating that BMECD's anomaly detection performance is superior to other comparative methods.
[0297] Table 2
[0298]
[0299] Introduction to actual electricity consumption datasets:
[0300] The specific characteristics of the actual electricity consumption dataset (ELE) are shown in Table 3. This dataset was collected from 9 physical three-phase electricity meters in multiple distribution areas. Each device includes 22 sensor values: current (phase A, phase B, phase C), voltage (phase A, phase B, phase C), energy reading (positive active), energy reading (reverse active), energy reading (positive reactive), energy reading (reverse reactive), active power (phase A, phase B, phase C, total), reactive power (phase A, phase B, phase C, total), and power factor (phase A, phase B, phase C, total).
[0301] Table 3
[0302]
[0303] Evaluation of actual electricity consumption dataset results:
[0304] Table 4 shows the AUC results of the embodiments of the present invention and other comparative methods on a real-world electricity consumption dataset. The results show that, compared to all comparative methods, the BMECD proposed in this invention achieves the highest AUC score, indicating that its anomaly detection performance on the real-world electricity consumption dataset is superior to the comparative methods, demonstrating the reliability and superiority of BMECD in real-world environments. Experimental results on both public datasets and real-world electricity consumption datasets demonstrate that the method proposed in this invention can effectively improve the accuracy of anomaly detection in electricity consumption data.
[0305] Table 4
[0306] method LOF iForest MSCRED USAD GDN GTA AUC 0.5694 0.5262 0.5720 0.4615 0.5617 0.5429 method TranAD AT TSMAE RAE DiffAD BMECD AUC 0.5051 0.4956 0.5341 0.5347 0.5344 0.5728
[0307] Example 2:
[0308] This invention also proposes a power consumption data anomaly detection device 200 based on Bayesian memory module enhancement, such as... Figure 1 As shown, it includes:
[0309] Window unit 201 is used to insert position information within and between windows for the original electricity consumption data to obtain sample data;
[0310] Reconstruction unit 202 is used to construct a feature extraction framework constrained by the joint reconstruction-regression task based on sample data using the Bayesian memory module.
[0311] Anomaly detection unit 203 is used to perform anomaly detection on electricity consumption data based on a feature extraction framework constrained by a joint reconstruction-regression task.
[0312] The insertion of inter-window position information includes:
[0313] For the time-series data X in the original electricity consumption data, a data normalization method is used to perform global encoding on the time-series data X, wherein the global position encoding PE at the pos position is... G for:
[0314]
[0315] PE G (pos,2i+1)=cos(pos / 10000 2i / F )
[0316] Where i represents the dimension index of the location encoding, and F represents the number of features in the time series;
[0317] Add the global code and the time series data X together so that the data contains absolute location information;
[0318] A fixed-length sample W is obtained through a sliding window. LW ={W L1 W L2 ,…,W Lt}, and in the process, obtain the position label of each window;
[0319] RevIN is used to normalize the data within the window, resulting in the normalized time window W′. LW ={W′ L1 ,W′ L2 ,…,W′ Lt The formula is as follows:
[0320]
[0321]
[0322] Wherein, μ(W i LW ) represents the mean of time values within the i-th time window, σ(W) i LW ) represents the variance of time values within the i-th time window, and γ and β represent the learnable affine transformation parameters.
[0323] The insertion of position information within the window includes:
[0324] After obtaining the normalized window, the window-normalized data is used to inject the window's position information, including:
[0325] Calculation window The Fast Fourier Transform (DFT) is used to obtain the spectrum of this time window. Given a sequence x[n] containing n time points, the DFT maps it to a complex sequence in the frequency domain using the following formula:
[0326]
[0327] Where X[k] represents the transformed frequency domain representation, j represents the imaginary unit, and n and k represent the indices in the time domain and frequency domain, respectively;
[0328] The formula for calculating X[k] represents multiplying each sample in the original signal sequence x[n] by the corresponding complex exponential basis. Summing all products yields a specific frequency component X[k] in the frequency domain. The k frequencies with the highest power are extracted based on their amplitudes at different frequencies. The frequencies with the highest and lowest power are then selected as the base wavelength λ. max and λ min The wavelength parameters covering the main frequency range are generated by setting a geometric sequence. The calculation formula is as follows:
[0329]
[0330] Where i represents the dimension index of the location encoding, F represents the number of features in the time series, and λ i This represents the wavelength corresponding to the i-th position index;
[0331] The position code within the window is generated using wavelength parameters through sine and cosine functions, calculated as follows:
[0332]
[0333] Among them, PE W The window position code representing the pos position;
[0334] The window-normalized data and the timestamp encoding are summed to obtain samples for location information and feature extraction. The calculation formula is as follows:
[0335]
[0336] Where α represents the learnable weight parameter, and ⊙ represents the Hadamard product.
[0337] After completing the insertion of position information within and between windows, the raw data was processed to obtain two sets of time window data with the same window length, one set W G Normalization is performed using global statistical features, for a set of samples Normalization is performed using statistical features within the window, and includes positional information within and between windows.
[0338] The feature extraction framework for constructing a joint reconstruction-regression task constraint includes:
[0339] Window normalization, window reconstruction, and addition of regression tasks.
[0340] Among them, window normalization and window reconstruction include:
[0341] For samples after location information insertion A reconstructed autoencoder based on a location memory module is used to extract the temporal features and location information stored therein while suppressing the impact of contaminated data on model training.
[0342] Sample An encoder consisting of stacked GRU layers extracts the temporal features and location information of the samples to obtain the latent variable z. P The calculation formula is as follows:
[0343]
[0344] Set the location memory module to store the latent variable z. P ;
[0345] The location memory matrix is a learnable matrix. H represents the size of the memory matrix, K represents the feature dimension of each typical pattern in the memory matrix, and m j This represents the j-th memory feature in the memory module;
[0346] The time-domain latent variable z i Treating query q as a key, the position memory matrix is used as the key, and the similarity Sim(q,m) between it and the feature vector in each memory matrix is calculated. j The calculation formula is as follows:
[0347]
[0348] Where T represents the transpose of the matrix;
[0349] The obtained similarity matrix is normalized to obtain the global memory score matrix, and the memory matrix is weighted by the score matrix to obtain the reconstructed latent variables. The calculation formula is as follows:
[0350]
[0351] The momentum update method updates the memory items in the display update memory. The momentum encoder adopts a non-linear mapping structure, and the calculation formula is as follows:
[0352]
[0353] in, It is the feature encoded by the momentum encoder, W M1 W M2 and bM1 b M2 These represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively. Indicates the momentum coefficient;
[0354] The latent variables are fed into the decoder and the original input is reconstructed through denormalization. And the reconstruction loss L of the normalized window is calculated. G The calculation formula is as follows:
[0355]
[0356] Wherein, μ(W L ) represents the mean of the time window, σ(W) L ) represents the variance of the time window, and N represents the number of samples.
[0357] Among them, window normalization and window reconstruction include:
[0358] For globally normalized sample W G The reconstructed autoencoder based on the Bayesian feature memory module, by fully integrating global-window position information and temporal features, accurately extracts normal temporal patterns while suppressing the influence of contaminated data, and obtains the query code z for querying position information. q The formula is as follows:
[0359] z G =GRUs(embadding(W G ))
[0360] z q =W2(ReLU(W1(z) G )+b1))+b2
[0361] Where W1, W2 and b1, b2 represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively;
[0362] The query code is used as the query of the location memory module. Its relevance is calculated with the memory vector in the location memory bank, and the query vector is reconstructed by a weighted combination of the memory vectors.
[0363] The query code is input into the Bayesian feature memory module, which makes the feature memory vector no longer a fixed single pattern by Bayesianizing the memory vector.
[0364] The feature memory matrix M is represented using different Gaussian distributions. P =[μ F ,σ F The distribution of memory vectors in [ ], where, I represents the size of the memory matrix, dmodel This represents the feature dimension of each typical pattern in the memory matrix;
[0365] For query code z q Calculate its Mahalanobis distance to the feature memory matrix. and similarity weight w i The calculation formula is as follows:
[0366]
[0367] Among them, Var(z) q The variance of the input features. Let represent the mean and variance of the i-th memory term. This represents the i-th memory item in the feature memory matrix;
[0368] The weighted mean and weighted variance are calculated using the following formulas:
[0369]
[0370] A resampling strategy is used to sample the reconstructed latent variables, and a weighted sum is used to obtain the final reconstructed query vector. The calculation formula is as follows:
[0371]
[0372] Where, N s Indicates the number of resampling attempts;
[0373] A gating mechanism is set up to merge the two reconstructed query vectors, and the calculation formula is as follows:
[0374]
[0375] Where η represents the learnable weight parameters;
[0376] The fused latent variables are fed into the decoder to reconstruct the original input. The calculation formula is as follows:
[0377]
[0378] This includes adding regression tasks, such as:
[0379] The labels of the time window are normalized and used as the final predicted labels. i ;
[0380] The windows and their corresponding labels are randomly shuffled and then fed into the model for learning. A mapping layer based on a non-linear activation function is set up to encode and regress the position labels of the time windows. The window normalization process is constrained by the MSE loss relative to the true location labels, making the model focus more on uncovering dependencies between windows. The loss calculation for the regression process is as follows:
[0381]
[0382] A positional contrast learning loss was designed to maximize the alignment between target similarity and feature similarity, and the calculation formula is as follows:
[0383] pos_sim i,j =|l i -l j |(i,j=1,…,B)
[0384]
[0385] Where B represents the size of the training batch, fea_sim represents the similarity between query features, and pos_sim represents the similarity between labels.
[0386] The feature extraction framework constrained by the joint reconstruction-regression task includes: pollution suppression and multi-objective optimization, including:
[0387] The loss adjustment strategy uses the difference between window-normalized reconstructed samples and globally normalized reconstructed samples as the loss adjustment weight. A weight difference mapper is designed to further amplify the weight difference between normal data and potentially contaminated data. The final reconstruction loss L of the model is:
[0388]
[0389] Where N represents the number of training samples, μ represents the loss weight. Dif denoted by , where τ represents the mean of the difference between the two paths, τ represents the temperature parameter, and ⊙ represents the Hadamard product operation.
[0390] A multi-objective loss optimization module based on uncertainty weighting is used to set a learnable variance parameter. This dynamically adjusts the magnitude of each loss term. For any loss term, the adjusted loss is... The calculation formula is as follows:
[0391]
[0392] The total loss of the entire model is:
[0393]
[0394] Anomaly detection includes:
[0395] Based on the dual-path reconstruction difference loss adjustment framework, a comprehensive anomaly score AS is set to determine whether an anomaly occurs at a time point. The calculation formula is as follows:
[0396]
[0397] The larger the AS value, the more likely an anomaly has occurred at that point in time.
[0398] After obtaining the abnormal scores of the test set data, the final detection result is obtained by using the optimal threshold method. Samples with abnormal scores greater than the threshold are classified as abnormal samples, and samples with abnormal scores less than or equal to the threshold are classified as normal samples.
[0399] This invention differs from traditional time series anomaly detection methods by explicitly incorporating both the global position information of the time window within the time series and the window position information of the time points within the window during feature extraction. This allows the model to directly utilize this dual positional information to obtain the position of each time point within the sequence. Furthermore, a joint feature extraction framework combining dual positional information reconstruction and position label regression is designed to further facilitate the model's explicit learning and utilization of the dual positional information of time points. In the dual positional information reconstruction task, this invention employs a position memory module and a Bayesian feature memory module to explicitly store the global-local positional information and typical normal patterns of the time series. This helps the model accurately extract temporal patterns while suppressing the impact of contaminated data on model training. Additionally, this invention proposes a multi-objective loss optimization module based on uncertainty weighting to ensure the stability of model training. A training-level contamination suppression method based on loss weight adjustment is introduced. Through joint adjustment with the model-level method of the memory module, the impact of contaminated data on model training is effectively suppressed, achieving robust and accurate anomaly detection.
[0400] Example 3:
[0401] Based on the same inventive concept, this invention also provides a computer device, which includes a processor and a memory. The memory stores a computer program, which includes program instructions. The processor executes the program instructions stored in the computer storage medium. The processor may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions in the computer storage medium to implement corresponding method flows or corresponding functions, thereby implementing the steps of the methods in the above embodiments.
[0402] Example 4:
[0403] Based on the same inventive concept, this invention also provides a storage medium, specifically a computer-readable storage medium (Memory), which is a memory device in a computer device used to store programs and data. It is understood that the computer-readable storage medium here can include both the built-in storage medium in the computer device and extended storage media supported by the computer device. The computer-readable storage medium provides storage space that stores the terminal's operating system. Furthermore, this storage space also stores one or more instructions suitable for loading and execution by a processor. These instructions can be one or more computer programs (including program code). It should be noted that the computer-readable storage medium here can be high-speed RAM or non-volatile memory, such as at least one disk storage device. The processor can load and execute one or more instructions stored in the computer-readable storage medium to implement the steps of the method in the above embodiments.
[0404] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The solutions in the embodiments of the present invention can be implemented using various computer languages, such as the object-oriented programming language Java and the interpreted scripting language JavaScript.
[0405] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0406] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0407] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0408] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0409] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A method for detecting abnormal electricity consumption data based on Bayesian memory modules, characterized in that, include: For the raw electricity consumption data, position information within and between windows is inserted to obtain sample data; Based on the Bayesian memory module, a feature extraction framework constrained by the joint reconstruction-regression task is constructed according to the sample data. An anomaly detection method for electricity consumption data is developed based on a feature extraction framework constrained by a joint reconstruction-regression task.
2. The method for detecting abnormal electricity consumption data according to claim 1, characterized in that, Insertion of inter-window position information, including: For the time-series data X in the original electricity consumption data, a data normalization method is used to perform global encoding on the time-series data X, wherein the global position encoding PE at the pos position is... G for: ON G (pos,2i+1)=cos(pos / 10000 2i / F ) Where i represents the dimension index of the location encoding, and F represents the number of features in the time series; Add the global code and the time series data X together so that the data contains absolute location information; A fixed-length sample W is obtained through a sliding window. LW ={W L1 W L2 ,…,W Lt }, and in the process, obtain the position label of each window; RevIN is used to normalize the data within the window, resulting in the normalized time window W′. LW ={K′ L1 ,K′ L2 ,…,W′ Lt The formula is as follows: Wherein, μ(W i LW ) represents the mean of time values within the i-th time window, σ(W) i LW ) represents the variance of time values within the i-th time window, and γ and β represent the learnable affine transformation parameters.
3. The method for detecting abnormal electricity consumption data according to claim 1, characterized in that, Insertion of position information within the window, including: After obtaining the normalized window, the window-normalized data is used to inject the window's position information, including: Calculation window The Fast Fourier Transform (DFT) is used to obtain the spectrum of this time window. Given a sequence x[n] containing n time points, the DFT maps it to a complex sequence in the frequency domain using the following formula: Where X[k] represents the transformed frequency domain representation, j represents the imaginary unit, and n and k represent the indices in the time domain and frequency domain, respectively; The formula for calculating X[k] represents multiplying each sample in the original signal sequence x[n] by the corresponding complex exponential basis. Summing all products yields a specific frequency component X[k] in the frequency domain. The k frequencies with the highest power are extracted based on their amplitudes at different frequencies. The frequencies with the highest and lowest power are then selected as the base wavelength λ. max and λ min The wavelength parameters covering the main frequency range are generated by setting a geometric sequence. The calculation formula is as follows: Where i represents the dimension index of the location encoding, F represents the number of features in the time series, and λ i This represents the wavelength corresponding to the i-th position index; The position code within the window is generated using wavelength parameters through sine and cosine functions, calculated as follows: Among them, PE W The window position code representing the pos position; The window-normalized data and the timestamp encoding are summed to obtain samples for location information and feature extraction. The calculation formula is as follows: Where α represents the learnable weight parameter, and ⊙ represents the Hadamard product; After completing the insertion of position information within and between windows, the raw data was processed to obtain two sets of time window data with the same window length, one set W G Normalization is performed using global statistical features, for a set of samples Normalization is performed using statistical features within the window, and includes positional information within and between windows.
4. The method for detecting abnormal electricity consumption data according to claim 1, characterized in that, The feature extraction framework for constructing a joint reconstruction-regression task constraint includes: Window normalization, window reconstruction, and addition of regression tasks.
5. The method for detecting abnormal electricity consumption data according to claim 4, characterized in that, The window normalization and window reconstruction includes: For samples after location information insertion A reconstructed autoencoder based on a location memory module is used to extract the temporal features and location information stored therein while suppressing the impact of contaminated data on model training. Sample An encoder consisting of stacked GRU layers extracts the temporal features and location information of the samples to obtain the latent variable z. P The calculation formula is as follows: Set the location memory module to store the latent variable z. P ; The location memory matrix is a learnable matrix. H represents the size of the memory matrix, K represents the feature dimension of each typical pattern in the memory matrix, and m j This represents the j-th memory feature in the memory module; The time-domain latent variable z i Treating query q as a key, the position memory matrix is used as the key, and the similarity Sim(q,m) between it and the feature vector in each memory matrix is calculated. j The calculation formula is as follows: Where T represents the transpose of the matrix; The obtained similarity matrix is normalized to obtain the global memory score matrix, and the memory matrix is weighted by the score matrix to obtain the reconstructed latent variables. The calculation formula is as follows: The momentum update method updates the memory items in the display update memory. The momentum encoder adopts a non-linear mapping structure, and the calculation formula is as follows: in, It is the feature encoded by the momentum encoder, W M1 W M2 and b M1 b M2 These represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively. Indicates the momentum coefficient; The latent variables are fed into the decoder and the original input is reconstructed through denormalization. And the reconstruction loss L of the normalized window is calculated. G The calculation formula is as follows: Wherein, μ(W L ) represents the mean of the time window, σ(W) L ) represents the variance of the time window, and N represents the number of samples.
6. The method for detecting abnormal electricity consumption data according to claim 4, characterized in that, The window normalization and window reconstruction includes: For globally normalized sample W G The reconstructed autoencoder based on the Bayesian feature memory module, by fully integrating global-window position information and temporal features, accurately extracts normal temporal patterns while suppressing the influence of contaminated data, and obtains the query code z for querying position information. q The formula is as follows: With G =GRUs(embadding(W G )) With q =W2(ReLU(W1(z G )+b1))+b2 Where W1, W2 and b1, b2 represent the weight and bias parameter matrices of the two linear layers of the momentum encoder, respectively; The query code is used as the query of the location memory module. Its relevance is calculated with the memory vector in the location memory bank, and the query vector is reconstructed by a weighted combination of the memory vectors. The query code is input into the Bayesian feature memory module, which makes the feature memory vector no longer a fixed single pattern by Bayesianizing the memory vector. The feature memory matrix M is represented using different Gaussian distributions. P =[μ F ,σ F The distribution of memory vectors in [ ], where, I represents the size of the memory matrix, d model This represents the feature dimension of each typical pattern in the memory matrix; For query code z q Calculate its Mahalanobis distance to the feature memory matrix. and similarity weight w i The calculation formula is as follows: Among them, Var(z) q The variance of the input features. Let represent the mean and variance of the i-th memory term. This represents the i-th memory item in the feature memory matrix; The weighted mean and weighted variance are calculated using the following formulas: A resampling strategy is used to sample the reconstructed latent variables, and a weighted sum is used to obtain the final reconstructed query vector. The calculation formula is as follows: Where, N s Indicates the number of resampling attempts; A gating mechanism is set up to merge the two reconstructed query vectors, and the calculation formula is as follows: Where η represents the learnable weight parameters; The fused latent variables are fed into the decoder to reconstruct the original input. The calculation formula is as follows:
7. The method for detecting abnormal electricity consumption data according to claim 4, characterized in that, The addition of regression tasks includes: The labels of the time window are normalized and used as the final predicted labels. i ; The windows and their corresponding labels are randomly shuffled and then fed into the model for learning. A mapping layer based on a non-linear activation function is set up to encode and regress the position labels of the time windows. The window normalization process is constrained by the MSE loss relative to the true location labels, making the model focus more on uncovering dependencies between windows. The loss calculation for the regression process is as follows: A positional contrast learning loss was designed to maximize the alignment between target similarity and feature similarity, and the calculation formula is as follows: pos_sim i,j =|l i -l j |(i,j=1,…,B) Where B represents the size of the training batch, fea_sim represents the similarity between query features, and pos_sim represents the similarity between labels.
8. A device for detecting abnormal power consumption data based on Bayesian memory modules, characterized in that, include: The window unit is used to insert position information within and between windows into the original electricity consumption data to obtain sample data; The reconstruction unit is used to construct a feature extraction framework constrained by the joint reconstruction-regression task based on sample data, using the Bayesian memory module. Anomaly detection unit is used to perform anomaly detection on electricity consumption data based on a feature extraction framework constrained by a joint reconstruction-regression task.
9. A computer device, characterized in that, include: One or more processors; A processor is used to execute one or more programs; When the one or more programs are executed by the one or more processors, the method described in any one of claims 1-7 is implemented.
10. A computer-readable storage medium, characterized in that, It contains a computer program, which, when executed, implements the method as described in any one of claims 1-7.
Citation Information
Patent Citations
Electric energy meter anomaly detection method based on double-memory enhanced auto-encoder
CN117491939A
Battery fault unsupervised detection method based on diffusion Transform and confidence coefficient calibration
CN120490880A
Bayesian and frequentist anomaly detection ensemble
US12450549B1
Automated window based feature generation for time-series forecasting and anomaly detection
US20200097810A1
Multivariate time series anomaly detection method for intelligent internet of things system
WO2024207627A1