A method and apparatus for detecting anomalies in electricity meters based on adversarial contrast autoencoders
By using an adversarial autoencoder-based anomaly detection method for smart meters, the problem of difficulty in learning the complex time dependencies and dynamic changes of multivariate time series data of smart meters in existing technologies is solved, achieving a more efficient anomaly detection effect.
Patent Information
- Application Number
- CN202310990073.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-08
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2043-08-08
AI Technical Summary
Existing reconstruction-based multidimensional time series anomaly detection methods struggle to learn the complex time dependencies and dynamic change patterns of multivariate time series data from smart meters, resulting in limited detection performance.
An anomaly detection method for electricity meters based on adversarial contrastive autoencoders is adopted. By normalizing and windowing multivariate long-term series data, adversarial contrastive autoencoders are used for feature extraction and reconstruction. Data augmentation is performed by combining multi-scale timestamp masks and comparative learning of feature combination and decomposition to improve the robustness of the model to normal data and the accuracy of anomaly detection.
It improves the accuracy and generalization ability of anomaly detection in multivariate time series data of smart meters, and can better capture the overall trend and high-level semantic features of time series, thereby enhancing the robustness and anomaly recognition ability of the model.
Smart Images

Figure CN117092582B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electricity meter testing technology, and more specifically, to an electricity meter anomaly detection method and apparatus based on an adversarial comparison autoencoder. Background Technology
[0002] Against the backdrop of meeting the evolving needs of smart meter verification methods, researching multi-dimensional time-series data anomaly detection methods for smart meters can not only safeguard the safe and stable operation of the smart grid, but also provide theoretical support and reference for multi-dimensional time-series data anomaly detection in various industrial equipment, contributing to the achievement of the national "dual carbon" goals and promoting sustainable socio-economic development. In anomaly detection tasks, anomalies can be defined as abnormal patterns of behavior that do not conform to expectations. The difference between time-series and non-time-series data lies in the fact that non-time-series data assumes independence, while time-series data exhibits correlations. That is, non-time-series anomaly detection, to some extent, falls under outlier detection, using distance-based correlation operations to identify scattered points that do not conform to normal patterns. However, time-series anomaly detection requires considering the sequential logic and recursive relationships between sampling time points within each sequence; single-point mining cannot extract the time dependencies within the sequence.
[0003] Since most of the data collected from actual electricity meter devices lack accurate positive anomaly labels, manual labeling is difficult and costly. Furthermore, due to the robustness of the devices, almost all the data collected is normal. Therefore, some supervised methods are limited in practical applications due to the lack of prior information. As a result, current research focuses on unsupervised anomaly detection that does not require accurate category labeling, and most studies assume that the training data is normal.
[0004] Currently, unsupervised anomaly detection methods for multidimensional time series data in smart meters can be categorized into three main types: statistical methods, machine learning methods, and deep learning methods. Statistical methods require data to satisfy pre-defined statistical assumptions, while real-world data often exhibits complex and unknown distributions, making it difficult to construct effective statistical models. Traditional machine learning models struggle to directly capture the contextual relationships within time series data, making it difficult to model the complex patterns of multidimensional time series. In the smart grid field, time series data from industrial equipment such as electricity meters have become increasingly complex and random with technological advancements. Various systems continue to generate massive amounts of data, necessitating the development of deep learning methods that require large datasets for training. In recent years, deep learning-based time series anomaly detection has become an important area of research. Numerous unsupervised deep anomaly detection methods have emerged, demonstrating significantly better performance than traditional anomaly detection methods. Overall, deep learning-based methods exhibit relatively high accuracy in multidimensional time series anomaly detection, and their model processing is relatively convenient.
[0005] Existing reconstruction-based multidimensional time series anomaly detection methods focus on learning point-by-point contextual information from multidimensional time series data, paying less attention to the long-term overall trend of the time series. However, multidimensional time series data from smart meters exhibits complex temporal dependencies and dimensional correlations, and its normal patterns change dynamically over time. Existing reconstruction-based methods cannot construct accurate profiles of normal patterns in multivariate time series data, which limits further performance improvements. Summary of the Invention
[0006] To address the shortcomings of existing technologies, this invention provides a method and apparatus for detecting anomalies in electricity meters based on an adversarial comparison autoencoder.
[0007] According to one aspect of the present invention, a method for detecting anomalies in an energy meter based on an adversarial contrast autoencoder is provided, comprising:
[0008] Acquire multivariate long-term series data of historical measurements of the energy meter under test;
[0009] Normalize multivariate long-term series data and divide the data into multiple time windows of preset window length;
[0010] Multiple time window data are input into a pre-trained anomaly detection model, and the reconstructed data corresponding to each time window data is output. The anomaly detection model uses an adversarial contrastive autoencoder.
[0011] Based on the reconstructed data and time window data for each time window, the anomaly score for each time point in the time window data is determined, and the degree of anomaly at each time point is determined based on the anomaly score.
[0012] Optionally, the multivariate long-term series data includes: phase A current, phase B current, phase C current, phase A voltage, phase B voltage, phase C voltage, forward active energy indication, reverse active energy indication, forward reactive energy indication, reverse reactive energy indication, phase A active power, phase B active power, phase C active power, total active power, phase A reactive power, phase B reactive power, phase C reactive power, total reactive power, phase A power factor, phase B power factor, phase C power factor, and total power factor.
[0013] Optionally, after acquiring the multivariate long-term series data of the historical measurements of the energy meter under test, the method further includes:
[0014] Z-Score standardization is used to ensure that all values of each variable in a multivariate long-term series data conform to a standard normal distribution.
[0015] The formula for Z-Score standardization is:
[0016]
[0017] In the formula, X i For multivariate long-term series data, Represents the standardized X i μ represents X i In the vector of all sample data for each variable, σ represents X. i A vector of standard deviations of all sample data for each variable.
[0018] Optionally, the training process for the anomaly detection model is as follows:
[0019] Acquire multivariate time series data samples from multiple historical energy meter readings and merge them into a single multivariate long-term data sample.
[0020] Z-Score standardization is used to ensure that all values of each variable in a multivariate long-term series data sample conform to a standard normal distribution.
[0021] Standardized multivariate long-term series data samples are windowed and divided into multiple time windows of data samples with preset windows;
[0022] After inputting data samples from multiple time windows into the projection layer, timestamp masks are applied to augment the data and determine positive and negative sample pairs.
[0023] The positive and negative sample pairs are input into the encoder for feature extraction to determine the features of the positive and negative sample pairs.
[0024] The anomaly detection model is determined by training the model using positive and negative samples to pair features, encoder, discriminator, and decoder.
[0025] Optionally, multiple time window data samples are input into the projection layer and then timestamp masks are applied for data augmentation to determine positive and negative sample pairs, including:
[0026] Input the time window data samples into the projection layer to obtain the projected representation of each sample;
[0027] Positive and negative samples of data for each time window are obtained using multi-scale timestamp masks and random sampling.
[0028] Multiple enhanced samples of a single sample are obtained by setting different masking probabilities in timestamp masking to determine positive sample pairs;
[0029] A predetermined number of samples are extracted from other original time window data samples and the augmented samples of each class as negative samples of the original time window data, and negative sample pairs are determined for each sample.
[0030] Optionally, the process of inputting positive and negative sample pairs into the encoder for feature extraction and determining the features of positive and negative sample pairs can be represented as follows:
[0031] z = E(a)
[0032] In the formula, E(·) represents the encoder, a is the projected representation or its enhanced sample obtained after the original time series window data is input into the projection layer, and z is the latent vector of a, i.e., the feature of the original sample or positive and negative sample pair, z∈R h h is the length of the implicit vector.
[0033] Optionally, the anomaly detection model is trained using positive and negative samples to pair features, the encoder, the discriminator, and the decoder, including:
[0034] The positive and negative sample pairs are recombined to determine the combined features of the positive and negative sample pairs.
[0035] The positive and negative sample pair features and the combined positive and negative sample pair features are input into the discriminator to obtain the prediction results and the discriminator loss.
[0036] Update the discriminator to minimize the discriminator loss, and then obtain the prediction result again;
[0037] The prediction results are input into the encoder to determine the encoding result and the encoding loss.
[0038] Update the encoder, minimize the encoding loss, and then obtain the encoding result again;
[0039] Based on the features of the positive and negative sample pairs reconstructed by the encoder and decoder, the reconstruction loss is determined.
[0040] Update the encoder and decoder, minimize the reconstruction loss, and determine the anomaly detection model.
[0041] Optionally, the process of reorganizing the features of positive and negative samples is as follows:
[0042]
[0043]
[0044] In the formula, α and β are combination parameters that determine the contribution of each old feature in the mixed features, z is the latent vector representation of a training sample, and z + , z - These are the latent vector representations of its positive and negative samples, respectively. These are positive combination features and negative combination features, respectively;
[0045] The loss function L of the discriminator d for:
[0046]
[0047] In the formula, N is the number of training windows. and These represent the decomposition results of the discriminator on the j-th positive mixture feature and the k-th negative mixture feature of the i-th sample, respectively. d + and l - These are real tags, where l d + = (1, α), l - = (0, β), where m is the number of positive samples, n+n×m is the number of negative samples, and α and β are combination parameters that determine the contribution of each old feature in the mixed features, β = 1-α;
[0048] The encoder's loss function L E for:
[0049]
[0050] In the formula, and These represent the decomposition results of the discriminator on the j-th positive mixture feature and the k-th negative mixture feature of the i-th sample, respectively. E + and l - These are real tags, where l E + =(1,1), l - = (0,β), where m is the number of positive samples and n+n×m is the number of negative samples;
[0051] Reconstruction loss function L recon for:
[0052]
[0053] In the formula, N is the number of training windows, and w is the window size. and x i,t These are the reconstructed data and the original data at time step t in the i-th window, respectively.
[0054] Optionally, the formula for calculating the outlier score is:
[0055]
[0056] In the formula, S i,t It is the outlier score at time step t of the i-th test data. and x i,t These are the reconstructed data and the original data at time step t in the i-th window, respectively.
[0057] According to another aspect of the present invention, an energy meter anomaly detection device based on an adversarial contrast autoencoder is provided, comprising:
[0058] The acquisition module is used to acquire multivariate long-term series data of historical tests of the energy meter under test;
[0059] The partitioning module is used to normalize multivariate long-term series data and divide the data into multiple time windows of a preset window length.
[0060] The output module is used to input multiple time window data into the pre-trained anomaly detection model and output the reconstructed data corresponding to each time window. The anomaly detection model uses an adversarial autoencoder.
[0061] The determination module is used to determine the anomaly score of each time point in the data of each time window based on the reconstructed data and the data of each time window, and to determine the degree of anomaly at each time point based on the anomaly score.
[0062] According to another aspect of the present invention, a computer-readable storage medium is provided, the storage medium storing a computer program for performing the methods described in any of the above aspects of the present invention.
[0063] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: a processor; a memory for storing executable instructions of the processor; the processor being configured to read the executable instructions from the memory and execute the instructions to implement the method described in any of the preceding aspects of the present invention.
[0064] Therefore, this application addresses the challenges of existing reconstruction-based multivariate time series anomaly detection methods for smart meters, which struggle to learn the overall trend of the data, and the unsuitability of data augmentation and surrogate tasks in existing contrastive learning methods for time series anomaly detection. To address these issues, an Adversarial Contrastive Autoencoder (ACAE) framework for multivariate time series anomaly detection in electricity meters is proposed. ACAE solves the problem of existing methods struggling to learn high-level semantic features of multivariate time series data with complex temporal, dimensional, and dynamic dependencies. ACAE improves the robustness of the model to normal data by introducing contrastive learning constraints on the autoencoder's latent space, making anomalies easier to identify. ACAE employs a multivariate time series data augmentation method based on multi-scale timestamp masks to obtain multiple augmented views of the original samples, encouraging the model to utilize multi-scale information of the time series to model its overall trend. Then, ACAE performs contrastive learning based on surrogate tasks of feature combination and decomposition. The robustness of the encoder's latent variables is improved by introducing an adversarial training process. This framework avoids the potential loss of effective information that may occur with existing contrastive learning frameworks for multivariate time series data. By comparing the joint training of learning and reconstruction tasks, the model can simultaneously consider point-by-point contextual information and overall trend information in the multivariate data of smart meters, thereby improving the model's generalization ability and the accuracy of anomaly detection. Attached Figure Description
[0065] Exemplary embodiments of the present invention can be more fully understood by referring to the following figures:
[0066] Figure 1 This is a flowchart illustrating an exemplary embodiment of the present invention for an anomaly detection method of an energy meter based on an adversarial comparison autoencoder.
[0067] Figure 2 This is a framework diagram of an anomaly detection module based on an adversarial contrastive autoencoder provided in an exemplary embodiment of the present invention;
[0068] Figure 3 This is a schematic diagram of the sample pair construction process provided in an exemplary embodiment of the present invention;
[0069] Figure 4 This is the structure of the encoder and decoder provided in an exemplary embodiment of the present invention;
[0070] Figure 5 This is a schematic diagram of the structure of a proxy task and discriminator based on feature combination and decomposition provided in an exemplary embodiment of the present invention;
[0071] Figure 6 This is a schematic diagram of the structure of an energy meter anomaly detection device based on an adversarial comparison autoencoder provided in an exemplary embodiment of the present invention;
[0072] Figure 7 This is the structure of an electronic device provided in an exemplary embodiment of the present invention. Detailed Implementation
[0073] Hereinafter, exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of the present invention, and not all embodiments of the present invention. It should be understood that the present invention is not limited to the exemplary embodiments described herein.
[0074] It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps described in these embodiments do not limit the scope of the invention.
[0075] Those skilled in the art will understand that the terms "first," "second," etc., in the embodiments of the present invention are only used to distinguish different steps, devices, or modules, and do not represent any specific technical meaning, nor do they indicate a necessary logical order between them.
[0076] It should also be understood that in the embodiments of the present invention, "multiple" can refer to two or more, and "at least one" can refer to one, two or more.
[0077] It should also be understood that any component, data or structure mentioned in the embodiments of the present invention can generally be understood as one or more unless explicitly defined or given contrary instructions in the context.
[0078] Furthermore, the term "and / or" in this invention is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this invention generally indicates that the preceding and following related objects have an "or" relationship.
[0079] It should also be understood that the description of the various embodiments in this invention emphasizes the differences between the various embodiments, and the similarities or similarities can be referred to each other. For the sake of brevity, they will not be described in detail.
[0080] At the same time, it should be understood that, for ease of description, the dimensions of the various parts shown in the accompanying drawings are not drawn according to actual scale.
[0081] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the invention or its application or use.
[0082] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, they should be considered part of the specification.
[0083] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.
[0084] The embodiments of this invention can be applied to electronic devices such as terminal devices, computer systems, and servers, and can operate together with a wide range of other general-purpose or special-purpose computing system environments or configurations. Well-known examples of terminal devices, computing systems, environments, and / or configurations suitable for use with electronic devices such as terminal devices, computer systems, and servers include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputer systems, mainframe computer systems, and distributed cloud computing environments including any of the above systems, etc.
[0085] Electronic devices such as terminal devices, computer systems, and servers can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in distributed cloud computing environments, where tasks are executed by remote processing devices linked through communication networks. In distributed cloud computing environments, program modules can reside on local or remote computing system storage media, including storage devices.
[0086] Exemplary methods
[0087] Figure 1 This is a schematic flowchart of an anomaly detection method for energy meters based on an adversarial contrast autoencoder, provided by an exemplary embodiment of the present invention. This embodiment can be applied to electronic devices, such as… Figure 1 As shown, the energy meter anomaly detection method 100 based on adversarial contrast autoencoder includes the following steps:
[0088] Step 101: Obtain multivariate long-term series data of historical tests of the electricity meter under test;
[0089] Step 102: Normalize the multivariate long-term series data and divide it into multiple time windows of a preset window length;
[0090] Step 103: Input multiple time window data into the pre-trained anomaly detection model and output the reconstructed data corresponding to each time window data. The anomaly detection model adopts an adversarial contrastive autoencoder.
[0091] Step 104: Determine the anomaly score for each time point of the time window data based on the reconstructed data and the time window data, and determine the degree of anomaly for each time point based on the anomaly score.
[0092] Specifically, the invention proposes an anomaly detection method for multivariate time series (MTS) data of electricity meters based on an adversarial contrastive autoencoder (ACAE), including:
[0093] 1. Problem Description
[0094] Let T∈R M×T This is a time series data set, where T represents the length of the time series and M represents its dimension. It is an observation sequence of T time steps collected from M observation objects. If M=1, the time series is a univariate time series; if M>1, the time series is an MTS (Multi-Stage Time Series). In this invention, the dimension represented by M specifically includes: A-phase current, B-phase current, C-phase current, A-phase voltage, B-phase voltage, C-phase voltage, forward active energy indication, reverse active energy indication, forward reactive energy indication, reverse reactive energy indication, A-phase active power, B-phase active power, C-phase active power, total active power, A-phase reactive power, B-phase reactive power, C-phase reactive power, total reactive power, A-phase power factor, B-phase power factor, C-phase power factor, and total power factor, totaling 22 dimensions. This invention primarily focuses on detecting anomalies in MTS data. Let s t ∈R M Let T represent the observed values of the time series at time t. Then T can be expressed as T∈{s1,s2,s3,...,s...} T The goal of MTS anomaly detection is to detect anomalous timestamps in a time series, specifically by calculating an anomaly score S for each time step of the time series. t And time steps with abnormal scores greater than the threshold are detected as abnormal.
[0095] Multivariate time series (MTS) / Multidimensional time series
[0096] adversarial contrastive autoencoder (ACAE)
[0097] 2. Framework Overview
[0098] The framework diagram of the method proposed in this invention is as follows: Figure 2As shown, ACAE mainly includes modules such as data preprocessing, sample pair construction, feature extraction, feature fusion, decomposition, and reconstruction. First, the data is standardized and divided using a sliding window. Second, to obtain positive and negative sample pairs for time-series contrastive learning, multiple enhanced views of the samples are obtained through multi-scale timestamp masks as positive samples, and negative samples are generated through sampling. Then, the encoder extracts features from the data and performs contrastive learning based on the feature combination and decomposition proxy task proposed in this invention. The main process is to first combine the features of positive or negative sample pairs, then adversarially train a discriminator to predict the category of the combined features and the proportion of each component. Finally, the decoder is trained to reconstruct the input samples, and the anomaly score for each time step is calculated based on the reconstruction error.
[0099] 3. Data Preprocessing
[0100] Raw multivariate time series data typically undergoes standardization before it can be used to train deep learning models. Standardization eliminates the influence of differences in units and scales between features, mapping the data distribution to the vicinity of the non-saturation region of the neural network activation function, greatly accelerating model training and improving its generalization performance. MTS standardization is usually achieved by appropriately shifting and scaling the original sequence.
[0101] Z-score standardization is the most widely used MTS standardization scheme. It uses the sample mean and standard deviation to scale each dimension of each multivariate time series, where μ k and σ k These refer to the global mean and standard deviation of the k-th feature, respectively.
[0102]
[0103] In the formula, s t The value of the kth feature.
[0104] The formula for Z-Score standardization is:
[0105]
[0106] In the formula, X i For multivariate long-term series data, Represents the standardized X i μ represents X i In the vector of all sample data for each variable, σ represents X. i A vector of standard deviations of all sample data for each variable.
[0107] First, the MTS data is normalized and scaled for each dimension to eliminate large-scale features, helping the model converge faster. To capture temporal correlations between time steps, continuous data segments are obtained as input to the model using a sliding window with intervals of d. A time window of data x... i It can be represented as x i ={x i,1 ,x i,2 ,x i,3 ,...,x i,w}, x i ∈RM×w, where M is the dimension of the data, w is the window size, and x i,t ∈RM, representing x i The observation vector at time step t.
[0108] 4. Data Augmentation
[0109] Creating different views of the same sample using data augmentation methods is crucial for contrastive learning. However, some current data transformation methods used in time series contrastive learning may disrupt the patterns of the original data, making it difficult for the model to learn reliable data representations. Masking learning has been successfully applied in machine vision and natural language processing. Models infer the invisible parts of samples by learning the visible parts, achieving strong representational capabilities. This invention uses masking to obtain augmented samples of time series window data. Although the masked samples and the original samples may differ significantly at the data level, they retain the high-level semantic features of the original time series without introducing additional noise. By maximizing the similarity of features between the masked samples and the original samples, the encoder can infer the invisible parts to a certain extent, enabling better learning of the main trends in the time series, which is crucial for learning the high-level semantic features of the time series.
[0110] While the original input could be directly masked, to enable the model to distinguish between the visible and masked portions of the time series data, this invention applies a timestamp mask to mask some time steps of the sample data after a projection layer is applied to the original data input. This is because it's difficult to find a specific marker within the range of values in the original time series. Intuitively, one could typically mask the input data with a value of 0, but a time series may contain many time steps with values of 0, making it difficult for the model to distinguish which time steps are masked. In ACAE, a projection layer is first applied to project the input vector at each time step into a higher-dimensional vector:
[0111] a i,t =Wx i,t +b
[0112] In the formula, x i,t ∈R M ai,t ∈R M ', and M'>M. Then, timestamp masking is applied to process the data representation 'a' in the projection space. Specifically, w*p time steps are sampled along the time axis of 'a' and set to 0, where p is the set masking probability. This sampling process is performed independently for each time window data in each forward channel. It can be proven that there exists a set of parameters {W,b} such that any time step of the original time series is not 0 in the projection space, thus the network is able to distinguish which time steps are masked. Experimental results also show that applying timestamp masking after the projection layer yields better performance. This projection layer will be optimized along with the encoder.
[0113] The specific process of constructing positive and negative sample pairs is as follows: Figure 3 As shown, by adjusting the masking probability p, a series of enhanced samples of the input data can be obtained. Enhanced samples with different masking rates help the model extract multi-scale information of the time series and enhance the effect of contrastive learning. For a projection space representation a from the original data, this invention obtains m enhanced views a+ by setting different p, that is, each sample has m positive sample pairs. Since there may be many "false negative samples" in the time series dataset, and in order to reduce computational overhead, this invention does not continue the traditional contrastive learning method of treating all other samples in a batch as negative samples of the current sample for the selection of negative samples. For each original sample, other samples in the same batch and their enhanced samples can be regarded as the negative sample pool of that sample. Given the hyperparameter n, this invention samples n samples from other original samples and their enhanced samples of each class as negative samples of that original sample. Therefore, each sample has n×(m+1) negative sample pairs.
[0114] 5. Feature Extraction -- Encoder
[0115] After constructing the positive and negative sample pairs, they are all sent to the Siamese encoder network to obtain the low-dimensional latent variables of all samples. The Siamese encoder is a residual network with three shared weights. This process can be represented as:
[0116] z = E(a)
[0117] In the formula, E(·) represents the encoder, a is the projected representation or its enhanced sample obtained after the original time series window data is input into the projection layer, and z is the latent vector of a, i.e., the feature of the original sample or positive and negative sample pair, z∈R h h is the length of the implicit vector.
[0118] 1D Convolutional Neural Networks (1D-CNNs) are among the most widely used neural networks for time series data analysis; therefore, this invention primarily uses 1D-CNN networks for feature extraction. Since ResNet exhibits excellent feature extraction performance in machine vision, this invention references the first two residual blocks of ResNet50 to implement the encoder, details of which are as follows... Figure 4 As shown on the left. In some convolutional layers, ( / 2) indicates that when multiple identical residual blocks are stacked, only the first residual block halves the time dimension of the input data, and subsequent residual blocks do not change the length of the time series.
[0119] The Siamese encoder can extract the latent vector representations of each training sample and the corresponding positive and negative samples. In the next section, we will introduce how ACAE uses the features of the extracted positive and negative sample pairs for comparative learning to improve the encoder's ability to learn high-level semantic features of time series data.
[0120] 6. Feature Combination and Decomposition
[0121] Individual discrimination is currently the mainstream proxy task in contrastive learning. It uses InfoNCE and its variant loss functions to directly calculate the similarity between features, maximizing the similarity between features from different views of the same sample and minimizing the similarity between features from different samples. Time series anomaly detection tasks only train models on normal data, which is essentially the same type of data. InfoNCE loss may cause the features of samples to be too scattered in the latent space, resulting in the loss of some effective information. Therefore, existing contrastive learning frameworks struggle to obtain robust data representations for time series data, which is detrimental to downstream anomaly detection tasks.
[0122] This invention proposes a surrogate task based on feature combination and decomposition. First, features from positive or negative sample pairs are combined to generate positive or negative mixed features. Then, a discriminator is trained to decompose the mixed features. If the discriminator can correctly predict the components of the negative mixed features but has difficulty predicting the components of the positive mixed features, it indicates that there are certain differences between the features of the negative sample pairs, while the features of the positive sample pairs have a high similarity, thus achieving contrastive learning. The surrogate task proposed in this invention includes two parts: feature combination and feature decomposition.
[0123] Feature combination. After obtaining the features of the original training samples and their positive and negative contrasting samples, ACAE combines the features of positive sample pairs or negative sample pairs in a certain proportion to obtain positive mixed features and negative mixed features. For example... Figure 5 As shown, z is the latent vector representation of a certain training sample, and z + , z - These are the latent vector representations of one of its positive and negative samples, respectively. Let z be a vector representing a positive sample and a negative sample, respectively. + and z -The process of combining positive and negative mixed features is as follows:
[0124]
[0125]
[0126] In the formula, α and β are combination parameters that determine the contribution of each old feature in the fusion feature. In each forward channel, when generating each fusion feature for each training sample, α and β are sampled separately from a uniform distribution with a minimum value of 0 and a maximum value of 1, i.e., α ~ U(0, 1) and β ~ U(0, 1).
[0127] Feature decomposition. ACAE uses a multilayer perceptron to implement the structure as follows: Figure 5 The discriminator shown is used to decompose the components from the mixed features before combination. Specifically, the original features of the sample and a mixed feature it generates are fed into the discriminator. After passing through a multilayer perceptron, a vector of length 2 is obtained as the result of feature decomposition. The discriminator has two objectives: first, to correctly classify the category of the mixed feature; and second, to correctly predict the proportion of the original features in the mixed feature, i.e., the combination parameters (α or β) used to generate the mixed feature. The first bit of the output vector represents the discriminator's prediction of the mixed feature category. 1 represents a positive mixed feature, and 0 represents a negative mixed feature. The second bit of the output vector represents the discriminator's prediction of the proportion of the mixed feature components; the standard value of this prediction is α or β. This invention uses mean squared error loss to constrain the difference between the discriminator's predicted vector and the true value; therefore, the discriminator's loss function is as follows:
[0128]
[0129] In the formula, N is the number of training windows. and These represent the decomposition results of the discriminator on the j-th positive mixture feature and the k-th negative mixture feature of the i-th sample, respectively. d + and l - These are real tags, where l d + = (1, α), l - = (0, β), where m is the number of positive samples, n+n×m is the number of negative samples, and α and β are combination parameters that determine the contribution of each old feature in the mixed features, β = 1-α.
[0130] If the discriminator can correctly decompose the mixed features, then the two components that make up the mixed features must have some differences. Furthermore, based on the idea of contrastive learning, the similarity between the features of different views of a sample should be maximized. When a sample has features z and z' of its augmented sample... + If they are consistent, then the mixed feature z obtained with any α c + Since all values are consistent with z, the discriminator will predict α as 1, meaning the mixed features all originate from the original samples. Based on this idea, the encoder will be trained under the guidance of the discriminator, aiming to correctly decompose negative mixed features while failing to decompose positive mixed features well. The concept of generative adversarial analysis is introduced into the discriminator's task of predicting the combination parameter α of positive mixed features, causing the encoder to generate as similar positive sample pairs as possible to confuse the discriminator. The generator's loss function is as follows:
[0131]
[0132] In the formula, and These represent the decomposition results of the discriminator on the j-th positive mixture feature and the k-th negative mixture feature of the i-th sample, respectively. E + and l - These are real tags, where l E + = (1,1) represents the difference in loss function calculation between the encoder and discriminator, and also embodies the generative adversarial approach. The discriminator and encoder are trained alternately, constraining the encoder to extract as similar as possible latent vectors from different views of the same sample, while extracting dissimilar latent vectors from different samples, thereby learning a robust data representation.
[0133] The contrastive learning framework based on feature combination and decomposition proposed in this invention is consistent with the basic idea of individual discrimination agent tasks. However, this invention uses a discriminative approach instead of directly calculating the similarity between features and does not constrain the distribution of features, making it more suitable for time series anomaly detection tasks.
[0134] 7. Refactoring and Anomaly Detection
[0135] The contrastive learning training task helps the encoder learn the overall trend and high-level semantic features of the time series, while the reconstruction task allows the model to focus more on fine-grained features. Furthermore, the two-stage task may lead to suboptimal model performance. Therefore, ACAE performs both contrastive learning and reconstruction tasks simultaneously. This invention implements a decoder whose structure is approximately symmetric to the encoder structure. Its main objective is to reconstruct the input data based on the latent vectors of the samples, and its structure is as follows: Figure 3 As shown on the right. Let D(·) represent the decoder; this process can be represented as:
[0136] x'=D(z)
[0137] In the formula, x'∈R M×w Let be the reconstructed data of sample x. The loss for reconstruction can be expressed as:
[0138]
[0139] Where N is the number of training windows, w is the window size, and... and x i,t These are the reconstructed data and the original data at time step t in the i-th window, respectively. The overall training loss of the proposed method can be expressed as the sum of the reconstruction loss and the contrastive loss:
[0140] L = L recon +λ1L d +λ2L E
[0141] Where λ1 and λ2 are hyperparameters controlling the relative importance of each loss. This invention employs an alternating optimization method in the model optimization stage, and Algorithm 1 summarizes the training process of the proposed method.
[0142] ACAE is optimized using a training set that consists mostly of normal data to learn normal patterns in the data. After training, the encoder and decoder are retained while the discriminator module is discarded. During the testing phase, similar to many other reconstruction-based methods, ACAE uses the encoder and decoder to reconstruct the test samples and calculates anomaly scores based on the reconstruction error of the samples at each time step, i.e.:
[0143]
[0144] Where S i,t Let be the anomaly score at time step t of the i-th test data. The choice of threshold depends on the application scenario, and there are many studies on dynamically configuring the threshold based on the anomaly score. This invention focuses on designing a framework for learning high-level semantic features of data and performing anomaly detection. Therefore, the experimental results reported in this invention are based on the highest-scoring threshold, as done in previous work.
[0145] The pseudocode for the implementation of this invention is shown in Table 1.
[0146] Table 1
[0147]
[0148]
[0149] Furthermore, this application verifies the effectiveness of the above solution using specific data, as follows:
[0150] First, we conducted comparative experiments with ACAE and 14 other advanced models on five authoritative real-world datasets representing the diversity of time-series data distributions and actual smart meter datasets. This demonstrated the effectiveness and advancement of the proposed multi-dimensional time-series anomaly detection method for electricity meters based on adversarial contrastive autoencoders.
[0151] Evaluation metrics: AUC, Fc1, and PA%K were selected as evaluation metrics to assess the performance of the proposed method and the baseline.
[0152] Area Under Curve (AUC). AUC is one of the most popular metrics for evaluating unsupervised anomaly detection tasks. It is the area under the receiver operating curve (ROC) and the coordinate axes. AUC directly reflects the quality of the algorithm's ranking of anomaly scores on the test samples, excluding the influence of thresholds. The AUC value ranges from 0 to 1. A perfect ranking will result in an AUC of 1, while a trivial model based on random guessing will have an AUC value close to 0.5.
[0153] Composite F-score (Fc1). Fc1 is a recently proposed metric that focuses on a model's ability to detect outliers while avoiding the overestimation of model performance caused by point adjustment strategies. It changes the original F1 score's recall calculation method to calculate the recall of outlier segments, while maintaining the original method of calculating point-by-point accuracy. A model with higher outlier recall and fewer false positives at normal time steps will receive a higher Fc1 score.
[0154] PointAdjustment%K (PA%K). To address the overestimation of model performance caused by point adjustment strategies, recent literature has proposed PA%K. It also calculates the F1 score for all time steps, but only applies the point adjustment strategy to adjust the predicted values when the proportion of outliers detected by the model in a continuous outlier segment exceeds K percent of the entire outlier segment's length. Then, the model's dependence on K is reduced by adjusting K and calculating the area under the curve of PA%K.
[0155] Comparison method:
[0156] The proposed ACAE method was compared with 14 baseline methods, as shown below. Among them, LOF, OSVM, and iForest are classic machine learning-based anomaly detection methods, while the others are recently popular deep learning-based time series anomaly detection algorithms.
[0157] LOF (Location of Fiber) is a method for anomaly detection by calculating the local density deviation of a given data point relative to its neighborhood.
[0158] OCSVM is a method that maps data samples to a high-dimensional feature space using a kernel function and delineates positive anomaly boundaries.
[0159] iForest is an ensemble model that isolates anomalies by randomly selecting features and randomly splitting observations.
[0160] MSCRED is a model that uses convolutional neural networks to obtain feature maps of samples at different scales and then reconstructs them at multiple scales using an attention-based convolutional long short-term memory network.
[0161] BeatGAN is a model based on an adversarial autoencoder structure. It adds a discriminator to the original autoencoder structure to improve the realism of the autoencoder reconstruction.
[0162] USAD. An anomaly detection method based on two autoencoders trained adversarially to reconstruct data. Anomaly scores are calculated using the reconstruction errors of the two autoencoders.
[0163] UAE. A simple model based on a fully connected autoencoder, which was proposed along with Fc1 and achieved good results on the Fc1 metric.
[0164] InterFusion. A reconstruction model based on two hierarchical variational autoencoders, which model the inter-metric correlation and temporal correlation of MTS, respectively.
[0165] GDN is a model that uses an attention mechanism and graph neural network to learn the structure graph of MTS and predict its future values, while utilizing the prediction error to detect outliers.
[0166] GTA. A predictive model that combines graph neural networks and Transformers to mine MTS features, and also uses the error between predicted and observed values to calculate anomaly scores.
[0167] TranAD is a deep Transformer-based reconstruction model that leverages self-regulation and adversarial training to amplify errors and achieve stable performance.
[0168] AT. A Transformer-based model that detects anomalies by combining reconstruction error and correlation differences between sequences.
[0169] TimeCLR is a contrastive learning framework for time series representation that uses dynamic time warping for data augmentation and InceptionTime for feature extraction.
[0170] CAE_AD. An end-to-end autoencoder that combines contrastive learning with contextual and instance contrast.
[0171] Implementation details:
[0172] ACAE was implemented using PyTorch. During the data augmentation phase, four time masks with masking ratios of 0.05, 0.15, 0.3, and 0.5 were used to generate four augmented views for each training data set. The optimal number of negative samples, n, was searched for for each dataset from 4, 8, 12, 16, and 20. The dimensions M' of the projection layer and h of the latent vectors were both set to 128; dropout of 0.5 was applied to the first two layers of the discriminator; λ1 and λ2 were both set to 1. The sliding window length w was set to 128, the stride to 8, and the batch size to 128. The training data was divided into training and validation sets in an 8:2 ratio, with a maximum of 200 training epochs. Training was stopped early if the reconstruction loss on the validation set did not decrease for five consecutive epochs, and the model with the lowest reconstruction loss on the validation set was retained. ACAE was trained using the Adam optimizer with a learning rate of 1e-4 and a weight decay of 1e-4. All experiments were repeated five times under different random seeds, and the average results were reported.
[0173] Introduction to the public dataset:
[0174] Five real-world datasets from three scenarios were used, and Table 2 summarizes the properties of these datasets.
[0175] Secure Water Treatment (SWaT). SWaT is a continuously operating water treatment system that collects data from 51 sensors, recording anomalous events caused by cyber and physical attacks.
[0176] Server Machine Dataset (SMD). SMD is a dataset collected and publicly released by a large internet company over a five-week period from server machines with 38 monitoring metrics.
[0177] PSM (Pooled Server Metrics) is a dataset collected from multiple application server nodes within eBay, comprising 26 dimensions.
[0178] The Mars Science Laboratory (MSL) dataset and the Soil Moisture Active Passive (SMAP) dataset. Both MSL and SMAP datasets are real-world datasets from NASA, with 55 and 25 dimensions respectively, and contain telemetry anomaly data derived from Incident Surprise Anomaly (ISA) reports from spacecraft monitoring systems.
[0179] Table 2 Characteristics of Public Datasets
[0180]
[0181] Evaluation of results from public datasets:
[0182] Table 3 reports the AUC, Fc1, and PA%K scores for ACAE and other baseline models. We use bold to indicate the best scores on each dataset and underline to indicate the second-best scores. Overall, ACAE achieves the highest scores across all three metrics, significantly outperforming other baselines, indicating that ACAE outperforms all baseline models. CAE_AD achieves second-best Fc1 and PA%K scores, similarly demonstrating that the reconstruction model incorporating contrastive learning can better model normal patterns in the data. iForest achieves a second-best AUC score, demonstrating good ranking quality for outlier scores at each time step; however, its inability to consider temporal correlation may prevent it from detecting consecutive outlier segments. Specifically, on the SWAT dataset, ACAE's Fc1 score is significantly higher than other baselines, while its AUC and PA%K scores are slightly below the best. On the SMD and PSM datasets, although ACAE's AUC score is high, its F1c and PA%K scores are somewhat below the best. On the MSL dataset, ACAE's AUC score is significantly higher than all baseline methods, while its Fc1 and PA%K scores are slightly below the best. On the SMAP dataset, it is at the average level.
[0183] Table 3. Baseline method and ACAE AUC, Fc1 and PA%K
[0184]
[0185] Introduction to electricity meter datasets:
[0186] The specific characteristics of the Smart Meter Dataset (ELE) are shown in Table 4. This dataset was collected from nine physical three-phase meters across multiple distribution areas. Each meter includes 22 sensor values: current (phase A, phase B, phase C), voltage (phase A, phase B, phase C), energy readings (positive active), energy readings (reverse active), energy readings (positive reactive), energy readings (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).
[0187] Table 4 Characteristics of Actual Electricity Meter Data Sets
[0188]
[0189] These three-phase electricity meters exhibited various anomalies during their respective data recording periods, including reverse power flow, overcurrent, current loss, meter reversal, meter flying away, uneven meter readings, meter stopping, and abnormal reverse power. The dataset contains data collected daily at 96 sampling points for 9-16 months from each meter, including both normal and abnormal meter data. The experiment used a data range containing only normal data for training and tested the data containing anomalies.
[0190] The evaluation results of the actual electricity meter dataset are shown in Table 5:
[0191] Experiments were conducted on a smart meter dataset using the ACAE algorithm and baseline methods, yielding results shown in Table 5. The results indicate that ACAE achieved the highest scores across all three evaluation metrics. Therefore, it can be concluded that ACAE's anomaly detection performance at the real-world meter data level is significantly superior to the baseline method, consistent with the results shown on publicly available datasets.
[0192] Table 5
[0193]
[0194] Therefore, this application addresses the challenges of existing reconstruction-based multivariate time series anomaly detection methods for smart meters, which struggle to learn the overall trend of the data, and the unsuitability of data augmentation and surrogate tasks in existing contrastive learning methods for time series anomaly detection. To address these issues, an Adversarial Contrastive Autoencoder (ACAE) framework for multivariate time series anomaly detection in electricity meters is proposed. ACAE solves the problem of existing methods struggling to learn high-level semantic features of multivariate time series data with complex temporal, dimensional, and dynamic dependencies. ACAE improves the robustness of the model to normal data by introducing contrastive learning constraints on the autoencoder's latent space, making anomalies easier to identify. ACAE employs a multivariate time series data augmentation method based on multi-scale timestamp masks to obtain multiple augmented views of the original samples, encouraging the model to utilize multi-scale information of the time series to model its overall trend. Then, ACAE performs contrastive learning based on surrogate tasks of feature combination and decomposition. The robustness of the encoder's latent variables is improved by introducing an adversarial training process. This framework avoids the potential loss of effective information that may occur with existing contrastive learning frameworks for multivariate time series data. By comparing the joint training of learning and reconstruction tasks, the model can simultaneously consider point-by-point contextual information and overall trend information in the multivariate data of smart meters, thereby improving the model's generalization ability and the accuracy of anomaly detection.
[0195] Exemplary device
[0196] Figure 6This is a schematic diagram of the structure of an energy meter anomaly detection device based on an adversarial comparison autoencoder provided in an exemplary embodiment of the present invention. Figure 6 As shown, the device 600 includes:
[0197] The acquisition module 610 is used to acquire multivariate long-term series data of historical detection of the energy meter under test;
[0198] The partitioning module 620 is used to normalize multivariate long-term series data and partition the data into multiple time windows of a preset window length.
[0199] The output module 630 is used to input multiple time window data into a pre-trained anomaly detection model and output the reconstructed data corresponding to each time window data. The anomaly detection model adopts an adversarial contrastive autoencoder.
[0200] The determination module 640 is used to determine the anomaly score of each time point of the time window data based on the reconstructed data and time window data of each time window data, and to determine the degree of anomaly at each time point based on the anomaly score.
[0201] Optionally, the multivariate long-term series data includes: phase A current, phase B current, phase C current, phase A voltage, phase B voltage, phase C voltage, forward active energy indication, reverse active energy indication, forward reactive energy indication, reverse reactive energy indication, phase A active power, phase B active power, phase C active power, total active power, phase A reactive power, phase B reactive power, phase C reactive power, total reactive power, phase A power factor, phase B power factor, phase C power factor, and total power factor.
[0202] Optionally, after acquiring multivariate long-term series data of historical measurements of the energy meter under test, the device 600 further includes:
[0203] The standardization module is used to standardize the data using Z-Score to ensure that all values of each variable in a multivariate long-term series data conform to a standard normal distribution.
[0204] The formula for Z-Score standardization is:
[0205]
[0206] In the formula, X i For multivariate long-term series data, Represents the standardized X i μ represents X i The mean of all sample data for each variable, σ represents X. i The standard deviation of all sample data for each variable.
[0207] Optionally, the training process of the anomaly detection model in output module 630 is as follows:
[0208] The acquisition submodule is used to acquire multivariate time series data samples from multiple historical energy meter readings and merge them into a single multivariate long-term data sample.
[0209] The standardization submodule is used to use Z-Score standardization to ensure that all values of each variable in a multivariate long-term series data sample conform to a standard normal distribution.
[0210] The windowing submodule is used to window standardized multivariate long-term series data samples, dividing them into multiple time window data samples with preset windows;
[0211] The first determination submodule is used to input multiple time window data samples into the projection layer and then apply timestamp masks for data augmentation to determine positive and negative sample pairs.
[0212] The second determination submodule is used to input positive and negative sample pairs into the encoder for feature extraction and to determine the features of positive and negative sample pairs.
[0213] The third determination submodule is used to train the model using positive and negative samples, features, encoder, discriminator, and decoder to determine the anomaly detection model.
[0214] Optionally, the first determined submodule includes:
[0215] The first acquisition unit is used to input the time window data samples into the projection layer and obtain the projection representation of each sample;
[0216] The second acquisition unit is used to acquire positive and negative samples of data samples for each time window using multi-scale timestamp masks and random sampling;
[0217] The first determining unit is used to determine positive sample pairs by setting multiple enhanced samples of a sample with different masking probabilities in timestamp masking.
[0218] The second determining unit is used to extract a predetermined number of samples from other original time window data samples and the enhanced samples of each class as negative samples of the original time window data, and to determine the negative sample pair of each sample.
[0219] Optionally, the process of inputting positive and negative sample pairs into the encoder for feature extraction and determining the features of positive and negative sample pairs can be represented as follows:
[0220] z = E(a)
[0221] In the formula, E(·) represents the encoder, z is the latent vector, i.e. the positive and negative sample pair features, z∈Rh, h is the length of the latent vector, and a is the projection representation obtained after the original time series window data is input into the projection layer.
[0222] Optionally, the third determining submodule includes:
[0223] The third determining unit is used to recombine the features of positive and negative sample pairs to determine the combined features of positive and negative sample pairs.
[0224] The third acquisition unit is used to input the positive and negative sample pair features and the combined features of positive and negative sample pairs into the discriminator to obtain the prediction results and the discriminator loss.
[0225] The first update unit is used to update the discriminator, minimize the discriminator loss, and obtain the prediction result again.
[0226] The fourth determining unit is used to input the prediction results into the encoder to determine the encoding result and the encoding loss;
[0227] The second update unit is used to update the encoder, minimize the encoding loss, and obtain the encoding result again.
[0228] The fifth determining unit is used to reconstruct the features of positive and negative sample pairs based on the encoder and decoder, and to determine the reconstruction loss.
[0229] The sixth determining unit is used to update the encoder and decoder, minimize the reconstruction loss, and determine the anomaly detection model.
[0230] Optionally, the process of reorganizing the features of positive and negative samples is as follows:
[0231]
[0232]
[0233] In the formula, α and β are combination parameters that determine the contribution of each old feature in the mixed features, z is the latent vector representation of a training sample, and z + , z - These are the latent vector representations of one of its positive and one of its negative samples, z. c + , z c - These are positive combination features and negative combination features, respectively;
[0234] The loss function L of the discriminator d for:
[0235]
[0236] In the formula, N is the number of training windows, pij and p ik These represent the decomposition results of the discriminator on the j-th positive mixture feature and the k-th negative mixture feature of the i-th sample, respectively. d + and l - These are real tags, where l + = (1, α), l - = (0, β), where m is the number of positive samples, n+n×m is the number of negative samples, and α and β are combination parameters β = 1-α that determine the contribution of each old feature in the mixed features;
[0237] The encoder's loss function L E for:
[0238]
[0239] In the formula, p ij and p ik These represent the decomposition results of the discriminator on the j-th positive mixture feature and the k-th negative mixture feature of the i-th sample, respectively. E + and l - These are real tags, where l E + = (1, 1), l - = (0, β), where m is the number of positive samples and n + n × m is the number of negative samples;
[0240] Reconstruction loss function L recon for:
[0241]
[0242] In the formula, N is the number of training windows, and w is the window size. and x i,t These are the reconstructed data and the original data at time step t in the i-th window, respectively.
[0243] Optionally, the formula for calculating the outlier score is:
[0244]
[0245] In the formula, S i,t It is the outlier score at time step t of the i-th test data. and x i,t These are the reconstructed data and the original data at time step t in the i-th window, respectively.
[0246] Exemplary electronic devices
[0247] Figure 7 This is the structure of an electronic device provided in an exemplary embodiment of the present invention. For example... Figure 7 As shown, the electronic device 70 includes one or more processors 71 and a memory 72.
[0248] The processor 71 may be a central processing unit (CPU) or other form of processing unit with data processing and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
[0249] The memory 72 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 71 may execute the program instructions to implement the methods of the software programs of the various embodiments of the present invention described above, and / or other desired functions. In one example, the electronic device may also include an input device 73 and an output device 74, these components being interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0250] In addition, the input device 73 may also include, for example, a keyboard, a mouse, etc.
[0251] The output device 74 can output various information to the outside. The output device 74 may include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, etc.
[0252] Of course, for the sake of simplicity, Figure 7 Only some of the components of this electronic device relevant to the present invention are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device may include any other suitable components depending on the specific application.
[0253] Exemplary computer program products and computer-readable storage media
[0254] In addition to the methods and apparatus described above, embodiments of the present invention may also be computer program products, which include computer program instructions that, when executed by a processor, cause the processor to perform the steps in the methods according to various embodiments of the present invention described in the "Exemplary Methods" section above.
[0255] The computer program product can be written in any combination of one or more programming languages to perform the operations of the embodiments of the present invention. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0256] Furthermore, embodiments of the present invention may also be computer-readable storage media storing computer program instructions thereon, which, when executed by a processor, cause the processor to perform the steps of the methods according to various embodiments of the present invention described in the "Exemplary Methods" section above.
[0257] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.
[0258] The basic principles of the present invention have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in the present invention are merely examples and not limitations, and should not be considered as essential features of each embodiment of the present invention. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the present invention to the necessity of employing the aforementioned specific details.
[0259] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system embodiments, since they largely correspond to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0260] The block diagrams of devices, systems, devices, and systems involved in this invention are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, systems, devices, and systems can be connected, arranged, and configured in any manner. Words such as “comprising,” “including,” “having,” etc., are open-ended terms meaning “including but not limited to,” and are used interchangeably with them. The terms “or” and “and” as used herein refer to the terms “and / or,” and are used interchangeably with them unless the context clearly indicates otherwise. The term “such as” as used herein refers to the phrase “such as but not limited to,” and is used interchangeably with it.
[0261] The methods and systems of the present invention may be implemented in many ways. For example, they may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above-described order of steps for the methods is for illustrative purposes only, and the steps of the methods of the present invention are not limited to the order specifically described above unless otherwise specifically stated. Furthermore, in some embodiments, the present invention may also be implemented as a program recorded on a recording medium, the program comprising machine-readable instructions for implementing the methods according to the present invention. Thus, the present invention also covers recording media storing programs for performing the methods according to the present invention.
[0262] It should also be noted that in the systems, apparatus, and methods of the present invention, the components or steps can be disassembled and / or recombined. These disassemblies and / or recombinations should be considered equivalents of the present invention. The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the invention. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein can be applied to other aspects without departing from the scope of the invention. Therefore, the invention is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features disclosed herein.
[0263] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of the invention to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations therein.
Claims
1. A method for detecting anomalies in an energy meter based on an adversarial contrast autoencoder, characterized in that, include: Acquire multivariate long-term series data of historical measurements of the energy meter under test; The multivariate long-term series data is normalized and divided into multiple time windows of a preset window length; Multiple time window data are input into a pre-trained anomaly detection model, and reconstructed data corresponding to each time window data is output. The anomaly detection model employs an adversarial contrastive autoencoder. Based on the reconstructed data of each time window and the time window data, the anomaly score of each time point in the time window data is determined, and the degree of anomaly at each time point is determined based on the anomaly score. The training process of the anomaly detection model is as follows: Acquire multivariate time series data samples from multiple historical energy meter readings and merge them into a single multivariate long-term data sample. Z-Score standardization was used to ensure that all values of each variable in the multivariate long-term series data sample conformed to a standard normal distribution. Standardized multivariate long-term series data samples are windowed and divided into multiple time window data samples of the preset window; After inputting multiple time window data samples into the projection layer, a timestamp mask is applied for data augmentation to determine positive and negative sample pairs. The positive and negative sample pairs are input into the encoder for feature extraction to determine the features of the positive and negative sample pairs. The anomaly detection model is determined by training the model using the positive and negative sample pairs, the encoder, the discriminator, and the decoder. Using the positive and negative sample pairs, the encoder, the discriminator, and the decoder, a model is trained to determine the anomaly detection model, including: First, the features of positive or negative sample pairs are combined to generate positive or negative mixed features. Then, the discriminator is trained to decompose the mixed features. If the discriminator can correctly predict the components of the negative mixed features but has difficulty predicting the components of the positive mixed features, it indicates that there are certain differences between the features of the negative sample pairs and high similarity between the features of the positive sample pairs, thus achieving contrastive learning. The positive and negative sample pairs are recombined to determine the combined features of the positive and negative sample pairs. The positive and negative sample pair features and the combined positive and negative sample pair features are input into the discriminator to obtain the prediction results and the discriminator loss. The encoder will be trained under the guidance of the discriminator, with the goal of making the negative mixed features correctly decomposed. Update the discriminator to minimize the discriminator loss, and obtain the prediction result again; The prediction result is input into the encoder to determine the encoding result and the encoding loss; Update the encoder, minimize the encoding loss, and obtain the encoding result again; Based on the encoder and the decoder, the features of the positive and negative sample pairs are reconstructed, and the reconstruction loss is determined. Update the encoder and the decoder, minimize the reconstruction loss, and determine the anomaly detection model.
2. The method according to claim 1, characterized in that, The multivariate long-term series data includes: phase A current, phase B current, phase C current, phase A voltage, phase B voltage, phase C voltage, forward active energy readings, reverse active energy readings, forward reactive energy readings, reverse reactive energy readings, phase A active power, phase B active power, phase C active power, total active power, phase A reactive power, phase B reactive power, phase C reactive power, total reactive power, phase A power factor, phase B power factor, phase C power factor, and total power factor.
3. The method according to claim 1, characterized in that, After acquiring the multivariate long-term series data of the historical measurements of the electricity meter under test, the following steps are also included: Z-Score standardization was used to ensure that all values of each variable in the multivariate long-term series data conformed to a standard normal distribution, where The formula for Z-Score standardization is: In the formula, For multivariate long-term series data, Represents the standardized , express A vector of the mean values of all sample data for each variable. express A vector of the standard deviations of all sample data for each variable.
4. The method according to claim 1, characterized in that, After inputting multiple time window data samples into the projection layer, a timestamp mask is applied for data augmentation to determine positive and negative sample pairs, including: The time window data samples are input into the projection layer to obtain the projection representation of each sample; Positive and negative samples of data for each time window are obtained using multi-scale timestamp masks and random sampling. Multiple enhanced samples of a single sample are obtained by setting different masking probabilities in timestamp masking to determine positive sample pairs; A predetermined number of samples are extracted from other original time window data samples and the augmented samples of each class as negative samples of the original time window data, and negative sample pairs are determined for each sample.
5. The method according to claim 1, characterized in that, The process of inputting the positive and negative sample pairs into the encoder for feature extraction and determining the features of the positive and negative sample pairs is represented as follows: In the formula, Represents encoder, It is the projected representation or its enhanced sample obtained after the original time-series window data is input into the projection layer. for The latent vectors are the features of the original samples or pairs of positive and negative samples. , is the length of the implicit vector.
6. The method according to claim 1, characterized in that, The process of recombining the features of the positive and negative samples is as follows: In the formula, and To determine the combined parameters for the contribution of each old feature in the mixed features, z is the latent vector representation of a training sample, and , These are the latent vector representations of its positive and negative samples, respectively. , These are positive combination features and negative combination features, respectively; The loss function of the discriminator L d for: In the formula, The number of training windows, and These represent the discriminator's pair with the first... The first sample The positive mixing feature and the first Decomposition results of negative mixed features and These are real labels, among which , , It is the number of positive samples in a single sample. It is the number of negative samples. and To determine the combined parameters of the contribution of each old feature in the mixed features, 1 represents a positive mixture feature, and 0 represents a negative mixture feature; The loss function of the encoder L E for: In the formula, and These represent the discriminator's pair with the first... The first sample The positive mixing feature and the first Decomposition results of negative mixed features and These are real labels, among which, , , It is the number of positive samples in a single sample. It is the number of negative samples; The reconstruction loss function L recon for: In the formula, The number of training windows, It refers to the size of the window. and They are the first Time step in each window The reconstructed data and the original data.
7. The method according to claim 1, characterized in that, The formula for calculating the abnormal score is: In the formula, It is the time step of the i-th test data. Abnormal scores, and They are the first Time step in each window The reconstructed data and the original data.
8. An energy meter anomaly detection device based on an adversarial contrast autoencoder, used to implement the method of claim 1, characterized in that, include: The acquisition module is used to acquire multivariate long-term series data of historical tests of the energy meter under test; The partitioning module is used to normalize the multivariate long-term series data and partition it into multiple time windows of a preset window length. The output module is used to input multiple time window data into a pre-trained anomaly detection model and output reconstructed data corresponding to each time window data. The anomaly detection model uses an adversarial contrastive autoencoder. The determination module is used to determine the anomaly score of each time point of the time window data based on the reconstructed data of each time window data and the time window data, and to determine the degree of anomaly at each time point based on the anomaly score.
Citation Information
Patent Citations
Electric energy meter abnormality diagnosis method and device
CN110888101A
