A data anomaly detection method and a power grid data anomaly detection method

By using dilated convolution, multi-scale generators and attention mechanisms of Transformer generative adversarial networks, and dynamically adjusting weights, combined with gradient penalty mechanisms, the problems of insufficient accuracy and generalization in time series anomaly detection are solved, achieving more efficient anomaly detection results.

CN113157771BActive Publication Date: 2026-11-20GUANGDONG HAILIAO TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110459689.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-27
Publication Date
2026-11-20
Estimated Expiration
2041-04-27

AI Technical Summary

Technical Problem

Existing time series anomaly detection methods struggle to achieve accuracy and generalization in complex data environments, and label acquisition is difficult or expensive, resulting in poor anomaly detection performance.

Method used

We employ dilated convolution and Transformer generative adversarial networks, dynamically adjust generator weights through multi-scale generators and attention mechanisms, and combine gradient penalty mechanisms to generate the final model for anomaly detection.

Benefits of technology

It improves the accuracy and generalization ability of anomaly detection, effectively solving the detection problem in complex environments of time series data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113157771B_ABST
    Figure CN113157771B_ABST
Patent Text Reader

Abstract

The application discloses a data anomaly detection method, comprising generating an initial model; using a multi-scale generator; training the initial model; generating a loss function; and performing anomaly detection. The application extracts data information of a time sequence through a sliding window, and uses a hollow convolution to improve the accuracy of the model and enhance the generalization ability of the model. The application also provides a power grid data anomaly detection method. The application uses multiple generators and a single discriminator to alleviate the mode collapse problem. Each generator contains a convolutional neural network of different sizes to obtain fine-grained and coarse-grained information of the time sequence. A Transformer module is included in the generator to process the time series data and improve the accuracy. The application uses an attention mechanism to balance the generators, which can better adapt to the currently used data. Therefore, the application can effectively solve the problems of low precision and poor generalization ability in streaming data anomaly detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of big data processing, specifically relating to a data anomaly detection method and a power grid data anomaly detection method. Background Technology

[0002] Using big data for anomaly detection saves manpower and resources, making it an increasingly common approach to problem-solving. Data anomaly detection methods typically employ time-series anomaly detection. Time-series anomalies refer to observations that differ significantly from other observations within a specific time series. Anomaly detection methods play a crucial role in numerous fields, including extreme weather or climate monitoring, network intrusion detection, chemical fault diagnosis, and power grid fault diagnosis. For example, in extreme weather, quantitative indicators such as wind direction, wind speed, and precipitation may exhibit varying degrees of anomaly; anomaly detection utilizes models to predict potential extreme weather events. In chemical faults, valve readings may show anomalies. In network intrusions, anomaly detection can promptly identify abnormal access and control operations. In power grid fault diagnosis, power faults can be detected through anomalies in power-related data. Failure to detect anomalies in a timely manner can lead to economic losses and even personal injury.

[0003] However, time series labels are often too difficult to obtain or too expensive. For decades, many researchers have dedicated themselves to detecting anomalies in time series. Some early methods attempted to build a mathematical model that perfectly fit the given data and treated outliers as anomalous. These methods distinguished between normal and anomalous samples by measuring the distance between each sample or the density of each point. Therefore, to obtain good experimental results, a model that perfectly fits the real data is needed; however, when the situation is complex and the data is influenced by multiple factors, it is difficult to describe real-world data using a single model. Summary of the Invention

[0004] One of the objectives of this invention is to provide a data anomaly detection method that utilizes dilated convolution and Transformer to generate adversarial data for data anomaly detection, thereby improving the accuracy and generalization of the anomaly detection method.

[0005] The second objective of this invention is to provide a method for detecting anomalies in power grid data.

[0006] The data anomaly detection method provided by this invention includes the following steps:

[0007] S1. Generate the initial model; use the Transformer module based on dilated convolution as the generator in the generative adversarial network;

[0008] S2. Use a multi-scale generator; extract features from the data from several perspectives, enabling the multi-scale generator to generalize its ability to extract features from information at different scales.

