Power grid real-time monitoring and anomaly detection method and device based on data stream processing

By adaptively segmenting and extracting features from the real-time data stream of the power grid, and combining an anomaly monitoring model with a dual-path time attention mechanism, the problem of insufficient adaptability and accuracy in the detection of power grid frequency fluctuation anomalies in the existing technology has been solved. This has enabled efficient identification and real-time early warning of power grid frequency anomalies, ensuring the stable operation of the power grid.

CN121584585APending Publication Date: 2026-02-27WENSHANG POWER SUPPLY CO OF STATE GRID SHANDONG ELECTRIC POWER CO
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511765992.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-27
Publication Date
2026-02-27

AI Technical Summary

Technical Problem

Existing methods for detecting abnormal power grid frequency fluctuations cannot adapt to dynamic changes in power grid frequency, resulting in insufficient accuracy in anomaly identification, especially when load changes are large or in the early stages of a fault.

Method used

A data stream-based approach is adopted to monitor key nodes of the target power grid in real time, generate real-time data streams, perform adaptive segmentation using frequency fluctuation entropy, extract features by calculating the frequency band energy ratio, and predict anomaly categories using an anomaly monitoring model with a dual-path time attention mechanism.

Benefits of technology

It enables efficient identification and real-time early warning of power grid frequency anomalies, improves the accuracy and adaptability of anomaly detection, and can accurately output anomaly category prediction results in the early stages of load changes or faults, ensuring the safety and stability of power grid operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121584585A_ABST
    Figure CN121584585A_ABST
Patent Text Reader

Abstract

The invention provides a power grid real-time monitoring and anomaly detection method and device based on data stream processing, relates to the technical field of artificial intelligence, and aims to adaptively segment a real-time data stream of a power grid by taking a frequency fluctuation entropy as a core, so that each divided data block can keep the continuity of frequency evolution, and the accuracy of the data stream processing is improved. And the problem of rigid splitting of the dynamic frequency by a traditional fixed window method is effectively avoided. Features are extracted based on a data block frequency band energy ratio, so that a target feature vector covers single-frequency-band characteristics and inter-frequency-band energy differences, and the problem that traditional feature expression is insufficient is solved. The feature vector is processed by using an anomaly monitoring model integrated with a dual-path time attention mechanism, a complex nonlinear frequency mode can be captured based on enhanced time context association, and the anomaly recognition precision of load dramatic change or initial fault stage is improved. Finally, the operation state of the power grid is determined in combination with a prediction result, efficient identification and real-time early warning can be realized, and the problems of poor adaptability, insufficient precision and the like in the prior art are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method and apparatus for real-time monitoring and anomaly detection of power grids based on data stream processing. Background Technology

[0002] With the rapid development of power systems, especially the increasing proportion of new energy sources, the frequency stability of power grids faces greater challenges. Frequency fluctuations are not only affected by load fluctuations but can also be caused by factors such as equipment failures and improper load regulation. These anomalies pose a serious threat to the operational safety of the power grid and the stability of the power system. Therefore, real-time monitoring of power grid frequency fluctuations, timely detection of anomalies, and early warning have become crucial tasks for ensuring the stable operation of the power grid.

[0003] Existing methods for detecting abnormal power grid frequency fluctuations mostly rely on traditional time series analysis or sliding window methods based on fixed windows. These methods typically perform poorly when dealing with power grid data exhibiting complex frequency patterns or abrupt changes. For example, traditional methods fail to adapt to the dynamic changes in power grid frequency, leading to inaccurate identification of certain abnormal events, especially when load changes are significant or in the early stages of a fault, where frequency fluctuations exhibit strong time-varying and nonlinear characteristics. Furthermore, most traditional feature extraction techniques are based on simple frequency domain analysis or global statistical features, but these methods fail to fully consider the characteristics of different frequency bands and ignore energy differences between bands, resulting in insufficient feature representation and an inability to effectively distinguish between normal and abnormal fluctuations. This limits the effectiveness of existing methods in handling power grid frequency anomalies, particularly when facing complex power grid faults, where efficient and accurate identification is often difficult. Summary of the Invention

[0004] The purpose of this invention is to provide a method and apparatus for real-time monitoring and anomaly detection of power grids based on data stream processing, so as to solve the problems of existing technologies being unable to adapt to dynamic changes in power grid frequency and insufficient accuracy in anomaly identification.

[0005] In a first aspect, embodiments of the present invention provide a method for real-time monitoring and anomaly detection of a power grid based on data stream processing. The method includes: real-time monitoring of key nodes in a target power grid to generate a real-time data stream of the target power grid; adaptive segmentation of the real-time data stream based on its frequency fluctuation entropy to generate multiple data blocks; continuous frequency evolution within each data block; calculation of the frequency band energy ratio corresponding to the data block; feature extraction of the data block based on the frequency band energy ratio to generate a target feature vector; anomaly category prediction of the target feature vector using a pre-constructed anomaly monitoring model; and outputting the anomaly category prediction result corresponding to the real-time data stream. The anomaly monitoring model enhances the temporal context of the target feature vector using a dual-path time attention mechanism to determine the anomaly category prediction result; and determining the operating status of the target power grid based on the anomaly category prediction result.

[0006] In conjunction with the first aspect, the present invention provides a first implementation of the first aspect, wherein the step of adaptively segmenting the real-time data stream and generating multiple data blocks based on the frequency fluctuation entropy of the real-time data stream includes: determining the frequency spectrum power distribution of multiple attribute data of the real-time data stream within the corresponding window based on a preset window function and short-time Fourier transform; determining the frequency fluctuation entropy corresponding to each attribute data based on the frequency spectrum power distribution; calculating the mean sequence corresponding to the frequency fluctuation entropy of the multiple attribute data; determining the frequency stable abrupt change point of the real-time data stream based on the mean sequence; and adaptively segmenting the real-time data stream based on the frequency stable abrupt change point to generate multiple data blocks.

[0007] In conjunction with the first aspect, this embodiment of the invention provides a second implementation of the first aspect, wherein the step of calculating the frequency band energy ratio corresponding to the data block includes: performing a discrete wavelet transform on the data block to decompose the data block into multiple frequency band components; each frequency band component belongs to a different frequency band boundary; determining the average frequency fluctuation entropy corresponding to each attribute data of the data block; and determining the frequency band energy ratio corresponding to each frequency band component of the data block based on the average frequency fluctuation entropy.

[0008] In conjunction with the first aspect, this embodiment of the invention provides a third implementation of the first aspect, wherein the step of extracting features from a data block based on the frequency band energy ratio to generate a target feature vector includes: determining the stability index corresponding to each frequency band component based on the fluctuation degree of the frequency band energy ratio; and using the frequency fluctuation entropy of each attribute data of the data block and the attribute weight corresponding to each attribute data to perform weighted fusion of the stability index to generate the target feature vector of the data block.

[0009] In conjunction with the first aspect, this invention provides a fourth implementation of the first aspect, wherein the step of using a pre-built anomaly monitoring model to predict the anomaly category of a target feature vector and outputting the anomaly category prediction result corresponding to the real-time data stream includes: performing frequency adaptive convolutional encoding on the target feature vector based on the frequency fluctuation entropy of the target feature vector to generate encoded time-frequency features; capturing short-term frequency abrupt changes in the encoded time-frequency features through a local transient attention path and capturing the long-term trend evolution of the encoded time-frequency features through a global trend attention path; determining the time-enhanced feature vector corresponding to the encoded time-frequency features based on the short-term frequency abrupt changes and the long-term trend evolution; determining the initial category score corresponding to the time-enhanced feature vector through the anomaly monitoring model, adjusting the initial category score in conjunction with the frequency stability index corresponding to the real-time data stream, and generating the anomaly category prediction result corresponding to the real-time data stream.

