Electrical load anomaly detection method based on time sequence contrast learning

Through the method based on time series comparison learning, the deep features of electricity load data are extracted, which solves the problem that traditional detection methods cannot identify electricity load abnormalities in real time, and achieves higher detection accuracy and real-time performance, adapting to the complex needs of modern power systems.

CN119720007APending Publication Date: 2025-03-28STATE GRID SHANGHAI MUNICIPAL ELECTRIC POWER CO +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411691553.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

Traditional power load abnormal detection methods cannot reflect the changes in the state of the power equipment in real time, resulting in the failure to detect potential problems in time and it is difficult to meet the increasingly complex needs of modern power systems.

Method used

The power load anomaly detection method based on time series comparison learning is adopted, and the deep features of power load data are extracted through deep learning technology, and the comparison learning model is constructed for training. The abnormal threshold is set using the clustering algorithm to detect abnormal power load in real time.

Benefits of technology

It improves the abnormality detection accuracy and real-time performance of power load data, can better identify abnormal points in complex load modes, and meet the complex needs of modern power systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119720007A_ABST
    Figure CN119720007A_ABST
Patent Text Reader

Abstract

The invention discloses an electrical load anomaly detection method based on time sequence comparative learning, and the method comprises the steps: S1, collecting electrical load data, and constructing a time sequence data set which comprises a training set and a test set; s2, constructing a comparative learning model, and training the comparative learning model based on the training set; s3, applying the trained comparative learning model to all the subsequences in the test set, performing feature extraction on all the subsequences, reconstructing the input subsequences to generate reconstructed data, performing clustering analysis on residual errors of the reconstructed data and original data by using a clustering algorithm, and setting an abnormal threshold value according to a clustering result; and S4, collecting real-time electrical load data of a user as new data, inputting the new data into the trained comparative learning model to obtain corresponding feature data, and if the corresponding feature data exceeds an abnormal threshold, determining that the new data is an abnormal electrical load. The method has the advantage that the anomaly detection precision of the electrical load data is improved through a comparative learning technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of data mining and machine learning, and in particular to a method for detecting abnormal power load using time series contrast learning technology. Background Art

[0002] With the global emphasis on energy efficiency and sustainable development, the power industry faces huge challenges and opportunities. Traditional power anomaly detection methods often rely on manual inspections and static data record comparisons, which cannot reflect the status changes of power equipment in real time, resulting in many potential problems not being discovered in time. In this context, power load anomaly detection based on smart meters and advanced data processing technology came into being.

[0003] Modern power systems not only need to meet the growing electricity demand of users, but also need to deal with the volatility and uncertainty of power supply. Especially in scenarios such as smart homes, industrial production, and commercial buildings, there are many types of electrical equipment and complex electricity usage behaviors. Traditional anomaly detection methods can no longer meet the requirements of real-time and accuracy. Therefore, it is particularly important to develop efficient and intelligent detection and analysis tools.

[0004] It should be understood that the above statements merely provide background technology related to the present invention and do not necessarily constitute prior art. Summary of the invention

[0005] Based on the above-mentioned technical problems, the purpose of the present invention is to provide a method for detecting power load anomaly based on time series comparative learning. This method improves the accuracy of anomaly detection of power load data through deep learning technology, and can better meet the increasingly complex needs of modern power systems.

[0006] In order to achieve the above object, the present invention is implemented by the following technical solutions:

[0007] A method for detecting abnormal power load based on time series contrast learning, comprising:

[0008] S1. Collect the user's electricity load data and construct a time series data set, wherein the time series data set includes a training set and a test set, and each of the training set and the test set includes multiple subsequences;

[0009] S2. constructing a contrastive learning model, and training the contrastive learning model based on the training set;

[0010] S3, applying the trained contrastive learning model to all subsequences in the test set, extracting features from all subsequences and reconstructing the input subsequences to generate reconstructed data, using a clustering algorithm to perform cluster analysis on the residuals between the reconstructed data and the original data, and setting an abnormal threshold according to the clustering results;

[0011] S4. Collect the user's real-time power load data as new data, input the new data into the trained comparative learning model to obtain its corresponding feature data, and if its corresponding feature data exceeds the abnormal threshold, the new data is determined to be abnormal power load.