[0009] S3. Train the initial model; in each iteration, use an attention mechanism to dynamically adjust the weights of several multi-scale generators so that these multi-scale generators have different weights;

[0010] S4. Generate the loss function, add a gradient penalty mechanism to the loss function, and generate the final model;

[0011] S5. Use the generated final model for anomaly detection.

[0012] Step S1 specifically involves the generator G. i ,make For pointing to generator G i The j-th convolution in The convolution kernel after the holes are filled; the kernel size is... The size of the dilated convolution kernel is stride is The void velocity is Fill p i The relationship between them satisfies the formula:

[0013]

[0014] If x refers to a sequence x with padding, then the third element of the result is hashed as follows:

[0015]

[0016] Among them, DilatedConv i,j (·) represents the generator G i The dilated convolution of the j-th convolution; m represents the m-th value of the dilated convolution result. Void ratio; The size of the dilated convolution kernel; This is the input for the dilated convolution; This represents the size of the dilated convolution kernel.

[0017] Add a Transformer-based network; the core of the Transformer-based network is the self-attention technique, which maps a query Q and a set of key-value pairs K and V to an output; for a generator G with the j-th convolutional kernel i ,at the same time, Where ω is the number of detection windows, and d is the dimension of the latent representation in the Transformer; for a given timestamp t, the following equation holds:

[0018]

[0019] Wherein, the function f is a set of linear projections; For a generator G with the j-th convolutional kernel at time t... i The query output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The key output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The value of self-attention; For detection window D i The sequence detected at time t; DilatedConv i,j (·) represents the generator G i The dilated convolution of the j-th convolution;

[0020] The self-attention block is formed as follows:

[0021]

[0022] Where Att(·) is a self-attention block; For length All one-dimensional vectors; For a generator G with the j-th convolutional kernel at time t... i The query output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The key output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The value of self-attention.

[0023] Step S2 specifically involves weighting several generators at several scales to improve the generator's generalization performance on the data, and proposing a GAN with multi-scale generators.

[0024] The weighting methods for several generators at several scales specifically include:

[0025] A1. Create q generators, each generator G i It consists of a DCT architecture and a set of linear projections, and is based on the detection window D. i Information is obtained from , where 1≤i≤q;

[0026] A2. Integrate the generators according to their importance and different weights to generate pseudo-data;

[0027] A3. Use a single discriminator D to compare the integrated pseudo data with the real data.

[0028] Step S3 specifically involves using a generative adversarial network based on dilated convolutions and Transformer modules as the training model, including the following steps:

[0029] B1. Extract the raw data and preprocess it;

[0030] B2. Update the generator's weights;

[0031] B3. Train the generator and discriminator, and update the generator and discriminator.

[0032] Step B1 specifically involves defining time series X as a series containing l X A sequence of data points is defined, along with a set of detection windows D; for a specific generator G... i Using detection window D i ∈D, the original data is cut into subsequences and then sent to the model for training.

[0033] Step B2 specifically involves using an attention mechanism to assign dynamic weights to each generator; the weights are calculated as follows:

[0034] Define initial weights Calculate the generator G in iteration B based on real samples. i weight

[0035]

[0036] in, The loss for the real samples in iteration B-1;

[0037] Calculate the generator G in iteration B based on pseudo-samples. i weight

[0038]

[0039] in, Let be the loss for pseudo-samples in iteration B-1.

[0040] Step B3 specifically involves alternately updating the discriminator D and the generator G during the training of the generative adversarial model; d is the dimension of the latent representation in the Transformer. In the B-th iteration, the discriminator D is updated based on the following equation:

[0041]

[0042] Where, θ d Here are the discriminator parameters; M is the maximum number of iterations during DCT-GAN training; q is the number of generators; x (B)The actual data used in the Bth iteration; z (B) Here are the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update;

[0043] Train the generator and update generator G according to the following equation:

[0044]

