Lightning time sequence signal identification method based on improved Transform, terminal and medium
Through the improved Transformer neural network, combined with self-attention and position encoding, the problems of feature screening and long-distance feature capture in lightning signal recognition in the existing technology are solved, and efficient and accurate lightning signal classification is achieved.
Patent Information
- Application Number
- CN202510784502.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-09-23
AI Technical Summary
Existing machine learning methods in lightning signal recognition have the problems of relying on manual feature screening, resulting in information loss, difficulty in capturing nonlinear time relationships and noise interference. Convolutional neural networks are unable to efficiently capture the long-distance characteristics of lightning signals due to local receptive field limitations.
An improved Transformer neural network is adopted, combined with the self-attention mechanism and relative position encoding. The data length is compressed through the downsampling convolution module, the position encoding module adds position information, the multi-layer Transformer encoder extracts the global temporal dependency, and the classification probability of the lightning discharge type is generated through the category output module.
It significantly improves the accuracy of lightning signal recognition and the versatility of the model, enhances the ability to understand complex contextual information, improves the signal-to-noise ratio and training stability of the model, and can efficiently identify the discharge type of lightning signals.
Smart Images

Figure CN120687790A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of lightning signal recognition, and in particular to a lightning time sequence signal recognition method, terminal, and medium based on an improved Transformer. Background Art
[0002] Lightning is an extreme weather phenomenon that occurs naturally, accompanied by high voltages, high currents, and strong electromagnetic pulses. Depending on where it occurs, lightning is primarily categorized as cloud-to-ground lightning (CG) and cloud-to-cloud lightning (IC). CG occurs between a thunderstorm cloud and the ground, while CG occurs within or between thunderstorm clouds. CG strikes the ground directly, posing a significant threat to human production and life. Therefore, research on and protection against lightning is becoming increasingly important. During lightning discharges, electromagnetic radiation signals of varying frequencies are generated, particularly very low frequency (VLF) and low frequency (LF) radiation signals, where the primary energy is concentrated. By detecting and collecting lightning signals in these frequency bands, we can analyze information such as the time, location, and amplitude of lightning occurrence. This allows us to accurately distinguish different types of lightning activity and further facilitate the inversion of key characteristic parameters such as lightning location and current. Therefore, accurate and efficient lightning signal identification provides data support for analyzing the rich physical characteristics of lightning electromagnetic waves, and is of great significance for understanding the occurrence mechanism and propagation characteristics of lightning.
[0003] In recent years, with the rapid development of artificial intelligence (AI), machine learning (particularly deep learning methods) has been widely applied in fields such as image recognition, speech analysis, and medical diagnosis. Similarly, lightning signals, like electrocardiogram (ECG) and speech signals, are one-dimensional time series signals. Currently, some researchers have applied machine learning methods to lightning signal recognition, achieving some success. Zhu Yanan et al. used the Support Vector Machine (SVM) algorithm to construct a classification model, training the model using features from 101 sample points. They achieved 97% accuracy in identifying ground-to-ground and cloud-to-cloud lightning flashes. Zhu Yanan et al. also used a supervised learning algorithm using logistic regression (LR) to manually filter actual lightning signals to construct a dataset. They then identified ground-to-ground and cloud-to-cloud lightning flashes in actual natural ground lightning, achieving 98% accuracy. They used manually designed time-domain features, such as rise time and zero-crossing time, to automatically extract waveform features and perform recognition using large-scale lightning observation data. However, traditional machine learning methods face the following bottlenecks: First, machine learning methods rely on manually designed features for feature screening, which can easily lead to the loss of waveform detail information and introduce subjective bias; second, models such as SVM and logistic regression have difficulty capturing the nonlinear time relationship of lightning radiation signals, such as the continuous pulse clusters in PB waveforms; in addition, the use of small sample training is susceptible to noise interference, resulting in poor model generalization ability.
[0004] Deep learning methods automatically extract deep features of samples directly from raw data through end-to-end learning. At the same time, deep learning methods such as convolutional neural networks (CNNs) use large amounts of labeled data for network training, designing multi-layer network structures to automatically learn waveform features for recognition, and can achieve high recognition rates. Currently, scholars Peng Changzhi et al. and Wang Jiaquan et al. have built one-dimensional convolutional neural networks to classify and identify various lightning signals, including ground-to-ground flashes (CG), cloud-to-cloud flashes (IC), narrow bipolar pulses (NB), and initial pre-breakdown (PB), with recognition accuracy exceeding 95%. Scholars Xiao Lilang et al. designed a multi-scale convolution kernel and short-connection model structure, achieving recognition accuracy exceeding 98% for four types of lightning signals. However, due to the limitations of the local receptive field, convolutional neural networks require stacking multiple layers or using dilated convolutions to expand the receptive field, which reduces recognition efficiency and makes it impossible to effectively capture the long-range characteristics of lightning signals. Summary of the Invention
[0005] In order to solve the technical problems existing in the prior art, the present invention provides a lightning time series signal recognition method, terminal and medium based on an improved Transformer. The method captures the long-range dependencies of lightning sequences through a self-attention mechanism, and combines relative position encoding to preserve position information, so as to efficiently capture the long-range characteristics of lightning signals, thereby improving the understanding of contextual lightning information and the ability to recognize complex patterns in the data.
[0006] To achieve the above object, the present invention provides the following technical solutions:
[0007] The present invention discloses a lightning time sequence signal recognition method based on an improved Transformer, comprising:
[0008] S1. Collecting the original lightning electric field time series signal and performing signal preprocessing to generate several lightning time series segments;
[0009] S2. selecting a key time sequence segment containing a lightning radiation pulse from a plurality of lightning time sequence segments;
[0010] S3. Input each key sequence segment as a single-channel one-dimensional time series data into an improved Transformer neural network model to output a corresponding lightning discharge type recognition result; wherein the Transformer neural network model includes:
[0011] A downsampling convolution module, used to compress the length of the one-dimensional time series data and extract local features;
[0012] Position encoding module, used to add position information to compressed one-dimensional time series data;
[0013] The multi-layer Transformer encoder is used to extract key temporal features from the output of the position encoding module to form a high-dimensional feature vector containing global temporal dependencies. Each layer of the Transformer encoder contains two levels of layer normalization, multi-head attention, two levels of random activation layers, and a feedforward neural network. In the forward propagation direction, the first-level layer normalization, multi-head attention, and first-level random activation layers are connected in sequence, and then the output of the first-level layer normalization is added to the output of the first-level random activation layer through a residual connection. Then, through the second-level layer normalization, feedforward neural network, and second-level random activation layer, the output of the second-level layer normalization is added to the output of the second-level random activation layer through a residual connection to form the output of the encoder layer. Layer normalization is used to improve training stability, and multi-head attention is used to capture long-range dependencies, and the feedforward neural network is used to enhance nonlinear capabilities.
[0014] The category output module is used to generate classification probabilities of multiple typical lightning discharge types according to the high-dimensional feature vector.
[0015] As a further improvement to the above scheme, the downsampling convolution module includes two convolution layers and a maximum pooling layer. The input of the downsampling convolution module is one-dimensional time series data. In the forward propagation direction, the first convolution layer, the maximum pooling layer, and the second convolution layer are connected in sequence, and each convolution layer is followed by batch normalization and ReLU activation function. The two convolution layers perform preliminary dimensionality reduction and extract local features, and the maximum pooling layer compresses the sequence length to further reduce the dimensionality.
[0016] The category output module includes a global average pooling layer and two-level fully connected layers; wherein, according to the forward propagation direction, the global average pooling layer, the first-level fully connected layer and the second-level fully connected layer are connected in sequence; the first-level fully connected layer is followed by a ReLU activation function and a random dropout layer; the second-level fully connected layer is followed by a Softmax activation function.
[0017] As a further improvement to the above solution, the position encoding module performs position encoding through sine and cosine functions, and the calculation formula is as follows:
[0018]
[0019]
[0020] Where PE represents the position encoding vector; the variable pos represents the position index in the compressed one-dimensional time series data; i represents the dimension index of the position encoding vector; d model Represents the hidden layer dimension of the improved Transformer neural network model; the even dimensions use the sine function, and the odd dimensions use the cosine function; the exponent term is 10000 2i d model Used to control waveforms in different dimensions so that position encoding captures position information in different dimensions.
[0021] As a further improvement of the above solution, step S1 specifically includes:
[0022] S11. Reconstruct the original lightning electric field time series signal by combining wavelet threshold denoising and empirical mode decomposition filtering method;
[0023] S12. Segment the reconstructed lightning time series signal using a sliding window method to form several lightning time series segments;
[0024] S13. Perform normalization processing on each lightning time series segment.
[0025] As a further improvement of the above solution, in step S11, when performing empirical mode decomposition filtering, the lightning signal is decomposed into multiple intrinsic mode functions, and low-frequency components with a main frequency lower than 3kHz are eliminated;
[0026] When performing wavelet threshold denoising, by setting the threshold, the signal-dominated wavelet coefficients are retained while the noise-related wavelet coefficients are suppressed. Finally, wavelet reconstruction is performed and the signal is reconstructed using the processed effective wavelet coefficients to achieve denoising. The sym5 wavelet basis is used for wavelet decomposition, and the number of decomposition layers is 5. When performing threshold processing, soft threshold processing is performed on the high-frequency signal part above 30kHz. The threshold formula is as follows:
[0027]
[0028] Where threshold is the set threshold; M is the length of the original lightning electric field time series signal, that is, the total number of sampling points contained in the data; ln is the natural logarithm function; σ is the standard deviation estimate of the noise.
[0029] As a further improvement of the above scheme, in step S12, by setting the size, step length and segment overlapping area ratio of the sliding window, the starting point of the sliding window is aligned with the time starting point of the reconstructed lightning time series signal, and the lightning time series segment data in the sliding window is intercepted to obtain the first lightning time series segment; then the sliding window is moved forward by the set step length to intercept the second lightning time series segment; the above process is repeated until the segmentation of the entire lightning time series signal is completed, and m lightning time series segments f1, f2, f3, ..., f m .
[0030] As a further improvement to the above solution, in step S13, the lightning time series segments are normalized to the interval [-1, 1] based on the minimum-maximum normalization method. The normalized lightning time series segment expression is:
[0031]
[0032] Where, f j is the jth lightning time series segment, j∈[1,m]; max(f j ) is the lightning sequence segment f j The maximum value, min(f j ) is f j The minimum value of f j ′ is f j Normalized lightning time series fragment.
[0033] As a further improvement of the above solution, step S2 specifically includes:
[0034] S21. Calculate the root mean square energy E of each normalized lightning time series segment RMS :
[0035]
[0036] Where N represents the frame length of each lightning time series segment, that is, the number of sampling points contained in the data; x n Indicates the amplitude of the nth sampling point;
[0037] S22. Determine the root mean square energy E RMS Is it less than a set energy threshold? If so, the corresponding lightning time sequence segment is determined to be a useless signal frame and discarded; otherwise, it is retained as a useful signal frame, namely the key time sequence segment.
[0038] The present invention also discloses a computer terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the lightning timing signal recognition method based on the improved Transformer are implemented as described above.
[0039] The present invention also discloses a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the steps of the lightning time sequence signal recognition method based on the improved Transformer are implemented as described above.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] 1. The lightning time series signal recognition method disclosed in the present invention adopts a Transformer encoder structure. By utilizing its built-in self-attention mechanism, this structure can fully capture the correlation between data points that are far apart in the lightning signal sequence, and significantly improve the ability to understand complex contextual information. The improved Transformer encoder structure not only improves the accuracy of lightning signal recognition, but also enhances the interpretability of model decisions. Designs such as layer normalization and residual connections effectively improve the training stability, convergence speed and overall performance of the model. The improved Transformer neural network model can deeply explore the subtle connections in lightning signals, provide more robust feature support for classification tasks, and has better versatility, thereby efficiently identifying the discharge type of lightning signals.
[0042] 2. The lightning signal preprocessing method employed in this paper combines a dual filtering mechanism of wavelet threshold denoising and empirical mode decomposition. This method precisely removes high-frequency noise through the time-frequency localization of the wavelet transform, while simultaneously utilizing the adaptive decomposition capabilities of EMD to effectively separate the signal's intrinsic modes, significantly improving the signal-to-noise ratio. A sliding window dynamic segmentation strategy, using a manually set fixed window, fully preserves the transient characteristics of lightning pulses. This preprocessing scheme improves the signal quality of subsequent model inputs and lays an ideal data foundation for feature extraction.
[0043] 3. The proposed method for screening key time series segments utilizes a dynamic energy analysis mechanism, breaking through the performance bottleneck of traditional static thresholding methods. The innovative dynamic energy threshold algorithm adaptively adjusts the discrimination criteria based on the signal background noise level. Combined with local saliency detection using a sliding energy window, it improves the accuracy of invalid segment removal. This design not only significantly reduces redundant computation (shortening data processing time), but more importantly, ensures that each time series segment in the input model contains interpretable physical features, providing high-quality samples with high physical information characteristics for subsequent classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 This is a flowchart of the lightning time sequence signal recognition method based on the improved Transformer in Example 1 of the present invention.
[0045] Figure 2 This is a timing signal diagram of a local original lightning electric field in Example 1 of the present invention.
[0046] Figure 3 For the present invention Figure 2 The signal diagram after denoising, filtering and normalization.
[0047] Figure 4 This is a typical waveform diagram of a return stroke (RS) lightning discharge event in Example 1 of the present invention.
[0048] Figure 5 This is a typical waveform diagram of a cloud-to-cloud (IC) lightning discharge event in Example 1 of the present invention.
[0049] Figure 6 This is a typical waveform diagram of a narrow bipolar pulse (NB) lightning discharge event in Example 1 of the present invention.
[0050] Figure 7 This is a typical waveform diagram of the initial pre-breakdown (PB) lightning discharge event in Example 1 of the present invention.
[0051] Figure 8 This is a structural diagram of the improved Transformer neural network model in Example 1 of the present invention.
[0052] Figure 9 This is the confusion matrix for evaluating the classification performance of the model in Example 1 of the present invention.
[0053] Figure 10 The accuracy and macro-average AUC change curves during the model training process in Example 1 of the present invention are shown.
[0054] Figure 11 This is a curve showing the change in loss value during the model training process in Example 1 of the present invention.
[0055] Figure 12 This is a schematic diagram of the structure of a computer terminal in Example 2 of the present invention. DETAILED DESCRIPTION
[0056] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0057] Example 1
[0058] See also Figure 1 This embodiment provides a lightning time series signal recognition method based on an improved Transformer, including steps S1 to S3.
[0059] S1. Collect the original lightning electric field time series signal and perform signal preprocessing to generate several lightning time series segments.
[0060] The raw lightning electric field signal time series collected by the lightning radiation detector contains 2,000,000 data points with a duration of 200ms. Due to the presence of significant background noise, the signal is preprocessed to extract the portion containing the lightning radiation pulse, thereby facilitating further annotation of its type when constructing the dataset for model training.
[0061] The signal preprocessing in step S1 mainly includes two parts: filtering and noise reduction and sliding window frame screening, and specifically includes the following steps S11 to S13.
[0062] S11. Combining the wavelet threshold denoising (Wavelet Denoising) and empirical mode decomposition (EMD) filtering methods, the signals in the high frequency range (greater than 30kHz) and the lower frequency range (less than 3kHz) in the original lightning electric field time series signal are further filtered out to reduce the interference of noise and highlight the characteristics of lightning pulses, thereby reconstructing the original lightning electric field time series signal.
[0063] When performing empirical mode decomposition filtering, the lightning signal is decomposed into multiple intrinsic mode functions (IMFs) and low-frequency components with a main frequency less than 3 kHz are eliminated.
[0064] When performing wavelet threshold denoising, the lightning signal is subjected to wavelet decomposition and the high-frequency coefficient threshold is processed to filter out the higher-frequency noise in the lightning signal. Finally, the processed signal is reconstructed to obtain the denoised lightning time series signal, and the signal edge characteristics are effectively retained. Specifically, the wavelet threshold denoising method utilizes the data decorrelation of the wavelet transform so that the energy of the effective lightning signal is concentrated in the wavelet coefficient domain with a larger amplitude, while the noise energy is dispersed in the entire wavelet domain. By effectively setting the threshold, the signal-dominated wavelet coefficients are retained, while the noise-related wavelet coefficients are suppressed. Finally, wavelet reconstruction is performed to reconstruct the signal with the processed effective coefficients, thereby achieving denoising. Specifically, when performing wavelet decomposition, the present invention selects the sym5 wavelet basis and decomposes the layers into 5 layers; when performing threshold processing, the high-frequency signal part is subjected to soft threshold processing, and the following threshold formula is used:
[0065]
[0066] Where threshold is the set threshold; M is the length of the original lightning electric field time series signal, that is, the total number of sampling points in the data; ln is the natural logarithm function; and σ is the estimated standard deviation of the noise. In this embodiment, the estimated standard deviation of the noise is the standard deviation of the absolute values of the first 1000 points of the original lightning electric field time series signal.
[0067] S12. Use a sliding window method to segment the reconstructed lightning time series signal to form a number of lightning time series segments.
[0068] The window size is set to 20,000 data points, the sliding step is set to 5,000, and the segment overlap rate is 75%. The fixed-size window is slid on the lightning signal, moving a certain distance each time to divide each lightning data frame. Specifically, the starting point of the sliding window is aligned with the starting point of the filtered lightning time series, and the lightning time series segment data within the sliding window is intercepted to obtain the first lightning time series segment; then the sliding window is moved forward by the set step length to intercept the second lightning time series segment; the above process is repeated until the entire lightning time series signal is segmented, and a total of m lightning time series segments f1, f2, f3, ..., f m .
[0069] S13. Normalize each lightning time series segment. Specifically, the lightning time series segment is normalized to the interval [-1, 1] based on the minimum-maximum normalization method to accelerate model convergence. The normalized lightning time series segment expression is:
[0070]
[0071] Where, f jis the jth lightning time series segment, j∈[1,m]; max(f j ) is the lightning sequence segment f j The maximum value, min(f j ) is f j The minimum value of f j ′ is f j Normalized lightning time series fragment.
[0072] See also Figure 2 and Figure 3 The two figures compare the denoising effects of the original lightning electric field time series signal before and after denoising filtering and normalization. Through these preprocessing methods, background noise is effectively filtered out and the lightning signal is significantly enhanced, facilitating the subsequent classification and identification of lightning time series.
[0073] S2. Filter out a key time sequence segment containing a lightning radiation pulse from a plurality of lightning time sequence segments.
[0074] To effectively distinguish lightning signal frames from noise frames in the lightning time series generated by sliding window framing, this paper employs an energy / amplitude-based threshold screening method. This method automatically removes useless frames (i.e., those containing no valid lightning pulses or only noise) by calculating and analyzing the energy characteristics of each frame, while retaining signal frames with significant lightning characteristics.
[0075] Step S2 specifically includes steps S21 to S22.
[0076] S21. Calculate the root mean square energy (RMS) of each normalized lightning time series segment, that is, E RMS :
[0077]
[0078] Where N represents the frame length of each lightning time series segment, that is, the number of sampling points contained in the data; x n Indicates the amplitude of the nth sampling point.
[0079] S22. Determine the root mean square energy E RMS If the energy is less than the set threshold, the corresponding lightning time sequence segment is determined to be a useless signal frame and discarded; otherwise, it is retained as a useful signal frame, namely the key time sequence segment. This method can effectively separate lightning pulse signal frames from background noise frames, providing a data foundation for subsequent signal recognition tasks.
[0080] In this embodiment, the construction of the training data set utilizes a lightning multi-parameter judgment method to extract standardized lightning samples S from the normalized lightning time series fragments, and then the discharge types of the lightning samples are labeled through manual screening and review. Finally, the lightning sample data S is paired with the corresponding discharge type label L to form the training data set required for supervised learning.
[0081] The lightning multi-parameter judgment method described above constructs a comprehensive judgment criterion based on lightning signal characteristic parameters, extracting samples of different categories from normalized lightning time series fragments. This method extracts several key time-domain characteristic parameters: rise time, fall time, pulse width, peak-to-peak ratio, peak-to-peak ratio, and signal-to-noise ratio. These parameters are statistically analyzed to determine judgment thresholds, ultimately forming a multi-parameter joint judgment criterion.
[0082] The dataset contains a total of 12,000 lightning samples, with 3,000 samples for each discharge type. The dataset is saved in PKL format, with a total of 12,000 rows and 20,001 columns, of which columns 1-20,000 are data columns and column 20,001 is the label column. Figures 4 to 7 These are waveform diagrams of four typical lightning discharge types. The time length of the four samples is 2ms, and they show the typical characteristics of the four types of lightning samples.
[0083] Observations show that the characteristic time distribution range of the initial pre-breakdown PB and cloud-to-cloud flash IC waveforms is typically up to 2ms, necessitating consideration of long-range feature dependencies. To this end, the lightning signal classification method of the present invention primarily captures the long-range dependencies of lightning sequences through a self-attention mechanism and combines relative position encoding to preserve position information, effectively capturing the long-range characteristics of lightning signals.
[0084] S3. Each key sequence segment is treated as a single-channel one-dimensional time series data and input into the improved Transformer neural network model (which has been trained), thereby outputting the corresponding lightning discharge type recognition result.
[0085] The structure of the Transformer neural network model is as follows Figure 8 As shown in the figure, it includes a downsampling convolution module, a position encoding module, a 4-layer Transformer encoder, and a category output module. The model input is 1×20,000 one-dimensional time series data. During the training phase, the input layer receives lightning sample data S and the corresponding discharge type label L.
[0086] The downsampling convolution module is used to compress the length of the one-dimensional time series data and extract local features. The downsampling convolution module includes two levels of convolutional layers and a maximum pooling layer; the input of the downsampling convolution module is 1×20000 one-dimensional time series data; wherein, according to the forward propagation direction, the first-level convolution layer, the maximum pooling layer, and the second-level convolution layer are connected in sequence. Each level of convolution layer is followed by batch normalization and ReLU activation function; the input data is downsampled by the downsampling convolution module, and the two-level convolution layer performs preliminary dimensionality reduction and extracts local features, and then the maximum pooling layer is used to compress the sequence length from 20000 to 2500 for further dimensionality reduction. Each level of convolution layer is followed by batch normalization and ReLU activation function to accelerate model convergence and enhance nonlinear expression capabilities.
[0087] The Positional Encoding (PE) module is used to add position information to the compressed one-dimensional time series data.
[0088] The position encoding module performs position encoding through sine and cosine functions, and the calculation formula is as follows:
[0089]
[0090]
[0091] Where PE represents the position encoding vector; the variable pos represents the position index in the compressed one-dimensional time series data; i represents the dimension index of the position encoding vector; d model Represents the hidden layer dimension of the improved Transformer neural network model; the even dimensions use the sine function, and the odd dimensions use the cosine function; the exponent term is 10000 2i d model Used to control waveforms in different dimensions so that position encoding captures position information in different dimensions.
[0092] The four-layer Transformer Encoder is used to extract key temporal features from the output of the positional encoding module to form a high-dimensional feature vector containing global temporal dependencies. Each layer of the Transformer Encoder contains two levels of layer normalization (Layer Norm), multi-headed attention, two levels of random dropout layers (Dropout), and a feed-forward neural network (FFN). In the forward propagation direction, the first-level layer normalization, multi-headed attention, and first-level random dropout layers are connected in sequence, and then the output of the first-level layer normalization is added to the output after the first-level Dropout through a residual connection. Then, through the second-level layer normalization, feed-forward neural network, and second-level random dropout layer, the output of the second-level layer normalization and the output after the second-level Dropout are added through a residual connection to form the output of the encoder layer. Layer normalization is used to improve training stability, and multi-headed attention is used to capture long-range dependencies, and the feed-forward neural network is used to enhance nonlinear capabilities.
[0093] The above multi-head attention mechanism can achieve dynamic weight distribution, and its calculation formula is:
[0094]
[0095] MultiHead(Q,K,V)=Concat(head1,...,head h )W O
[0096] Where Q, K, and V represent the query, key, and value matrices of the input sequence, respectively. i Q 、W i K and W i V Denote the projection matrices of query, key and value of the i-th head respectively, W O Represents the output linear transformation matrix, mapping the multi-head output back to the original dimension, d k Denotes the dimension of each head, h is the number of attention heads, and the superscript T denotes transposition. Concat(·) is the concatenation process.
[0097] The self-attention mechanism aggregates global information through weighted summation. Specifically, the inputs Q, K, and V are split into multiple heads through different linear transformations, focusing on different subspace feature maps. First, the attention matrix is obtained through linear calculation and Softmax normalization, and then the attention matrix is obtained through d kThe scaling factor effectively controls the gradient update during backpropagation, ensuring the stability of model training. Next, the outputs of all heads are concatenated and linearly transformed. This multi-head parallel structure allows the model to simultaneously focus on sequence features at different input time scales, improving its ability to model complex dependencies.
[0098] After multi-head self-attention processing, a feedforward neural network is introduced to enhance the model's ability to capture local contextual information. Specifically, FFN introduces nonlinearity through the activation function, helping the model learn more complex features. The FFN results are processed through residual connections and layer normalization to achieve the transmission and fusion of richer feature information, accelerate model training, improve final convergence speed, and ensure high consistency and stability of intermediate outputs throughout the network.
[0099] The category output module is used to generate classification probabilities of multiple typical lightning discharge types based on the high-dimensional feature vector. The category output module includes a global average pooling layer and a two-level fully connected layer; wherein, according to the forward propagation direction, the global average pooling layer, the first-level fully connected layer and the second-level fully connected layer are connected in sequence; the first-level fully connected layer is followed by a ReLU activation function and a random deactivation layer; the second-level fully connected layer is followed by a Softmax activation function. After the classification head of the global average pooling layer, the two fully connected layers and the S random deactivation layer, the features extracted by the model are generated, and the normalized category probability is output by the Softmax activation function. In this embodiment, the classification probabilities of the four lightning discharge types of return stroke (RS), initial pre-breakdown (PB), narrow bipolar pulse (NB) and cloud flash (IC) are output, thereby achieving efficient and accurate classification of lightning signals.
[0100] In this embodiment, the training and testing methods of the Transformer neural network model are as follows:
[0101] The aforementioned dataset is divided into two parts in a ratio of 7:3 to obtain the training set and the test set, respectively. The random seed is fixed at 42.
[0102] The hyperparameters used in model training include model structure hyperparameters, optimizer, loss function, learning rate scheduling strategy and batch size. First, set the model structure hyperparameters and embedding dimension d modelThe parameter size was set to 64, the number of attention heads was set to 8, and the feedforward network dimension was set to 256. The optimizer was set to the Adam algorithm. The cross entropy loss function was selected as the loss function, the initial value of the learning rate (LR) was set to 0.001, and the learning rate scheduler used the ReduceLROnPlateau method to dynamically adjust the learning rate change process. When the learning rate did not improve within the set patience period, the learning rate was multiplied by the factor factor to help the model find the local minimum. The batch size was set to 32. Training was performed on an NVIDIA GeForce RTX 3090 GPU with a maximum training epoch number of 100. Model convergence was determined by observing the fluctuations in the training loss curve (Training Loss). The model was considered converged when the loss value was less than the set minimum threshold for five consecutive times. When the model converged, the parameter weights within the model were saved, and the model parameter file (.pt file) with the highest accuracy on the training set was selected and saved.
[0103] Load the model file with the highest training accuracy, perform forward calculations on the test set with a batch size of 64, and evaluate the model's classification prediction performance using classification metrics such as accuracy, precision, recall, F1 score, and confusion matrix.
[0104] After completing the parameter tuning of the neural network model, load the optimal model parameter configuration, use the batch size of Batch Size = 64 to perform forward calculations on the test set, and finally obtain the trained model structure.
[0105] The classification indicators of the lightning signal time series four-classification model training are shown in Table 1. The model can achieve high accuracy, precision, recall rate, and F1 score for the four types of discharge events: RS, PB, NB, and IC, indicating that the model has no imbalance problem and the classification accuracy is reliable.
[0106] Table 1: Lightning time series classification performance indicators
[0107]
[0108] like Figure 9 As shown in the figure, the confusion matrix is used to evaluate the performance of the classification model. Multiple classification performance indicators are used for evaluation, including accuracy, precision, recall, and F1 score. The calculation formulas for each classification performance indicator are as follows:
[0109]
[0110]
[0111]
[0112]
[0113] Where TP (True Positive) means that the actual example is a positive example and the model predicts it to be a positive example; FP (False Positive) means that the actual example is a negative example and the model predicts it to be a positive example; TN (True Negative) means that the actual example is a negative example and the model predicts it to be a negative example; FN (False Negative) means that the actual example is a positive example and the model predicts it to be a negative example.
[0114] See also Figure 10 and Figure 11 , showing the loss function value and accuracy change curve during the training process of the four-category lightning signal time series classification model. It can be seen that the model reaches convergence after about 40 iterations, and the final classification accuracy is about 94.9%. At this time, the model training is completed and the model is saved as transformer_iteration_accuracy.pt file.
[0115] Example 2
[0116] This embodiment provides a computer terminal, 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, the steps of the lightning timing signal recognition method based on the improved Transformer as described in Example 1 are implemented.
[0117] like Figure 12 As shown, the computer terminal provided in this embodiment includes: at least one processor 101, and a memory 102 connected to the at least one processor 101. The specific connection medium between the processor 101 and the memory 102 is not limited in this embodiment. Figure 12 In the example, the processor 101 and the memory 102 are connected via the bus 100. Figure 12 The bus 100 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 12 The bus is represented by only one thick line, but it does not mean that there is only one bus or one type of bus. Alternatively, the processor 101 can also be called a controller, and there is no limitation on the name.
[0118] In this embodiment, the memory 102 stores instructions that can be executed by at least one processor 101 , and the at least one processor 101 can perform the aforementioned method by executing the instructions stored in the memory 102 .
[0119] Among them, the processor 101 is the control center of the device, which can use various interfaces and lines to connect the various parts of the entire control device, and monitor the device as a whole by running or executing instructions stored in the memory 102 and calling data stored in the memory 102, the various functions of the device and processing data.
[0120] In one possible design, processor 101 may include one or more processing units. Processor 101 may integrate an application processor and a modem processor. The application processor primarily processes the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 101. In some embodiments, processor 101 and memory 102 may be implemented on the same chip. In some embodiments, they may also be implemented on separate chips.
[0121] The processor 101 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments. A general-purpose processor can be a microprocessor or any conventional processor. In conjunction with the steps of the improved Transformer-based lightning timing signal recognition method disclosed in Example 1, the steps can be directly implemented as a hardware processor, or can be implemented using a combination of hardware and software modules in the processor 101.
[0122] The memory 102 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 102 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (RAM), a static random access memory (SRAM), a programmable read-only memory (PROM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic memory, a magnetic disk, an optical disk, etc. The memory 102 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 102 in this embodiment can also be a circuit or any other device that can implement a storage function, for storing program instructions and / or data.
[0123] By programming the processor 101, the code corresponding to the security verification method described in the above embodiment can be fixed into the chip, so that the chip can execute the security verification method when it is running. Figure 1 The steps of the lightning timing signal recognition method based on the improved Transformer are shown. How to design and program the processor 101 is a technology well known to those skilled in the art and will not be described in detail here.
[0124] Example 3
[0125] This embodiment provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the steps of the lightning time series signal recognition method based on the improved Transformer as described in Example 1 are implemented.
[0126] The computer-readable storage medium may include flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the storage medium may be an internal storage unit of a computer device, such as the hard disk or memory of the computer device. In other embodiments, the storage medium may also be an external storage device of the computer device, such as a plug-in hard disk equipped on the computer device, a smart media card (SMC), a secure digital (SD) card, a flash memory card, etc. Of course, the storage medium may also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the memory is generally used to store the operating system and various application software installed on the computer device. In addition, the memory may also be used to temporarily store various types of data that have been output or are about to be output.
[0127] The above description is only a preferred specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any technician familiar with the technical field, within the technical scope disclosed by the present invention, who makes equivalent replacements or changes based on the technical solution and inventive concept of the present invention, should be covered by the scope of protection of the present invention.
Claims
1. A lightning time series signal recognition method based on an improved Transformer is characterized by: include: S1. Collecting the original lightning electric field time series signal and performing signal preprocessing to generate several lightning time series segments; S2. selecting a key time sequence segment containing a lightning radiation pulse from a plurality of lightning time sequence segments; S3. Input each key sequence segment as a single-channel one-dimensional time series data into an improved Transformer neural network model to output a corresponding lightning discharge type recognition result; wherein the Transformer neural network model includes: A downsampling convolution module, used to compress the length of the one-dimensional time series data and extract local features; Position encoding module, used to add position information to compressed one-dimensional time series data; The multi-layer Transformer encoder is used to extract key temporal features from the output of the position encoding module to form a high-dimensional feature vector containing global temporal dependencies. Each layer of the Transformer encoder contains two levels of layer normalization, multi-head attention, two levels of random activation layers, and a feedforward neural network. In the forward propagation direction, the first-level layer normalization, multi-head attention, and first-level random activation layers are connected in sequence, and then the output of the first-level layer normalization is added to the output of the first-level random activation layer through a residual connection. Then, through the second-level layer normalization, feedforward neural network, and second-level random activation layer, the output of the second-level layer normalization is added to the output of the second-level random activation layer through a residual connection to form the output of the encoder layer. Layer normalization is used to improve training stability, and multi-head attention is used to capture long-range dependencies, and the feedforward neural network is used to enhance nonlinear capabilities. The category output module is used to generate classification probabilities of multiple typical lightning discharge types according to the high-dimensional feature vector.
2. The lightning time series signal recognition method based on improved Transformer according to claim 1 is characterized in that: The downsampling convolution module includes two convolutional layers and a maximum pooling layer. The input of the downsampling convolution module is one-dimensional time series data. In the forward propagation direction, the first convolutional layer, the maximum pooling layer, and the second convolutional layer are connected in sequence, and each convolutional layer is followed by batch normalization and ReLU activation function. The two convolutional layers are used to perform preliminary dimensionality reduction and extract local features, and the maximum pooling layer is used to compress the sequence length to further reduce the dimensionality. The category output module includes a global average pooling layer and two-level fully connected layers; wherein, according to the forward propagation direction, the global average pooling layer, the first-level fully connected layer and the second-level fully connected layer are connected in sequence; the first-level fully connected layer is followed by a ReLU activation function and a random dropout layer; the second-level fully connected layer is followed by a Softmax activation function.
3. The lightning time series signal recognition method based on improved Transformer according to claim 1 is characterized in that: The position encoding module performs position encoding through sine and cosine functions, and the calculation formula is as follows: Where PE represents the position encoding vector; the variable pos represents the position index in the compressed one-dimensional time series data; i represents the dimension index of the position encoding vector; d model Represents the hidden layer dimension of the improved Transformer neural network model; the even dimensions use the sine function, and the odd dimensions use the cosine function; the exponent term is 10000 2i d model Used to control waveforms in different dimensions so that position encoding captures position information in different dimensions.
4. The lightning time series signal recognition method based on improved Transformer according to claim 1 is characterized in that: Step S1 specifically includes: S11. Reconstruct the original lightning electric field time series signal by combining wavelet threshold denoising and empirical mode decomposition filtering method; S12. Segment the reconstructed lightning time series signal using a sliding window method to form several lightning time series segments; S13. Perform normalization processing on each lightning time series segment.
5. The lightning time series signal recognition method based on improved Transformer according to claim 4 is characterized in that: In step S11, when performing empirical mode decomposition filtering, the lightning signal is decomposed into multiple intrinsic mode functions, and low-frequency components with a main frequency lower than 3kHz are eliminated; When performing wavelet threshold denoising, by setting the threshold, the signal-dominated wavelet coefficients are retained while the noise-related wavelet coefficients are suppressed. Finally, wavelet reconstruction is performed and the signal is reconstructed using the processed effective wavelet coefficients to achieve denoising. The sym5 wavelet basis is used for wavelet decomposition, and the number of decomposition layers is 5. When performing threshold processing, soft threshold processing is performed on the high-frequency signal part above 30kHz. The threshold formula is as follows: Where threshold is the set threshold; M is the length of the original lightning electric field time series signal, that is, the total number of sampling points contained in the data; ln is the natural logarithm function; σ is the standard deviation estimate of the noise.
6. The lightning time series signal recognition method based on improved Transformer according to claim 4 is characterized in that: In step S12, by setting the size, step length and segment overlap area ratio of the sliding window, the starting point of the sliding window is aligned with the time starting point of the reconstructed lightning time series signal, and the lightning time series segment data in the sliding window is intercepted to obtain the first lightning time series segment; then the sliding window is moved forward by the set step length to intercept the second lightning time series segment; the above process is repeated until the segmentation of the entire lightning time series signal is completed, and m lightning time series segments f1, f2, f3, ..., f m .
7. The lightning time series signal recognition method based on improved Transformer according to claim 6 is characterized in that: In step S13, the lightning time series segment is normalized to the interval [-1, 1] based on the minimum-maximum normalization method. The normalized lightning time series segment expression is: Where, f j is the jth lightning time series segment, j∈[1,m]; max(f j ) is the lightning time sequence segment f j The maximum value, min(f j ) is f j The minimum value of f j ′ is f j Normalized lightning time series fragment.
8. The lightning time series signal recognition method based on improved Transformer according to claim 1 is characterized in that: Step S2 specifically includes: S21. Calculate the root mean square energy E of each normalized lightning time series segment RMS : Where N represents the frame length of each lightning time series segment, that is, the number of sampling points contained in the data; x n Indicates the amplitude of the nth sampling point; S22. Determine the root mean square energy E RMS Is it less than a set energy threshold? If so, the corresponding lightning time sequence segment is determined to be a useless signal frame and discarded; otherwise, it is retained as a useful signal frame, namely the key time sequence segment.
9. A computer terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the lightning time sequence signal recognition method based on the improved Transformer are implemented as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the lightning time sequence signal recognition method based on the improved Transformer as claimed in any one of claims 1 to 8 are implemented.
Citation Information
Cited By
Atmospheric electric field prediction method under Transform hybrid model
CN121500274A
Lightning very-low-frequency electromagnetic wave signal compression method based on importance perception
CN122268379A