[0012] Optionally, the S1 comprises:

[0013] Collect users' electricity load data and pre-process it;

[0014] The preprocessed data is divided into a plurality of time series subsequences of fixed length, and a training set and a test set are divided based on the plurality of subsequences, wherein the training set is used to train the contrastive learning model, and the test set is used to test the contrastive learning model.

[0015] Optionally, the preprocessing includes denoising and normalization.

[0016] Optionally, the contrastive learning model includes an encoder and a decoder, the encoder is used to extract features from input data and output its corresponding output matrix, and the decoder reconstructs the input data based on the output matrix.

[0017] Optionally, the encoder includes a multi-head self-attention mechanism module, which is trained by means of a feedforward neural network. The multi-head self-attention mechanism module includes h head attention sub-modules connected in sequence, the output of the previous head attention sub-module is the input of the next head attention sub-module, and the calculation method of each head attention sub-module is the same.

[0018] Optionally, training the contrastive learning model based on the training set includes:

[0019] Select subsequences from the training set and divide the subsequences into historical parts and future parts;

[0020] Add position encoding to the subsequence to get the input vector X embed , and use it as the input of the first head attention submodule of the multi-head self-attention mechanism module;

[0021] The head attention submodule pays attention to the input vector X embed Perform linear transformation to obtain three learnable matrices: query Q, key K, and value V;

[0022] Compute the similarity between query Q and key K using scaled dot product:

[0023]

[0024] Among them, Attention(Q,K,V) is the output matrix of the head attention submodule, d k is the dimension of the key vector used for scaling, and T represents the transformation of the matrix;

[0025] The output matrix of the previous head attention submodule is used as the input of the next head attention submodule to obtain the output matrix of each head attention submodule respectively;

[0026] The results of the h head attention submodules are concatenated through multi-head attention, and the output matrix MultiHead(Q, K, V) is obtained through a linear transformation:

[0027] MultiHead(Q,K,V)=Concat(head1,head2,...,head h )W O (2)

[0028] Among them, head1, head2, ···, head h are the output matrices of each head attention submodule Attention(Q,K,V), W O is the parameter matrix;

[0029] Through the residual connection MultiHead(Q,K,V) and layer normalization, the output matrix Z of the encoder is obtained;

[0030] The decoder outputs reconstructed data of the subsequence based on the output matrix Z of the encoder;

[0031] The reconstructed data of the future part of the subsequence generated by the decoder is compared with its corresponding real data through the loss function to optimize the contrastive learning model.

[0032] Optionally, the loss function is:

[0033]

[0034] Where n is the number of samples, y i For the real data of the future part, Reconstruction data for future parts.

[0035] Optionally, the S3 includes:

[0036] Applying the trained contrastive learning model to all subsequences in the test set, and outputting the reconstructed data of each subsequence in the test set through the contrastive learning model;

[0037] The reconstructed data of each subsequence in the test set is compared with the corresponding real data through the loss function, and the residual of each data point is calculated;

[0038] Clustering is performed based on residuals to divide data points into different categories, where the cluster with the largest residual is the abnormal category;

[0039] Set anomaly thresholds based on clustering results.

[0040] Optionally, also include:

[0041] S5. Evaluate the detection effect of the contrastive learning model.

[0042] Optionally, evaluate the detection effect of the contrast learning model by accuracy, recall and F1-score.

[0043] The accuracy rate includes:

[0044]

[0045] Among them, Precision represents the accuracy rate; TP is the true positive example, which means the number of samples correctly predicted as positive by the model; FP is the false positive example, which means the number of samples incorrectly predicted as positive by the model;

[0046] The recall rate includes:

[0047]

[0048] Among them, Recall represents the recall rate; FN is the false negative example, which means the number of samples that are incorrectly predicted as negative by the model;

[0049] The F1-score includes:

[0050]

[0051] Compared with the prior art, the present invention has the following advantages:

[0052] The power load anomaly detection method based on time series contrastive learning of the present invention utilizes time series contrastive learning to extract deep features of power load data, so that the contrastive learning model can better understand the intrinsic structure of the time series, thereby identifying anomalies. This method can improve the anomaly detection accuracy and real-time performance of power load data, thereby better meeting the increasingly complex needs of modern power systems. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for the description. Obviously, the drawings described below are an embodiment of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work:

[0054] Figure 1 A schematic diagram of a method for detecting abnormal power load based on time series contrast learning of the present invention;

[0055] Figure 2 A schematic diagram of a flow chart of a method for detecting abnormal power load based on time series contrast learning of the present invention;

[0056] Figure 3 It is a structural schematic diagram of a contrastive learning model of the present invention;

[0057] Figure 4 A simplified flowchart of a workflow for training a contrastive learning model according to the present invention;

[0058] Figure 5 It is a schematic diagram of negative sampling of the present invention. DETAILED DESCRIPTION

[0059] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0060] It should be noted that, in this article, the terms "include", "comprises", "has" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "includes..." or "comprising..." do not exclude the existence of other elements in the process, method, article or terminal device including the elements.

[0061] It should be noted that the drawings are all in very simplified form and use inaccurate ratios, and are only used to conveniently and clearly assist in explaining the embodiments of the present invention.

[0062] Change Point Detection (CPD) is an important research area in time series data analysis. It aims to identify the moments when significant changes occur in the data, which may represent the transition of system state, abnormal events, or the emergence of other important features. Traditional change point detection methods usually rely on statistical models, and their accuracy and real-time performance often cannot meet actual needs.

[0063] Based on the foregoing, the present invention provides a method for detecting anomalies in power load based on time series contrastive learning. Contrastive learning is a self-supervised learning method that learns feature representations by comparing similarities and differences between samples. In the context of time series, contrastive learning can effectively capture the temporal features in the data and help identify potential change points. Compared with traditional methods, the change point detection method based on contrastive learning has stronger adaptability and robustness, especially when faced with high-dimensional and complex data. The power load anomaly detection method based on time series contrastive learning of the present invention aims to improve the accuracy and real-time performance of anomaly detection of power load data through deep learning technology to adapt to the increasingly complex needs of modern power systems; the method can effectively identify anomalies, and relevant decision makers can take timely measures to reduce risks and optimize resource allocation.

[0064] The core of the power load anomaly detection method based on time series contrastive learning of the present invention is to use time series contrastive learning to extract the deep features of power load data. This method requires the construction of appropriate positive samples and negative samples, which divides the time series data into different time segments, and then uses the similarity of these segments for learning. Through contrastive learning, the contrastive learning model can better understand the intrinsic structure of the time series, thereby identifying anomalies. This method not only improves the accuracy of detection, but also can be effectively trained in the absence of labeled data.

[0065] Specifically, Figure 1 and Figure 2 As shown, the power load anomaly detection method based on time series contrast learning of the present invention includes:

[0066] S1. Collect the user's electricity load data and construct a time series data set, wherein the time series data set includes a training set and a test set, and each of the training set and the test set includes multiple subsequences.

[0067] Specifically, S1 includes: collecting users' electricity load data and preprocessing it; dividing the preprocessed data into multiple time series subsequences of fixed length, and dividing the training set and the test set based on the multiple subsequences, the training set is used to train the contrastive learning model, and the test set is used to test the contrastive learning model, and the training set and the test set are mutually exclusive.

[0068] In the initial stage of implementing this method, it is necessary to first install smart meters in the target monitoring area. The smart meters can collect power load data in real time, including information such as current, voltage, and power. In order to ensure the timeliness and accuracy of the data, a reasonable data collection frequency can be set according to actual needs. Usually, data collection can be performed once a minute or once an hour. In this way, a rich time series data set is established, laying a solid foundation for subsequent analysis and processing.

[0069] Optionally, the preprocessing may include denoising and normalization to improve data quality and consistency. In practical applications, the data in the collected time series data set are denoised to eliminate outliers caused by equipment failure or environmental factors. After denoising, it is necessary to process the missing values ​​in the data. Commonly used methods include interpolation methods, such as linear interpolation or spline interpolation, to fill in missing data and ensure the integrity and coherence of the time series. Finally, the preprocessed data is normalized using methods such as minimum-maximum normalization or Z-score normalization to make the data in the same order of magnitude, thereby improving the effect and efficiency of subsequent model training.