[0045] Where, θ d Here are the discriminator parameters; M is the maximum number of iterations during DCT-GAN training; and q is the number of generators. For generator G in iteration B i The weights of z; (B) Here are the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update.

[0046] The loss function mentioned in step S4 is as follows: In the generative adversarial model proposed in this invention, the loss function includes the loss of the GAN itself and the gradient penalty; the loss of the GAN itself represents the accuracy of the discriminator in distinguishing between generated data and real data; the gradient penalty is used to implement the Lipschitz constraint; in the Bth iteration of the generative adversarial model, the entire loss function is defined as follows:

[0047]

[0048] in, M is the maximum number of iterations when training DCT-GAN; q is the number of generators; For generator G in iteration B i The weights; x (B) The actual data used in the Bth iteration; z (B) Here are the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update.

[0049] This invention also discloses a power grid data anomaly detection method based on the above-mentioned data anomaly detection method, comprising the following steps:

[0050] C1. Extract power grid data;

[0051] C2. Generate the final model from the power grid data through steps S1 to S4;

[0052] C3. Use the generated final model to perform anomaly detection on the power grid data.

[0053] This invention provides a data anomaly detection method and a power grid data anomaly detection method. It uses a sliding window to extract time series data information and employs dilated convolution to improve model accuracy and generalization ability. This invention utilizes multiple generators and a single discriminator to mitigate the pattern collapse problem. Each generator contains a convolutional neural network of different sizes to obtain fine-grained and coarse-grained information from the time series. Simultaneously, each generator includes a Transformer module for processing the time series data to improve accuracy; furthermore, an attention mechanism is used to balance these generators, enabling them to adapt well to the currently used data. Therefore, this invention effectively solves the problems of low accuracy and poor generalization ability in streaming data anomaly detection. Attached Figure Description

[0054] Figure 1 This is a flowchart illustrating the method of the present invention.

[0055] Figure 2 This is a schematic diagram of data extraction based on a sliding window according to an embodiment of the present invention.

[0056] Figure 3 This is a schematic diagram of feature extraction based on a sliding window according to an embodiment of the present invention.

[0057] Figure 4 This is a schematic diagram of a generative adversarial network model according to an embodiment of the present invention.

[0058] Figure 5 This is a schematic diagram of the anomaly detection network model according to an embodiment of the present invention. Detailed Implementation

[0059] like Figure 1 The following is a flowchart illustrating the method of the present invention: The data anomaly detection method provided by the present invention includes the following steps:

[0060] S1. Generate the initial model; use a dilated convolution-based Transformer module as the generator in the generative adversarial network; the dilated convolution refers to a convolutional neural network with a fixed interval in the convolution kernel; the Transformer module refers to the Transformer generator module defined in the original Transformer model (including a multi-head attention module, a feedforward neural network, and residual connections).

[0061] S2. Use a multi-scale generator; extract features from the data from several perspectives, including coarse-grained and fine-grained, so that the multi-scale generator has the ability to generalize feature extraction for information at different scales.

[0062] S3. Train the initial model; in each iteration, use an attention mechanism to dynamically adjust the weights of several multi-scale generators so that these multi-scale generators have different weights;

[0063] S4. Generate a loss function, and add a gradient penalty mechanism to the loss function to make it less prone to mode collapse; generate the final model; the gradient penalty mechanism refers to the 1-GP gradient penalty term used in WGAN;

[0064] S5. Use the generated final model for anomaly detection.

[0065] The data anomaly detection method proposed in this invention is based on GAN-based temporal data anomaly detection. Transformer is a technique that updates a matrix using only the relationships between information within the matrix; for example... Figure 2 This is a schematic diagram of data extraction based on a sliding window according to an embodiment of the present invention; Figure 3 This is a schematic diagram of feature extraction based on a sliding window according to an embodiment of the present invention.