[0010] In conjunction with the first aspect, this embodiment of the invention provides a fifth implementation of the first aspect, wherein the step of performing frequency adaptive convolutional coding on the target feature vector based on the frequency fluctuation entropy of the target feature vector to generate coded time-frequency features includes: generating a frequency band modulation matrix based on the frequency band energy ratio corresponding to the target feature vector; constructing a frequency band gating matrix by combining the importance score of each frequency band contained in the target feature vector; dynamically modulating the preset convolution kernel weights using the frequency band gating matrix, and performing a convolution operation on the target feature vector based on the dynamically modulated convolution kernel weights to determine the coded time-frequency features corresponding to the target feature vector.

[0011] In conjunction with the first aspect, this invention provides a sixth implementation of the first aspect, wherein the method further includes: acquiring a pre-constructed training sample set, inputting the training sample set into a preset initial model, and training the initial model; calculating the regularization loss corresponding to the initial model based on the frequency band energy ratio of preset frequency band components of the training sample set; calculating the cross-entropy loss corresponding to the initial model based on the difference between the predicted probability distribution of the initial model and the true label; calculating the total loss function of the initial model based on the regularization loss and the cross-entropy loss; updating the model parameters of the initial model based on the total loss function until the initial model meets the preset training requirements, and constructing an anomaly detection model based on the current initial model.

[0012] Secondly, embodiments of the present invention provide a real-time power grid monitoring and anomaly detection device based on data stream processing. The device includes: a data acquisition module for real-time monitoring of key nodes in a target power grid and generating a real-time data stream of the target power grid; a data processing module for adaptively segmenting the real-time data stream based on its frequency fluctuation entropy to generate multiple data blocks; the frequency evolution within each data block is continuous; a feature extraction module for calculating the frequency band energy ratio corresponding to the data block, and extracting features from the data block based on the frequency band energy ratio to generate a target feature vector; an execution module for using a pre-built anomaly monitoring model to predict the anomaly category of the target feature vector and outputting the anomaly category prediction result corresponding to the real-time data stream; wherein the anomaly monitoring model uses a dual-path time attention mechanism to enhance the temporal context of the target feature vector to determine the anomaly category prediction result; and an output module for determining the operating status of the target power grid based on the anomaly category prediction result.

[0013] Thirdly, embodiments of the present invention provide an electronic device, which includes a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor. The processor executes the machine-executable instructions to implement the power grid real-time monitoring and anomaly detection method based on data stream processing of any of the above embodiments.

[0014] Fourthly, embodiments of the present invention provide a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are invoked and executed by a processor, the machine-executable instructions cause the processor to implement the power grid real-time monitoring and anomaly detection method based on data stream processing of any of the above embodiments.

[0015] The embodiments of this invention bring the following beneficial effects: This invention provides a method and apparatus for real-time monitoring and anomaly detection of power grids based on data stream processing. It generates a high-frequency real-time data stream by real-time monitoring of key nodes in the target power grid. The data stream is adaptively segmented using frequency fluctuation entropy as the core, ensuring that each data block maintains the continuity of frequency evolution, effectively avoiding the rigid segmentation problem of dynamic frequencies inherent in traditional fixed-window methods. Furthermore, feature extraction is performed based on the frequency band energy ratio of each data block, allowing the generated target feature vector to simultaneously encompass single-band characteristics and inter-band energy differences, significantly enhancing the sufficiency of feature expression and solving the deficiency of traditional feature extraction that ignores frequency band characteristics and energy differences. Finally, by using an anomaly monitoring model incorporating a dual-path time attention mechanism to process the target feature vector, the temporal context of the features can be enhanced, enabling accurate capture of complex nonlinear frequency patterns. This allows the model to output high-precision anomaly category prediction results even during significant load changes or the initial stages of a fault, compensating for the poor performance of traditional methods in handling complex fluctuations and sudden changes. Ultimately, by combining the prediction results, the operating status of the power grid can be clearly defined, enabling efficient identification and real-time early warning of power grid frequency anomalies. This solves the problems of existing technologies being unable to adapt to dynamic changes in power grid frequency and insufficient accuracy in anomaly identification, thus providing a reliable guarantee for the frequency stability and operational safety of the power grid in the context of increasing renewable energy share.

[0016] Other features and advantages of the invention will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the techniques described above.

[0017] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0018] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0019] Figure 1 A flowchart of a real-time power grid monitoring and anomaly detection method based on data stream processing provided in an embodiment of the present invention; Figure 2 A flowchart of another real-time power grid monitoring and anomaly detection method based on data stream processing provided in an embodiment of the present invention; Figure 3A schematic diagram illustrating the experimental comparison of different time series segmentation methods provided in this embodiment of the invention; Figure 4 A schematic diagram illustrating accuracy comparison provided in an embodiment of the present invention; Figure 5 This is a schematic diagram illustrating recall rate comparison provided in an embodiment of the present invention; Figure 6 This is a comparative diagram of comprehensive evaluation indicators provided in an embodiment of the present invention; Figure 7 This is a schematic diagram illustrating a detection delay comparison provided in an embodiment of the present invention; Figure 8 A schematic diagram of a power grid real-time monitoring and anomaly detection device based on data stream processing is provided in an embodiment of the present invention. Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0021] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0022] This invention provides a method and apparatus for real-time monitoring and anomaly detection of power grids based on data stream processing, in order to solve the problems of existing technologies being unable to adapt to dynamic changes in power grid frequency and insufficient accuracy in anomaly identification.

[0023] To facilitate understanding, the real-time power grid monitoring and anomaly detection method based on data stream processing provided in this embodiment of the invention will be described first, referring to... Figure 1 The method includes the following steps: Step S102: Real-time monitoring of key nodes of the target power grid is performed to generate a real-time data stream of the target power grid.

[0024] The target power grid is a specific power system for which frequency anomaly monitoring and operational status assessment are to be conducted. It can be defined as a regional power grid, a provincial power grid, or a local power grid including renewable energy connections, depending on monitoring requirements. The key locations within the target power grid that significantly influence frequency fluctuations or centrally reflect the grid's operational status are the aforementioned critical nodes, including but not limited to renewable energy grid connection points, main transformer connection points, load center busbars, and regional tie-line monitoring points. In this embodiment, monitoring equipment continuously collects data at these critical nodes, obtaining a time-based sequence of power grid operating parameters as the aforementioned real-time data stream. The core data includes frequency data, and may also include auxiliary parameters such as voltage and current. The data update frequency meets real-time monitoring requirements (e.g., not less than 50Hz). In one implementation, the real-time power grid monitoring data acquisition process can be achieved through a high-precision sensor network deployed at key nodes of the power grid, continuously collecting time-series data of current, voltage, power, and load attributes. The sampling frequency is set to 100Hz to ensure coverage of the power grid's fundamental frequency and harmonic components.

[0025] Step S104: Based on the frequency fluctuation entropy of the real-time data stream, adaptively segment the real-time data stream to generate multiple data blocks.

[0026] Frequency fluctuation entropy is used to quantify the degree of disorder in frequency changes in real-time data streams, integrating the amplitude, speed, and duration of frequency fluctuations. Its entropy value is positively correlated with the complexity of frequency fluctuations. Unlike dynamic data partitioning methods with fixed window segments, this embodiment of the invention automatically adjusts the segmentation boundaries using frequency fluctuation entropy as the criterion, enabling the partitioning results to match the actual characteristics of frequency evolution. Correspondingly, multiple data blocks are obtained, and the evolution of frequency from one stable state to another within each data block unit is continuous and uninterrupted, fully reflecting a specific frequency change pattern.

[0027] Step S106: Calculate the frequency band energy ratio corresponding to the data block, and extract features from the data block based on the frequency band energy ratio to generate the target feature vector.

[0028] The band energy ratio is used to characterize the ratio of the energy of each frequency band to the total energy after the frequency signal of a data block is decomposed into different frequency bands (such as low frequency, mid frequency, and high frequency). It can highlight the distribution differences of different frequency components. Feature extraction based on the band energy ratio can break the limitations of traditional feature extraction that only focuses on global statistics or a single frequency domain. By highlighting the distribution differences of different frequency components through the band energy ratio, the feature vector can simultaneously reflect the overall pattern and local details of frequency fluctuations.