[0070] After completing the data preprocessing, construct the time series subsequences. Specifically, through the sliding window technology, the time series data in the time series data set is divided into multiple subsequences of fixed length for subsequent feature extraction and analysis. For example, the window size can be set to 24 hours (or 1440 minutes), so that each subsequence will contain the power load data of the past 24 hours. In this way, the continuous time series can be effectively converted into a format that can be used for model training. At the same time, a label is assigned to each subsequence to identify whether it is a normal load or an abnormal load. This process will provide the necessary supervision information for subsequent model training.

[0071] S2. Constructing a contrastive learning model, that is, constructing a deep learning model based on contrastive learning, and training the contrastive learning model based on the training set.

[0072] Specifically, S2 includes: S21, constructing a contrastive learning model. When constructing a contrastive learning model, it is necessary to select a deep learning framework suitable for time series analysis, such as SimCLR or BYOL. The key to these models is to use the mechanism of self-supervised learning to extract effective features through contrastive learning. After the contrastive learning model is built, the contrastive learning model is trained and tested. Each subsequence in the time series data set is divided into a training set and a test set to ensure the generalization ability of the model. Perform model training on the training set, optimize the model parameters through the contrastive learning mechanism, and iteratively update until the model converges.

[0073] Furthermore, when training the contrastive learning model, the feature representation ability of the model on positive and negative samples can be optimized by designing a suitable loss function to ensure that the model can effectively distinguish normal samples from abnormal samples. Optionally, a contrastive loss or a triplet loss function can be used to enable the model to better learn the potential structure of the power load data. Based on the above, the model can automatically identify normal and abnormal patterns in the power load data by learning the similarities and differences of the data.

[0074] like Figure 3 The figure shows a schematic diagram of the structure of a contrastive learning model of the present invention (multiple Transformers are stacked). The contrastive learning model includes an encoder and a decoder, wherein the encoder is used to extract features from input data and output its corresponding output matrix, and the decoder reconstructs the input data based on the output matrix.

[0075] Specifically, the encoder includes a multi-head self-attention mechanism module, namely a multi-head self-attention mechanism (Multi-Head Self-Attention), which is trained by a feedforward neural network to adapt to the characteristics of time series data. In the encoder layer, the multi-head self-attention mechanism captures different feature relationships through multiple different attention heads. Specifically, the multi-head self-attention mechanism module includes h sequentially connected head attention submodules, each head attention submodule includes a multi-head attention layer, the output of the previous head attention submodule is the input of the next head attention submodule, and the calculation method of each head attention submodule is the same.

[0076] Furthermore, the S2 further comprises: S22, training the contrastive learning model based on the training set. Figure 4 As shown, the S22 comprises:

[0077] S221. Select a subsequence from the training set, and divide the subsequence into a historical part and a future part.

[0078] When the contrastive learning model is trained using the training set, the data sampling and input of the contrastive learning model are performed using negative sampling (see Figure 5 ), partially mask the positive sample (+) to generate the negative sample (-). This method first obtains samples, i.e., subsequences, from the training set, and divides the subsequences into a history part (History) and a future part (Future). That is, the input data for training the contrastive learning model includes two parts, namely, the history data of the time series and the future data, which will be used for model reconstruction and analysis. In the training stage, all subsequences in the training set are divided in the above manner (divided into a history part and a future part).

[0079] S222, add position encoding to the subsequence to obtain input vector X embed , and use it as the input of the first head attention submodule of the multi-head self-attention mechanism module.

[0080] Specifically, the historical part and the future part of the subsequence are encoded to generate a universal representation of the time series (encoded vector). The input received by the encoder is a subsequence X = [x1, x2, ..., x n ], where x i represents the input vector at the i-th position. In order to capture the position information in the subsequence, the input vector will add the position code X embed =X+PE, where PE represents position encoding, which is used to introduce the relative position information of each position.

[0081] Next, the multi-head self-attention mechanism module captures different feature relationships through multiple different head attention sub-modules.

[0082] S223, linear transformation: the head attention submodule is used to transform the input vector X embed Perform linear transformation to obtain three learnable matrices: query Q (Query), key K (Key), and value V (Value).