[0066] The model generated in step S1 is a Dilated Convolutional Transformer model, which forms the main structure of the generator and discriminator in a Generative Adversarial Network (GAN). Although the Transformer is a powerful tool for processing text sequences, it still struggles to directly extract information from the latent space. Therefore, we propose a Dilated Convolutional Transformer (DCT) architecture to address this issue. The DCT architecture includes multi-scale feature extraction and a Transformer-based network; multi-scale dilated CNNs are used for multi-scale feature extraction. Dilated CNNs can be used in semantic segmentation to expand the receptive field without reducing resolution and to acquire multi-scale information from the detection window. Since the current data is a single time series, a one-dimensional dilated CNN is chosen to process the data. Simultaneously, to ensure that the generators simultaneously acquire the same amount of information, multiple dilated CNN networks between each generator maintain a stable receptive field, encouraging the generators to acquire equal amounts of information simultaneously. To match the Transformer network, the detection window is padded to ensure that the output size of the detection window is equal.

[0067] Specifically for generator G i ,make For pointing to generator G i The j-th convolution in This is the convolution kernel after the holes are filled. The kernel size is... The size of the dilated convolution kernel is stride is The void velocity is Fill pi The relationship between them satisfies the formula: and

[0068] Formally, assuming x refers to a sequence x with padding, the third element of the result is scattered as follows:

[0069]

[0070] Among them, DilatedConv i,j (·) represents the generator G i The dilated convolution of the j-th convolution; m represents the m-th value of the dilated convolution result. Void ratio; The size of the dilated convolution kernel; This is the input for the dilated convolution; This represents the size of the dilated convolution kernel.

[0071] While dilated CNNs can extract multi-scale features from a single detection window, they are not adept at handling sequential data. Therefore, Transformer-based networks are added. The core of Transformer-based networks is the self-attention technique. Self-attention maps a query Q and a set of key-value pairs K and V to an output. For a generator G with the j-th convolutional kernel... i ,at the same time Where ω is the number of detection windows, and d is the dimension of the latent representation in the Transformer; for a given timestamp t, the following equation holds:

[0072]

[0073] Among them, DilatedConv i,j (·) represents the generator G i The dilated convolution of the j-th convolution; the function f is a set of linear projections; For a generator G with the j-th convolutional kernel at time t... i The query output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The key output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The value of self-attention; For detection window D i The sequence detected at time t;

[0074] The self-attention block is formed as follows:

[0075]

[0076] Where Att(·) is a self-attention block, For length All one-dimensional vectors; For a generator G with the j-th convolutional kernel at time t... i The query output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The key output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The value of self-attention.

[0077] Step S2 specifically involves weighting several generators across multiple scales to improve their generalization performance on the data. The DCT architecture possesses multi-scale feature extraction and time-series processing capabilities and can learn from the detection window, but a conflict exists: if the detection window... If the size is set to a small value, the mode may become ineffective due to the limited information received when long-term context exceptions are met; if the detection window is increased... Setting the size of the generator to a large value will cause the model to receive too much useless information, resulting in low accuracy or low efficiency. Therefore, GANs with multi-scale generators have been proposed.

[0078] The weighting methods for several generators at several scales specifically include:

[0079] A1. Create q generators, each generator G i (1≤i≤q) consists of a DCT architecture and a set of linear projections, and is derived from the detection window D. i To obtain information;

[0080] A2. Integrate the generators according to their importance and different weights to generate pseudo-data;

[0081] A3. Use a single discriminator D to compare the integrated pseudo data with the real data.

[0082] Step S3 specifically involves using a generative adversarial network based on dilated convolutions and Transformer modules as the training model, such as... Figure 4 This is a schematic diagram of a generative adversarial network model according to an embodiment of the present invention. It includes the following steps:

[0083] B1. Extract the raw data and preprocess it;

[0084] B2. Update the generator's weights;

[0085] B3. Train the generator and discriminator, and update the generator and discriminator.

[0086] Step B1 specifically involves defining time series X as a series containing l X A sequence of data points is defined, along with a set of detection windows D; for a specific generator G... i Using detection window D i ∈D, the original data is cut into subsequences and then sent to the model for training.

