An unmanned aerial vehicle anomaly detection method based on multi-scale spatio-temporal graph representation and contrast learning
By employing a multi-scale spatiotemporal graph representation and comparative learning approach, the complex relationships between variables and the diverse temporal feature scales in UAV multivariate flight data are addressed, thereby improving the accuracy and robustness of UAV anomaly detection and enabling it to adapt to complex flight environments.
Patent Information
- Application Number
- CN202611389863.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-09
- Publication Date
- 2026-11-27
AI Technical Summary
Existing UAV anomaly detection methods are unable to effectively capture the spatial correlation between variables and the dynamic change patterns at different time scales in multivariate flight data. Furthermore, they are prone to false alarms or missed alarms under complex flight conditions, affecting the accuracy and robustness of detection.
We employ a multi-scale spatiotemporal graph representation and contrastive learning approach, combining Wasserstein generative adversarial networks, multi-scale adaptive routing mechanisms, graph multi-head self-attention mechanisms, and bidirectional exponential weighted smoothing methods to construct a joint modeling mechanism for multi-scale spatiotemporal feature extraction and contrastive learning. The graph multi-head self-attention mechanism captures spatial relationships between variables, the hybrid encoder captures temporal relationships between segments, and the bidirectional exponential weighted smoothing method is used for anomaly detection.
It improves the accuracy and robustness of UAV anomaly detection, effectively reconstructs missing data, distinguishes between normal and abnormal samples, and enhances adaptability to complex flight environments.
Smart Images