[0083] S224, attention calculation: Calculate the similarity between query Q and key K, using scaled dot product to achieve:

[0084]

[0085] Among them, Attention(Q,K,V) is the output matrix of the head attention submodule, d k It is the dimension of the key vector used for scaling to prevent the gradient from disappearing due to excessive values; T represents the transformation of the matrix.

[0086] S225. Use the output matrix of the previous head attention sub-module as the input of the next head attention sub-module, that is, transform it to obtain three learnable matrices, and calculate to obtain the output matrices of each head attention sub-module respectively.

[0087] S226, multi-head mechanism: The results of h head attention sub-modules are spliced ​​through multi-head attention, and the output matrix MultiHead(Q, K, V) is obtained through a linear transformation:

[0088] MultiHead(Q,K,V)=Concat(head1,head2,...,head h )W O (2)

[0089] Among them, head1, head2, ···, head h are the output matrices of each head attention submodule Attention(Q,K,V), W O is the parameter matrix.

[0090] S227, residual connection and layer normalization: Through residual connection MultiHead(Q, K, V) and layer normalization processing, the model can be helped to train a deeper structure to obtain the output matrix Z of the encoder, where the output matrix Z is the feature representation of the real subsequence. The output matrix Z contains the high-level feature representation of the input subsequence for use in subsequent tasks (such as classification, prediction, etc.).

[0091] S228. The decoder outputs the reconstructed subsequence data based on the output matrix Z of the encoder.

[0092] S229. Compare the subsequence reconstructed data reconstructed by the decoder with the corresponding subsequence real data through the loss function, and optimize the contrast learning model through the stochastic gradient descent algorithm (SGD).

[0093] Specifically, by comparing the similarity between the reconstructed data of the future part of the subsequence and the real data, a contrast loss is calculated. The purpose of this loss is to ensure that the decoder can reconstruct a representation that conforms to the characteristics of time series changes. The loss function is:

[0094]

[0095] Where n is the number of samples, y i For the real data of the future part, Reconstruction data for future parts.

[0096] Based on the above method, the contrastive learning model is trained through the subsequences in the training set. After the contrastive learning model training is completed, it is switched to the test mode. In the test mode, all weights and parameters in the contrastive learning model are fixed. At this time, each subsequence in the test set is equivalent to the future part as a whole.

[0097] Based on this, the power load anomaly detection method based on time series contrast learning of the present invention also includes: S3, applying the trained contrast learning model to all subsequences in the test set, extracting features from all subsequences and reconstructing the input subsequences to generate reconstructed data, using a clustering algorithm to perform clustering analysis on the residuals between the reconstructed data and the original data, and setting an anomaly threshold based on the clustering results.

[0098] Specifically, S3 includes: S31, applying the trained contrastive learning model to all subsequences in the test set, and outputting the reconstructed data of each subsequence in the test set through the contrastive learning model. Specifically, when the contrastive learning model is tested with the test set, each subsequence in the test set is substituted into the contrastive learning model respectively to obtain the reconstructed data of each subsequence in the test set, so as to perform high-dimensional feature representation on it.

[0099] S32, using a loss function to compare the reconstructed data of each subsequence in the test set with the corresponding real data, and calculating the residual of each data point, i.e., the reconstruction error. A data point with a large residual means that there is a significant difference from the normal mode. Optionally, the loss function used for the comparison may be the above-mentioned MSE loss function.

[0100] S33. Clustering is performed based on residuals to divide data points into different categories. The cluster with the largest residual is the abnormal category. The features of such points are significantly different from the general time series features and are candidates for change points. After feature extraction is completed, clustering algorithms (such as K-Means or DBSCAN) are used to perform cluster analysis on the extracted features to identify normal and abnormal load patterns.

[0101] S34, setting an abnormal threshold based on the clustering result. A threshold is set according to the clustering result so as to mark the detected abnormal power load data. The above clustering-based abnormality detection method can effectively improve the accuracy of detection and reduce false positives and false negatives.