[0087] Step B2 specifically involves the following: Since the generator has its own preferences for different types of anomalies, using fixed weights to weight the generator cannot achieve good results. Therefore, an attention mechanism is adopted to assign dynamic weights to each generator, that is, the loss value during training is used as the basis for the importance of a specific generator.

[0088] Suppose that in an iteration B-1, a generator G is used. u With the use of generator G v In comparison, the discriminator's loss (BCE loss) is larger, so regardless of whether the sample passed to the generator is a real sample or generated data, the generator G is considered to be... v It is more suitable for the current data because in iteration B-1, the generator G v This provides a more accurate assessment of the data. Therefore, a generator G was added in the next iteration B. v The weight.

[0089] The method for calculating weights is as follows: Define initial weights. Calculate the generator G in iteration B based on real samples. i weight

[0090]

[0091] in, The loss for the real samples in iteration B-1;

[0092] Calculate the generator G in iteration B based on pseudo-samples. i weight

[0093]

[0094] in, Let be the loss for pseudo-samples in iteration B-1.

[0095] Step B3 is similar to the initial GAN, alternating updates to the discriminator D and generator G during the training of the generative adversarial model. In the B-th iteration, the discriminator D is updated based on the following equation:

[0096]

[0097] Where, θ d Here are the discriminator parameters; M is the maximum number of iterations during DCT-GAN training; q is the number of generators; x (B) The actual data used in the Bth iteration; z (B) Here are the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update;

[0098] Train the generator and update generator G according to the following equation:

[0099]

[0100] Where, θ d Here are the discriminator parameters; M is the maximum number of iterations during DCT-GAN training; and q is the number of generators. For generator G in iteration B i The weights of z (B) Here are the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update.

[0101] The loss function described in step S4 is as follows: In the generative adversarial model proposed in this invention, the loss function mainly consists of two parts: the loss of the GAN itself and the gradient penalty. The loss of the GAN itself represents the accuracy with which the discriminator distinguishes between generated data and real data, while the gradient penalty is used to implement the Lipschitz constraint and make the model more likely to converge. In the Bth iteration of the generative adversarial model, the entire loss function is defined as follows:

[0102]

[0103] in, M is the maximum number of iterations when training DCT-GAN; q is the number of generators. For generator G in iteration B i The weights; The actual data used in the Bth iteration; z (B) Here are the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update.

[0104] In a specific implementation, Algorithm 1 for training the model is as follows:

[0105] Input: X is a time series; D is a set of detection windows; b is the batch size when training DCT-GAN; M is the maximum number of iterations; q is the number of generators;

[0106] Output: G is a set of trained generators; D is a set of trained discriminators;

[0107] Initialize generator G and discriminator D, each generator The initial weight is (0);

[0108] for B=1,B <M,B++do;

[0109] for i = 1, i <M,i++do;

[0110] From S i Sample b sequence

[0111] From Sample noise z i ;

[0112] In each generator G i The previous iteration of calculating the real data and the previous iteration of pseudo data The training loss (BCE loss);

[0113] Calculate separately and

[0114] end for

[0115] Calculate L DG And by minimizing L DG To update the discriminator;

[0116] for i = 1, i <q,i++do 11;

[0117] Update generator G i ;

[0118] end for

[0119] end for

[0120] One implementation method for step S5 is as follows:

[0121] Step (1) Anomaly detection model structure.

[0122] Since the number of abnormal samples is small, all data can be used directly for training with a GAN structure to generate pseudo-samples that closely resemble real normal data. Therefore, this invention uses one of multiple generators to reconstruct the actual data; in a specific implementation, the generator is selected based on the required sliding window length, and in this embodiment, generator G is selected. a Perform anomaly detection. Due to generator G a Since it originates from a pre-trained model with a fixed structure, the hidden variable z is found in the latent space through backpropagation. * This makes the generating variable G a (z) is more similar to the real sample, such as Figure 5 This is a schematic diagram of the anomaly detection network model according to an embodiment of the present invention.

[0123] Step (2), loss function and algorithm for anomaly detection stage.