[0029] Step S108: Use the pre-built anomaly monitoring model to predict the anomaly category of the target feature vector and output the anomaly category prediction result corresponding to the real-time data stream.

[0030] The anomaly detection model is a classification model built on machine learning. Its core functionality involves using a dual-path temporal attention mechanism to mine the temporal correlation of target feature vectors and determine the anomaly category. In one implementation, the dual-path temporal attention mechanism includes a local temporal path (capturing short-term frequency mutation features) and a global temporal path (mining long-term frequency evolution patterns), which can be weighted to strengthen key temporal information. This invention, by utilizing a dual-path attention mechanism to construct the temporal correlation of features, not only improves the ability to identify short-term mutation features such as those in the early stages of a fault, but also avoids misjudgments caused by isolated analysis of single data blocks, thus solving the problem of poor performance of traditional models in handling complex frequency patterns.

[0031] Step S110: Determine the operating status of the target power grid based on the anomaly category prediction results.

[0032] In one implementation, the above-mentioned anomaly prediction results can be categorized into normal, harmonic distortion, load surge, voltage sag, and frequency oscillation. A mapping rule between anomaly categories and grid operating states can be established. For example, if the prediction result is normal fluctuation, the grid operating state is determined to be stable; if it is harmonic distortion, the grid is determined to be in a state of power quality anomaly requiring remediation based on the distortion occurrence node and harmonic content; if it is load surge, the grid is determined to be in a state requiring rapid load adjustment based on the surge amplitude and duration; if it is voltage sag, the sag depth and impact range are correlated to determine a state of local power supply reliability decline requiring investigation; if it is frequency oscillation, the grid is determined to be in a state of frequency stability risk requiring intervention based on the oscillation frequency and amplitude. Furthermore, detailed status reports containing handling suggestions can be generated for the corresponding states to transform abstract anomaly prediction results into intuitive operating state judgments, providing clear decision-making basis for grid dispatchers.

[0033] Furthermore, regarding the above-mentioned problems, existing technologies have the following shortcomings in practical applications: 1. Traditional power grid anomaly detection methods typically rely on fixed-length sliding windows for data segmentation, which cannot effectively adapt to the dynamic frequency fluctuations of power grid data, leading to inaccurate capture of frequency features, especially during load fluctuations and fault initiation stages. 2. Existing feature extraction methods often only focus on the statistical features of the entire frequency band, failing to fully consider the contribution of different frequency bands to anomalies, resulting in high-frequency noise drowning out low-frequency anomaly signals and affecting the anomaly detection effect. 3. Current convolutional neural network models often use fixed convolution kernels, failing to adaptively adjust according to the stability of different frequency bands, resulting in insufficient sensitivity to frequency fluctuations, especially during periods of drastic frequency changes. 4. Conventional time-series anomaly detection methods fail to fully consider the changes in short-term anomalies and long-term trends in power grid data; traditional methods identify anomaly events too smoothly, making it difficult to effectively capture key time points.

[0034] To address the aforementioned problems, based on the above embodiments, this invention also provides another method for real-time power grid monitoring and anomaly detection based on data stream processing, referring to... Figure 2 The method includes the following steps: Step S202: Real-time monitoring of key nodes of the target power grid is performed to generate a real-time data stream of the target power grid.

[0035] Step S204: Based on the preset window function and short-time Fourier transform, determine the frequency spectrum power distribution of multiple attribute data of the real-time data stream within the corresponding window.

[0036] The monitoring data in real-time power grid monitoring tasks include current, voltage, power, and load attributes, which typically exhibit non-stationary frequency fluctuations and abrupt changes in frequency spectrum distribution. Conventional methods use fixed-length sliding windows to segment time-domain data, ignoring the dynamic correlation in the frequency domain. This leads to inconsistent frequency characteristics within each segment, making it difficult to effectively capture frequency pattern jumps at the onset of anomalies. Furthermore, random drift of frequency components caused by power grid load fluctuations disrupts the continuous evolution of frequency stability, making it difficult for models to distinguish between gradual anomalies and noise disturbances. This invention combines a preset window function and short-time Fourier transform for adaptive segmentation of power grid data, ensuring continuous frequency evolution within each data block and effectively capturing load switching or fault initiation events.

[0037] In practical implementation, window functions and short-time Fourier transforms are used to optimize the spectral analysis effect through window functions. In one implementation, the frequency spectrum power distribution can be determined as follows: Hanning window + short-time Fourier transform. This is a signal processing method that combines the Hanning window (smoothed cosine square window function) with the short-time Fourier transform (STFT). First, the Hanning window extracts short-time sub-signals from the real-time data stream, and then performs a Fourier transform on each sub-signal, thereby simultaneously obtaining the time and frequency domain information of the signal, achieving joint time-frequency analysis. The Hanning window exhibits bell-shaped smoothness, effectively reducing spectral leakage caused by signal truncation and ensuring that the frequency spectrum power distribution truly reflects the frequency composition of the power grid attribute data (such as the frequency components of frequency and voltage). The short-time sliding analysis mode of this transform method can capture instantaneous changes in the power grid frequency, avoiding the deficiency of long-time Fourier transforms in reflecting short-time fluctuations, and achieving refined perception of frequency changes.

[0038] Furthermore, a Hamming window + STFT can be used: The Hamming window, like the Hanning window, is a cosine window, with slightly lower sidelobe attenuation but a narrower main lobe, resulting in slightly better spectral resolution, suitable for scenarios requiring high frequency discrimination accuracy. A Blackman window + STFT offers stronger sidelobe attenuation and better spectral leakage suppression than the Hanning window, but a wider main lobe, making it suitable for frequency analysis in high-noise power grid environments. A Chebyshev window + STFT allows for parameter control of sidelobe levels, offering high flexibility and suitability for power grid signal processing under complex interference, but with slightly higher computational complexity.

[0039] In practical implementation, the short-time Fourier transform output is a frequency characteristic, and the corresponding calculation method for the frequency spectrum power distribution is as follows:

[0040] This represents the normalized frequency spectral power at time t and for the i-th attribute, used to describe the relative energy of the frequency distribution. For frequency index, ; Indicates low frequency, default definition This corresponds to the starting point of the power grid's base frequency; Indicates the highest frequency, the default definition. This corresponds to the end point of the power grid's base frequency; This represents the logarithmic function with base 2.

[0041]

[0042] In the above formula, For attribute index, ,in Corresponding current properties Corresponding voltage attribute, Corresponding power attributes, Corresponding load attributes; This indicates that the i-th attribute is within the time interval. The subsequence with dimension is , representing data within a local time window; This represents the short-time Fourier transform operator, used to calculate the frequency spectrum within a local time window. The preferred setting is the window length for the short-time Fourier transform. For 128, covering the number of A local time interval centered on a specific moment; For time point indexing, , which represents the time sequence position of data sampling.

[0043] Step S206: Based on the frequency spectrum power distribution, determine the frequency fluctuation entropy corresponding to each attribute data.

[0044] Combining the above steps, this embodiment of the invention calculates the frequency fluctuation entropy of each attribute using short-time Fourier transform, and further adaptively determines the segmentation boundary based on the frequency fluctuation entropy (e.g., dynamically determining the segmentation boundary based on the peak of the absolute value of the first derivative of the mean of the frequency fluctuation entropy of multiple attributes), thereby dividing the time series into multiple data blocks. Specifically, for the current, voltage, power, and load attributes in each sample data matrix, combining the above steps, a Hanning window short-time Fourier transform is applied centered on each time point to calculate the frequency spectrum power distribution within the window. Furthermore, the frequency fluctuation stability is quantified based on the entropy of the normalized power spectrum, thus obtaining the frequency fluctuation entropy of each attribute at each time point. A lower entropy value indicates a more concentrated frequency and higher stability, while the entropy value increases significantly under abnormal conditions, achieving an effective measure of the dispersion of the frequency distribution. The calculation method of frequency fluctuation entropy is expressed as follows:

[0045] In the formula, This represents the frequency fluctuation entropy of the i-th attribute at time t, used to quantify the dispersion of the frequency distribution. In this calculation method, frequency component diffusion during anomalies can lead to an increase in the entropy value. Let represent the normalized frequency spectral power of the i-th attribute at time t, where satisfies .

[0046] Step S208: Calculate the mean sequence corresponding to the frequency fluctuation entropy of multiple attribute data, and determine the frequency stability mutation point of the real-time data stream based on the mean sequence.

[0047] In practical implementation, the mean sequence of frequency fluctuation entropy for all attributes is calculated, and frequency stability abrupt changes are detected based on the absolute value of the first derivative of this mean sequence. When the absolute value of the derivative exceeds a preset threshold, a frequency mode jump is identified, thereby extracting a set of segmented boundary points. This allows the time series to be divided into multiple data blocks, ensuring continuous frequency evolution within each data block, and effectively capturing load switching or fault initiation events. This is represented as:

[0048] In the formula, This represents the set of segment boundary points, containing all detected boundary locations, used to divide the data into segments; For the first One boundary point; For boundary point indexing, ; This represents the total number of boundary points; The average entropy of the multi-attribute frequency fluctuations at time t reflects the overall frequency stability level. It reduces the impact of noise by averaging the entropy values ​​of each attribute. The calculation method is as follows: ; express The discrete first derivative is calculated as follows: It is used to capture abrupt changes in entropy values ​​and identify frequency pattern transitions. Indicates the t-th The mean entropy of multi-attribute frequency fluctuations at any given time; The preferred value is the derivative threshold. When the absolute value of the derivative exceeds the threshold, it indicates a frequency mode transition, which is used to control the sensitivity of boundary detection; For point-in-time indexing, default settings .

[0049] Step S210: Based on the frequency stable mutation point, the real-time data stream is adaptively divided to generate multiple data blocks.

[0050] Furthermore, based on the set of segmented boundary points The time series is divided into B=K One data block, with consistent frequency characteristics within each block, where K represents the total number of segment boundary points, i.e., the number of detected frequency abrupt changes, in the b-th data block. The dimension is , It is the block length. It is a data block index. , It is the total number of data blocks. .

[0051] Furthermore, this embodiment of the invention also performs a comparative analysis of frequency fluctuation entropy to verify the advantages of the adaptive segmentation method based on frequency fluctuation entropy proposed in this invention in terms of frequency stability. (Refer to...) Figure 3This paper provides experimental comparison diagrams of different time series segmentation methods, including the traditional fixed-window segmentation method, the wavelet transform-based segmentation method, the empirical mode decomposition (EMD)-based segmentation method, and the method of this invention. The fixed-window segmentation method is a conventional technique in power grid monitoring, specifically using a fixed-length time window to segment the data, ignoring the dynamic changes in frequency characteristics. The wavelet transform segmentation method utilizes the multi-resolution characteristics of wavelet analysis for signal decomposition. The EMD segmentation method is an adaptive signal processing method. The box plots show significant differences in the distribution of frequency fluctuation entropy values ​​among the different methods. The frequency fluctuation entropy value on the ordinate reflects the dispersion of the frequency distribution; the lower the entropy value, the more concentrated the frequency and the higher the stability. The fixed-window segmentation method has the widest entropy value distribution range and the highest median, indicating that the frequency characteristics within the segments generated by this method are inconsistent and the stability is poor. The wavelet transform segmentation method and the EMD segmentation method show some improvement in entropy value distribution, but still have many high-entropy outliers. The entropy distribution of the method of this invention is the most concentrated, the median is significantly lower than that of other methods, and the number of outliers is the fewest. This indicates that by segmenting the data by dynamically detecting frequency mode transition points, the frequency evolution within each data block can be ensured to be continuous, effectively improving frequency stability.

[0052] Step S212: Calculate the frequency band energy ratio corresponding to the data block, and extract features from the data block based on the frequency band energy ratio to generate the target feature vector.

[0053] In a specific implementation, this embodiment of the invention performs discrete wavelet transform on the data block, decomposing the data block into multiple frequency band components. The average frequency fluctuation entropy corresponding to each attribute data of the data block is determined; based on the average frequency fluctuation entropy, the frequency band energy ratio corresponding to each frequency band component of the data block is determined.

[0054] In segmented data blocks, anomalies are usually manifested as energy anomalies in specific frequency bands, such as changes in fundamental frequency, harmonics, or noise components. Conventional feature extraction methods use statistics across the entire frequency band, which cannot distinguish the stability differences between different frequency bands. This results in high-frequency noise drowning out low-frequency anomaly signs. Conventional techniques, by calculating the time-domain mean or variance, ignore the differences in the contribution of frequency sub-bands to anomaly classification, thereby weakening the features of key frequency bands.

[0055] This invention decomposes attribute data into multiple frequency bands (e.g., by using a preset transformation method to decompose attribute data into three frequency bands: a low-frequency stable band, a mid-frequency transition band, and a high-frequency noise band), calculates the weighted energy ratio of each frequency band, and obtains a stability index through adaptive weighted fusion, thereby enhancing feature focusing on anomalously sensitive frequency bands. Taking discrete wavelet transform as an example, discrete wavelet transform is applied to each attribute subsequence in each data block to decompose the signal into three frequency band components: a low-frequency stable band, a mid-frequency transition band, and a high-frequency noise band, obtaining the corresponding approximation coefficients and detail coefficient vectors, thus achieving the separation of signals in different frequency bands, expressed as:

[0056] In the formula, This represents the discrete wavelet transform operator. The default decomposition level is 3. Specifically, it uses the Daubechies4 wavelet basis to decompose the signal into different frequency band components, where each frequency band component belongs to a different frequency band boundary. The vector of low-frequency approximation coefficients, dimension Corresponding frequency band boundary This represents the low-frequency stable component of the signal; The mid-frequency detail coefficient vector, dimension Corresponding frequency band boundary This represents the mid-frequency transition component of the signal; For high-frequency detail coefficient vectors, dimension Corresponding frequency band boundary , representing the high-frequency noise component of the signal; Indicates the first The subsequence of the i-th attribute in a data block is The i-th row represents the subsequence of the i-th attribute in the b-th data block, with dimension . .

[0057] Furthermore, based on the frequency band coefficient vectors obtained from discrete wavelet transform, their L2 norm squared is calculated to characterize energy. This is then weighted by combining the average frequency fluctuation entropy of the attributes in the data block, and normalized to obtain the weighted energy ratio of each frequency band. This quantifies the contribution of each frequency band to the total energy. Under abnormal conditions, the mid-frequency band energy ratio increases, enhancing the focus on anomalously sensitive frequency bands, expressed as:

[0058] In the formula, This indicates that the i-th attribute is in the frequency band. The weighted energy ratio quantifies the contribution of this frequency band to the total energy; during anomalies, the energy ratio of the intermediate frequency band increases. Represents the natural exponential function; Indicates the scaling factor, preferably set as follows: To control the influence of entropy on weights; The average frequency fluctuation entropy of the i-th attribute in the b-th data block is expressed as follows: It is used to weight the frequency band energy. When there is an anomaly, the entropy value increases, thereby enhancing the sensitive frequency band. Represents the L2 norm; This is the frequency band index, with a default value. , Corresponding to low frequency band, Corresponding to the mid-frequency band, Corresponding to the high-frequency band.

[0059] Furthermore, based on the fluctuation degree of the frequency band energy ratio, the stability index corresponding to each frequency band component is determined. Using the frequency fluctuation entropy of each attribute data in the data block, and the attribute weight corresponding to each attribute data, the stability index is weighted and fused to generate the target feature vector of the data block. In specific implementation, the coefficient of variation of each frequency band energy ratio is calculated as a stability index, and weighted fusion is performed by combining the dynamic weights of each attribute and the attribute weight matrix. The feature vectors of each attribute are concatenated into an overall feature vector, outputting a multi-frequency band feature matrix. This strengthens the dominant role of load and power attributes, achieving effective integration of multi-attribute and multi-frequency band stability features, expressed as:

[0060] In the formula, Indicates the first Multi-band feature matrix of data blocks The feature vector (i.e., the target feature vector) at time t has the following dimensions. It characterizes the fusion stability features of multiple attributes and multiple frequency bands. This indicates that the i-th attribute is in the frequency band. The stability index is used to quantify the fluctuation of the bandwidth energy ratio, and is calculated as follows: ; This is a moving average operator with a default window length of 32, used to calculate the average level of the energy ratio sequence as a reference benchmark. The sliding standard deviation operator has a default window length of 32 and is used to calculate the fluctuation of the energy ratio sequence, reflecting changes in stability. This represents the dynamic weight of the i-th attribute at time t, calculated as follows: This causes the weights to change with the entropy value; when the entropy value is high during anomalies, the weights increase. Indicates the first Frequency fluctuation entropy of each attribute At all points in time The maximum value in; This is the attribute weight matrix, with dimension 1. , are trainable parameters, initialized as a diagonal matrix. Based on weighted power and load attributes; This represents the vector diagonalization operation; Indicates the transpose operation; This represents a vector concatenation operation that concatenates the feature vectors of four attributes (current, voltage, power, and load) into a single feature vector. This represents the low-frequency stability index of the i-th attribute at time t, used to evaluate low-frequency stability; This represents the mid-frequency stability index of the i-th attribute at time t, used to evaluate mid-frequency stability; This represents the high-frequency band stability index of the i-th attribute at time t, used to evaluate high-frequency stability. In specific implementations, , and They represent the first The attribute in the first The stability indices of the low-frequency, mid-frequency, and high-frequency bands at any given time are the i-th attribute in the frequency band. stability index The specific value at time t is calculated based on the coefficient of variation of the frequency band energy ratio, that is, the fluctuation of the energy ratio sequence is obtained by calculating the fluctuation through a sliding window.

[0061] It should be noted that, because power and load changes are more significant during power grid anomalies, the attribute weight matrix... Initialize to The weighted power and load attributes are then used to further output a multi-band feature matrix. Multi-band feature matrix From all time points of Stacked together, with dimensions of It contains fused features from all time points, characterizing the temporal evolution of multi-band stability within a data block.

[0062] Step S214: Use the pre-built anomaly monitoring model to predict the anomaly category of the target feature vector and output the anomaly category prediction result corresponding to the real-time data stream.

[0063] 1) Based on the frequency fluctuation entropy of the target feature vector, perform frequency adaptive convolutional coding on the target feature vector to generate encoded time-frequency features.

[0064] The feature matrix exhibits frequency band-time coupling characteristics, and abnormal patterns are unevenly distributed across frequency bands. Conventional convolutional neural networks use fixed convolution kernels, which cannot adapt to stability changes in different frequency bands, leading to deviations in the extraction of key abnormal features. Furthermore, the kernel weights of standard two-dimensional convolutions are independent of frequency components, making it difficult to focus on anomalously sensitive frequency bands. This invention generates frequency band importance weights and a frequency band modulation matrix, dynamically modulates the convolution kernel weights, and performs gated convolution operations on multi-frequency band feature matrices, thereby enhancing the feature response to unstable frequency bands and achieving adaptive feature extraction of frequency stability changes in power grid data. The specific implementation includes the following steps: a- Generate a frequency band modulation matrix based on the frequency band energy ratio corresponding to the target feature vector.

[0065] The frequency band adjustment matrix is ​​a diagonal matrix, whose diagonal elements consist of the overall coefficient of variation of the frequency band energy ratio, and is expressed as: , This is a frequency band modulation matrix. In one implementation, its dimension is... , The frequency band modulation vector has a dimension of This is used to introduce a priori information about frequency band fluctuations and amplify anomalous frequency bands. The first term of the frequency band modulation vector is defined. The elements are The calculation method is expressed as follows:

[0066] in, Indicates the first Multi-band feature matrix of data blocks The Column feature sequence; Indicates the first Multi-band feature matrix of data blocks The Column feature sequence The standard deviation is calculated as follows:

[0067] The above standard deviation is used to quantify the first The degree of global fluctuation in the characteristic channel; Indicates the first Multi-band feature matrix of data blocks The Column feature sequence The mean is calculated as follows: , used to quantify the first The global average level of each feature channel. Represents the multi-band feature matrix of the b-th data block At time t, the The value of each characteristic channel is a scalar, reflecting the time-t and time-th characteristic channel values. The stability level of the frequency band-attribute combination features; Indicates the feature channel index. Corresponding to multi-band feature matrix The system has 12 feature channels, each corresponding to a frequency band-attribute combination feature.

[0068] It should be noted that the frequency band modulation vector It is a modulation vector based on the global volatility of frequency band characteristics. The larger the element value, the more unstable the corresponding frequency band. It is given higher weight in gated convolution, so that the model focuses on the abnormally sensitive frequency band.

[0069] b - Combine the importance scores of each frequency band contained in the target feature vector to construct a frequency band gating matrix.

[0070] A fully connected layer is applied to the input multi-band feature matrix to calculate the importance score of each band. The output weight vector is then activated by a sigmoid function and dynamically modulated using a band modulation matrix based on the band energy ratio variation coefficient, generating a band-gated matrix. This allows the convolutional kernel weights to focus more on bands with significant fluctuations, improving the response capability to abnormal frequency components of the power grid, as expressed below:

[0071] In the formula, It is a frequency band gated matrix with dimension . It is used to dynamically modulate the weights of the convolution kernel to enhance the response to key frequency bands; This is the frequency band importance weight vector, with dimension . Each element corresponds to an importance score for a frequency band feature channel. The learned weights are used to focus on abnormally sensitive frequency bands. The calculation method is expressed as follows: . This represents the Sigmoid activation function; This is the gated weight matrix, with dimension 1. , are trainable parameters used to calculate the importance of the frequency band; This represents the matrix vectorization operation, which takes the input feature matrix as an example. Flattening it into a vector makes it easier for fully connected layers to process; It is a multi-band feature matrix, composed of all time points. of Stacked together, with dimensions of The temporal evolution of multi-band stability within a data block; The gating bias term has a dimension of 12 and is a trainable parameter used to adjust the importance score.

[0072] c- The preset convolution kernel weights are dynamically modulated using a frequency band gating matrix, and the target feature vector is convolved with the dynamically modulated convolution kernel weights to determine the encoded time-frequency features corresponding to the target feature vector.

[0073] Specifically, a frequency-gated matrix is ​​used to adjust the convolution kernel weights, and a one-dimensional convolution operation is performed on the multi-frequency band feature matrix. This is combined with ReLU activation and modulation based on the mean sequence of multi-attribute frequency fluctuation entropy to output an encoded feature matrix. This enhances the feature response to abnormally sensitive frequency bands and time, achieving adaptive feature extraction of frequency stability changes in power grid data, as shown below:

[0074] In the formula, The encoding feature matrix has a dimension of . It characterizes the time-frequency features after frequency adaptive convolutional coding, and by fusing frequency band gating and frequency fluctuation entropy modulation, it can enhance the feature response of abnormally sensitive frequency bands and time. This represents the entropy modulation factor, a trainable parameter with an initial value of 0.1. It is used to control the impact of frequency fluctuation entropy on the convolution output, enhancing the feature response to unstable time points. Indicates the first A multi-attribute frequency fluctuation entropy mean sequence of data blocks, dimension The time evolution of frequency stability within a data block is used to characterize the average entropy of multi-attribute frequency fluctuations at time t within the time interval corresponding to the b-th data block. The result is represented as:

[0075] in, Let b be the start time of the data block. The end time of the b-th data block; Indicates the first The mean entropy of multi-attribute frequency fluctuations at any given time. Indicates the first The mean entropy of multi-attribute frequency fluctuations at any given time. Indicates the first The mean entropy of multi-attribute frequency fluctuations at any given time; Indicates will The vector is copied 64 times along the column direction to obtain the dimension. The matrix is ​​used to modulate the convolution output at each time point, making the model more focused on moments with unstable frequencies. To modify the activation function of the linear unit. The convolution kernel weight tensor has a dimension of . It contains 64 filters, each with a size of [size missing]. , are trainable parameters used to extract time-frequency features; This represents the element-wise multiplication operation; This represents a one-dimensional convolution operation that slides along the time dimension with a stride of 1 and padding of 2 to maintain the length of the time dimension. The convolution bias term has a dimension of . , are trainable parameters used to adjust output features.

[0076] 2) Capture short-term frequency mutation points of encoded time-frequency features through local transient attention pathways, and capture long-term trend evolution of encoded time-frequency features through global trend attention pathways.

[0077] The encoded features contain long-range temporal dependencies, but anomalous events are sparsely distributed in time. Conventional recurrent neural networks process all time steps equally, making it difficult to focus on key anomalous moments, resulting in the smoothing of key signals. This invention captures short-term frequency abrupt changes through a local transient attention path and captures the long-range trend evolution of frequency stability within data blocks through a global trend attention path. Finally, the dual-path outputs are fused with the mean vector of the multi-band feature matrix to obtain a time-enhanced feature vector, achieving an enhanced representation of the temporal context. The specific steps are as follows: a-Local Transient Attention Path: One-dimensional convolution is applied to the encoded feature matrix to extract local time window features, the attention score within the window is calculated, and the mean of multi-attribute frequency fluctuation entropy is used for modulation. The local path output vector is obtained by weighted summation, thereby focusing on short-term frequency change points and highlighting the features of moments of frequency instability. This is represented as:

[0078] In the formula, Let be the local attention weight at time t, with dimension 1, representing the importance of that time point within the local window, used to focus on short-term anomalies, and calculated as follows: ; is a local modulation factor, a trainable parameter with an initial value of 0.05, which controls the effect of frequency stability on the features; This represents the average entropy of the multi-attribute frequency fluctuations of the b-th data block at time t, which is the... Multi-attribute frequency fluctuation entropy mean sequence of data blocks The specific value at time t; To normalize the exponential function, ensure that the sum of attention weights is 1, thus achieving weight normalization; This is a local attention weight vector with a dimension of 32. These are trainable parameters used to calculate the attention score. for transpose; It is the hyperbolic tangent activation function; This is the local attention weight matrix, with dimension 1. , is a trainable parameter that maps local temporal window features to a 32-dimensional hidden space, used to calculate attention scores and capture transient changes in frequency patterns within the window; Represents the encoded feature matrix In the time window The submatrix, with a window length of 16, represents the local time context centered at time t, used to capture short-term frequency fluctuations; The local path output vector has a dimension of 64 and represents the short-term anomalous features after fusion frequency modulation, highlighting frequency abrupt changes. Represents the encoded feature matrix The feature vector at time t has dimension . Encoding feature matrix The row vector at time t represents the time-frequency characteristics at time t.

[0079] b-Global Trend Attention Path: A fully connected layer is applied to the encoded feature matrix to calculate global temporal attention weights, which are then modulated using the mean repetition matrix of the frequency band modulation vector. The global path output vector is obtained through weighted summation, thereby capturing the long-range trend evolution of frequency stability within the data block and enhancing the feature response to high-fluctuation frequency bands. This is represented as:

[0080] In the formula, The global attention weight vector has dimensions of . This characterizes the importance of each time point in the global context, and is used to capture long-term trends. The calculation method is expressed as follows: ; is the global modulation factor, a trainable parameter with an initial value of 0.05, used to adjust the sensitivity of the global attention path to the prior of frequency band fluctuations; It is the frequency band modulation vector The mean repeating matrix with dimension 1. This is used to introduce a global frequency band fluctuation prior, specifically by calculating the frequency band modulation vector. After the mean scalar, The mean scalar repeated expansion is as follows The matrix is ​​obtained by having all elements in the matrix as equal to 0. The mean scalar; is the global attention weight vector with a dimension of 48, which are trainable parameters used to calculate the global attention score; The global path output vector has a dimension of 64 and is a weighted summation of features, integrating global trend information. This is the global attention weight matrix, with dimension 1. , is a trainable parameter that maps global features to a 48-dimensional hidden space and is used to calculate attention scores, capturing the overall trend of frequency stability within data blocks.

[0081] It should be noted that when the global modulation factor At that time, the model enhances its characteristic response to high-fluctuation frequency bands and improves its ability to capture abnormal trends, when the global modulation factor At that time, it degenerates into standard global attention, ignoring prior frequency band fluctuations.

[0082] 3) Determine the time-enhanced feature vector corresponding to the encoded time-frequency features based on short-term frequency mutation points and long-term trend evolution.

[0083] Combining the above steps, the local and global path output vectors are concatenated with the mean vector of the multi-band feature matrix, and then mapped to a time-enhanced feature vector through a fully connected layer. This process integrates local transient anomaly features, global trend evolution features, and overall frequency band stability levels to achieve an enhanced representation of the temporal context, expressed as:

[0084] In the formula, The time-enhanced feature vector has a dimension of 128 and integrates local transient anomaly features, global trend evolution features, and overall frequency band stability level. It is a multi-band feature matrix The mean vector, dimension The calculation method is expressed as It characterizes the overall level of frequency band stability within a data block; To fuse the weight matrix, the dimension is , are trainable parameters that map the concatenated features to 128-dimensional temporal augmentation features; The fusion bias term has a dimension of 128 and is a trainable parameter used to adjust the output features. This indicates a vector concatenation operation.

[0085] 4) Determine the initial category score corresponding to the time-enhanced feature vector through the anomaly monitoring model, and adjust the initial category score in combination with the frequency stability index corresponding to the real-time data stream to generate the anomaly category prediction result corresponding to the real-time data stream.

[0086] This invention obtains a logits vector by applying a fully connected layer to the time-enhanced feature vector, adjusts the logits vector by combining it with the frequency stability index of the sample, and then outputs the class probability distribution through the Softmax function, thereby enhancing the classification ability of frequency stability anomalies.

[0087] In practical implementation, a fully connected layer is applied to the temporal augmentation feature vector to obtain the logits vector. The logits vector is then adjusted using a stability bias factor based on the frequency stability index of the samples. Finally, a softmax function is used to output the class probability distribution, thereby mapping the features to anomaly class probabilities and enhancing the classification ability for frequency stability anomalies. This is represented as:

[0088] In the formula, The predicted probability vector has dimension . , representing the probability that a sample belongs to each anomaly category; The frequency stability index of the sample is calculated as follows: , used to adjust logits. is the stability bias factor, a trainable parameter with an initial value of 0.1, used to adjust the bias of the frequency stability index on the logits vector.

[0089] Let logits be a vector with dimension 1. , representing the unnormalized category score, is calculated as follows: ; This represents the total number of categories, including normal and abnormal categories; the default setting is... This corresponds to five states in power grid monitoring: normal, harmonic distortion, load change, voltage sag, and frequency oscillation. The output layer weight matrix has dimensions of . , are trainable parameters used to map features to the class space; The output layer bias term has a dimension of , are trainable parameters used to adjust the class scores. It should be noted that the logits vector is an unnormalized class score vector, which physically represents the model's raw predicted score for each class, without probability normalization.

[0090] Furthermore, the embodiments of the present invention also perform model training through the following steps: 1) Obtain a pre-built training sample set, input the training sample set into the preset initial model, and train the initial model.

[0091] The training sample set can be referenced from the aforementioned real-time data stream, and will not be elaborated further here. This training dataset is constructed based on historical operating records and expert annotations. The collection period covers normal operating conditions and typical abnormal events (such as harmonic distortion, load surges, voltage sags, and frequency oscillations). The data length is uniformly set at 4096 time points to match subsequent segmented processing requirements. In one implementation, the data annotation method employs a multi-expert collaborative annotation strategy, combining power grid event logs and waveform analysis tools to assign a category label to each time series sample. The labeled categories include five types: normal, harmonic distortion, load surges, voltage sags, and frequency oscillations.