[0102] Furthermore, the power load anomaly detection method based on time series contrast learning of the present invention also includes: S4, collecting the user's real-time power load data as new data, inputting the new data into the trained contrast learning model to obtain its corresponding feature data, and if its corresponding feature data exceeds the abnormal threshold, then the new data is determined to be an abnormal power load. In practical applications, when the feature representation of the new data exceeds the abnormal threshold, it can be determined to be an abnormal power load, and an abnormal point label can be assigned to it. In this way, real-time monitoring and anomaly detection of power load data can be achieved.

[0103] Furthermore, to ensure the validity and reliability of the model, the power load anomaly detection method based on time series contrast learning of the present invention further comprises: S5, evaluating the detection effect of the contrast learning model.

[0104] Specifically, in one embodiment, the detection effect of the contrastive learning model is evaluated by accuracy, recall and F1-score, so as to continuously optimize and adjust the model parameters. Generally speaking, the higher the above three indicators are, the better the performance of the model is.

[0105] Specifically, the accuracy rate includes:

[0106]

[0107] Among them, Precision represents the accuracy rate; TP (True Positive) is the true positive example, which means the number of samples correctly detected as positive by the model; FP (False Positive) is the false positive example, which means the number of samples incorrectly detected as positive by the model; in this method, TP means that the model successfully identifies the actual anomaly points, and P means that the model mistakenly detects the normal points as anomalies, which is called "false alarm".

[0108] The recall rate includes:

[0109]

[0110] Among them, Recall represents the recall rate; FN is the false negative example, which means the number of samples that are mistakenly predicted as negative by the model.

[0111] The F1-score includes:

[0112]

[0113] Further, based on the above scheme, the applicant team used the method of the present invention to detect and process the electricity load data of a certain region in 2023, and compared it with the detection method using other models. Specifically, the data set information is shown in Table 1 below. The time span of the data source is from January 1, 2022 to June 30, 2024, and the sampling time interval of the smart meter is 1 hour. In the experiment, the data in 2023 was mainly preprocessed to construct a time series data set.

[0114] Table 1 Dataset information used for detection

[0115]

[0116] Based on the above data from 2023, the experimental results of detection methods based on different models are compared in Table 2:

[0117] Table 2 Comparison of various models

[0118]

[0119]

[0120] Among them, RMSE is the root mean square error, MAE is the mean absolute error, and MAPE is the mean absolute percentage error. The above indicators are used to evaluate the performance of each regression model.

[0121] Based on the above results, it can be seen that the power load anomaly detection method using the contrast learning model in the present invention has better detection effect. Specifically, please refer to the evaluation comparison results in Table 3 below.

[0122] Table 3 Detection and evaluation comparison table

[0123]

[0124] In summary, the above-mentioned power load anomaly detection method based on time series contrast learning of the present invention can effectively overcome the limitations of traditional power load anomaly detection and achieve in-depth analysis and accurate identification of complex load patterns. This method not only improves the efficiency of anomaly detection, but also can adapt to the changing power environment in real time, providing strong technical support for the safe operation of smart grids.

[0125] Although the content of the present invention has been described in detail through the above preferred embodiments, it should be appreciated that the above description should not be considered as a limitation of the present invention. After reading the above content, it will be apparent to those skilled in the art that various modifications and substitutions of the present invention will occur. Therefore, the protection scope of the present invention should be limited by the appended claims.

Claims

1. A method for detecting abnormal power load based on time series contrast learning, characterized in that: Include: S1. Collect the user's electricity load data and construct a time series data set, wherein the time series data set includes a training set and a test set, and each of the training set and the test set includes multiple subsequences; S2. constructing a contrastive learning model, and training the contrastive learning model based on the training set; S3, applying the trained contrastive learning model to all subsequences in the test set, extracting features from all subsequences and reconstructing the input subsequences to generate reconstructed data, using a clustering algorithm to perform cluster analysis on the residuals between the reconstructed data and the original data, and setting an abnormal threshold according to the clustering results; S4. Collect the user's real-time power load data as new data, input the new data into the trained comparative learning model to obtain its corresponding feature data, and if its corresponding feature data exceeds the abnormal threshold, the new data is determined to be abnormal power load.