[0124] The loss function for anomaly detection consists of two main parts: the loss between real and pseudo data, and the loss between features extracted from real data and features extracted from pseudo data using a discriminator. The complete loss function can be expressed by the following formula:

[0125]

[0126] in f is the output of the intermediate layer of the discriminator.

[0127] In a specific implementation, the anomaly detection is as shown in Algorithm 2 below:

[0128] Input: T is the number of iterations; Parameters are assigned to the weights in the loss function; E represents the anomaly detection order; s w For detecting window size; G a To detect window-related trained generators, generate those related to G. a The prior probability of compatible noise; η is the anomaly rate;

[0129] Output: A list of anomalies detected in E and A;

[0130] for i = 1, i <T,i++do

[0131] Use E to train the latent space z

[0132] if i == T then

[0133] Store the trained potential space z a =z

[0134] end if

[0135] end if

[0136] At that time, L was calculated TSAD The value of l is used to sort the sequence E according to the loss, and the largest l is selected. E·η The samples are used to form an anomaly list A.

[0137] In specific implementations, power grid faults caused by transmission and transformation equipment include:

[0138] External damage to power transmission lines includes cranes hitting towers or lines, lightning strikes causing short circuits, tree branches or kites falling onto the lines causing short circuits, and pollution flashover caused by severe weather. These can all cause line tripping, accidents, or equipment damage.

[0139] Power equipment may be damaged or tripped due to excessive temperature, deterioration of insulation performance, excessive load, excessive electrical parameters, or mechanical reasons, which may further lead to power grid accidents.

[0140] To detect data anomalies in the power grid, the following steps are included:

[0141] C1. Extract power grid data;

[0142] C2. Generate the final model from the power grid data through steps S1 to S4;

[0143] C3. Use the generated final model to perform anomaly detection on the power grid data.

[0144] In practical implementation:

[0145] S0. Extract power grid data;

[0146] S1. Generate the initial model; use the Transformer module based on dilated convolution as the generator in the generative adversarial network;

[0147] S2. Using a multi-scale generator; extracting features from data from several perspectives, enabling the multi-scale generator to have the generalization ability to extract features from information at different scales; for power grid implementation examples, this invention can extract relevant parameters such as local load, voltage, and frequency in the power grid transmission and transformation process from multiple perspectives such as the rationality of the operation mode and the overload rate of the line, and form multi-scale measurement based on the weekly, monthly, quarterly, and annual fault occurrence of power equipment, thereby constituting a multi-scale generator, enabling the corresponding multi-scale generator to have the generalization ability to extract features from relevant parameters such as local load, voltage, and frequency in the power grid transmission and transformation process.

[0148] S3. Train the initial model; in each iteration, use the attention mechanism to dynamically adjust the weights of several multi-scale generators so that these multi-scale generators have different weights; in each iteration, use the attention mechanism to dynamically adjust the weights of multi-scale generators formed by the weekly, monthly, quarterly, and yearly fault occurrences of power equipment so that these multi-scale generators have different weights.

[0149] By conducting multiple experiments on the data features extracted from several multi-scale generators, the different weights of each multi-scale generator are dynamically adjusted to achieve the optimal state.

[0150] S4. Generate the loss function, add a gradient penalty mechanism to the loss function, and generate the final model;

[0151] S5. Use the generated final model for anomaly detection.

[0152] Step S1 specifically involves the generator G. i ,make For pointing to generator G i The j-th convolution in The convolution kernel after the holes are filled; the kernel size is... The size of the dilated convolution kernel is stride is The void velocity is Fill p i The relationship between them satisfies the formula:

[0153] and

[0154] If x refers to a sequence x with padding, then the third element of the result is hashed as follows:

[0155]

[0156] Among them, DilatedConv i,j (·) represents the generator G i The dilated convolution of the j-th convolution; m represents the m-th value of the dilated convolution result. Void ratio; The size of the dilated convolution kernel; This is the input for the dilated convolution; This represents the size of the dilated convolution kernel.

