Power data anomaly detection method and model based on generative adversarial network
By using adversarial training with generative adversarial networks and an LSTM network architecture, the challenges of temporal characteristics and nonlinear correlations in power data anomaly detection were addressed, achieving efficient power data anomaly detection and improving the model's recognition accuracy and applicability.
Patent Information
- Application Number
- CN202311024532.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-14
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2043-08-14
AI Technical Summary
Existing methods for detecting anomalies in power data are ineffective in handling the multivariate time-series characteristics and nonlinear intrinsic correlations of power data, resulting in poor anomaly detection performance, especially in the absence of labeled data under unsupervised learning conditions.
A Generative Adversarial Network (GAN) model is adopted to optimize data generation and anomaly detection capabilities through adversarial training between the generator and discriminator. An LSTM network architecture is used to process power time series data, extract effective features, and calculate anomaly scores for detection.
It improves the accuracy and practicality of power data anomaly detection, effectively identifies anomalies under small dataset conditions, and enriches the application scenarios of generative adversarial networks in power data detection.
Smart Images

Figure CN117150402B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of anomaly detection, in particular to the field of power data anomaly detection method and model. BACKGROUND
[0002] With the popularity of Internet of Things technology, a variety of information sensors have been seen everywhere in people's lives, and information collection of power data has been fully transformed from manual recording to automatic input by electronic sensing devices, making data collection more efficient. However, due to various factors, abnormal power data may still occur. Traditionally, rule-based anomaly detection methods are commonly used solutions for detecting abnormal data, but power data is an analog signal and has continuous changes over time, so power data has correlation in time steps, and thus power data has multivariate time series characteristics, which cannot be accurately distinguished by rule-based methods.
[0003] In the face of the above problems, in the existing anomaly detection task in time series data, the supervised machine learning method needs a large amount of real normal data and labeled abnormal data for training and learning, but in practice, power data lacks labels, so the anomaly detection in power time series data is usually considered as an unsupervised machine learning task, and unsupervised learning is mostly embedding vector space after linear transformation and projection of sample data, and detecting anomalies by comparing the difference between original data and predicted data, but the inherent correlation of complex power time series data is often nonlinear. Another method compares the system state value of the current time step with the predicted normal range to detect anomalies, but because most power systems are highly dynamic in nature, it is difficult to define a normal measurement range, so there is a certain error, resulting in poor anomaly detection effect. SUMMARY
[0004] Therefore, the present application proposes a power data anomaly detection model and method based on generative adversarial network. The present application uses an anomaly detection model containing a generator and a discriminator to process power time series data, and through adversarial training, continuously optimizes the data generation ability and anomaly discrimination ability of the generator and the discriminator, and improves the anomaly detection ability of the model. The application of generative adversarial network in power data anomaly detection is enriched, the application scenarios are expanded, and the practicability of the model is improved.
[0005] The present application is realized by the following technical solutions:
[0006] On the one hand, the present application provides a power data anomaly detection method based on generative adversarial network, which comprises the following steps:
[0007] S1: obtaining an original data signal, dividing the original data signal into small sequence signal groups through a sliding window Sw, obtaining a corresponding latent vector through mapping for each small sequence signal group in the small sequence signal groups, and thus forming a latent vector group;
[0008] S2: mapping the latent vectors in the latent vector group one by one to obtain a group of pseudo time sequence data;
[0009] S3A1: calculating the true probability of each subsequence of the pseudo time sequence data and the true probability of each small sequence signal;
[0010] S3A2: comparing the true probability of the subsequence of the pseudo time sequence data with the true probability of each small sequence signal in the small sequence signal group to calculate the discrimination loss of each group of subsequences, and finally summing to obtain the total discrimination loss;
[0011] S3B: comparing each subsequence of the pseudo time sequence data with each small sequence signal in the small sequence signal group to obtain the residual loss of each group of subsequences, and finally summing to obtain the total residual loss;
[0012] S4: calculating the residual score and the discrimination score according to the residual loss and the discrimination loss of each group of subsequences, and performing weighted processing on the residual score and the discrimination score to obtain an anomaly score;
[0013] S5: comparing the anomaly score with a preset threshold to obtain a discrimination result.
[0014] Further, the total discrimination loss calculation formula of S31A is:
[0015]
[0016] Wherein, x is a small sequence signal group, D1(·) represents the calculation of the true probability evaluation value of the corresponding data, and is a function body of the specified input sequence statistics.
[0017] Further, the total residual loss calculation formula of S3B is:
[0018]
[0019] Wherein, x is a small sequence signal group, G(z λ ) is pseudo time sequence data.
[0020] Further, the parameters of steps S2 and S3A1 are optimized through the following first training method:
[0021] A noise vector is randomly selected from a potential vector group and input into a mapping module of the generator, and a power data is randomly selected from the original power data set and input into a true probability calculation module of the discriminator;
[0022] The noise vector is generated into a pseudo time series data by the mapping module;
[0023] The true probability of the pseudo time series and the true probability of the power data in the original power data set are calculated;
[0024] According to the true probability of the pseudo time series and the true probability of the power data in the original power data set, the total loss is calculated, and the network parameters of the mapping module and the true probability calculation module are updated;
[0025] If not, repeat the above steps, if yes, complete the model training.
[0026] Further, the target loss function in the first training method of the parameters of steps S2 and S3A1 is specifically:
[0027]
[0028] Where Ex is the expected value of the real data space X, Ez is the expected value of the latent space Z, D1(x) represents the true probability of the normal power data obtained by the discriminator, and D1(G(z)) represents the true probability of the pseudo time series obtained by the discriminator.
[0029] Further, the mapping rule of mapping the small sequence signal to obtain the corresponding latent vector in step S1 is optimized by the following second training method:
[0030] An original power data is randomly selected from the original power data set and input into the anomaly detection model for operation, to obtain the remaining loss of the generator and the discrimination loss of the discriminator;
[0031] The mapping rule of the signal preprocessing module when performing data compression on the original power data is updated in combination with the remaining loss and the discrimination loss;
[0032] It is judged whether the total loss function constructed by the remaining loss and the discrimination loss is converged, if not, the above steps are repeated, if yes, the model training is completed.
[0033] Further, the total loss function of the second training method is specifically:
[0034] The remaining loss L R :
[0035] L R (z λ) = å |x - G(z λ )|
[0036] wherein x is a small sequence signal group, G(z λ ) is pseudo time series data;
[0037] loss function L D :
[0038]
[0039] wherein x is a small sequence signal group, D1(·) represents a true probability evaluation value of corresponding data, and is a function body of statistical data of a specified input small sequence;
[0040] The loss function L is defined as a weighted sum of the residual loss and the discriminative loss, as follows:
[0041] L(z λ ) = (1 - y)L R (z λ ) + yL D (z λ )
[0042] wherein y is a weighting coefficient.
[0043] In another aspect, the application also provides a power data anomaly detection model based on a generative adversarial network, comprising:
[0044] a signal preprocessing module: configured to acquire an original data signal, divide the original data signal into small sequence signal groups through a sliding window Sw, and obtain corresponding latent vectors through mapping of each small sequence signal group in the small sequence signal groups, thereby forming a latent vector group;
[0045] a mapping module: configured to map the latent vectors in the latent vector group one by one to obtain a group of pseudo time series data;
[0046] a true probability calculation module: configured to calculate a true probability of a subsequence of each pseudo time series data and a true probability of each small sequence signal;
[0047] a discriminative loss calculation module: configured to compare the true probability of the subsequence of the pseudo time series data with the true probability of each small sequence signal of the small sequence signal group, calculate a discriminative loss of each group of subsequences, and finally sum to obtain a total discriminative loss;
[0048] a residual loss calculation module: configured to compare each subsequence of each pseudo time series data with each small sequence signal of the small sequence signal group to obtain a residual loss of each group of subsequences, and finally sum to obtain a total residual loss;
[0049] Anomaly score calculation module: used for calculating residual score and discrimination score according to residual loss and discrimination loss of each group of sub-sequences, and obtaining an anomaly score by weighting residual score and discrimination score;
[0050] Threshold comparison module: used for comparing the anomaly score with a preset threshold to obtain a discrimination result.
[0051] Further, the mapping module and the residual loss calculation module constitute a generator, and the for-true probability calculation module, the discrimination loss calculation module, the anomaly score calculation module and the threshold comparison module constitute a discriminator.
[0052] And the generator comprises three layers of long short-term memory networks, and the discriminator comprises a single layer of long short-term memory networks.
[0053] On the other hand, the application also provides a computer device, which comprises at least one memory and at least one processor.
[0054] The memory is used for storing one or more programs; when the one or more programs are executed by the at least one processor, the at least one processor implements the steps of the power data anomaly detection method based on the generative adversarial network according to any one of the above.
[0055] The application inherits the idea of the anomaly detection algorithm based on unsupervised learning, and is inspired by the game principle of the GAN model, and proposes a power data anomaly detection model and a training method based on the generative adversarial network; the application uses LSTM as the network architecture of the generator and the discriminator of the GAN network, obtains an anomaly detection model for processing power time series data, uses different effective architectures to detect anomalies in small data sets, the model is first used in power time series data, enriches the application of the generative adversarial network in power data anomaly detection, expands the application scenario, improves the practicability of the model, and in the model structure, the discriminator uses a layer of LSTM for training, with 100 hidden units; the generator uses three layers of LSTM, starts from a small number of hidden units, and gradually increases the number of hidden units in each continuous layer, wherein the number of hidden units in each continuous layer is 32, 64 and 128 respectively, so that the model can be trained under the condition of small data set, and the generated generator is effective, and can effectively identify anomalies in data.
[0056] In order to better understand and implement, the application will be described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS
[0057] Figure 1 It is a module schematic diagram of the power data anomaly detection model based on the generative adversarial network.
[0058] Figure 2 For Figure 1 The detection step flow chart of the power data anomaly detection model based on the generative adversarial network of the application;
[0059] Figure 3 For the flow chart of the first training method of the generative adversarial network-based power data anomaly detection model of the application;
[0060] Figure 4 For the flow chart of the second training method of the generative adversarial network-based power data anomaly detection model of the application. DETAILED DESCRIPTION
[0061] Based on the existing anomaly detection method in the power system, the correlation in the time step in the time series data cannot be considered, and the problem of nonlinear interaction in the time series data cannot be processed. The inventors analyzed that the user power consumption data has time correlation characteristics and high dimension characteristics, and proposed to use a generative adversarial network as a model for power data anomaly detection. The model proposed in the application first performs dimension reduction processing on the power data to be detected, extracts effective features, and inputs them into the trained model. The trained generator and discriminator are used to obtain an anomaly loss, and an anomaly score is calculated and compared with a set threshold to detect anomalies in time series data, complete the extraction and analysis of user power consumption behavior load characteristics, realize high-precision detection of user power consumption anomalies, and improve the recognition accuracy and reduce the recognition time of user abnormal power consumption behavior.
[0062] Please refer to Figure 1 And Figure 2 , Figure 1 The module schematic diagram of the power data anomaly detection model based on the generative adversarial network of the application, Figure 2 For Figure 1 The detection step flow chart of the power data anomaly detection model based on the generative adversarial network of the application, wherein the power data anomaly detection model based on the generative adversarial network of the application comprises a signal preprocessing module, a mapping module, a true probability calculation module, a discrimination loss calculation module, a residual loss calculation module, an anomaly score calculation module and a threshold comparison module.
[0063] Specifically, the signal preprocessing module is used to perform step S1: obtaining an original data signal, and passing the original data signal through a sliding window S wThe original data signal is a continuous analog signal, the latent vector is a vector form obtained by mapping the original data signal from a continuous analog signal through a mapping relationship, the latent vector is located in a latent space, the latent space is an abstract multi-dimensional space, and mapping the original data signal to the latent space can compress the original data.
[0064] The mapping module is configured to perform step S2: mapping the latent vectors in the latent vector group one by one to obtain a group of pseudo time series data, the pseudo time series data being pseudo power time series data generated by the generator according to the original data, and the pseudo time series data being similar enough to the real data to make the discriminator unable to distinguish. In a specific process, the mapping module reconstructs each latent vector through a function G(z, θ1) to obtain a corresponding pseudo time series data subsequence G(z). θ1 is a parameter of the mapping module.
[0065] The true probability calculation module is configured to perform step S3A1: calculating the true probability of each pseudo time series data subsequence and calculating the true probability of each small sequence signal.
[0066] The discrimination loss calculation module is configured to perform step S3A2: comparing the true probability of the pseudo time series data subsequence with the true probability of each small sequence signal in the small sequence signal group to calculate the discrimination loss of each group of subsequences, and finally summing to obtain the total discrimination loss.
[0067] Loss function L D is defined as:
[0068]
[0069] where x is the small sequence signal group, D1(·) represents the calculation of the true probability evaluation value of the corresponding data, and is a function body of the specified input small sequence statistical data.
[0070] The residual loss calculation module is configured to perform step S3B: comparing each pseudo time series data subsequence with each small sequence signal in the small sequence signal group to obtain the residual loss of each group of subsequences, and finally summing to obtain the total residual loss.
[0071] Residual loss L R The specific calculation method is:
[0072]
[0073] where x is a small sequence signal group, G(z λ ) is a pseudo-time series data.
[0074] The abnormal score calculation module is configured to perform step S4: calculating a residual score and a discriminant score according to the residual loss and the discriminant loss of each group of sub-sequences, and weighting the residual score and the discriminant score to obtain an abnormal score.
[0075] After the above processing of an original data, an abnormality detection loss set {L = Li, s, i = 1, 2,..., m; s = 1, 2,... s w}
[0076] The specific calculation formula of the abnormality detection loss is as follows:
[0077] L(z λ ) = (1 - γ) L R (z λ ) + γz D (z λ )
[0078] where γ is a weighting coefficient.
[0079] The residual score R(x) is calculated according to the following formula:
[0080]
[0081] l ct = count(i, s ∈ {i + s = t})
[0082] where L R,s is the residual loss corresponding to each sub-sequence.
[0083] The calculation formula of the discriminant score D2(x) is as follows:
[0084]
[0085] l ct = count(i, s ∈ {i + s = t})
[0086] where L D,s is the discriminant loss corresponding to each sub-sequence.
[0087] The abnormal score A(x) represents the fitting degree of the given simulation data distribution G(z, θ1) and the general data distribution (i.e. the normal time series model), and the specific formula is as follows:
[0088] A(x) = (1 - γ) R(x) + γD2(x)
[0089] wherein, the parameter γ is a weighting coefficient.
[0090] The threshold comparison module is configured to perform step S5: comparing the anomaly score with a preset threshold to obtain a discrimination result.
[0091]
[0092] When the anomaly score is greater than the preset threshold, it is determined that the to-be-detected data is abnormal, and when the anomaly score is less than the preset threshold, it is determined that the to-be-detected data is normal.
[0093] The power data anomaly detection model of the present application can use some existing operation models to perform specific module execution, for example, a generator can be used to perform data processing of the above-mentioned mapping module and residual loss calculation module; and a discriminator is used to perform data processing of the above-mentioned discrimination loss calculation module, anomaly score calculation module and threshold comparison module.
[0094] Further, the network parameters of the above-mentioned generative adversarial network (i.e. the generator and the discriminator) are optimized based on the general distribution of the real space power data, and the learning of the general distribution of the real space power data is obtained by the first training. Specifically,
[0095] Please refer to Figure 3 , Figure 3 is a flowchart of the first training method of the generative adversarial network-based power data anomaly detection model of the present application.
[0096] First, a standard database is preset, and the standard database includes an original power data set, which includes n power data; wherein the power data in the original power data set are all normal data. Randomly select n noise vectors from the latent space as a latent vector group.
[0097] Randomly select a noise vector from a latent vector group and input it into the mapping module of the generator, and randomly select a power data from the original power data set and input it into the true probability calculation module of the discriminator.
[0098] The noise vector is generated into a pseudo time series data through the mapping module.
[0099] The true probability of the pseudo time series and the true probability of the power data in the original power data set are calculated.
[0100] According to the true probability of the pseudo time series and the true probability of the power data in the original power data set, the total loss is calculated, and the network parameters of the mapping module and the true probability calculation module are updated.
[0101] If not, repeat the above steps, if yes, complete the model training.
[0102] The first training process is similar to the generator G taking the discriminator D as an opponent. The generator G needs to learn how to generate data so that the discriminator D can no longer distinguish it as false. Assuming that the normal power data used for training is x, the distribution of the power data is p data (x), the generator G needs to learn the real data distribution p data (x). The distribution of the noise vector z is assumed to be p z (z), where p z (z) is known, and p data (x) is unknown. In an ideal state, the distribution of G(z) should be as close to p data (x) as possible, and G maps the z variable with a known distribution to the x variable with a location distribution. The specific training process is as follows:
[0103] First, a raw data time series is divided into small sequences with a sliding window sw before being sent to the discriminator D, and then the input of the generator is a noise signal randomly selected from the latent vector group. Finally, the generator generates a pseudo time series according to the noise signal, and the true probability calculation module of the discriminator calculates the true probability of the pseudo time series and the normal power data respectively. Finally, the discrimination loss is calculated according to the true probability.
[0104] Both the generator G and the discriminator D try to optimize the competition loss function during training. Therefore, they can be considered as two processes using the function V(G, D) for a minimax game. The generator G tries to maximize the probability that G(z) is identified as a real value, while the discriminator D tries to minimize the probability that G(z) is identified as a real value.
[0105] Adversarial training can be seen as a minimax strategy between the generator and the discriminator, and the target loss function is as follows:
[0106]
[0107] Where Ex is the expected value of the real data space X, Ez is the expected value of the latent space Z; D1(x) represents the true probability of the normal power data obtained by the discriminator, and D1(G(z)) represents the true probability of the pseudo time series obtained by the discriminator.
[0108] Every time it is updated, θ θ and θ2 of the discriminator D(x, θ2) learn the general data distribution of the normal power data in the standard database, and when the target loss function converges, the first stage of training is completed.
[0109] The G(z, θ1) function models the process of mapping the input noisy latent vector z to the real data space x e X (i.e. time series subsequences). The D(x, θ2) function comes from the discriminator, through which the probability of data being real can be predicted. Here θ1 and θ2 are the parameters of the model. The objective loss function of the network maximizes the function D1(x) and minimizes D1(G(z)), i.e. the discriminator maximizes the probability of normal data being real, while minimizes the probability of the pseudo time data generated by the generator being real. After enough iterations of training, the generator G and the discriminator D will reach a point where they cannot be improved anymore, i.e. they cannot be improved. At this point, the generator G generates real time series data, while the discriminator D cannot distinguish between fake data and real data.
[0110] The purpose of the first training phase is to learn the general data distribution p g of the data in the given standard database through adversarial training. The process simultaneously trains the generator G to generate pseudo time series data and the discriminator D to distinguish between pseudo data generated by the generator and normal power data. In order to solve the problem of small number of data points, the inventors propose to use a three-layer LSTM as the generator and a single-layer LSTM as the discriminator. Because when the data set is very small, a large discriminator is easy to overfit the data, and a shallow generator cannot generate enough real data to defeat the discriminator. Therefore, the inventors use a simple shallow discriminator D and a medium-depth generator G to solve the above problem when the data set is small.
[0111] In order to speed up the training, the inventors also use the stochastic gradient descent method to train the model
[0112] The stochastic gradient descent (SGD) algorithm randomly selects a group of samples, updates the weights once after training, and then selects another group of samples and updates again. In the case of extremely large sample size, a model with an acceptable loss value can be obtained without training all samples. Gradient descent is a direction in which the function rises most quickly at a given point. Therefore, when we do gradient descent, we update the weights in the opposite direction of the gradient, which can effectively find the global optimal solution. Here, random means that the samples are randomly shuffled in each iteration process. Shuffling can effectively reduce the problem of parameter update cancellation caused by samples. The inventors use the stochastic gradient descent algorithm to train the GAN network. After adversarial training, the time series subsequence x e X is mapped to the latent space z e Z for anomaly detection.
[0113] The inventors found in the research that in the adversarial training, the generator learns a mapping G: Z→X such that G(z)∈X, i.e. from the latent space representation z to the real data space normal time series x. In order to detect anomalies, we first need to map the real time series x∈X to the latent space z∈Z, and observe the degree to which the corresponding latent space generates real time series. However, the GAN does not exist G -1 :X→Z inverse mapping, such that G -1 (x)∈Z, or when different data its mapping relationship is not fixed, just rely on the preset mapping function, reduces the prediction result accuracy, and the universality of the model is not high, therefore the application also increases the mapping ability training process of the model of the adversarial generative network, i.e. the second training phase, for solving the above defects.
[0114] Please refer to Figure 4 , Figure 4 The second training process of the generative adversarial network power data anomaly detection model of the application is shown in the flowchart, and the second training method specifically includes:
[0115] An original power data is randomly selected from an original power data set and input into the anomaly detection model for operation, to obtain the remaining loss of the generator and the discrimination loss of the discriminator.
[0116] The mapping rule of the signal preprocessing module when compressing the original power data is updated in combination with the remaining loss and the discrimination loss.
[0117] It is judged whether the total loss function constructed by the remaining loss and the discrimination loss is converged, if not, the above steps are repeated, and if yes, the model training is completed.
[0118] Given a real time series x∈X, we need to find the latent vector z∈Z corresponding to the pseudo time series G(z) most similar to the real time series x. The degree of similarity between x and G(z) depends on the degree to which x follows the data distribution p g used to train the generator G.
[0119] In order to find the best z for a given x, this process starts with a random sampling z1∈Z and inputs it into the generator G completed in the first training to obtain a fake time series G(z1). Based on the fake time series G(z1), we define a loss function L, which provides a gradient to update the parameters of z 12 , so as to obtain the updated position z2∈Z. In order to find the most similar sequence G(z λ )~x, the parameters in the signal preprocessing module are constantly updated to optimize the obtained latent vector z.
[0120] Further, a loss function L is defined to map the real time series x e X to the best latent space position z e Z. The loss function L consists of two parts, the reconstruction loss L R and the discriminative loss L D , as follows.
[0121] The loss function L is defined as the weighted sum of the reconstruction loss and the discriminative loss, as follows:
[0122] L(z λ ) = (1 - y)L R (z λ ) + yL D (z λ )
[0123] L R makes the fake sequence G(z λ ) similar to the real sequence x at the point. L D makes the fake sequence G(z λ ) located in X. This means that both G and D are used to update the parameters of z by backpropagation. In this reflection process, only the parameters of z are updated by backpropagation; the parameters of the generator G and the discriminator D remain unchanged.
[0124] That is, according to the loss function, find an inverse mapping G -1 : X→Z from the real space to the latent space, so that after X→Z, the distribution of G(z) is closest to the original x.
[0125] When the loss function L converges, the second training is completed.
[0126] After the model training reaches the fitting, the trained discriminator and generator are used together to detect anomalies, as shown by the anomaly score A(x). Applying both parts to anomaly judgment can better identify anomalies, so the GAN-based anomaly detection consists of the above two parts. The larger the anomaly score A(x), the more abnormal the time series; the smaller the anomaly score, the more normal the time series learned by the generator G in the adversarial training is the general data distribution of X.
[0127] The application inherits the abnormality detection algorithm idea based on unsupervised learning, and is inspired by the game principle of a GAN model, and proposes a power data abnormality detection model training method based on a generative adversarial network; the abnormality detection model trained by the generator and discriminator based on the generative adversarial network is used to process power time series data, and through adversarial training, the data generation ability and abnormality discrimination ability of the generator and discriminator are continuously optimized, the abnormality detection ability of the model is improved, the model is first used in power time series data, enriches the application of the generative adversarial network in power data abnormality detection, expands the application scene, improves the practicability of the model, and the model structure uses different effective architectures to detect abnormalities in small data sets, the discriminator uses a layer of LSTM for training, and has 100 hidden units; the generator uses three layers of LSTM, starts from a small number of hidden units, and gradually increases the number of hidden units in each continuous layer, wherein the number of hidden units in each continuous layer is 32, 64 and 128 respectively, so that the model can train the generator under the condition of small data set, and the generator can effectively identify the abnormality in the data.
[0128] Based on the same inventive concept as described above, the present application also provides an electronic device, which can be a server, a desktop computing device or a mobile computing device (such as a laptop computer, a handheld computing device, a tablet computer, a netbook, etc.) and the like terminal device. The device includes one or more processors and a memory, wherein the processor is used to execute the program to realize the above-mentioned one kind of power data abnormality detection model training method based on generative adversarial network; the memory is used to store the computer program executable by the processor.
[0129] Based on the same inventive concept, the present application also provides a computer readable storage medium, corresponding to the above-mentioned one kind of power data abnormality detection method based on generative adversarial network, the computer readable storage medium has a computer program stored thereon, and the program is executed by a processor to realize the steps recorded in any of the above embodiments.
[0130] The application can take the form of a computer program product accessible from a storage medium (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing program code for use by or in connection with a computer. Computer-usable storage media include permanent and non-permanent, movable and non-movable media that can be implemented by any method or technology for information storage. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to: phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape, magnetic disk storage or other magnetic storage device, or any other non-transmission medium that can be used to store information accessible by a computing device.
[0131] The above-described embodiments only express several embodiments of the present application, which are described in detail and specifically, but cannot be understood as a limitation on the scope of the patent. It should be noted that for those skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, and the present application also intends to include these modifications and improvements.
Claims
1. A method for power data anomaly detection based on a generative adversarial network, characterized in that, The abnormality detection model is obtained by using LSTM as the network architecture of the generator and the discriminator of the GAN network, the discriminator is trained by using one layer of LSTM with 100 hidden units; The generator uses three layers of LSTM, and the number of hidden units of each consecutive layer is 32, 64 and 128 respectively; The abnormality detection method comprises the following steps: S1: obtaining an original data signal, dividing the original data signal into small sequence signal groups by a sliding window Sw, and obtaining corresponding latent vectors from each small sequence signal group by mapping, thereby forming a latent vector group; S2: mapping the latent vectors in the latent vector group one by one to obtain a group of pseudo time series data; S3A1: calculating the true probability of each subsequence of the pseudo time series data and the true probability of each small sequence signal; S3A2: comparing the true probability of each subsequence of the pseudo time series data with the true probability of each small sequence signal of the small sequence signal group to calculate the discrimination loss of each group of subsequences, and finally summing to obtain the total discrimination loss; The total discrimination loss calculation formula of S3A2 is: wherein x is a small sequence signal group, represents a calculation of a true probability evaluation value of corresponding data, and is a function body of statistical data of a specified input small sequence. S3B: comparing each subsequence of the pseudo time series data with each small sequence signal of the small sequence signal group to obtain the residual loss of each group of subsequences, and finally summing to obtain the total residual loss; The total residual loss calculation formula of S3B is: Wherein, x is a small sequence signal group, ) is a pseudo-time series data; S4: calculating the residual score and the discrimination score according to the residual loss and the discrimination loss of each group of subsequences, and weighting the residual score and the discrimination score to obtain an abnormality score; S5: comparing the abnormality score with a preset threshold to obtain a discrimination result. 2.The power data anomaly detection method based on a generative adversarial network according to claim 1, characterized in that, The parameters of steps S2 and S3A1 are optimized by the following first training method: A noise vector is randomly selected from a latent vector group and input into the mapping module of the generator, and an electric power data is randomly selected from an original electric power data set and input into the true probability calculation module of the discriminator; The noise vector generates a pseudo time series data through the mapping module; The true probability of the pseudo time series and the true probability of the electric power data in the original electric power data set are calculated; According to the true probability of the pseudo time series and the true probability of the electric power data in the original electric power data set, the total loss is calculated, and the network parameters of the mapping module and the true probability calculation module are updated; It is judged whether the target loss function converges or not, if not, the above steps are repeated, if yes, the model training is completed. 3.The power data anomaly detection method based on a generative adversarial network according to claim 2, characterized in that, The target loss function in the first training method of the parameters of steps S2 and S3A1 is specifically: where Exis the expected value of the real data space X, Ezis the expected value of the latent space Z, D1(x) represents the probability of being true of normal power data obtained by the discriminator, D1 represents the probability of being true of pseudo time series obtained by the discriminator.
4. The power data anomaly detection method based on a generative adversarial network according to claim 3, characterized in that, The mapping rule of mapping the small sequence signal to the corresponding latent vector in step S1 is optimized by the following second training method: An original electric power data is randomly selected from an original electric power data set and input into the abnormality detection model for operation to obtain the residual loss of the generator and the discrimination loss of the discriminator; The residual loss and the discrimination loss are combined to update the mapping rule when the original electric power data is compressed. whether the total loss function constructed by the residual loss and the discrimination loss converges, if not, repeating the above steps, if yes, completing the model training.
5. The power data anomaly detection method based on a generative adversarial network according to claim 4, characterized in that, The total loss function of the second training method is specifically: residual loss : Wherein, x is a small sequence signal group, ) is a pseudo-time series data; Loss function : wherein x is a small sequence signal group, represents a calculation of the probability evaluation value of the corresponding data being true, and is a function body of the statistical data of the specified input small sequence. The loss function L is defined as the weighted sum of the residual loss and the discrimination loss, as follows: wherein is a weighting factor.
6. The power data anomaly detection method based on a generative adversarial network according to any one of claims 1-5, characterized in that, The anomaly detection model comprises: The signal preprocessing module is configured to obtain an original data signal, divide the original data signal into small sequence signal groups through a sliding window Sw, obtain corresponding latent vectors through mapping of each small sequence signal group in the small sequence signal groups, and thus form a latent vector group; The mapping module is configured to map the latent vectors in the latent vector group one by one to obtain a group of pseudo-time sequence data; The true probability calculation module is configured to calculate the true probability of each subsequence of the pseudo-time sequence data and the true probability of each small sequence signal. The discrimination loss calculation module is configured to compare the true probability of each subsequence of the pseudo-time sequence data with the true probability of each small sequence signal of the small sequence signal group, calculate the discrimination loss of each group of subsequences, and finally sum to obtain the total discrimination loss. The residual loss calculation module is configured to compare each subsequence of the pseudo-time sequence data with each small sequence signal of the small sequence signal group to obtain the residual loss of each group of subsequences, and finally sum to obtain the total residual loss. The anomaly score calculation module is configured to calculate a residual score and a discrimination score according to the residual loss and the discrimination loss of each group of subsequences, and perform weighted processing on the residual score and the discrimination score to obtain an anomaly score. The threshold comparison module is configured to compare the anomaly score with a preset threshold to obtain a discrimination result.
7. The power data anomaly detection method based on the generative adversarial network according to claim 6, wherein: The mapping module and the residual loss calculation module of the anomaly detection model form a generator, and the true probability calculation module, the discrimination loss calculation module, the anomaly score calculation module, and the threshold comparison module form a discriminator. The generator comprises three layers of long short-term memory networks, and the discriminator comprises a single layer of long short-term memory networks.
8. A computer device, comprising: The anomaly detection method comprises: at least one memory and at least one processor; The memory is configured to store one or more programs; When the one or more programs are executed by the at least one processor, the at least one processor implements the steps of the anomaly detection method based on the generative adversarial network according to any one of claims 1-6.