Power system dynamic safety assessment method and system based on self-attention mechanism
By using a Transformer-based self-attention mechanism and feature selection method, the problems of low computational efficiency and insufficient accuracy in dynamic security assessment in new power systems are solved, and efficient and accurate dynamic security assessment is achieved.
Patent Information
- Application Number
- CN202511611097.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-05
- Publication Date
- 2026-02-10
AI Technical Summary
Traditional dynamic security assessment methods are computationally intensive and inefficient in new power systems. Furthermore, artificial intelligence models lack the learning ability to handle high-dimensional and complex nonlinear features, resulting in insufficient assessment accuracy, especially in the identification of instability scenarios where there is a risk of missed detection.
A Transformer-based self-attention mechanism is adopted to adaptively capture the dependencies between features and dynamically allocate feature weights through feature dimensionality reduction, sample augmentation, and two-stage random forest selection, thereby establishing a dynamic security assessment model for power systems.
It improves the identification accuracy under unstable operating conditions, reduces the false alarm rate, enhances computational efficiency and model training convergence speed, and ensures the safe and stable operation of the new power system.
Smart Images

Figure CN121504148A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of dynamic security assessment technology for power systems, and particularly relates to a method and system for dynamic security assessment of power systems based on Transformer. Background Technology
[0002] The statements in this section are merely background information related to the present invention and do not necessarily constitute prior art.
[0003] Dynamic security assessment is a core component of power system security analysis. It mainly studies the ability of a power system to maintain transient and dynamic stability after being subjected to large disturbances (such as short-circuit faults, sudden tripping of lines or generators, etc.).
[0004] As the power system gradually evolves into a new type of power system with a high proportion of new energy sources, the inherent intermittency and volatility of these new energy sources significantly increase the dynamic security risks faced by the power system. To ensure the safe and stable operation of the system, it is necessary to generate a large number of possible operating scenarios for the diverse operating environments of the system, and to identify potential dynamic security risks in a timely manner through dynamic security assessments, providing dispatchers with early warning information and a basis for prevention and control decisions.
[0005] Traditional dynamic security assessment methods are mostly based on time-domain simulation technology, which uses a step-by-step integration method to solve the differential-algebraic equations formed by the mathematical models of each system component. In new power systems, the complexity of grid operation modes has significantly increased, and the drawbacks of time-domain simulation-based dynamic security assessment methods—high computational cost and low efficiency—have become increasingly apparent. Artificial intelligence technologies, such as machine learning, can directly learn the system's operating rules from generated operating scenarios, establishing a nonlinear mapping relationship from high-dimensional input features to dynamic security margin indicators. After model training, these methods offer significant advantages in assessment efficiency, providing solid technical support for dynamic security assessment of new power systems.
[0006] Artificial intelligence technology is transforming dynamic security assessment from a method reliant on large-scale computation to one based on deep cognition. Although fully AI-driven dynamic security assessment systems are still in the exploratory and demonstration application stage in core power grid control, AI-based dynamic security assessment methods for power systems still face two key challenges.
[0007] The accuracy of artificial intelligence models is highly dependent on the quality and representativeness of the training samples. In actual power grid operation, the system is in a stable state most of the time. The proportion of unstable samples in historical power grid data is extremely low, preventing the model from fully learning the characteristics and patterns of unstable samples, resulting in insufficient accuracy in assessing unstable scenarios. In practical applications, unstable scenarios are more risky; any missed detection could lead to serious consequences due to the failure to take timely preventative measures.
[0008] The operational characteristics of power grids are extremely high-dimensional, with complex coupling relationships among variables such as source load power, bus voltage, and line power flow. Traditional artificial intelligence models, such as support vector regression (SVR) and shallow neural networks (SNN), have inherent limitations in their model architecture and internal mathematical mechanisms when dealing with high-dimensional, complex, nonlinear dynamic security data with deep feature interactions. This results in insufficient learning and expressive capabilities, often failing to fully capture the nonlinear interaction patterns between these features, leading to errors in prediction results and reducing the assessment accuracy of dynamic security assessment models. Summary of the Invention
[0009] To overcome the shortcomings of the prior art, this invention provides a dynamic security assessment method and system for power systems based on Transformer, which can adaptively capture the dependencies between features and dynamically allocate feature weights according to task requirements, breaking through the limitation of traditional models that treat different input features equally. Transformer: self-attention mechanism.
[0010] To achieve the above objectives, one or more embodiments of the present invention provide the following technical solutions: Firstly, a dynamic security assessment method for power systems based on a self-attention mechanism is disclosed, including: Basic training samples are generated based on historical operating data and day-ahead forecast data of new energy sources and loads. Based on the basic training samples, feature dimensionality reduction visualization is used to screen out unstable samples that are sparsely distributed in the feature space; Small noise perturbations are set in the high-dimensional feature space of sparse unstable samples to generate neighboring samples of sparse unstable samples. The generated neighboring samples of sparse unstable samples are then added to the basic training samples for sample augmentation. A power system dynamic security assessment model is established based on the self-attention mechanism: the features of the enhanced basic training samples are screened in two stages to obtain a key feature subset, and the key feature subset is used as the input information of the power system dynamic security assessment model for offline training of the model to obtain the trained power system dynamic security assessment model. Uncertain operating scenarios are generated based on new energy power generation forecasting, load forecasting, and dispatching plans. The scenarios to be evaluated are obtained through scenario reduction methods. The scenarios to be evaluated are then input into the trained power system dynamic security assessment model for online evaluation to obtain the evaluation results.
[0011] As a further technical solution, the specific steps for generating basic training samples are as follows: Based on the new energy output and load data of multiple time sections, the output of synchronous generators is adjusted according to the net load level and the upper and lower limits of synchronous generator output to perform power flow calculation and generate multiple sets of system operation scenarios with power flow convergence. For diverse anticipated fault scenarios, time-domain simulation is used to calculate the dynamic safety margin index of the power system; The steady-state operation characteristics of the power system are extracted and combined with the dynamic safety margin value after the expected fault occurs to form the basic training sample of the power system.
[0012] As a further technical solution, the specific steps for screening out unstable samples that are sparsely distributed in the feature space include: For each sample in the basic training samples, its value is compared with the previous... k The sparsity is estimated by the average distance of the nearest neighbor samples; Normalize the sparsity of all samples and calculate the sparsity weights. By incorporating sparsity weights into the loss function, we obtain the optimized loss function. Based on the optimized loss function, sparsely distributed unstable samples are selected in two-dimensional space using sparsity index, which serve as the benchmark samples for sample augmentation.
[0013] As a further technical solution, the step of generating neighboring samples of sparse unstable samples is as follows: For each sparse instability sample to be enhanced, a portion of synchronous generators with adjustment capabilities are randomly selected, and their output is fixed and not used for disturbance, in order to adjust the source-load power balance after disturbance. A Gaussian perturbation is applied to the original high-dimensional feature space; Add constraints to the intermediate results, mainly upper and lower limits of source load power; Based on the power difference between the source and load before the disturbance, calculate the change in the power difference between the source and load caused by the disturbance, and share the burden according to the proportion of the standby capacity of the synchronous generators participating in the power balance adjustment. Perform power flow calculations and add the resulting enhanced unstable samples to the training sample set.
[0014] As a further technical solution, the enhanced sample features are screened in two stages, specifically including: In the initial high-dimensional feature set, features below a threshold are removed to obtain the candidate feature set. ; The random forest is retrained based on the candidate feature set, and the feature weights are recalculated based on the importance metric weighted by the number of samples, finally obtaining the key feature subset; The subset of key features selected in the two-stage screening process is used as the input features of the power system dynamic security assessment model based on the self-attention mechanism.
[0015] As a further technical solution, the structure of the self-attention mechanism includes: The feature grouping embedding module is configured to design embedding methods for different categories of input features. Feature grouping embedding enables the operating features of the power system to be mapped from numerical values to vector representations, and different categories of features remain distinguishable during the embedding stage. The feature category encoding module is configured to add a category vector to the embedding vector of any feature to facilitate the capture of differences between different feature categories. The feature weight-based attention mechanism module is configured to introduce feature importance weights provided by random forests into the attention mechanism to highlight features with stronger discriminative power.
[0016] As a further technical solution, the power system dynamic security assessment model is to... N The model is built by stacking several self-attention mechanism sub-modules. The first sub-module's multi-head attention mechanism introduces a feature weight correction strategy, using the feature importance provided by random forest to weight and adjust the attention distribution, so that key features can be given higher weights in the initial stage, thereby guiding the model's subsequent learning direction. The remaining sub-modules... Each submodule maintains a standard attention mechanism; After the key feature set is filtered, it is embedded by feature grouping and encoded by feature category to obtain the final input matrix. Through multi-layer self-attention calculation and feedforward network mapping, the dynamic security assessment result is output.
[0017] Secondly, a dynamic security assessment system for power systems based on a self-attention mechanism is disclosed, including: The basic training sample generation module is configured to generate basic training samples based on historical operating data and day-ahead forecast data of new energy sources and loads. The unstable sample screening module is configured to: screen out unstable samples that are sparsely distributed in the feature space by using feature dimensionality reduction visualization based on the basic training samples; The sample augmentation module is configured to: set a small noise perturbation in the high-dimensional feature space of sparse unstable samples, generate neighboring samples of sparse unstable samples, and add the generated neighboring samples of sparse unstable samples to the basic training samples for sample augmentation. The power system dynamic security assessment model training module is configured to: establish a power system dynamic security assessment model based on a self-attention mechanism; perform a two-stage screening of the features of the enhanced basic training samples to obtain a key feature subset; use the key feature subset as input information for the power system dynamic security assessment model to perform offline model training; and obtain the trained power system dynamic security assessment model. The online evaluation module is configured to generate uncertain operating scenarios based on new energy power generation forecasts, load forecasts, and dispatch plans, obtain the scenario to be evaluated through scenario reduction methods, input the scenario to be evaluated into the trained power system dynamic security evaluation model for online evaluation, and obtain the evaluation results.
[0018] The above one or more technical solutions have the following beneficial effects: This invention addresses the problem of uneven sample distribution by screening and enhancing unstable samples. This allows the model to fully learn the characteristic patterns of unstable samples, thereby effectively improving the recognition accuracy under unstable operating conditions, reducing the false alarm rate, and thus minimizing the safety risks caused by the failure to detect unstable samples. This invention uses a two-stage random forest for feature screening, which can remove redundant features from high-dimensional original features and retain the key features that have the most significant impact on the dynamic security of the system. While ensuring the effectiveness of information, it reduces the dimensionality of the model input, improves computational efficiency, and increases the model training convergence speed.
[0019] Advantages of additional aspects of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0020] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.
[0021] Figure 1 This is a schematic diagram of the overall process of an embodiment of the present invention; Figure 2 Schematic diagram of system transient frequency security assessment based on TFDA; Figure 3 Schematic diagram of sample enhancement; Figure 4 Flowchart for enhancing dynamic security assessment samples of power systems; Figure 5 A schematic diagram of a dynamic security assessment model for power systems based on an improved Transformer; Figure 6 A schematic diagram of the overall framework of the dynamic security assessment system for power systems. Detailed Implementation
[0022] It should be noted that the following detailed descriptions are exemplary and intended to provide further illustration of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0023] It should be noted that the terminology used herein is for the purpose of describing particular implementations only and is not intended to limit the exemplary implementations of the present invention.
[0024] Where there is no conflict, the embodiments and features in the embodiments of the present invention can be combined with each other.
[0025] The core self-attention mechanism of the Transformer model can adaptively capture the dependencies between features and dynamically allocate feature weights according to task requirements, overcoming the limitation of traditional models that treat different input features equally. Therefore, combining sample augmentation, feature selection, and improved Transformer techniques for dynamic power grid security assessment helps ensure the safe and stable operation of new power systems.
[0026] Definitions: Transformer: Self-attention mechanism.
[0027] Example 1 See appendix Figure 1 As shown, this embodiment discloses a power system dynamic security assessment method based on Transformer, including: Step 1: Based on historical operating data and day-ahead forecast data of new energy sources and loads, generate the set of operating modes required for training the dynamic safety assessment model; based on the set of operating modes, simulate and calculate the dynamic safety margin index under different types of anticipated faults, determine the transient stability state of various operating modes of the system, obtain the dynamic safety margin value of the system, and the dynamic safety margin value of the system and the characteristic quantities of the steady-state operation of the system constitute the basic training sample.
[0028] In this step, for new energy and load data at the same time point, the net load level, i.e., the actual load value that needs to be balanced by synchronous generators, is calculated. Based on the net load level and the upper and lower limits of synchronous generator output, the output of synchronous generators is adjusted, and power flow calculation is performed. The result of the power flow calculation is the operating mode set. The operating mode set specifically includes: characteristic quantities of the power system's steady-state operation, namely, the active and reactive power of generators and loads; and the amplitude and phase angle of the bus voltage.
[0029] Step 2: Using the t-SNE feature dimensionality reduction visualization method that considers sparsity weights, unstable samples with sparse distribution in the feature space are selected based on the basic training samples.
[0030] Step 3: Set a small noise perturbation in the high-dimensional feature space of the sparse and unstable sample to generate neighboring samples with a similar Euclidean distance to the original sparse and unstable sample, thereby achieving sample enhancement.
[0031] Step 4: Based on the random forest method, a two-stage screening is performed on the sample features, i.e. the steady-state operating features of all samples after sample augmentation, to select key features as input information for the power system dynamic security assessment model. The key features are: steady-state operating features that have a significant impact on the dynamic security margin value, such as the voltage of some key nodes, the power of key generators and loads.
[0032] Step 5: Establish a dynamic security assessment model for the power system based on the improved Transformer, and conduct offline training and online evaluation of the model.
[0033] In this embodiment, following the aforementioned technical solution, to address the problem of insufficient evaluation accuracy caused by the scarcity of unstable samples and the difficulty in fully learning the characteristics of the samples in the dynamic security assessment of new power systems, a power system dynamic security assessment scheme based on an improved Transformer is proposed. This scheme alleviates the sample imbalance problem through unstable sample screening and enhancement; combines a two-stage random forest for feature screening to reduce high-dimensional feature redundancy; and finally improves the Transformer by introducing feature grouping input embedding, feature category encoding, and a feature weight-based attention mechanism to establish a power system dynamic security assessment model and achieve offline training and online evaluation, providing dispatchers with accurate dynamic security assessment results.
[0034] To more clearly illustrate this embodiment, the implementation process of the above steps can be specifically described as follows: In step one, generating offline training samples covering multiple operating states is a crucial prerequisite for ensuring the accuracy of the evaluation model. Simultaneously, to enhance the model's ability to discriminate unstable samples, it is necessary to select unstable samples that are sparsely distributed in the feature space and perform sample augmentation based on these samples.
[0035] The steps to generate basic training samples are as follows: 1-1) Based on historical operating data and day-ahead forecast data of new energy sources and loads from multiple time sections, the output of synchronous generators is adjusted according to the net load level and the upper and lower limits of synchronous generator output to perform power flow calculations and generate multiple sets of system operation scenarios with power flow convergence.
[0036] 1-2) For diverse anticipated fault scenarios, such as line breakage, three-phase short circuit in a line or bus, DC blocking, etc., time-domain simulation is used to calculate the dynamic safety margin index of the power system for multiple power flow convergence system operation scenarios. The dynamic safety margin index is used as the sample label for deep learning.
[0037] 1-3) Extract steady-state operating characteristics of the power system, such as source load power and bus voltage, from the power flow calculation results, and combine them with dynamic safety margin indicators after the occurrence of anticipated faults, such as the transient stability index with a value of 0.1, to form a power system sample. Specifically, the steady-state operating characteristics are used as the sample input features for deep learning, and the dynamic safety margin value is used as the sample label for deep learning.
[0038] The power system sample is a combination of steady-state operating characteristics and dynamic safety margin values. For example, the format of a sample is: Generator 1 active power, Generator 2 active power, ..., Generator a active power; Generator 1 reactive power, Generator 2 reactive power, ..., Generator a reactive power; Load 1 active power, Load 2 active power, ..., Load b active power; Load 1 reactive power, Load 2 reactive power, ..., Load b reactive power; Bus 1 voltage amplitude, Bus 2 voltage amplitude, ..., Bus n voltage amplitude; Bus 1 voltage phase angle, Bus 2 voltage phase angle, ..., Bus n voltage phase angle; Dynamic safety margin value of the system.
[0039] Among them, the dynamic safety margin index of the power system can be set manually according to actual research needs. For example, the power angle stability margin index adopts the transient stability index (TSI), i.e. (1) In the formula, δ max This represents the maximum rotor angle difference between any two synchronous generators in the system during the transient process. δ set The rotor angle offset threshold is typically set to 180°. The aforementioned transient stability index serves as the sample label for deep learning.
[0040] Transient frequency safety refers to the frequency deviation of each bus in the system not exceeding the allowable range for a certain period of time. Binary tables are commonly used in engineering. f cr,1 , T fcr,1 ),..., ( f cr,j , T fcr,j ), ...., ( f cr,M , T cr,M The evaluation of it. Among them M This represents the number of buses being evaluated in the system. f cr,j For the first j Frequency offset threshold value for each bus,T fcr,j For the first j The maximum permissible offset time for each bus. Therefore, the frequency safety margin indicator can be the transient frequency deviation acceptability (TFDA), i.e. (2) In the formula, f′ cr,j This makes the first j The time during which the frequency dynamic curve of each busbar remains below this value is exactly the allowable deviation time. T fcr,j The frequency value; f N This is the system's rated frequency, which is 50Hz or 60Hz. η f =0 indicates that the system is in a safe state at the critical transient frequency. η f >0 and η f When <0, it indicates that the system is in a transient frequency-safe and unsafe state, respectively. A binary table is used to measure the... j The schematic diagrams of the transient frequency safety state and critical safety state for each bus are shown below. Figure 2 As shown, the frequency safety margin metric serves as a sample label for deep learning.
[0041] Similar to transient frequency deviation acceptability (TFDA), voltage safety margin can be measured using transient voltage deviation acceptability (TVDA).
[0042] (3) In the formula, v′ cr,j In order to make the first j The time during which the voltage dynamic curve of each bus remains below this value is exactly the allowable deviation time. t vcr,j The voltage value; v cr,j This is the voltage threshold value of the binary table corresponding to the bus voltage safety. v N This is the voltage rating, which is 1.0 pu; η v=0 indicates that the system is in a critical transient voltage safe state. The acceptability of transient voltage deviation is used as a sample label for deep learning.
[0043] In one implementation example, in step two, after generating the basic training samples, considering the characteristics of unstable samples being few in proportion and sparsely distributed in the high-dimensional feature space, it is necessary to use dimensionality reduction methods to reconstruct their relative positional relationships in the low-dimensional space, thereby achieving visual identification and centralized screening. Here, unstable samples are defined as samples with a negative dynamic safety margin index.
[0044] It should be noted that the high-dimensional feature vector composed of power grid operation modes refers to the steady-state operation feature quantity of the system, and the basic training sample refers to the combination of the steady-state operation feature quantity of the system and the dynamic safety margin value.
[0045] Due to the strong nonlinear characteristics of the samples, this embodiment employs the t-distributed stochastic neighbor embedding (t-SNE) method to reduce the dimensionality of the high-dimensional feature vector composed of power grid operation modes. t-SNE measures the sample similarity relationship in the high-dimensional space by constructing a conditional probability distribution centered on each sample, and further symmetrizes it to obtain the joint probability; in the low-dimensional space, a corresponding joint probability distribution is constructed, and by minimizing the difference between the two, the high-dimensional samples are mapped to a two-dimensional plane. Let the high-dimensional samples... x i and x j The joint similarity is p ij Low-dimensional mapping samples y i and y j The similarity is q ij The optimization objective is to minimize the Kullback-Leibler divergence between the two, and the loss function is: (4) Instable samples constitute a very small proportion of the sample set, and their distribution in high-dimensional space tends to exhibit sparsity and discreteness. To further enhance the ability of t-SNE to separate and identify sparse unstable samples, this example proposes a t-SNE dimensionality reduction method that considers sparsity weights, thereby increasing the influence of sparse samples in the low-dimensional mapping process and enhancing its clustering representation ability.
[0046] For each sample in the basic training samples, its value is compared with the previous... k The sparsity is estimated by the average distance of the nearest neighbor samples: (5) In the formula,x i Indicates the first i The original high-dimensional feature vectors of each sample; x j express x i The j The original high-dimensional feature vectors of the nearest neighbor samples; k This represents the number of nearest neighbors for density estimation. The larger this index, the sparser the sample area.
[0047] Normalize the sparsity of all samples and calculate the sparsity weights: (6) In the formula, w i For the first i Sparsity weights for each sample; i ′ is the normalized sparsity index; α The adjustment parameter for controlling the amplification of sparse sample weights can be adaptively adjusted based on the standard deviation of sparsity, specifically:
[0048] In the formula, The standard deviation of the normalized sparsity index for all samples; c It is a constant factor, which can be 1 or 2.
[0049] Introducing sparsity weights into the loss function yields the improved optimization objective: (7) After the weighted loss function is optimized, the visual distribution of the samples in the low-dimensional space can be obtained based on t-SNE that takes sparsity weights into account. Based on the t-SNE dimensionality reduction results, sparsely distributed unstable samples are screened out in the two-dimensional space using sparsity indices, serving as benchmark samples for sample augmentation.
[0050] The aforementioned improvements enable sparse samples to achieve stronger representation in dimensionality reduction projection, significantly enhancing their separability in two-dimensional space. Based on the t-SNE dimensionality reduction results, sparsely distributed unstable samples are selected in two-dimensional space using sparsity indices as benchmark samples for sample enhancement.
[0051] In one implementation example, step three involves sample enhancement for dynamic security assessment of the power system based on sparse instability sample characteristic disturbances.
[0052] Given that unstable samples constitute a very small proportion of the training sample set and exhibit sparse and discrete distribution in the high-dimensional feature space, it is necessary to generate representative augmented samples to expand the training sample set in order to improve the model's ability to distinguish unstable samples.
[0053] Therefore, after sample selection, unstable samples with sparsity indices exceeding a preset threshold are defined as sparse unstable samples. Small-amplitude noise perturbations are then applied to the high-dimensional feature space of these sparse unstable samples to generate similar samples, thus achieving sample augmentation. A schematic diagram is shown below. Figure 3 As shown.
[0054] To ensure the physical feasibility of the generated new samples, boundary constraint control and source load power balance correction are implemented, and power flow calculations and time-domain simulations are used for verification. The specific steps are as follows: 3-1) For each sparse unstable sample to be enhanced, randomly select some synchronous generators with adjustment capabilities, fix their output and do not participate in the disturbance, and use them for source-load power balance adjustment after the disturbance.
[0055] 3-2) Set a Gaussian perturbation in the original high-dimensional feature space, expressed as: (8) In the formula, x ij Original sample x i The first in j One characteristic quantity; To generate the first in the new sample j Each feature can take a value; ε ij It follows a mean of 0 and a variance of . σ 2 The perturbation quantity of the Gaussian distribution is used to determine the first... j Apply random perturbations to each feature; σ 2 These are the disturbance intensity control parameters; m j ∈{0,1} represents the perturbation mask, if the feature x ij The output of the synchronous generator selected to participate in source-load power balance regulation. m j The value is 0, otherwise m j The value is 1.
[0056] 3-3) Ensure that the perturbed feature combination is within a physically feasible range, and add constraints to the intermediate results, mainly upper and lower limits of source load power. The expression is: (9) In the formula, This refers to the sparsely distributed unstable samples selected in the previous step from the basic training samples. x i The first in j The values of each characteristic quantity after perturbation; This represents the final value of the variable after applying upper and lower bound constraints; and These are the minimum and maximum allowed values for the variable, respectively.
[0057] 3-4) Based on the power difference between the source and load before the disturbance, calculate the change in the power difference between the source and load caused by the disturbance, and share the burden according to the proportion of the standby capacity of the synchronous generators participating in the power balance adjustment.
[0058] 3-5) Power flow calculations are performed using the Newton-Raphson method or PQ decomposition method. The convergence mode of the power flow is simulated in the time domain, and the resulting unstable samples are added to the training sample set. The unstable samples obtained here are obtained by adding a small amount of noise to the original sparsely distributed unstable samples. Therefore, the positions of the obtained unstable samples and the original sparse unstable samples in the feature space are very close. Thus, the obtained unstable samples can be regarded as the neighboring samples of the original sparse unstable samples.
[0059] In the above steps, step 3-1 selects synchronous generator sets for source-load power balance regulation, so that source-load power balance regulation can be performed in step 3-4; step 3-2 adds random noise to the original features other than the synchronous generator sets selected in step 3-1, and outputs the original features after adding noise; step 3-3 adds upper and lower limit constraints to the original features after adding noise to ensure that the feature values are within the physically feasible range, and outputs the features after adding constraints; step 3-4 adjusts the output of the pre-selected synchronous generator sets to achieve source-load power balance, and outputs the updated value of the output of the synchronous generator sets selected in step 3-1; step 3-5 uses the outputs of steps 3-3 and 3-4 as inputs for power flow calculation, performs power flow calculation and time-domain simulation, and outputs samples labeled as unstable.
[0060] The flowchart for enhancing the dynamic security assessment sample of power systems is as follows: Figure 4 As shown.
[0061] Based on the above process, the neighboring samples of the generated sparse unstable samples are added to the basic training sample set. When the number of stable samples and unstable samples in the sample set are equal, the sample augmentation process ends.
[0062] In one implementation example, in step four, key features of power system dynamic security assessment samples are screened in two stages based on random forest.
[0063] The operational features of power systems are extremely high-dimensional. Directly inputting them into the evaluation model without filtering would significantly increase computational complexity, thereby reducing the effectiveness of the Transformer's self-attention mechanism in capturing key feature dependencies. Therefore, this paper proposes a feature filtering method based on a two-stage random forest as a pre-optimization step for the Transformer. This method filters the high-dimensional feature set, retaining key operational features of the power system, thus significantly reducing the dimensionality of the Transformer's input features and improving the model's evaluation efficiency.
[0064] Random forest is an ensemble learning method that measures the importance of features to a prediction task based on the splitting results of multiple decision trees. Its core idea is that if a feature significantly reduces impurity during node splitting, then that feature is more important.
[0065] Traditional methods assess feature importance by summing the contributions from different trees and taking the average. However, this approach does not explicitly consider the sample size covered by the split nodes, which may lead to small sample nodes exaggerating feature contributions.
[0066] To overcome the above shortcomings, this embodiment introduces sample number weighting into the feature importance measurement. For the first... t Nodes in a tree s If features are used f m If it splits, its importance contribution Δ Imp ( t ) s Defined as: (10) In the formula, Δ i ( t ) s This indicates the decrease in impurity before and after the node splits; N s The number of node samples; N This represents the total number of samples. This ensures that the contribution of a node is proportional to the size of the sample it covers, preventing small sample nodes from being overestimated.
[0067] The overall importance of a feature in a forest is defined as follows: (11) In the formula, Imp ( f m ) represents a feature f m The average contribution to the prediction task throughout the entire random forest model; T The total number of decision trees; St ( f m ) indicates the first t In a tree, use features f m The set of all nodes to be split.
[0068] Given the extremely high dimensionality of power system operations, directly using a single threshold for screening can lead to several problems. If the threshold is too low, too many redundant features will remain, resulting in excessive computational burden on subsequent models. Conversely, if the threshold is too high, some potentially critical features may be mistakenly deleted, affecting model accuracy. Therefore, a two-stage screening approach is adopted to gradually narrow the feature set, thereby improving the robustness of the screening and the reliability of the final results.
[0069] First, in the initial high-dimensional feature set enhanced in step three, features below a certain threshold are removed. θ The features of 1 are used to obtain the candidate feature set. F (1) (12) Among them, threshold θ 1. It can be set according to the median of the feature importance distribution.
[0070] Based on candidate feature sets F (1) The random forest is retrained, and feature weights are recalculated based on an importance metric weighted by the number of samples. To ensure the rationality of the selection, a second threshold is used. θ 2. Adaptive setting method, for example: (13) In the formula, μ Imp′ The mean value representing the importance of the candidate feature set; σ Imp′ The standard deviation representing the importance of the candidate feature set; α This is the adjustment coefficient.
[0071] In this way, if the importance distribution is relatively dispersed, the threshold will be increased to ensure that only the most discriminative features are retained; if the distribution is concentrated, the threshold will be appropriately decreased to avoid excessive removal of important features. The final feature subset is: (14) In the formula, Imp ′( f m (Based on candidate feature sets) F (1) The feature importance values are calculated after retraining the random forest.
[0072] The feature subset after two-stage screeningF (2) Features used as input to the Transformer power system dynamic security assessment model. Regarding feature subsets. F (2) For example, steady-state operating characteristics that have a significant impact on dynamic safety margin values, such as the voltage of some key nodes, the power of key generators and loads.
[0073] In this embodiment of the sub-technical solution, the improvements to Transformer are described below.
[0074] After completing sample augmentation and feature selection, it is necessary to build an efficient and high-precision discriminant model to achieve rapid dynamic security assessment of the power system. The Transformer, with its self-attention mechanism at its core, can capture global dependencies between input features, making it suitable for modeling tasks with high-dimensional and complex features.
[0075] A traditional Transformer consists of an embedding layer, a self-attention layer, a feedforward network, and an output layer. Its core computation is the self-attention mechanism, defined as... (15) (16) (17) (18) In the formula, Q , K , V These are the query matrix, key matrix, and value matrix, respectively, derived from the input feature matrix. X Transformation generation; , , All are linear transformation matrices; d This is the scaling factor; , , They are respectively to Q , K , V Projected to the i The transformation matrix of each subspace; i =1,2,…, h , h This represents the total number of subspaces. H i For the first i Single-head attention value for each subspace; W O This is the transformation matrix used to connect the attention values of all subspaces; This represents the attention mechanism, which assigns weights based on the similarity between the query vector and the key vector, and performs a weighted summation of the value vectors to model the correlation between different features. This represents the normalization function, used to map the correlation scores to a probability distribution, ensuring that the weights are non-negative and sum to 1; This refers to a multi-head attention mechanism, which involves performing attention calculations in parallel across multiple subspaces, concatenating the results from each subspace, and then performing a linear transformation to enhance the model's ability to capture multi-level feature associations.
[0076] However, directly applying the Transformer to the dynamic security assessment of power systems still has certain shortcomings: Directly mapping different physical quantity characteristics can easily lead to information confusion; the characteristics of power systems are static operating states, limiting the applicability of traditional time-series-based location information encoding; and the standard attention mechanism fails to effectively utilize the prior feature weights provided by random forests, limiting the model's ability to identify and model key features. To address these issues, this embodiment's sub-solution improves the Transformer by adding the following modules: Feature grouping embedding module.
[0077] Power system sample features include various categories of physical quantities such as active power, reactive power, voltage amplitude, and voltage phase angle. A uniform mapping can easily lead to information confusion. Therefore, it is necessary to design separate embedding methods for different categories of features. The expression is as follows: (19) In the formula, f m Indicates the first m One input feature; type( m The ) indicates the category to which the feature belongs, such as active power category, reactive power category, voltage amplitude category, and voltage phase angle category; W type(m) This represents the parameter corresponding to the category, used to convert the original numerical values into a vector representation that the model can process; b type(m) This represents the bias parameter corresponding to the category, used for fine-tuning the results; d This indicates the number of feature dimensions retained after feature filtering; W type(m) and b type(m) The value is learned automatically during the training process; x m Indicates the first m Embedding vectors of features.
[0078] Feature grouping embedding maps the operating characteristics of the power system from numerical values to vector representations. Different categories of features remain distinct during the embedding stage, avoiding information aliasing and thus better preserving physical meaning.
[0079] Feature category encoding module.
[0080] Since power system sample features do not contain temporal sequence information, traditional time-series-based location information encoding is no longer entirely applicable. Therefore, feature category encoding is introduced into the Transformer to replace location encoding, enhancing the model's ability to identify physical feature categories. Specifically, for features... f m In its embedding vector x m Add category vectors on top of c type(m) ,Right now (20) In the formula, c type(m) This represents a trainable vector corresponding to a category, used to provide additional category information for the features of that category; z m This represents the final input representation after the category coding; d This indicates the number of key input features retained after feature filtering.
[0081] This improvement allows features of different physical quantity categories to be explicitly distinguished at the input stage, which helps the model better capture the differences between different feature categories.
[0082] Attention mechanism module based on feature weights.
[0083] The attention mechanism assumes all features contribute equally during calculation, which may weaken the role of key features. This embodiment introduces feature importance weights provided by random forests into the attention mechanism to highlight features with stronger discriminative power. The revised attention calculation formula is as follows: (twenty one) In the formula, Q , K , V These are the query matrix, key matrix, and value matrix, respectively. d This is the scaling factor; Imp ( F ) represents the feature importance calculated by the random forest; β This is an adjustment coefficient used to control the degree to which feature weights affect the attention distribution.
[0084] This method gives greater weight to key features that have a higher impact on the dynamic security assessment results of the system in the attention calculation, thereby improving the model's ability to identify key features in the dynamic security assessment of the power system.
[0085] In one implementation example, step five involves constructing a dynamic security assessment model for the power system based on an improved Transformer.
[0086] Improvements are made to address the limitations of the traditional Transformer, and a dynamic security assessment model for power systems based on the improved Transformer is further established, such as... Figure 5 As shown.
[0087] To further improve the accuracy of the assessment, N A dynamic security assessment model for power systems is established by stacking several Transformer submodules. Each submodule includes basic structures such as multi-head attention computation and feedforward neural networks. The first submodule's multi-head attention mechanism introduces a feature weight correction strategy, utilizing the feature importance provided by random forests to weight and adjust the attention distribution, ensuring that key features receive higher weights in the initial stage, thus guiding the model's subsequent learning direction. The remaining submodules... Each submodule maintains a standard attention mechanism to avoid the model over-relying on prior weights and preserve its deep self-learning capabilities.
[0088] The set of key features after screening is as follows: F (2) ={ f 1, f 2,…, f d After feature group embedding and feature category encoding, the final input matrix is obtained. Z =[ z 1, z 2,…, z d The improved Transformer uses... Z As input, through multi-layer self-attention computation and feedforward network mapping, the output is a dynamic security assessment result. (twenty two) In the formula, This represents an improved Transformer. θ For all trainable parameters, y This represents the results of a dynamic security assessment of the system.
[0089] Based on the above steps, in practical applications, the overall framework of the power system dynamic security assessment system is as follows: Figure 6 As shown.
[0090] The offline training module, based on the training set sample data, first uses the t-SNE dimensionality reduction method considering sparsity weights to screen sparse unstable samples; then, it performs sample augmentation based on the sparse unstable sample neighborhood expansion method to achieve sample balance; further, it uses the random forest method to perform importance analysis and key feature screening of sample features to obtain a key feature subset; finally, it inputs the screened key feature subset into the power system dynamic security assessment model established using the improved Transformer to complete the model training.
[0091] The online assessment module combines new energy generation forecasting, load forecasting, and dispatching plans to generate uncertain operating scenarios. It then uses scenario reduction methods to obtain representative scenarios to be assessed. These scenarios are input into a pre-trained power system dynamic security assessment model, which outputs corresponding dynamic security assessment results. For example, it might state that at a future time segment, after a anticipated fault occurs, the system will experience power angle transient instability. Ultimately, the assessment results are provided to dispatchers as a basis for prevention and control decisions, ensuring the safe and stable operation of the power grid.
[0092] This embodiment addresses the problems of scarce instability samples, high dimensionality of input features, and insufficient characterization of complex nonlinear relationships between input features in dynamic security assessment of new power systems, leading to low efficiency and accuracy in dynamic security assessment. It proposes a power system dynamic security assessment method and system based on an improved Transformer. By screening and enhancing instability samples, the problem of uneven sample distribution is solved, enabling the model to fully learn the characteristic patterns of instability samples, thereby effectively improving the identification accuracy under unstable operating conditions, reducing the false alarm rate, and ultimately minimizing safety hazards caused by missed detection of instability samples. A two-stage random forest is used for feature screening, which can remove redundant features from the high-dimensional original features, retaining the key features that have the most significant impact on the dynamic security of the system. This reduces the dimensionality of the model input while ensuring information effectiveness, improving computational efficiency and model training convergence speed. By introducing feature grouping embedding, feature category encoding, and feature weight-based attention mechanism into Transformer, differentiated modeling of different physical quantity features such as voltage, power, and power flow is achieved, effectively enhancing the model's ability to distinguish and represent multi-source heterogeneous features and overcoming the information confusion problem that exists in traditional Transformer applications in power systems.
[0093] The dynamic security assessment model constructed by the sub-technical solution in this embodiment can achieve offline training and online application. It can learn fully based on training samples and quickly assess uncertain scenarios in the actual operation of the power system, providing power system dispatchers with more accurate and reliable dynamic security assessment results.
[0094] Example 2 The purpose of this embodiment is to provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the above-described method.
[0095] Example 3 The purpose of this embodiment is to provide a computer-readable storage medium.
[0096] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the steps of the above method.
[0097] Example 4 The purpose of this embodiment is to provide a power system dynamic security assessment system based on a self-attention mechanism, including: The basic training sample generation module is configured to generate basic training samples based on historical operating data and day-ahead forecast data of new energy sources and loads. The unstable sample screening module is configured to: screen out unstable samples that are sparsely distributed in the feature space by using feature dimensionality reduction visualization based on the basic training samples; The sample augmentation module is configured to: set a small noise perturbation in the high-dimensional feature space of sparse unstable samples, generate neighboring samples of sparse unstable samples, and add the generated neighboring samples of sparse unstable samples to the basic training samples for sample augmentation. The power system dynamic security assessment model training module is configured to: establish a power system dynamic security assessment model based on a self-attention mechanism; perform two-stage screening of the features of the enhanced basic training samples; use the resulting key feature subset as input information for the power system dynamic security assessment model to conduct offline model training; and obtain the trained power system dynamic security assessment model. The online evaluation module is configured to generate uncertain operating scenarios based on new energy power generation forecasts, load forecasts, and dispatch plans, obtain the scenario to be evaluated through scenario reduction methods, input the scenario to be evaluated into the trained power system dynamic security evaluation model for online evaluation, and obtain the evaluation results.
[0098] Example 5 The purpose of this embodiment is to provide a computer program product containing instructions that, when run on a computer, cause the computer to perform the methods and functions involved in any of the above embodiments. The steps and methods involved in the apparatus of the above embodiments correspond to those in Embodiment 1. For specific implementation details, please refer to the relevant description section of Embodiment 1. The term "computer-readable storage medium" should be understood as a single medium or multiple media including one or more instruction sets; it should also be understood as including any medium capable of storing, encoding, or carrying an instruction set for execution by a processor and enabling the processor to perform any of the methods in this invention.
[0099] Those skilled in the art will understand that the modules or steps of the present invention described above can be implemented using general-purpose computer devices. Optionally, they can be implemented using computer-executable program code, thereby allowing them to be stored in a storage device for execution by a computer device, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. The present invention is not limited to any particular combination of hardware and software.
[0100] While the specific embodiments of the present invention have been described above in conjunction with the accompanying drawings, this is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art without creative effort based on the technical solutions of the present invention are still within the scope of protection of the present invention.
Claims
1. A dynamic security assessment method for power systems based on a self-attention mechanism, characterized by: include: Basic training samples are generated based on historical operating data and day-ahead forecast data of new energy sources and loads. Based on the basic training samples, feature dimensionality reduction visualization is used to screen out unstable samples that are sparsely distributed in the feature space; Small noise perturbations are set in the high-dimensional feature space of sparse unstable samples to generate neighboring samples of sparse unstable samples. The generated neighboring samples of sparse unstable samples are then added to the basic training samples for sample augmentation. A power system dynamic security assessment model is established based on the self-attention mechanism: the features of the enhanced basic training samples are screened in two stages to obtain a key feature subset, and the key feature subset is used as the input information of the power system dynamic security assessment model for offline training of the model to obtain the trained power system dynamic security assessment model. Uncertain operating scenarios are generated based on new energy power generation forecasting, load forecasting, and dispatching plans. The scenarios to be evaluated are obtained through scenario reduction methods. The scenarios to be evaluated are then input into the trained power system dynamic security assessment model for online evaluation to obtain the evaluation results.
2. The power system dynamic security assessment method based on self-attention mechanism as described in claim 1, characterized in that, The specific steps for screening out unstable samples that are sparsely distributed in the feature space include: For each sample in the basic training samples, its value is compared with the previous... k The sparsity is estimated by the average distance of the nearest neighbor samples; Normalize the sparsity of all samples and calculate the sparsity weights. By incorporating sparsity weights into the loss function, we obtain the optimized loss function. Based on the optimized loss function, sparsely distributed unstable samples are selected in two-dimensional space using sparsity index, which serve as the benchmark samples for sample augmentation.
3. The power system dynamic security assessment method based on self-attention mechanism as described in claim 1, characterized in that, The step of generating neighbor samples of sparse unstable samples is as follows: For each sparse instability sample to be enhanced, a portion of synchronous generators with adjustment capabilities are randomly selected, and their output is fixed and not used for disturbance, in order to adjust the source-load power balance after disturbance. A Gaussian perturbation is applied to the original high-dimensional feature space; Add constraints to the intermediate results, mainly upper and lower limits of source load power; Based on the power difference between the source and load before the disturbance, calculate the change in the power difference between the source and load caused by the disturbance, and share the burden according to the proportion of the standby capacity of the synchronous generators participating in the power balance adjustment. Perform power flow calculations and add the resulting enhanced unstable samples to the training sample set.
4. The power system dynamic security assessment method based on self-attention mechanism as described in claim 1, characterized in that, The enhanced samples undergo a two-stage screening process, specifically including: In the initial high-dimensional feature set, features below a threshold are removed to obtain the candidate feature set. ; The random forest is retrained based on the candidate feature set, and the feature weights are recalculated based on the importance metric weighted by the number of samples, finally obtaining the key feature subset; The subset of key features selected in the two-stage screening process is used as the input features of the power system dynamic security assessment model based on the self-attention mechanism.
5. The power system dynamic security assessment method based on self-attention mechanism as described in claim 1, characterized in that, The structure of the self-attention mechanism includes: The feature grouping embedding module is configured to design embedding methods for different categories of input features. Feature grouping embedding enables the operating features of the power system to be mapped from numerical values to vector representations, and different categories of features remain distinguishable during the embedding stage. The feature category encoding module is configured to add a category vector to the embedding vector of any feature to facilitate the capture of differences between different feature categories. The feature weight-based attention mechanism module is configured to introduce feature importance weights provided by random forests into the attention mechanism to highlight features with stronger discriminative power.
6. The power system dynamic security assessment method based on self-attention mechanism as described in claim 1, characterized in that, The power system dynamic security assessment model is to... N The model is built by stacking several self-attention mechanism sub-modules. The first sub-module's multi-head attention mechanism introduces a feature weight correction strategy, using the feature importance provided by random forest to weight and adjust the attention distribution, so that key features can be given higher weights in the initial stage, thereby guiding the model's subsequent learning direction. The remaining sub-modules... Each submodule maintains a standard attention mechanism; After the key feature set is filtered, it is embedded by feature grouping and encoded by feature category to obtain the final input matrix. Through multi-layer self-attention calculation and feedforward network mapping, the dynamic security assessment result is output.
7. A power system dynamic security assessment system based on a self-attention mechanism, characterized by: include: The basic training sample generation module is configured to generate basic training samples based on historical operating data and day-ahead forecast data of new energy sources and loads. The unstable sample screening module is configured to: screen out unstable samples that are sparsely distributed in the feature space by using feature dimensionality reduction visualization based on the basic training samples; The sample augmentation module is configured to: set a small noise perturbation in the high-dimensional feature space of sparse unstable samples, generate neighboring samples of sparse unstable samples, and add the generated neighboring samples of sparse unstable samples to the basic training samples for sample augmentation. The power system dynamic security assessment model training module is configured to: establish a power system dynamic security assessment model based on a self-attention mechanism; perform a two-stage screening of the features of the enhanced basic training samples to obtain a key feature subset; use the key feature subset as input information for the power system dynamic security assessment model to perform offline model training; and obtain the trained power system dynamic security assessment model. The online evaluation module is configured to generate uncertain operating scenarios based on new energy power generation forecasts, load forecasts, and dispatch plans, obtain the scenario to be evaluated through scenario reduction methods, input the scenario to be evaluated into the trained power system dynamic security evaluation model for online evaluation, and obtain the evaluation results.
8. The power system dynamic security assessment system based on self-attention mechanism as described in claim 7, characterized in that, The power system dynamic security assessment model is to... N The model is built by stacking several self-attention mechanism sub-modules. The first sub-module's multi-head attention mechanism introduces a feature weight correction strategy, using the feature importance provided by random forest to weight and adjust the attention distribution, so that key features can be given higher weights in the initial stage, thereby guiding the model's subsequent learning direction. The remaining sub-modules... Each submodule maintains a standard attention mechanism; After the key feature set is filtered, it is embedded by feature grouping and encoded by feature category to obtain the final input matrix. Through multi-layer self-attention calculation and feedforward network mapping, the dynamic security assessment result is output.
9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 6.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method described in any one of claims 1-6.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it performs the steps of the method described in any one of claims 1-6 above.