[0157] Add a Transformer-based network; the core of the Transformer-based network is the self-attention technique, which maps a query Q and a set of key-value pairs K and V to an output; for a generator G with the j-th convolutional kernel i ,at the same time, Where ω is the number of detection windows, and d is the dimension of the latent representation in the Transformer; for a given timestamp t, the following equation holds:

[0158]

[0159] Wherein, the function f is a set of linear projections; For a generator G with the j-th convolutional kernel at time t... i The query output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The key output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The value of self-attention; For detection window D i The sequence detected at time t; DilatedConv i,j (·) represents the generator G i The dilated convolution of the j-th convolution;

[0160] The self-attention block is formed as follows:

[0161]

[0162] Where Att(·) is a self-attention block; For length All one-dimensional vectors; For a generator G with the j-th convolutional kernel at time t... i The query output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The key output of self-attention; For a generator G with the j-th convolutional kernel at time t... i The value of self-attention.

[0163] Step S2 specifically involves weighting several generators at several scales to improve the generator's generalization performance on the data, and proposing a GAN with multi-scale generators.

[0164] The weighting methods for several generators at several scales specifically include:

[0165] A1. Create q generators, each generator G i It consists of a DCT architecture and a set of linear projections, and is based on the detection window D. i Information is obtained from , where 1≤i≤q;

[0166] A2. Integrate the generators according to their importance and different weights to generate pseudo-data;

[0167] A3. Use a single discriminator D to compare the integrated pseudo data with the real data.

[0168] Step S3 specifically involves using a generative adversarial network based on dilated convolutions and Transformer modules as the training model, including the following steps:

[0169] B1. Extract the raw data and preprocess it;

[0170] B2. Update the generator's weights;

[0171] B3. Train the generator and discriminator, and update the generator and discriminator.

[0172] Step B1 specifically involves defining time series X as a series containing l X A sequence of data points is defined, along with a set of detection windows D; for a specific generator G... i Using detection window D i ∈D, the original data is cut into subsequences and then sent to the model for training.

[0173] Step B2 specifically involves using an attention mechanism to assign dynamic weights to each generator; the weights are calculated as follows:

[0174] Define initial weights Calculate the generator G in iteration B based on real samples. i weight

[0175]

[0176] in, The loss for the real samples in iteration B-1;

[0177] Calculate the generator G in iteration B based on pseudo-samples. i weight

[0178]

[0179] in, Let be the loss for pseudo-samples in iteration B-1.

[0180] Step B3 specifically involves alternately updating the discriminator D and the generator G during the training of the generative adversarial model; d is the dimension of the latent representation in the Transformer. In the B-th iteration, the discriminator D is updated based on the following equation:

[0181]

[0182] Where, θ d Here are the discriminator parameters; M is the maximum number of iterations during DCT-GAN training; q is the number of generators; x (B) The actual data used in the Bth iteration; z (B) Here are the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update;

[0183] Train the generator and update generator G according to the following equation:

[0184]

[0185] Where, θ d Here are the discriminator parameters; M is the maximum number of iterations during DCT-GAN training; and q is the number of generators. For generator G in iteration B i The weights of z; (B ) represents the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update.

[0186] The loss function mentioned in step S4 is as follows: In the generative adversarial model proposed in this invention, the loss function includes the loss of the GAN itself and the gradient penalty; the loss of the GAN itself represents the accuracy of the discriminator in distinguishing between generated data and real data; the gradient penalty is used to implement the Lipschitz constraint; in the Bth iteration of the generative adversarial model, the entire loss function is defined as follows:

[0187]

[0188] in, M is the maximum number of iterations when training DCT-GAN; q is the number of generators; For generator G in iteration B i The weights; x( B ) represents the actual data used in the Bth iteration; z( B ) represents the pseudo-data used in the B-th iteration; log(·) represents taking the logarithm, used to calculate the reduced number; D(·) is the discriminator before the update; G i (·) represents the generator before the update.

Claims