[0092] 2) Calculate the regularization loss corresponding to the initial model based on the frequency band energy ratio of the preset frequency band components in the training sample set; and calculate the cross-entropy loss corresponding to the initial model based on the difference between the predicted probability distribution of the initial model and the true label.

[0093] 3) Calculate the total loss function of the initial model based on regularization loss and cross-entropy loss.

[0094] The aforementioned features need to be mapped to anomaly category probabilities. However, the inter-class differences in frequency stability anomalies such as harmonic distortion in the training samples are small. Conventional cross-entropy loss ignores frequency stability constraints, leading to ambiguity in the classification of stability anomalies. This embodiment of the invention further incorporates an auxiliary regularization term based on the mid-band energy ratio on top of the standard cross-entropy loss. This regularization term calculates the binary cross-entropy loss between the mid-band energy ratio and the true anomaly label, enabling the model to focus more intently on anomaly-sensitive frequency band features during training, thereby improving the discriminative power for frequency stability anomalies such as harmonic distortion. The total loss function is composed of a weighted sum of the cross-entropy loss and the regularization loss.

[0095] The total loss function is expressed by the following formula:

[0096] In the formula, This represents the total loss function, used to optimize model parameters. The cross-entropy loss function measures the difference between the predicted probability distribution and the true label. Its calculation method is as follows:

[0097] This represents the regularization loss function, calculated based on the mid-band energy ratio, used to enhance the model's sensitivity to anomalous frequency band features. The calculation method is expressed as follows:

[0098] The regularization weight coefficients are trainable parameters with an initial value of [value missing]. This is used to balance the effects of cross-entropy loss and regularization loss; The true label vector is in the th order. The values ​​for each category are one-hot encoded vectors with dimensions of . ; Represents the prediction probability vector In the Values ​​in each category, with dimension . ; This represents the natural logarithm function. When no base is specified, the default base is the natural constant.

[0099] This represents an anomaly indicator variable, calculated as follows: ,in This represents the probability value of the normal category in the true label, when the sample is an anomaly. Normally ; Indicates the first The average mid-band energy ratio of each data block is calculated as follows:

[0100] in, It is the first Each attribute in The corresponding weighted energy ratio of the mid-frequency band. It should be noted that by using the mid-frequency band energy ratio as an auxiliary monitoring signal, the regularization loss function... This allows the model to explicitly focus on the increasing trend of mid-band energy ratio under abnormal conditions during training, thereby enhancing its ability to capture patterns with frequency stability anomalies.

[0101] 4) Update the model parameters of the initial model based on the total loss function until the initial model meets the preset training requirements, and build an anomaly detection model based on the current initial model.

[0102] The anomaly detection model employs a mini-batch gradient descent algorithm during iterative training. The gradient is calculated based on the total loss function, and all trainable parameters of the model are updated. During training, the input data consists of adaptively segmented data blocks and their corresponding labeled categories. Each batch contains 32 data blocks. Multi-band feature matrices, encoded feature matrices, and temporally augmented feature vectors are calculated through forward propagation. The final output is the category probability distribution, and the sum of cross-entropy loss and regularization loss is calculated. Parameter updates use the Adam optimizer, with an initial learning rate of 0.001 that decays exponentially with each training epoch to achieve stable convergence. Gradient clipping is used to prevent gradient explosion. The stopping condition is based on performance monitoring on the validation set. Training is terminated early when the validation set loss no longer decreases or the classification accuracy no longer improves after 10 consecutive training epochs to avoid overfitting. If the maximum number of training epochs (default 200) is reached, training is forcibly stopped, and the optimal model parameters are saved to ensure the model's generalization ability.

[0103] Step S216: Determine the operating status of the target power grid based on the anomaly category prediction results.

[0104] In summary, after the above model is trained, real-time power grid monitoring and anomaly detection can be achieved through an online data stream processing pipeline. Real-time data on current, voltage, power, and load attributes can be collected and dynamically analyzed using the trained model. In the above embodiment, firstly, adaptive segmentation based on frequency fluctuation entropy is performed on the input real-time data stream, dividing continuous data into data blocks with continuous frequency evolution. Then, for each data block, multi-band stability feature extraction, frequency adaptive convolutional coding, dual-path time attention enhancement, and stability regularization classification are performed sequentially, outputting the probability distribution of the current data block belonging to each anomaly category. The corresponding detection results can be compared with preset thresholds. When the anomaly category probability exceeds 0.8, an alarm is triggered, and the anomaly type, occurrence time, and frequency stability index are recorded. Simultaneously, the frequency fluctuation entropy curve and segmentation boundary points are visualized to assist in operation and maintenance decision-making.

[0105] In summary, the embodiments of the present invention also conduct a comprehensive comparison of detection performance, comparing the performance of the method of the present invention with four conventional power grid anomaly detection methods on multiple performance indicators. (Refer to...) Figures 4-7The comparison methods included Long Short-Term Memory (LSTM) networks, Support Vector Machines (SVMs), Random Forests, and One-Dimensional Convolutional Networks (BCNNs). The experiments comprehensively evaluated the methods across four dimensions: detection accuracy, recall, overall evaluation metrics, and detection latency. The experimental configuration used the same dataset and evaluation criteria, with all methods trained and tested on a labeled dataset containing five power grid states. The dataset included normal operating conditions and four typical abnormal states, with multiple samples for each state to ensure statistical significance. In the accuracy, recall, and overall evaluation metrics sub-graphs, the bar chart of the method presented in this invention showed significantly higher heights than the other methods, with the optimal performance highlighted by thick red lines at the edges. In the detection latency sub-graph, the bar chart of the method presented in this invention had the lowest height, indicating the fastest detection speed. The experimental results fully demonstrate the comprehensive advantages of the method presented in terms of detection accuracy, speed, and robustness.

[0106] This invention proposes a real-time power grid monitoring and anomaly detection method based on data stream processing, which is innovative in the following aspects compared with existing technologies: 1. The adaptive segmentation method of power grid data based on frequency fluctuation entropy can dynamically capture frequency mode jumps, avoiding the problem that traditional fixed window segmentation methods cannot accurately identify frequency characteristic changes, and effectively handle frequency changes in load fluctuations and the initial stage of faults.

[0107] 2. A multi-band stability feature extraction and fusion module is adopted. The power grid data is decomposed by discrete wavelet transform, and the energy of abnormal features in different frequency bands is weighted and fused, which solves the feature weakening problem caused by ignoring frequency band differences in traditional methods.

[0108] 3. A frequency-adaptive convolutional feature encoding module is adopted, which dynamically adjusts the convolution kernel weights by utilizing the frequency band importance weights and the frequency band modulation matrix, thereby enhancing the model's response capability to unstable frequency bands and improving the accuracy of identifying frequency fluctuation anomalies.

[0109] 4. A dual-path time attention module is adopted, which combines local transient attention and global trend attention to optimize the model's representation of time context. This enables the model to accurately capture short-term mutations and long-term trends in power grid data, thereby improving the sensitivity of anomaly detection.

[0110] Based on the above system embodiments, this invention also provides a power grid real-time monitoring and anomaly detection device based on data stream processing, referring to... Figure 8The device includes: a data acquisition module 100 for real-time monitoring of key nodes of the target power grid and generating a real-time data stream of the target power grid; a data processing module 200 for adaptively segmenting the real-time data stream based on the frequency fluctuation entropy of the real-time data stream to generate multiple data blocks; the frequency evolution within each data block is continuous; a feature extraction module 300 for calculating the frequency band energy ratio corresponding to the data block, and extracting features from the data block based on the frequency band energy ratio to generate a target feature vector; an execution module 400 for using a pre-built anomaly monitoring model to predict the anomaly category of the target feature vector and outputting the anomaly category prediction result corresponding to the real-time data stream; wherein, the anomaly monitoring model uses a dual-path time attention mechanism to enhance the temporal context of the target feature vector to determine the anomaly category prediction result; and an output module 500 for determining the operating status of the target power grid based on the anomaly category prediction result.