2. The method for detecting abnormal power load based on time series contrast learning according to claim 1, characterized in that: The S1 comprises: Collect users' electricity load data and pre-process it; The preprocessed data is divided into a plurality of time series subsequences of fixed length, and a training set and a test set are divided based on the plurality of subsequences, wherein the training set is used to train the contrastive learning model, and the test set is used to test the contrastive learning model.

3. The method for detecting abnormal power load based on time series contrast learning according to claim 2, characterized in that: The preprocessing includes denoising and normalization.

4. The method for detecting abnormal power load based on time series contrast learning according to claim 1, characterized in that: The contrastive learning model includes an encoder and a decoder, wherein the encoder is used to extract features from input data and output a corresponding output matrix, and the decoder reconstructs the input data based on the output matrix.

5. The method for detecting abnormal power load based on time series contrast learning according to claim 4, characterized in that: The encoder includes a multi-head self-attention mechanism module, which is trained by a feedforward neural network. The multi-head self-attention mechanism module includes h head attention sub-modules connected in sequence, the output of the previous head attention sub-module is the input of the next head attention sub-module, and the calculation method of each head attention sub-module is the same.

6. The method for detecting abnormal power load based on time series contrast learning according to claim 5, characterized in that: Training the contrastive learning model based on the training set includes: Select subsequences from the training set and divide the subsequences into historical parts and future parts; Add position encoding to the subsequence to get the input vector X embed , and use it as the input of the first head attention submodule of the multi-head self-attention mechanism module; The head attention submodule pays attention to the input vector X embed Perform linear transformation to obtain three learnable matrices: query Q, key K, and value V; Compute the similarity between query Q and key K using scaled dot product: Among them, Attention(Q,K,V) is the output matrix of the head attention submodule, d k is the dimension of the key vector used for scaling, and T represents the transformation of the matrix; The output matrix of the previous head attention submodule is used as the input of the next head attention submodule to obtain the output matrix of each head attention submodule respectively; The results of the h head attention submodules are concatenated through multi-head attention, and the output matrix MultiHead(Q, K, V) is obtained through a linear transformation: MultiHead(Q,K,V)=Concat(head1,head2,...,head h )W O (2) Among them, head1, head2, ···, head h are the output matrices of each head attention submodule Attention(Q,K,V), W O is the parameter matrix; Through the residual connection MultiHead(Q,K,V) and layer normalization, the output matrix Z of the encoder is obtained; The decoder outputs reconstructed data of the subsequence based on the output matrix Z of the encoder; The reconstructed data of the future part of the subsequence generated by the decoder is compared with its corresponding real data through the loss function to optimize the contrastive learning model.

7. The method for detecting abnormal power load based on time series contrast learning according to claim 6, characterized in that: The loss function is: Where n is the number of samples, y i For the real data of the future part, Reconstruction data for future parts.

8. The method for detecting abnormal power load based on time series contrast learning according to claim 1, characterized in that: The S3 includes: Applying the trained contrastive learning model to all subsequences in the test set, and outputting the reconstructed data of each subsequence in the test set through the contrastive learning model; The reconstructed data of each subsequence in the test set is compared with the corresponding real data through the loss function, and the residual of each data point is calculated; Clustering is performed based on residuals to divide data points into different categories, where the cluster with the largest residual is the abnormal category; Set anomaly thresholds based on clustering results.

9. The method for detecting abnormal power load based on time series contrast learning according to claim 1, characterized in that: Also includes: S5. Evaluate the detection effect of the contrastive learning model.

10. The method for detecting abnormal power load based on time series contrast learning according to claim 9, characterized in that: The detection effect of the contrast learning model is evaluated by accuracy, recall and F1-score, where the accuracy includes: Among them, Precision represents the accuracy rate; TP is the true positive example, which means the number of samples correctly predicted as positive by the model; FP is the false positive example, which means the number of samples incorrectly predicted as positive by the model; The recall rate includes: Among them, Recall represents the recall rate; FN is the false negative example, which means the number of samples that are incorrectly predicted as negative by the model; The F1-score includes:

Citation Information

Cited By

  • Substation simulation through-flow test method based on comparative learning

    CN121598272A

  • A substation analog through-flow test method based on contrast learning

    CN121598272B