1. A method for detecting anomalies in power grid data, comprising the following steps: C1. Extract power grid data; extract local loads, voltages, and frequencies during power grid transmission and transformation processes from the perspectives of operational rationality and line overload rates; C2. Generate the final model from the power grid data through steps S1-S4; specifically, the following steps are included: S1. Generate the initial model; use the Transformer module based on dilated convolution as the generator in the generative adversarial network; specifically, for the generator... G i ,make For pointer generator G i The first in j One convolutional kernel, The first after the cavity j There are 1 convolutional kernel; the kernel size is 1. The size of the dilated convolution kernel is stride is The void velocity is Fill with p i , The relationship between the parameters satisfies the formula: and Add a Transformer-based network; the core of a Transformer-based network is self-attention, which handles queries. Q and a set of key-value pairs K and V Mapped to an output; for the first... j Generator of convolutional kernels G i At a given timestamp t When the following equation holds: in, f The function is a set of linear projections; In order to be in t Time for having the first j Generator of convolutional kernels G i The query output of self-attention; In order to be in t Time for having the first j Generator of convolutional kernels G i The key output of self-attention; In order to be in t Time for having the first j Generator of convolutional kernels G i The value of self-attention; For detection window D i exist t The sequence detected at each moment; DilatedConv i,j (·) represents the generator G i The j Dilated convolution with a kernel; The self-attention block is formed as follows: Where Att(·) is a self-attention block; ; For length All one-dimensional vectors; d It is the dimension of the latent representation in the Transformer; S2. Use a multi-scale generator; extract features from the data from several perspectives, enabling the multi-scale generator to generalize its feature extraction capabilities across different scales; specifically, weight several generators at several scales to improve the generator's generalization performance on the data, and propose a GAN with a multi-scale generator; form multi-scale measurements based on the weekly, monthly, quarterly, and annual fault occurrences of power equipment, thereby constructing a multi-scale generator, enabling the corresponding multi-scale generator to generalize its feature extraction capabilities for local loads, voltages, and frequencies in the power grid transmission and transformation process; The weighting methods for several generators at several scales specifically include: A1. Establish q Each generator has 1 generator. G i It consists of a Transformer module based on dilated convolution and a set of linear projections, and it starts from the detection window. D i The information is obtained from , where 1≤ i ≤ q ; A2. Integrate the generators according to their importance and different weights to generate pseudo-data; A3. Using a single discriminator F Compare the integrated pseudo data with the real data; S3. Train the initial model; in each iteration, use an attention mechanism to dynamically adjust the weights of several multi-scale generators, giving them different weights; in each iteration, use an attention mechanism to dynamically adjust the weights of multi-scale generators formed by the weekly, monthly, quarterly, and yearly fault occurrences of power equipment, giving them different weights. Specifically, use a generative adversarial network based on dilated convolutions and Transformer modules as the training model, including the following steps: B1. Extract the raw data and preprocess it; specifically, define the time series. X For a containing l X A sequence of data points, and a set of detection windows defined simultaneously. D For a specific generator G i Using a detection window D i ∈ D The original data is cut into subsequences and then sent to the model for training. B2. Update the weights of the generators; specifically, use an attention mechanism to assign dynamic weights to each generator; the weights are calculated as follows: Define initial weights Iteration is calculated based on real samples. B Generator G i weight , in, In iteration B Loss on the real samples in -1; Iteration based on pseudo-samples B Generator G i weight , in, In iteration B -1 loss of pseudo-samples; B3. Train the generator and discriminator, and update the generator and discriminator; specifically, alternately update the discriminator while training the generative adversarial model. F and generator G ; S4. Generate a loss function and add a gradient penalty mechanism to the loss function. The gradient penalty mechanism refers to the 1-GP gradient penalty term used in WGAN to generate the final model. In the generative adversarial model, the loss function includes the loss of GAN itself and the gradient penalty. The loss of GAN itself represents the accuracy of the discriminator in distinguishing between generated data and real data. The gradient penalty is used to implement the Lipschitz constraint. C3. Use the generated final model to perform anomaly detection on the power grid data.