Figure CN123179226A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of UAV flight status monitoring and intelligent fault diagnosis technology, and relates to the field of UAV anomaly detection technology, specifically to a UAV anomaly detection method based on multi-scale spatiotemporal graph representation and comparative learning. Background Technology
[0002] Unmanned aerial vehicle (UAV) flight data is a typical example of multivariate spatiotemporal sequence data, describing changes in attitude, speed, altitude, position, sensor status, and control response of UAVs during different flight phases and operating environments. UAV anomaly detection has significant application value in flight safety monitoring, fault early warning, intelligent operation and maintenance, and reliable mission execution. However, multivariate flight data collected during actual flights typically exhibits characteristics such as high dimensionality, strong temporal sequence, complex coupling relationships between variables, and inconsistent sampling frequencies, making data analysis and prediction extremely challenging. Furthermore, due to factors such as sensor failure, communication packet loss, environmental disturbances, and noise interference, UAV flight data may suffer from data gaps or difficulty in capturing anomalous patterns.
[0003] While existing UAV anomaly detection methods have considered the temporal variation characteristics of flight state data, traditional methods typically rely on manual feature design or single temporal modeling, making it difficult to fully capture the spatial correlations between different flight state variables and the dynamic changes of the same variable at different time scales. Furthermore, existing deep learning methods rarely simultaneously consider issues such as missing data reconstruction, multi-scale spatiotemporal feature extraction, differentiation between normal and abnormal samples, and residual sequence stability determination. This leads to false positives or false negatives in complex flight conditions, severely impacting the accuracy and robustness of anomaly detection. Summary of the Invention
[0004] In view of this, the purpose of this invention is to provide a UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning. Addressing the problems of complex variable coupling relationships, diverse temporal feature scales, data gaps, and unclear anomaly representations in multivariate UAV flight data, this invention constructs a joint modeling mechanism for multi-scale spatiotemporal feature extraction and contrastive learning, and combines it with a bidirectional exponential weighted smoothing method for anomaly determination, thereby improving the accuracy, robustness, and adaptability of UAV anomaly detection.
[0005] To achieve the above objectives, the present invention provides the following technical solution:
[0006] A method for detecting UAV anomalies based on multi-scale spatiotemporal graph representation and contrastive learning, specifically including the following steps:
[0007] S1: Multivariate flight data acquisition and preprocessing; specifically: acquiring multivariate flight data of UAVs, constructing a unified timeline, resampling and aligning the data with timestamps, generating a missing mask, normalizing the data, and constructing data samples based on the sliding window method.
[0008] S2: Sample construction based on Wasserstein generative adversarial network and masking enhancement; specifically: extract sample features using Wasserstein generative adversarial network WGAN, capture the correlation between variables and the temporal relationship within variables using attention mechanism, construct the loss function of generator and discriminator to obtain the reconstructed complete data sample, and construct enhanced samples using random masking strategy;
[0009] S3: Construct a multi-scale adaptive routing mechanism; specifically: perform seasonal trend decomposition on the data samples, then fuse the seasonal terms, trend terms and the original data samples to obtain a temporal routing representation, and adaptively determine the expert network routing weights based on the temporal routing representation.
[0010] S4: Capture spatial relationships between variables based on graph multi-head self-attention mechanism; specifically: divide the input sample into multiple segments according to the segment scale of each expert network and map them to hidden node features; determine the spatial relationships between nodes based on graph multi-head self-attention mechanism and update the sample feature matrix accordingly;
[0011] S5: Capturing temporal correlations of segments based on a hybrid encoder; specifically: the constructed hybrid encoder consists of a multi-head self-attention mechanism, a multi-branch deep convolutional network, and an adaptive gating mechanism, wherein the multi-head self-attention mechanism captures global temporal features, and the multi-branch deep convolutional network captures local temporal features; the gating weight vector is determined based on the global and local temporal features, thereby obtaining spatiotemporal fusion features;
[0012] S6: Construct the loss function; specifically: based on the spatiotemporal fusion feature embedding representation, for a given reconstructed sample, define positive and negative samples, and construct a contrastive learning loss function; construct a reconstruction loss function based on the complete data sample reconstructed by WGAN and the reconstructed data sample, and then construct a system loss function based on the contrastive learning loss function and the reconstruction loss function;
[0013] S7: Anomaly detection based on the Bi-AEWMA method of bidirectional exponential weighted smoothing; specifically: based on the reconstructed complete data sample and the reconstructed data sample, calculate the residual matrix and residual sequence, use the Bi-AEWMA method to smooth the residual sequence, compare the smoothed residual value with the threshold, and determine whether the UAV flight status is abnormal.
[0014] Furthermore, in step S1: multivariate flight data acquisition and preprocessing, specifically including: Let K represent the number of flight state variables, V k V represents the k-th flight state variable. k The sampled dataset is ,in, V represents k In the The sampled values at each sampling time point V represents k The nth sampling timestamp, V represents k The number of sampling points ; Resample and timestamp-align the sampled datasets for each flight state variable, so that Indicates the sampling start timestamp. Indicates the sampling interval. Indicates the first From the sampling timestamps, we can obtain: , , Indicates the number of sampling timestamps; let , V k In the The sampled values and missing value identifiers at each sampling time point, if ,but , ;make This indicates a preset time interval threshold. and Then, linear interpolation is used to determine V. k exist The sampled value at the location, and Set to 1, that is: , Otherwise, V k In the The sampled value at each sampling time point is 0, and... Setting it to 0 indicates missing data, that is: , ;make , Representing the multivariate flight data and the missing mask matrix respectively, we can obtain , ;right Perform normalization, let , V k The mean and standard deviation are modeled as follows: , ;make V represents k In the The normalized values at each sampling time point are modeled as follows: ;make Representing the normalized UAV flight data, we can obtain Using the sliding window method and Divide into N data samples, let This indicates the size of the sliding window and the sliding step. and They represent the first From the data samples and the missing mask samples, we can obtain , ,in, , , .
[0015] Furthermore, in step S2: the sample construction based on the Wasserstein generative adversarial network and mask enhancement specifically includes: the constructed Wasserstein generative adversarial network consists of a feature extractor, a generator, and a discriminator; constructing the input feature vector of the WGAN, letting... Indicates the first V in a data sample k At the sampling time point The feature vectors are modeled as follows: ,in, This represents the input feature mapping matrix. Indicates the bias term. This indicates the hidden feature dimension; a self-attention mechanism is used to capture the correlation between variables, making... Indicates the first Each data sample at the sampling time point The feature matrix, based on Construct query vector Key vector Sum value vector The model is as follows: , , ,in , , These represent the query, the key-value mapping matrix, and capture the relationships between variables. After representing the association between aggregate variables, the first... Each data sample at the sampling time point The feature matrix is modeled as follows: ,in, Indicates the vector scaling factor;
[0016] A self-attention mechanism is used to capture the temporal correlation of the same variable, allowing... Indicates the first V in a data sample k The time feature matrix, based on Construct query vector Key vector Sum value vector The model is as follows: , , ,in, , , These represent the query, key, and value mapping matrices, respectively, capturing the temporal relationships between variables. After representing the aggregation time-series association, the first V in a data sample k The feature matrix is modeled as follows: ,make Indicates the first The feature matrix of each data sample; a random masking strategy is used to... Perform a masking operation, making Indicates the first The random mask matrix of each data sample can be obtained. ,in, ;Will Input generator, let Representing the generator's output samples, we can obtain ,in, Represents a generator. Let represent the parameter vector of the generator, and let Indicates will The complete data sample after replacing the masked data with the generator's output data can be obtained. ,in, This indicates element-wise multiplication. Let represent a matrix of all 1s; let Indicates the discriminator pair The test score, for the data sample Define the discriminator loss as The generator loss is ,in, Represents the mean function, For hyperparameters, Describing the L2 norm, Let represent the parameter vector of the discriminator, and let This represents the complete data sample after reconstruction, which can be obtained. Enhanced samples are constructed using a random masking strategy. Setting the values of some flight state variables in the time series to 0 can yield enhanced samples. ,in, , Let represent a vector consisting entirely of 1s, and let This indicates the number of flight state variables randomly selected. , Indicates the preset mask ratio. This indicates the rounding up operation.
[0017] Furthermore, in step S3: constructing a multi-scale adaptive routing mechanism specifically includes: performing seasonal trend decomposition on the data samples, then fusing the seasonal term, trend term, and original data samples to obtain a temporal routing representation, and adaptively determining the expert network routing weights based on the temporal routing representation. Specifically, let... The input sample is extracted using the Discrete Fourier Transform (DFT). frequency domain amplitude ,Right now: Select the one with the highest percentage of amplitude Each dominant frequency component is used to construct a frequency domain sample, and the inverse discrete Fourier transform (IDFT) is used to extract the input sample. Seasonal items ,make This represents the residual term after removing the seasonal term, and the trend term is extracted based on the multi-scale average pooling method. ,in, This represents the weights corresponding to different scales. Indicates a linear layer. Indicates the first Average pooling function for each kernel To indicate the number of nuclei, let This indicates that the input sample, seasonality, and trend are fused and then obtained based on a linear mapping to obtain the first... Temporal routing representation of each data sample, based on The expert network routing weight vector is calculated and modeled as follows: ,in, , Indicates the routing function. , All are learnable parameters. Indicates the number of expert networks, selected before Find the maximum weight and set the remaining weights to 0 to obtain the updated route weight vector. , .
[0018] Furthermore, in step S4: capturing spatial relationships between variables based on a graph multi-head self-attention mechanism specifically includes: according to the fragment scale of each expert network, processing the input samples... Divide the data into multiple segments along the time dimension to obtain a segment sequence; let Indicates the first The size of a segment in an expert network. Indicates the first In an expert network, the input sample The partitioned sequence is defined as: ,in, express The A segment, Indicates the first In the expert network, the first The first data sample V in the segment k The sampled value vector, Indicates the first The number of segments in an expert network ;right The hidden features are obtained by performing a linear transformation, and the model is as follows: ,in, Indicates the first The segment feature mapping matrix of an expert network. Indicates the bias term. Let the first dimension represent the node feature dimension; The first expert network The node feature tensor of each data sample is Each node feature is used Group-independent learnable parameters, mapped to The subspaces with different characteristics are modeled as follows: ,in, Indicates the attention head number, Indicates the first The first expert network The linear projection matrix of each attention head. Represent the feature dimension of the subspace; within the i-th subspace of the same segment, calculate the spatial association score between any two nodes, let Indicates the first segment of the same segment Within a subspace, nodes and Spatial association scores are modeled as follows: ,in, , Indicates the first The first expert network Shared attention weight vector for each size This indicates a splicing operation. Represents a nonlinear activation function; based on The corresponding attention weights are calculated and modeled as follows: ,calculate The average of the feature outputs of each subspace is used to obtain the final spatially enhanced node features, which are modeled as follows: ,make After representing the relationships between nodes aggregated by multi-head self-attention in the graph, the th The data sample at the ... Feature matrix in an expert network.
[0019] Furthermore, in step S5: capturing the temporal correlation of segments based on the hybrid encoder specifically includes: letting Indicates the first The data sample at the ... The first expert network Spatial enhancement features of individual segments, for Construct a time token, modeled as follows: ,in, Indicates the first A time token mapping matrix for an expert network, Indicates the bias term. Representing the time token feature dimension; employing multi-head self-attention to capture the global temporal correlation of segments, making... Indicates the first The data sample at the ... A time token sequence for an expert network; the number of time attention heads is set to [number]. ,based on Construct query vector Key vector Value vector The model is as follows: , , ,in, , , Represents the projection matrix. , The feature dimension representing the temporal attention head captures the global temporal correlation of segments and is modeled as follows: By concatenating the outputs of all attention heads along the feature dimension, we can obtain: ,in, Indicates the first The global temporal feature mapping matrix of an expert network; a multi-branch deep convolutional network is used to capture the local temporal correlation of segments, specifically, let This indicates the number of convolutional branches in a multi-branch depthwise convolutional network. Indicates the first The kernel size corresponding to each convolutional branch ,make Indicates the first The output of each convolutional branch is modeled as follows: ,in, Indicates the first The one-dimensional convolution operation of each convolution branch concatenates the temporal features output by all convolution branches along the feature dimension, and models it as follows: ,in, The projection matrix is represented; the gating weight vector is determined based on global and local temporal features. The global and local temporal features are concatenated, and the gating weight vector of the global temporal features is obtained through linear mapping and activation functions, modeled as follows: ,in, express The Middle Global temporal features of each segment express The Middle Local temporal features of each segment , Represent the learnable parameters; let The gated weight vector represents the local temporal features, based on , The global and local temporal features are fused and modeled as follows: ,in, This indicates element-wise multiplication. Let represent a vector consisting entirely of 1s, and let Indicates the first The data sample at the ... The spatiotemporal fusion characteristics of an expert network.
[0020] Furthermore, in step S6: constructing the loss function specifically includes: based on the spatiotemporal fusion feature embedding representation, for a given reconstructed sample, defining positive and negative samples, constructing a contrastive learning loss function, and letting... , They represent , The spatiotemporal fusion features obtained through expert network output are used to... , The embedding representation is obtained by performing nonlinear mappings separately, and the model is as follows: , ,in, , , Indicates the embedding dimension. This represents a nonlinear mapping network, using cosine similarity to measure the correlation between the embedded representations of two samples, and is modeled as follows: ,in, Let represent the cosine similarity function. For a given reconstructed sample, let its corresponding augmented sample be a positive sample, and all other reconstructed samples and their corresponding augmented samples be negative samples. Construct a contrastive learning loss function, modeled as follows: ,in, This represents the temperature coefficient.
[0021] Based on the complete data samples reconstructed by WGAN and the reconstructed data samples, a reconstruction loss function is constructed. Specifically, the output features of each expert network are weighted and fused according to the routing weights, and the model is as follows: ,in, Indicates the first The data sample at the ... The routing weights of each expert network, for Perform decoding and reconstruction, so that Indicates the first The output corresponding to each data sample is used to construct a reconstruction loss function, which is modeled as follows: ,in, Represent the mean squared error function; construct the loss function, modeled as: ,in, This is a hyperparameter.
[0022] Furthermore, in step S7: the anomaly detection based on the bidirectional exponentially weighted smoothing Bi-AEWMA method specifically includes: calculating the residual matrix and residual sequence based on the reconstructed complete data sample and the reconstructed data sample, and calculating... and residual matrix The model is as follows: Calculate the first The residual values of each data sample are modeled as follows: ,in, express Norm, to obtain residual sequence The Bi-AEWMA method was used to smooth the residual sequence in both forward and reverse directions, letting... and They represent the first The forward and reverse smoothing values of the residuals of each data sample are modeled as follows: , , , , , ,in, This represents the residual sequence smoothing factor; the forward and reverse smoothing values are fused to obtain the first... The residuals of each data sample after bidirectional smoothing are modeled as follows: The smoothed residual sequence is obtained. ,calculate The mean and standard deviation are modeled as follows: , Calculate the abnormal threshold The model is as follows: ,in, This represents the threshold adjustment coefficient; the smoothed residual value is compared with the judgment threshold for discrimination. Then determine the drone's first An anomaly was detected in the first data sample, triggering an alert; otherwise, the drone's first... The data samples are in a normal state.
[0023] The beneficial effects of this invention are as follows: The method of this invention, when dealing with complex variable coupling relationships, diverse temporal feature scales, missing data, and unclear anomaly representations in UAV multivariate flight data, is based on multi-scale spatiotemporal graph representation and comparative learning. It combines Wasserstein generative adversarial networks and mask-enhanced sample construction, multi-scale adaptive routing mechanisms, graph multi-head self-attention mechanisms, hybrid encoders, and bidirectional exponentially weighted smoothing (Bi-AEWMA) anomaly detection methods to fully capture the spatial correlation between flight state variables and the temporal dynamic features at different time scales. This enables effective reconstruction of missing data, effective differentiation between normal and abnormal sample representations, and stable determination of residual sequences, thereby improving the accuracy, robustness, and adaptability to complex flight environments in UAV anomaly detection.
[0024] Other advantages, objectives, and features of the invention will be set forth in part in the description which follows, and in part will be apparent to those skilled in the art from the following examination, or may be learned from practice of the invention. The objectives and other advantages of the invention can be realized and obtained through the following description. Attached Figure Description
[0025] To make the objectives, technical solutions, and advantages of the present invention clearer, the preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings, wherein:
[0026] Figure 1 This is a schematic diagram of the UAV anomaly detection proposed in this invention;
[0027] Figure 2 This is a flowchart illustrating the UAV anomaly detection method based on multi-scale spatiotemporal graph representation and comparative learning according to the present invention. Detailed Implementation
[0028] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0029] The accompanying drawings are for illustrative purposes only and are schematic diagrams, not actual pictures. They should not be construed as limiting the invention. To better illustrate the embodiments of the invention, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0030] In the accompanying drawings of the embodiments of the present invention, the same or similar reference numerals correspond to the same or similar components. In the description of the present invention, it should be understood that if terms such as "upper," "lower," "left," "right," "front," and "rear" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, they are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, the terms used to describe positional relationships in the drawings are only for illustrative purposes and should not be construed as limiting the present invention. For those skilled in the art, the specific meaning of the above terms can be understood according to the specific circumstances.
[0031] Please see Figures 1-2 , Figure 1 This is a schematic diagram of the UAV anomaly detection proposed in this invention, as shown below. Figure 1As shown, this method resamples, aligns timestamps, generates missing masks, normalizes, and constructs sliding window samples from collected UAV multivariate flight data. Based on Wasserstein generative adversarial networks and mask enhancement strategies, it extracts features from samples, reconstructs missing data, and enhances sample construction. It performs seasonal trend decomposition on the samples and fuses seasonal terms, trend terms, and original data samples to determine the routing weights of different expert networks. It captures the spatial correlation between different flight state variables based on a graph multi-head self-attention mechanism. A hybrid encoder composed of a multi-head self-attention mechanism, a multi-branch deep convolutional network, and an adaptive gating mechanism captures the temporal correlation of segments, obtaining spatiotemporal fusion features. A system loss function is constructed based on a contrastive learning loss function and a reconstruction loss function. The residuals are calculated based on the reconstructed complete data samples and the reconstructed data samples. The Bi-AEWMA method is used to smooth the residual sequence, and a threshold is calculated. The smoothed residual value is compared with the threshold to determine whether the UAV flight state is abnormal.
[0032] Figure 2 This is a flowchart illustrating the UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning according to the present invention. Figure 2 As shown, the method specifically includes the following steps:
[0033] Step 1: Multivariate flight data acquisition and preprocessing.
[0034] Let K represent the number of flight state variables, and V k V represents the k-th flight state variable. k The sampled dataset is ,in, V represents k In the The sampled values at each sampling time point V represents k The nth sampling timestamp, V represents k The number of sampling points ; Resample and timestamp-align the sampled datasets for each flight state variable, so that Indicates the sampling start timestamp. Indicates the sampling interval. Indicates the first From the sampling timestamps, we can obtain: , , Indicates the number of sampling timestamps; let , V k In the The sampled values and missing value identifiers at each sampling time point, if ,but , ;make This indicates a preset time interval threshold. and Then, linear interpolation is used to determine V. k exist The sampled value at the location, and Set to 1, that is: , Otherwise, V k In the The sampled value at each sampling time point is 0, and... Setting it to 0 indicates missing data, that is: , ;make , Representing the multivariate flight data and the missing mask matrix respectively, we can obtain , ;right Perform normalization, let , V k The mean and standard deviation are modeled as follows: , ;make V represents k In the The normalized values at each sampling time point are modeled as follows: ;make Representing the normalized UAV flight data, we can obtain Using the sliding window method and Divide into N data samples, let This indicates the size of the sliding window and the sliding step. and Let the i-th data sample and the missing mask sample be represented respectively. Then we can obtain... , ,in, , , .
[0035] Step 2: Constructing samples based on Wasserstein generative adversarial networks and mask enhancement.
[0036] The constructed Wasserstein generative adversarial network consists of a feature extractor, a generator, and a discriminator; the input feature vector of the WGAN is constructed by letting... Indicates the first V in a data sample k At the sampling time point The feature vectors are modeled as follows: ,in, This represents the input feature mapping matrix. Indicates the bias term. This indicates the hidden feature dimension; a self-attention mechanism is used to capture the correlation between variables, making... Indicates the first Each data sample at the sampling time point The feature matrix, based on Construct query vector Key vector Sum value vector The model is as follows: , , ,in , , These represent the query, the key-value mapping matrix, and capture the relationships between variables. After representing the association between aggregate variables, the first... Each data sample at the sampling time point The feature matrix is modeled as follows: ,in, Indicates the vector scaling factor;
[0037] A self-attention mechanism is used to capture the temporal correlation of the same variable, allowing... Indicates the first V in a data sample k The time feature matrix, based on Construct query vector Key vector Sum value vector The model is as follows: , , ,in, , , These represent the query, key, and value mapping matrices, respectively, capturing the temporal relationships between variables. After representing the aggregation time-series association, the first V in a data sample k The feature matrix is modeled as follows: ,make Indicates the first The feature matrix of each data sample; a random masking strategy is used to... Perform a masking operation, making Indicates the first The random mask matrix of each data sample can be obtained. ,in, ;Will Input generator, let Representing the generator's output samples, we can obtain ,in, Represents a generator. Let represent the parameter vector of the generator, and let Indicates will The complete data sample after replacing the masked data with the generator's output data can be obtained. ,in, This indicates element-wise multiplication. Let represent a matrix of all 1s; let Indicates the discriminator pair The test score, for the data sample Define the discriminator loss as The generator loss is ,in, Represents the mean function, For hyperparameters, Describing the L2 norm, Let represent the parameter vector of the discriminator, and let This represents the complete data sample after reconstruction, which can be obtained. Enhanced samples are constructed using a random masking strategy. Setting the values of some flight state variables in the time series to 0 can yield enhanced samples. ,in, , Let represent a vector consisting entirely of 1s, and let This indicates the number of flight state variables randomly selected. , Indicates the preset mask ratio. This indicates the rounding up operation.
[0038] Step 3: Construct a multi-scale adaptive routing mechanism.
[0039] The data samples are decomposed into seasonal trends, and then the seasonal terms, trend terms, and original data samples are merged to obtain a time-series routing representation. Based on this time-series routing representation, the expert network routing weights are adaptively determined. Specifically, let... The input sample is extracted using the Discrete Fourier Transform (DFT). frequency domain amplitude ,Right now: Select the one with the highest percentage of amplitude Each dominant frequency component is used to construct a frequency domain sample, and the inverse discrete Fourier transform (IDFT) is used to extract the input sample. Seasonal items ,make This represents the residual term after removing the seasonal term, and the trend term is extracted based on the multi-scale average pooling method. ,in, This represents the weights corresponding to different scales. Indicates a linear layer. Indicates the first Average pooling function for each kernel To indicate the number of nuclei, let This indicates that the input sample, seasonality, and trend are fused and then obtained based on a linear mapping to obtain the first... Temporal routing representation of each data sample, based on The expert network routing weight vector is calculated and modeled as follows: ,in, , Indicates the routing function. , All are learnable parameters. Indicates the number of expert networks, selected before Find the maximum weight and set the remaining weights to 0 to obtain the updated route weight vector. , .
[0040] Step 4: Capture spatial relationships between variables based on graph multi-head self-attention mechanism.
[0041] Based on the segment scale of each expert network, the input samples are... Divide the data into multiple segments along the time dimension to obtain a segment sequence; let Indicates the first The size of a segment in an expert network. Indicates the first In an expert network, the input sample The partitioned sequence is defined as: ,in, express The A segment, Indicates the first In the expert network, the first The first data sample V in the segment k The sampled value vector, Indicates the first The number of segments in an expert network ;right The hidden features are obtained by performing a linear transformation, and the model is as follows: ,in, Indicates the first The segment feature mapping matrix of an expert network. Indicates the bias term. Let the first dimension represent the node feature dimension; The first expert network The node feature tensor of each data sample is Each node feature is used Group-independent learnable parameters, mapped to The subspaces with different characteristics are modeled as follows: ,in, Indicates the attention head number, Indicates the first The first expert network The linear projection matrix of each attention head. Represents the feature dimension of the subspace; the first dimension of the same segment Within each subspace, calculate the spatial association score between any two nodes, let Indicates the first segment of the same segment Within a subspace, nodes and Spatial association scores are modeled as follows: ,in, , Indicates the first The first expert network Shared attention weight vector for each size This indicates a splicing operation. Represents a nonlinear activation function; based on The corresponding attention weights are calculated and modeled as follows: ,calculate The average of the feature outputs of each subspace is used to obtain the final spatially enhanced node features, which are modeled as follows: ,make After representing the relationships between nodes aggregated by multi-head self-attention in the graph, the th The data sample at the ... Feature matrix in an expert network.
[0042] Step 5: Capture the temporal correlation of segments based on the hybrid encoder.
[0043] make Indicates the first The data sample at the ... The first expert network Spatial enhancement features of individual segments, for Construct a time token, modeled as follows: ,in, Indicates the first A time token mapping matrix for an expert network, Indicates the bias term. Representing the time token feature dimension; employing multi-head self-attention to capture the global temporal correlation of segments, making... Indicates the first The data sample at the ... A time token sequence for an expert network; the number of time attention heads is set to [number]. ,based on Construct query vector Key vector Value vector The model is as follows: , , ,in, , , Represents the projection matrix. , The feature dimension representing the temporal attention head captures the global temporal correlation of segments and is modeled as follows: By concatenating the outputs of all attention heads along the feature dimension, we can obtain: ,in, Indicates the first The global temporal feature mapping matrix of an expert network; a multi-branch deep convolutional network is used to capture the local temporal correlation of segments, specifically, let This indicates the number of convolutional branches in a multi-branch depthwise convolutional network. Indicates the first The kernel size corresponding to each convolutional branch ,make Indicates the first The output of each convolutional branch is modeled as follows: ,in, Indicates the first The one-dimensional convolution operation of each convolution branch concatenates the temporal features output by all convolution branches along the feature dimension, and models it as follows: ,in, The projection matrix is represented; the gating weight vector is determined based on global and local temporal features. The global and local temporal features are concatenated, and the gating weight vector of the global temporal features is obtained through linear mapping and activation functions, modeled as follows: ,in, express The Middle Global temporal features of each segment express The Middle Local temporal features of each segment , Represent the learnable parameters; let The gated weight vector represents the local temporal features, based on , The global and local temporal features are fused and modeled as follows: ,in, This indicates element-wise multiplication. Let represent a vector consisting entirely of 1s, and let Indicates the first The data sample at the ... The spatiotemporal fusion characteristics of an expert network.
[0044] Step 6: Construct the loss function.
[0045] Based on spatiotemporal fusion feature embedding representation, for a given reconstructed sample, positive and negative samples are defined, and a contrastive learning loss function is constructed, letting... , They represent , The spatiotemporal fusion features obtained through expert network output are used to... , The embedding representation is obtained by performing nonlinear mappings separately, and the model is as follows: , ,in, , , Indicates the embedding dimension. This represents a nonlinear mapping network, using cosine similarity to measure the correlation between the embedded representations of two samples, and is modeled as follows: ,in, Let represent the cosine similarity function. For a given reconstructed sample, let its corresponding augmented sample be a positive sample, and all other reconstructed samples and their corresponding augmented samples be negative samples. Construct a contrastive learning loss function, modeled as follows: ,in, This represents the temperature coefficient.
[0046] Based on the complete data samples reconstructed by WGAN and the reconstructed data samples, a reconstruction loss function is constructed. Specifically, the output features of each expert network are weighted and fused according to the routing weights, and the model is as follows: ,in, Indicates the first The data sample at the ... The routing weights of each expert network, for Perform decoding and reconstruction, so that Indicates the first The output corresponding to each data sample is used to construct a reconstruction loss function, which is modeled as follows: ,in, Represent the mean squared error function; construct the loss function, modeled as: ,in, This is a hyperparameter.
[0047] Step 7: Anomaly detection based on the bidirectional exponentially weighted smoothing Bi-AEWMA method.
[0048] Based on the reconstructed complete data sample and the reconstructed data sample, calculate the residual matrix and residual sequence, and calculate... and residual matrix The model is as follows: Calculate the first The residual values of each data sample are modeled as follows: ,in, express Norm, to obtain residual sequence The Bi-AEWMA method was used to smooth the residual sequence in both forward and reverse directions, letting... and They represent the first The forward and reverse smoothing values of the residuals of each data sample are modeled as follows: , , , , , ,in, This represents the residual sequence smoothing factor; the forward and reverse smoothing values are fused to obtain the first... The residuals of each data sample after bidirectional smoothing are modeled as follows: The smoothed residual sequence is obtained. ,calculate The mean and standard deviation are modeled as follows: , Calculate the abnormal threshold The model is as follows: ,in, This represents the threshold adjustment coefficient; the smoothed residual value is compared with the judgment threshold for discrimination. Then determine the drone's first An anomaly was detected in the first data sample, triggering an alert; otherwise, the drone's first... The data samples are in a normal state.
[0049] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A method for detecting unmanned aerial vehicle (UAV) anomalies based on multi-scale spatiotemporal graph representation and contrastive learning, characterized in that, Includes the following steps: S1: Multivariate flight data acquisition and preprocessing; Specifically, the process involves: collecting multi-dimensional flight data from drones, constructing a unified timeline, resampling and aligning the data with timestamps, generating a missing mask, normalizing the data, and constructing data samples based on the sliding window method. S2: Sample construction based on Wasserstein generative adversarial network and masking enhancement; specifically: extract sample features using Wasserstein generative adversarial network WGAN, capture the correlation between variables and the temporal relationship within variables using attention mechanism, construct the loss function of generator and discriminator to obtain the reconstructed complete data sample, and construct enhanced samples using random masking strategy; S3: Construct a multi-scale adaptive routing mechanism; specifically: perform seasonal trend decomposition on the data samples, then fuse the seasonal terms, trend terms and the original data samples to obtain a temporal routing representation, and adaptively determine the expert network routing weights based on the temporal routing representation. S4: Capture spatial relationships between variables based on graph multi-head self-attention mechanism; specifically: divide the input sample into multiple segments according to the segment scale of each expert network and map them to hidden node features; The spatial relationships between nodes are determined based on the graph multi-head self-attention mechanism, and the sample feature matrix is updated accordingly. S5: Capturing temporal correlations of segments based on a hybrid encoder; specifically: the constructed hybrid encoder consists of a multi-head self-attention mechanism, a multi-branch deep convolutional network, and an adaptive gating mechanism, wherein the multi-head self-attention mechanism captures global temporal features, and the multi-branch deep convolutional network captures local temporal features; the gating weight vector is determined based on the global and local temporal features, thereby obtaining spatiotemporal fusion features; S6: Construct the loss function; specifically: based on the spatiotemporal fusion feature embedding representation, for a given reconstructed sample, define positive and negative samples, and construct a contrastive learning loss function; construct a reconstruction loss function based on the complete data sample reconstructed by WGAN and the reconstructed data sample, and then construct a system loss function based on the contrastive learning loss function and the reconstruction loss function; S7: Anomaly detection based on the Bi-AEWMA method of bidirectional exponential weighted smoothing; specifically: based on the reconstructed complete data sample and the reconstructed data sample, calculate the residual matrix and residual sequence, use the Bi-AEWMA method to smooth the residual sequence, compare the smoothed residual value with the threshold, and determine whether the UAV flight status is abnormal.
2. The UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning according to claim 1, characterized in that: In S1, the multivariate flight data acquisition and preprocessing specifically involves: Let K represent the number of flight state variables, V k V represents the k-th flight state variable. k The sampled dataset is ,in, V represents k In the The sampled values at each sampling time point V represents k The nth sampling timestamp, V represents k The number of sampling points ; Resample and timestamp-align the sampled datasets for each flight state variable, so that Indicates the sampling start timestamp. Indicates the sampling interval. Indicates the first From the sampling timestamps, we can obtain: , , Indicates the number of sampling timestamps; let , V k In the The sampled values and missing value identifiers at each sampling time point, if ,but , ;make This indicates a preset time interval threshold. and Then, linear interpolation is used to determine V. k exist The sampled value at the location, and Set to 1, that is: , Otherwise, V k In the The sampled value at each sampling time point is 0, and... Setting it to 0 indicates missing data, that is: , ;make , Representing the multivariate flight data and the missing mask matrix respectively, we can obtain , ;right Perform normalization, let , V k The mean and standard deviation are modeled as follows: , ;make V represents k In the The normalized values at each sampling time point are modeled as follows: ;make Representing the normalized UAV flight data, we can obtain Using the sliding window method and Divide into N data samples, let This indicates the size of the sliding window and the sliding step. and They represent the first From the data samples and the missing mask samples, we can obtain , ,in, , , .
3. The UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning according to claim 1, characterized in that: In S2, the sample construction based on the Wasserstein generative adversarial network and mask enhancement is specifically as follows: the constructed Wasserstein generative adversarial network consists of a feature extractor, a generator, and a discriminator; the input feature vector of the WGAN is constructed, letting... Indicates the first V in a data sample k At the sampling time point The feature vectors are modeled as follows: ,in, This represents the input feature mapping matrix. Indicates the bias term. This indicates the hidden feature dimension; a self-attention mechanism is used to capture the correlation between variables, making... Indicates the first Each data sample at the sampling time point The feature matrix, based on Construct query vector Key vector Sum value vector The model is as follows: , , ,in , , These represent the query, the key-value mapping matrix, and capture the relationships between variables. After representing the association between aggregate variables, the first... Each data sample at the sampling time point The feature matrix is modeled as follows: ,in, Indicates the vector scaling factor; A self-attention mechanism is used to capture the temporal correlation of the same variable, allowing... Indicates the first V in a data sample k The time feature matrix, based on Construct query vector Key vector Sum value vector The model is as follows: , , ,in, , , These represent the query, key, and value mapping matrices, respectively, capturing the temporal relationships between variables. After representing the aggregation time-series association, the first V in a data sample k The feature matrix is modeled as follows: ,make Indicates the first The feature matrix of each data sample; a random masking strategy is used to... Perform a masking operation, making Indicates the first The random mask matrix of each data sample can be obtained. ,in, ;Will Input generator, let Representing the generator's output samples, we can obtain ,in, Represents a generator. Let represent the parameter vector of the generator, and let Indicates will The complete data sample after replacing the masked data with the generator's output data can be obtained. ,in, This indicates element-wise multiplication. Let represent a matrix of all 1s; let Indicates the discriminator pair The test score, for the data sample Define the discriminator loss as The generator loss is ,in, Represents the mean function, For hyperparameters, Describing the L2 norm, Let represent the parameter vector of the discriminator, and let This represents the complete data sample after reconstruction, which can be obtained. Enhanced samples are constructed using a random masking strategy. Setting the values of some flight state variables in the time series to 0 can yield enhanced samples. ,in, , Let represent a vector consisting entirely of 1s, and let This indicates the number of flight state variables randomly selected. , Indicates the preset mask ratio. This indicates the rounding up operation.
4. The UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning according to claim 1, characterized in that: In S3, a multi-scale adaptive routing mechanism is constructed, specifically by: performing seasonal trend decomposition on the data samples, then fusing the seasonal term, trend term, and original data samples to obtain a temporal routing representation, and adaptively determining the expert network routing weights based on the temporal routing representation. Specifically, let... The input sample is extracted using the Discrete Fourier Transform (DFT). frequency domain amplitude ,Right now: Select the one with the highest percentage of amplitude Each dominant frequency component is used to construct a frequency domain sample, and the inverse discrete Fourier transform (IDFT) is used to extract the input sample. Seasonal items ,make This represents the residual term after removing the seasonal term, and the trend term is extracted based on the multi-scale average pooling method. ,in, This represents the weights corresponding to different scales. Indicates a linear layer. Indicates the first Average pooling function for each kernel To indicate the number of nuclei, let This indicates that the input sample, seasonality, and trend are fused and then obtained based on a linear mapping to obtain the first... Temporal routing representation of each data sample, based on The expert network routing weight vector is calculated and modeled as follows: ,in, , Indicates the routing function. , All are learnable parameters. Indicates the number of expert networks, selected before Find the maximum weight and set the remaining weights to 0 to obtain the updated route weight vector. , .
5. The UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning according to claim 1, characterized in that: In S4, spatial relationships between variables are captured based on a graph multi-head self-attention mechanism. Specifically, this involves: according to the fragment scale of each expert network, the input samples... Divide the data into multiple segments along the time dimension to obtain a segment sequence; let Indicates the first The size of a segment in an expert network. Indicates the first In an expert network, the input sample The partitioned sequence is defined as: ,in, express The A segment, Indicates the first In the expert network, the first The first data sample V in the segment k The sampled value vector, Indicates the first The number of segments in an expert network ;right The hidden features are obtained by performing a linear transformation, and the model is as follows: ,in, Indicates the first The segment feature mapping matrix of an expert network. Indicates the bias term. Let the first dimension represent the node feature dimension; The first expert network The node feature tensor of each data sample is Each node feature is used Group-independent learnable parameters, mapped to The subspaces with different characteristics are modeled as follows: ,in, Indicates the attention head number, Indicates the first The first expert network The linear projection matrix of each attention head. Represents the feature dimension of the subspace; the first dimension of the same segment Within each subspace, calculate the spatial association score between any two nodes, let Indicates the first segment of the same segment Within a subspace, nodes and Spatial association scores are modeled as follows: ,in, , Indicates the first The first expert network Shared attention weight vector for each size This indicates a splicing operation. Represents a nonlinear activation function; based on The corresponding attention weights are calculated and modeled as follows: ,calculate The average of the feature outputs of each subspace is used to obtain the final spatially enhanced node features, which are modeled as follows: ,make After representing the relationships between nodes aggregated by multi-head self-attention in the graph, the th The data sample at the ... Feature matrix in an expert network.
6. The UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning according to claim 1, characterized in that: In S5, the temporal correlation of segments is captured based on the hybrid encoder, specifically as follows: Let Indicates the first The data sample at the ... The first expert network Spatial enhancement features of individual segments, for Construct a time token, modeled as follows: ,in, Indicates the first A time token mapping matrix for an expert network, Indicates the bias term. Representing the time token feature dimension; employing multi-head self-attention to capture the global temporal correlation of segments, making... Indicates the first The data sample at the ... A time token sequence for an expert network; the number of time attention heads is set to [number]. ,based on Construct query vector Key vector Value vector The model is as follows: , , ,in, , , Represents the projection matrix. , The feature dimension representing the temporal attention head captures the global temporal correlation of segments and is modeled as follows: By concatenating the outputs of all attention heads along the feature dimension, we can obtain: ,in, Indicates the first The global temporal feature mapping matrix of an expert network; a multi-branch deep convolutional network is used to capture the local temporal correlation of segments, specifically, let This indicates the number of convolutional branches in a multi-branch depthwise convolutional network. Indicates the first The kernel size corresponding to each convolutional branch ,make Indicates the first The output of each convolutional branch is modeled as follows: ,in, Indicates the first The one-dimensional convolution operation of each convolution branch concatenates the temporal features output by all convolution branches along the feature dimension, and models it as follows: ,in, The projection matrix is represented; the gating weight vector is determined based on global and local temporal features. The global and local temporal features are concatenated, and the gating weight vector of the global temporal features is obtained through linear mapping and activation functions, modeled as follows: ,in, express The Middle Global temporal features of each segment express The Middle Local temporal features of each segment , Represent the learnable parameters; let The gated weight vector represents the local temporal features, based on , The global and local temporal features are fused and modeled as follows: ,in, This indicates element-wise multiplication. Let represent a vector consisting entirely of 1s, and let Indicates the first The data sample at the ... The spatiotemporal fusion characteristics of an expert network.
7. The UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning according to claim 1, characterized in that: In step S6, the loss function is constructed as follows: based on the spatiotemporal fusion feature embedding representation, for a given reconstructed sample, positive and negative samples are defined, and a contrastive learning loss function is constructed, letting... , They represent , The spatiotemporal fusion features obtained through expert network output are used to... , The embedding representation is obtained by performing nonlinear mappings separately, and the model is as follows: , ,in, , , Indicates the embedding dimension. This represents a nonlinear mapping network, using cosine similarity to measure the correlation between the embedded representations of two samples, and is modeled as follows: ,in, Let represent the cosine similarity function. For a given reconstructed sample, let its corresponding augmented sample be a positive sample, and all other reconstructed samples and their corresponding augmented samples be negative samples. Construct a contrastive learning loss function, modeled as follows: ,in, This represents the temperature coefficient. Based on the complete data samples reconstructed by WGAN and the reconstructed data samples, a reconstruction loss function is constructed. Specifically, the output features of each expert network are weighted and fused according to the routing weights, and the model is as follows: ,in, Indicates the first The data sample at the ... The routing weights of each expert network, for Perform decoding and reconstruction, so that Indicates the first The output corresponding to each data sample is used to construct a reconstruction loss function, which is modeled as follows: ,in, Represent the mean squared error function; construct the loss function, modeled as: ,in, This is a hyperparameter.
8. The UAV anomaly detection method based on multi-scale spatiotemporal graph representation and contrastive learning according to claim 1, characterized in that: In S7, the UAV anomaly determination based on the bidirectional exponentially weighted smoothing Bi-AEWMA method specifically involves: calculating the residual matrix and residual sequence based on the reconstructed complete data sample and the reconstructed data sample, and calculating... and residual matrix The model is as follows: Calculate the first The residual values of each data sample are modeled as follows: ,in, express Norm, to obtain residual sequence The Bi-AEWMA method was used to smooth the residual sequence in both forward and reverse directions, letting... and They represent the first The forward and reverse smoothing values of the residuals of each data sample are modeled as follows: , , , , , ,in, This represents the residual sequence smoothing factor; the forward and reverse smoothing values are fused to obtain the first... The residuals of each data sample after bidirectional smoothing are modeled as follows: The smoothed residual sequence is obtained. ,calculate The mean and standard deviation are modeled as follows: , Calculate the abnormal threshold The model is as follows: ,in, This represents the threshold adjustment coefficient; the smoothed residual value is compared with the judgment threshold for discrimination. Then determine the drone's first An anomaly was detected in the first data sample, triggering an alert; otherwise, the drone's first... The data samples are in a normal state.