[0111] The real-time power grid monitoring and anomaly detection device based on data stream processing provided in this embodiment of the invention has the same implementation principle and technical effects as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.

[0112] This invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described... Figures 1-2 The steps of any of the methods shown. Embodiments of the present invention also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the above-described steps. Figures 1-2 The steps of any of the methods shown. Embodiments of the present invention also provide a structural schematic diagram of an electronic device, such as... Figure 9 The diagram shows the structure of the electronic device, which includes a processor 101 and a memory 100. The memory 100 stores computer-executable instructions that can be executed by the processor 101. The processor 101 executes the computer-executable instructions to implement the above-mentioned... Figures 1-2 Any of the methods shown.

[0113] exist Figure 9In the illustrated embodiment, the electronic device further includes a bus 102 and a communication interface 103, wherein the processor 101, the communication interface 103, and the memory 100 are connected via the bus 102. The memory 100 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk drive. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), using the Internet, wide area network, local area network, metropolitan area network, etc. Bus 102 can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, or an AMBA (Advanced Microcontroller Bus Architecture) bus. AMBA defines three types of buses: APB (Advanced Peripheral Bus), AHB (Advanced High-performance Bus), and AXI (Advanced eXtensible Interface). Bus 102 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 9The diagram uses only a single double-headed arrow, but this does not imply a single bus or a single type of bus. Processor 101 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 101 or by instructions in software form. Processor 101 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory, and the processor 101 reads information from the memory and, in conjunction with its hardware, completes the aforementioned tasks. Figures 1-2 Any of the methods shown.

[0114] The computer program product of the power grid real-time monitoring and anomaly detection method and apparatus based on data stream processing provided in this invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. Specific implementations can be found in the method embodiments and will not be repeated here. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system described above can be referred to the corresponding process in the preceding method embodiments, and will not be repeated here. Furthermore, in the description of this invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances. If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0115] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Finally, it should be noted that the above embodiments are merely specific implementations of the invention, used to illustrate the technical solutions of the invention, and not to limit it. The scope of protection of the invention is not limited thereto. Although the invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in this invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this invention, and should all be covered within the scope of protection of this invention. Therefore, the scope of protection of this invention should be determined by the scope of the claims.

Claims

1. A method for real-time monitoring and anomaly detection of power grids based on data stream processing, characterized in that, The method includes: Real-time monitoring of key nodes in the target power grid generates a real-time data stream of the target power grid; Based on the frequency fluctuation entropy of the real-time data stream, the real-time data stream is adaptively segmented to generate multiple data blocks; the frequency evolution within each data block is continuous. Calculate the frequency band energy ratio corresponding to the data block, and based on the frequency band energy ratio, perform feature extraction on the data block to generate a target feature vector; An anomaly category prediction is performed on the target feature vector using a pre-built anomaly detection model, and the anomaly category prediction result corresponding to the real-time data stream is output; wherein, the anomaly detection model uses a dual-path temporal attention mechanism to enhance the temporal context of the target feature vector in order to determine the anomaly category prediction result; The operating status of the target power grid is determined based on the anomaly category prediction results.

2. The method according to claim 1, characterized in that, The step of adaptively segmenting the real-time data stream and generating multiple data blocks based on the frequency fluctuation entropy of the real-time data stream includes: Based on a preset window function and short-time Fourier transform, the frequency spectrum power distribution of multiple attribute data of the real-time data stream is determined within the corresponding window. Based on the frequency spectrum power distribution, determine the frequency fluctuation entropy corresponding to each of the attribute data. Calculate the mean sequence corresponding to the frequency fluctuation entropy of multiple attribute data, and determine the frequency stability mutation point of the real-time data stream based on the mean sequence; Based on the frequency stability mutation point, the real-time data stream is adaptively divided to generate multiple data blocks.

3. The method according to claim 1, characterized in that, The step of calculating the frequency band energy ratio corresponding to the data block includes: The data block is subjected to discrete wavelet transform to decompose the data block into multiple frequency band components; each frequency band component belongs to a different frequency band boundary. Determine the average frequency fluctuation entropy corresponding to each attribute data of the data block; Based on the average frequency fluctuation entropy, the frequency band energy ratio corresponding to each frequency band component of the data block is determined.

4. The method according to claim 3, characterized in that, The step of extracting features from the data block based on the frequency band energy ratio and generating a target feature vector includes: Based on the fluctuation of the frequency band energy ratio, the stability index corresponding to each frequency band component is determined. By using the frequency fluctuation entropy of each attribute data in the data block and the attribute weight corresponding to each attribute data, the stability index is weighted and fused to generate the target feature vector of the data block.

5. The method according to claim 1, characterized in that, The steps of using a pre-built anomaly detection model to predict the anomaly category of the target feature vector and outputting the anomaly category prediction result corresponding to the real-time data stream include: Based on the frequency fluctuation entropy of the target feature vector, frequency adaptive convolutional coding is performed on the target feature vector to generate encoded time-frequency features; The local transient attention path captures short-term frequency abrupt changes in the encoded time-frequency features, and the global trend attention path captures the long-term trend evolution of the encoded time-frequency features. Based on the short-term frequency mutation points and the long-term trend evolution, the time-enhanced feature vector corresponding to the encoded time-frequency features is determined; The anomaly detection model determines the initial category score corresponding to the time-enhanced feature vector, and the initial category score is adjusted in combination with the frequency stability index corresponding to the real-time data stream to generate the anomaly category prediction result corresponding to the real-time data stream.

6. The method according to claim 5, characterized in that, The step of performing frequency-adaptive convolutional coding on the target feature vector based on the frequency fluctuation entropy of the target feature vector to generate encoded time-frequency features includes: Based on the frequency band energy ratio corresponding to the target feature vector, a frequency band modulation matrix is ​​generated; By combining the importance scores of each frequency band contained in the target feature vector, a frequency band gating matrix is ​​constructed; The preset convolution kernel weights are dynamically modulated using the frequency band gating matrix, and the target feature vector is convolved based on the dynamically modulated convolution kernel weights to determine the encoded time-frequency features corresponding to the target feature vector.

7. The method according to claim 1, characterized in that, The method further includes: Obtain a pre-constructed training sample set, input the training sample set into a preset initial model, and train the initial model; Based on the frequency band energy ratio of the preset frequency band components of the training sample set, calculate the regularization loss corresponding to the initial model; and based on the difference between the predicted probability distribution of the initial model and the true label, calculate the cross-entropy loss corresponding to the initial model. Based on the regularization loss and the cross-entropy loss, calculate the total loss function of the initial model; The model parameters of the initial model are updated based on the total loss function until the initial model meets the preset training requirements, and an anomaly detection model is constructed based on the current initial model.

8. A real-time power grid monitoring and anomaly detection device based on data stream processing, characterized in that, The device includes: The data acquisition module is used to monitor key nodes of the target power grid in real time and generate a real-time data stream of the target power grid. The data processing module is used to adaptively segment the real-time data stream based on the frequency fluctuation entropy of the real-time data stream to generate multiple data blocks; the frequency evolution within each data block is continuous. The feature extraction module is used to calculate the frequency band energy ratio corresponding to the data block, and perform feature extraction on the data block based on the frequency band energy ratio to generate a target feature vector; An execution module is used to predict the anomaly category of the target feature vector using a pre-built anomaly detection model and output the anomaly category prediction result corresponding to the real-time data stream; wherein, the anomaly detection model uses a dual-path temporal attention mechanism to enhance the temporal context of the target feature vector in order to determine the anomaly category prediction result; The output module is used to determine the operating status of the target power grid based on the anomaly category prediction results.

9. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, and the processor executing the machine-executable instructions to implement the power grid real-time monitoring and anomaly detection method based on data stream processing as described in any one of claims 1 to 7.

10. A machine-readable storage medium, characterized in that, The machine-readable storage medium stores machine-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the power grid real-time monitoring and anomaly detection method based on data stream processing as described in any one of claims 1 to 7.