Time sequence anomaly detection method based on PatchTST dual reconstruction consistency constraint
By employing the PatchTST dual reconstruction consistency constraint method, combined with a Transformer encoder and a dual-branch GRU, the global-local feature fusion problem of multivariate time series data is solved, improving the robustness and accuracy of anomaly detection. This method is applicable to scenarios such as industrial control systems and network traffic monitoring.
Patent Information
- Application Number
- CN202511647208.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-11
- Publication Date
- 2026-03-10
AI Technical Summary
Existing time series anomaly detection methods struggle to effectively integrate global and local features when dealing with multivariate data, and lack multiple reconstruction constraints, leading to false positives or false negatives. In particular, the simplified handling of missing values affects detection accuracy and robustness.
The PatchTST dual reconstruction consistency constraint method is adopted. Global context features are obtained through the Transformer encoder, local features are extracted by combining dual-branch GRU and convolution operation, and consistency constraints are introduced to optimize the stability and accuracy of reconstruction results.
It enhances the ability to model complex time-series patterns, improves the robustness and accuracy of anomaly detection, optimizes the ability to handle data defects, and increases the flexibility and applicability of anomaly judgment, making it suitable for diverse scenarios such as industrial control systems and network traffic monitoring.
Smart Images

Figure CN121637381A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of time series anomaly detection, and particularly relates to a time series anomaly detection method based on PatchTST dual reconstruction consistency constraint. BACKGROUND
[0002] In the fields of industrial control systems, network traffic monitoring, medical monitoring devices, financial transaction records, etc., multivariate time series data is the core carrier reflecting the system operation state, equipment working condition or physiological indicators. Such data usually contains multiple parallel monitoring variables and dynamically changes over time. The normal mode often presents complex time-dependent and variable coupling relationships. At the same time, in the actual collection process, it is inevitably affected by factors such as sensor failure, transmission interference and environmental noise, and there are problems such as missing values, abnormal sampling points and dimension differences, which bring significant challenges to anomaly detection. The core goal of anomaly detection is to identify "abnormal signals" that deviate from the normal operation mode from time series data. Such anomalies often correspond to key events such as system failure, network attack, and sudden illness. Timely and accurate anomaly detection is of great significance to ensure stable system operation and reduce security risks. Traditional time series anomaly detection methods mainly fall into three categories: the first is based on statistics, such as fitting normal time series patterns with ARIMA models and identifying outliers that deviate from the mean. However, this method has poor adaptability to non-stationary data and is difficult to handle complex correlations between multiple variables. The second is based on traditional machine learning methods, such as using isolation forest and support vector machine models to construct normal mode boundaries. However, this method has limited feature extraction capability when dealing with global dependencies and local mutation characteristics of long time series data. The third is early deep learning methods, such as recurrent neural network models based on LSTM and GRU. Although they can capture time-dependent relationships, they have weak global context modeling capabilities for long sequences and are prone to gradient vanishing or pattern forgetting problems. Time series modeling methods based on Transformer have shown advantages in time series data processing due to their global dependency modeling capabilities. PatchTST can efficiently learn the global patterns of long sequences by dividing time series data into patches and mapping them to hidden spaces. However, there are two main shortcomings when using PatchTST alone: first, relying solely on a single reconstruction process makes it vulnerable to noise interference, leading to ambiguous boundaries between abnormal and normal patterns. Second, it lacks consistency constraints on the reconstruction results, which may cause false positives or false negatives due to single reconstruction bias. Moreover, existing techniques have a simple approach to handling missing values in the data preprocessing stage, filling them with mean or interpolation without considering the impact of missing duration on data authenticity, which may introduce false features. In time series feature modeling, either only global dependencies or only local features are considered, and there is a lack of effective global-local feature fusion mechanism. In the anomaly judgment stage, multiple reconstruction errors are mainly relied on, and the complementarity of multi-branch modeling is not fully utilized, making it difficult to balance detection accuracy and robustness.
[0003] Therefore, there is an urgent need for a technical solution that can efficiently handle data defects, fuse global-local time series features, and improve the reliability of anomaly detection through multiple reconstruction constraints to meet the actual needs of multivariate time series anomaly detection in complex scenarios. SUMMARY
[0004] The technical problem solved by the present application is a time series anomaly detection method based on PatchTST double reconstruction consistency constraint, which can efficiently process data defects, fuse global-local time series features, and improve the reliability of anomaly detection through multiple reconstruction constraints to meet the actual needs of multivariate time series anomaly detection in complex scenarios.
[0005] To solve the above technical problems, the technical scheme adopted by the present application is: a time series anomaly detection method based on PatchTST double reconstruction consistency constraint, comprising the following steps: S1, obtaining multivariate time series data, preprocessing the multivariate time series data, the preprocessing operation including missing value processing, normalization processing, and detrending processing; S2, dividing the data after S1 preprocessing into several patches, each patch being input into a Transformer encoder as a token to obtain global context features; S3, inputting the Transformer encoder output features into an MLP decoding head to perform the first reconstruction to obtain the first reconstruction result X recon1 ; S4, weighting fusion of the original input and the first reconstruction result X recon1 to obtain fusion data X fuse ; S5, performing convolution on the fusion data X fuse to obtain a convolution feature map F1; S6, double-branch time series modeling: Branch one: inputting the convolution feature map F1 into a gated recurrent unit GRU to obtain a time series feature map Feat A ; Branch two: twice convolution of the convolution feature map F1, then inputting into a gated recurrent unit GRU, and then recovering the time dimension through deconvolution to obtain a time series feature map Feat B ; S7, concatenating the time series feature map Feat A and the time series feature map Feat B to input into a decoder to obtain a final fusion reconstruction result X recon2 ; S8, obtaining an anomaly score based on the second reconstruction error and the consistency error, and performing time step anomaly detection by comparing the anomaly score with a threshold.
[0006] In S1, the missing value processing specifically includes: The threshold T is set to 5 time steps. When the length of consecutive missing data is less than the threshold T, a padding method based on the mean of the sliding window is adopted. When the missing span is greater than T, a masking mechanism is introduced, that is, zeros are padded in the data tensor, and a mask matrix of the same shape is constructed to mark the missing positions. The masking mechanism is specifically as follows: In the original multivariate time series data tensor, fill all positions with 0 for any consecutive missing length greater than T time steps. At the same time, create a binary mask matrix with the same shape as the data tensor to mark the state of each data point. If the original data is a true observation at that time step, the value of the corresponding position in the mask matrix is 1; if it is a time step that has been padded with 0, the value of the corresponding position in the mask matrix is 0. Data with missing values processed is input along with the data during forward propagation; In S1, the normalization process specifically includes: To perform z-score standardization for each dimension: (1); In formula (1): This represents time series data after z-score standardization. This represents the raw numerical values of the input time series, where μ and σ are the mean and standard deviation on the training set, respectively. In S1, the specific method of detrending processing is as follows: If the original data has a clear long-term trend, first-order differencing is used for detrending, and zero-padding is performed at the beginning of the first-order differencing sequence. The first-order difference operation: First-order differencing eliminates long-term trends in the original data by calculating the difference between two adjacent time steps, resulting in a first-order differencing sequence: (2); In formula (2): This represents the difference between time step t and the previous time step (t-1), i.e., the change in the original time series data between adjacent time steps. ,when At that time, because it did not exist The difference sequence will have a missing value at the beginning position. Therefore, in order to keep the difference sequence the same length as the original sequence, ... Missing values at a location are filled with zeros, i.e. , where n is the sequence length.
[0007] S2 includes the following steps: S2.1, the preprocessed input tensor:
[0008] Divided into continuous patches of length p according to the time dimension; In formula (3): This represents a real number data type, used to describe tensors. All elements stored in it are real numbers; Indicates batch size. Indicates the number of dimensions of the variable. ; S2.2 flattens each patch into a one-dimensional vector and maps it to a fixed-length vector through a linear projection layer; After dimensional rearrangement, the patch becomes a one-dimensional vector: (4); In equation (4): Let represent the two-dimensional feature matrix obtained after flattening the i-th time series patch. This indicates that the flattened feature matrix is a two-dimensional real tensor; Then through a learnable linear transformation matrix The flattened patch vector is mapped to the latent space dimension d of the Transformer encoder: (5); In formula (5): , This represents the compressed vectorized representation of the i-th time series Patch after linear projection; is a learnable neural network weight matrix that is responsible for converting a flattened high-dimensional data slice vector into a fixed-dimensional latent feature vector. This conversion process extracts and compresses the core pattern information from the original data by learning the optimal mapping relationship, so that it can be processed by subsequent modules. b is a learnable bias term. S2.3, stack the projection results of all patches to form a sequence input; (6); In formula (6): This represents a batch processing sequence tensor formed by stacking the projection results of all patches. This represents the compressed vectorized representation of the i-th time series patch after linear projection. express It is a three-dimensional real tensor containing B independent sequences, each of which consists of N elements, and each element is represented by a d-dimensional eigenvector; S2.4, Add learnable positional encoding to the input sequence Z in S2.3. : (7); In equation (7): This represents a position-aware sequence tensor that simultaneously contains semantic content information of the original time segment and its position information within the entire sequence. It is a learnable positional code whose core function is to provide the model with explicit information about the order of each patch in the sequence; Structurally, Defined as a two-dimensional, trainable parameter matrix, its mathematical representation is: (8); In equation (8): the first dimension N represents the number of rows of the matrix, and its value corresponds to the length of the input sequence Z; the second dimension d represents the number of columns of the matrix, and its value is consistent with the dimension of the latent feature vector of each time slice. By using the position vector of the corresponding position content feature vectors of the corresponding time slices By adding them together, the model generates a position-aware sequence tensor. This injects the order of the sequence into the originally disordered set of features; S2.5 takes the sequence from S2.4 with the addition of learnable position encoding and inputs it into a multi-layer Transformer encoder. This part of the encoder structure includes a multi-head self-attention layer, a feedforward network, residual connections, and LayerNorm.
[0009] The core computation of the Transformer encoder is a self-attention mechanism: (9); In equation (9): This represents the attention output calculated using Q, K, and V. Each is derived from the input The query, key, and value obtained from a linear transformation; The calculation result is an attention weight matrix. In this part, it is first calculated by... Calculate the association score for each query pair across all keys in the sequence, and then... Perform numerical scaling, and finally... The function normalizes these scores to a probability distribution that sums to 1. This represents the transpose of the key matrix K. After transposing, the dot product similarity between the query matrix Q and all keys can be calculated. Indicates the dimension of the key vector; After Transformer encoding, the output feature matrix is obtained: (10); In equation (10): the feature matrix H is a sequence representation that deeply integrates contextual information, and is related to the input. compared to, Although they have the same shape, H is a context-aware feature representation with a global perspective, formed by weighted aggregation of all other patch information in the sequence through a self-attention mechanism.
[0010] In S3, the MLP decoding head consists of three fully connected layers, wherein each of the two hidden layers is followed by a non-linear activation function ReLU and Dropout. The Dropout operation is a random shutdown of neurons, which uses a preset probability p to randomly and temporarily set the output of a portion of neurons to zero; S3 further includes: S3.1, reshape the reconstruction result of each patch into the same shape as the original patch: (11); In equation (11): This represents the reconstruction result of the i-th patch, which is the flattened vector output by the MLP decoder head. The result obtained after the Reshape operation Represents a single Patch tensor after reconstruction. Mathematical space and three-dimensional shape, B indicates that the elements in the tensor are real numbers, C indicates the number of variable dimensions, and P indicates the time step length of each patch. S3.2, Reassemble all patches in chronological order: In PyTorch, directly... Input the data into the `concatenate` function to get the final refactoring result; The final splicing result is: (12); In equation (12): The final shape of the complete, end-to-end time series reconstruction result generated by the representative model in the first stage. Consistent with the shape of the initial input tensor of the model. This represents all the reconstructed independent time segments, each Each of these is a three-dimensional tensor of shape B×C×P, which is the reconstruction result of the model decoder of the original i-th time segment.
[0011] In S4, weighted fusion specifically involves generating input fusion data for subsequent bi-branch modeling by using an element-wise weighted summation method. The original input sequence is The result of the first reconstruction is The element-wise weighted summation method is as follows: , (13); In equation (13): The fusion coefficient is a hyperparameter. To convert the original input and The first reconstruction result The result of linear combination preserves both the true details of the original signal and the underlying structure processed by the Transformer.
[0012] In S5, the convolutional structure uses a one-dimensional convolutional kernel of size k that slides along the time dimension. When the missing span in S1 is greater than the threshold T and a missing mask is used, the mask matrix is used as an additional channel in this convolutional part and fused with the data. Convolution with input together; the convolution operation is as follows: ; In equation (14): It is a local temporal feature matrix generated after the Conv1D operation, which is a comprehensive representation of local waveform features extracted by the convolutional layer and multivariate correlation features. This represents a one-dimensional convolution kernel pair of size k. Slide along the time dimension, for Perform local feature extraction; The shape of the output feature map is: (15); In equation (15): The number of output channels for the convolution. , The length of the time dimension after convolution. In this case, the convolution kernel k=3, the dilation rate d=1, the stride s=1, and the padding p=(k-1) / 2, therefore the output length is still L, i.e. ; In S6, based on the convolutional feature map obtained in S5, a dual-branch temporal modeling based on convolution and gated recurrent unit (GRU) is adopted to obtain complementary temporal features. Branch 1: Using direct time series modeling, Transpose ,Will Input GRU: (16); In equation (16): the hidden dimension of GRU is The output shape is (B, , ); Will Transpose back to the original dimension: , ; In equation (17): This represents the time-series feature matrix output after learning and transposing by the GRU. This is a tensor dimension rearrangement operation, representing the feature matrix output by the GRU. The core of dimensional rearrangement is adjusting the order of dimensions; Branch Two: First, check... Perform a second convolution to extract higher-order local patterns, then use GRU to model these more robust temporal signals, and finally use deconvolution to restore the same time dimension as branch one. This part combines the representation of local details and cross-time information. Secondary convolution: for Execute Conv1d to extract the local time pattern: (18); In formula (18): This represents the high-order local feature matrix obtained after performing a second one-dimensional convolution on the convolutional feature map F1 of branch one, with dimensions of... , This represents the number of output channels for the second convolution. This represents a one-dimensional convolution kernel pair of size k. Slide along the time dimension, for Perform a secondary feature extraction operation; Then Input GRU: The hidden dimension of GRU is The output shape is (B, , ); To ensure alignment with the time dimension of branch one, the GRU output is transposed as follows: ; Using ConvTranspose1D to perform a deconvolution operation, the deconvolution yields: (19); In equation (19): This is the timing feature map of the final output of branch two. Indicates to Perform the deconvolution operation.
[0013] In S7, the splicing includes splicing along the feature dimension. : (20); In equation (20): It is The fused feature map is obtained by concatenating the features along the feature dimension. This indicates an operation that concatenates the features of the two branches along the H feature dimension; The First transpose to sequence format Then, the hidden features are remapped to the same dimension as the original input in the MLP decoder: (twenty one); In equation (21): Indicates the fusion of features The feature matrix obtained after mapping by the MLP decoder The feature mapping operation is represented by an MLP consisting of multiple fully connected layers. Each layer introduces non-linearity through the ReLU activation function, and finally maps the 2H dimension to the C dimension through the output layer. The purpose of transposition is to... The dimension from " "Transformed into the preprocessed input" Dimensions To maintain consistency, the permute operation is used to obtain the final secondary reconstruction result. ; The permute operation specifically refers to directly referencing the dimension rearrangement operation in the code.
[0014] In S8, Anomaly scores are obtained based on the secondary reconstruction error and consistency error: Consistency regularization constraints are introduced during training to avoid detection instability caused by excessive differences between the two reconstruction results; The first reconstruction error is defined as: (twenty two); In equation (22): The first reconstruction loss is represented by the squared Euclidean distance between the original sequence and the first reconstruction result, which quantifies the accuracy of the reconstruction. It represents the reconstruction capability of a branch pair of the original input. This represents the original input time series tensor after preprocessing. This represents the time series result of the first reconstruction. The second reconstruction error is defined as: (twenty three); In equation (23): The loss represents the second reconstruction, calculating the difference between the original input sequence and the reconstruction result after the two-branch fusion. This represents the global reconstruction capability of the fusion branch on the input. This represents the second reconstructed time series result generated after dual-branch time series modeling and the final decoder; Introducing a consistency regularization term: (twenty four); In equation (24): The consistency loss is used to quantify the difference between the two reconstruction results. This term acts as a regularization constraint, forcing the model in this instance to learn a consistent sequence representation on two different decoding paths, thereby enhancing the stability and robustness of the model. The ultimate training goal is: (25); In equation (25): The final loss function used for model training is a weighted sum with coefficients... Coefficients used to control the importance of the second reconstruction. The weights used to adjust the consistency regularization are L, which is the total loss function. After the model training is complete, load the trained model for the test sequence. Calculate the error under each of the two reconstructions: , (26); In equation (26): This represents the outlier score calculated based on the first reconstruction. This represents the outlier score calculated based on the second reconstruction. The two outlier scores are then merged to obtain the final outlier score: (27); In equation (27): This represents the final fusion anomaly score at time step t. These are the weighting coefficients; Threshold setting uses the percentile method: A series of anomaly scores are calculated for normal samples on the training set. This forms a distribution; Next, select the q-percentile to set the threshold θ: (28); In equation (28): Percentile is a function for calculating percentiles, and q is a preset hyperparameter whose value defines the rarity of the anomaly; If the final anomaly score of the test sequence at time step t... If so, that moment is considered abnormal.
[0015] The main beneficial effects of this invention are as follows: 1. Enhance the ability to model complex time series patterns: By capturing the global contextual dependencies of multivariate time series using PatchTST's Transformer encoder, and combining a dual-branch GRU with convolutional operations to extract local fine features, a deep fusion of global and local features is achieved. This solves the problems of insufficient global dependency modeling or coarse local feature capture in traditional methods for long sequences, and is more adaptable to complex time series data that are non-stationary and coupled with multiple variables.
[0016] 2. Enhance the robustness and accuracy of anomaly detection: A dual reconstruction consistency constraint mechanism is introduced: the first reconstruction recovers the overall data pattern based on global features, and the second reconstruction optimizes the detailed representation by combining local features. Simultaneously, the deviation between the two reconstruction results is constrained through consistency error. This design reduces the impact of noise interference on the single reconstruction process, makes the boundary between abnormal and normal patterns clearer, and effectively reduces false positives and false negatives.
[0017] 3. Optimize the ability to handle data defects; adopt a tiered handling strategy for missing values: Short-term missing values are filled with the mean of a sliding window to preserve local trends, while long-term missing values are filled with zeros and marked with a mask matrix, avoiding false features introduced by the traditional uniform filling method. At the same time, z-score normalization and detrending processing reduce the interference of dimensional differences and non-stationarity on the model, improving the detection stability in high-noise and multi-missing test scenarios.
[0018] 4. Improve the flexibility and applicability of anomaly detection: The anomaly score calculation integrates the errors from two reconstructions, taking into account both global pattern deviations and local detail anomalies. The threshold setting adopts the percentile method, which can be dynamically adjusted according to the false alarm tolerance of different scenarios, making it suitable for diverse needs such as industrial monitoring and network monitoring, thus expanding the practical scope of the technical solution. Attached Figure Description
[0019] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0020] Fig. 1 This is a flowchart of the present invention.
[0021] Fig. 2 This is a schematic diagram of the process of the present invention. Detailed Implementation
[0022] like Figs. 1-2 The present invention relates to a time series anomaly detection method based on PatchTST dual reconstruction consistency constraints, comprising the following steps: S1, acquire multivariate time series data, and preprocess the multivariate time series data. The preprocessing operations include missing value handling, normalization, and detrending. S2 divides the preprocessed data from S1 into several patches, and each patch is used as a token to input the Transformer encoder to obtain global context features; S3, input the output features of the Transformer encoder into the MLP decoder head for the first reconstruction, and obtain the first reconstruction result X. recon1 ; S4. Compare the original input with the first reconstruction result X recon1 Weighted fusion yields fused data X. fuse ; S5, for fused data X fuse Perform convolution to obtain the convolutional feature map F1; S6, dual-branch timing modeling: Branch 1: The convolutional feature map F1 is input into the gated recurrent unit (GRU) to obtain the temporal feature map Feat. A ; Branch 2: The convolutional feature map is subjected to a second convolution (F1), then input into a gated recurrent unit (GRU), and subsequently deconvolution is used to recover the time dimension, resulting in the temporal feature map. B ; S7, Feat the time series feature map A With temporal feature map Feat B The components are concatenated and input into the decoder to obtain the final fused and reconstructed result X. recon2 ; S8. Based on the secondary reconstruction error and consistency error, anomaly scores are obtained, and time-step anomaly detection is performed by comparing the anomaly scores with the threshold.
[0023] Multivariate time series data can come from scenarios such as industrial control systems, network traffic monitoring, and medical monitoring equipment. This type of data usually contains multiple parallel detection variables and there are missing and abnormal sampling points in the actual collection process. Therefore, in order to ensure the stability of the model input, this embodiment performs preprocessing operations on the raw data.
[0024] Preferably, in S1, the missing value processing specifically includes: The threshold T is set to 5 time steps. When the length of consecutive missing data is less than the threshold T, a padding method based on the mean of the sliding window is adopted. When the missing span is greater than T, a masking mechanism is introduced, that is, zeros are padded in the data tensor, and a mask matrix of the same shape is constructed to mark the missing positions. This is input together during the forward propagation of the model, so that the model can distinguish between real data and padded data, thereby avoiding incorrect learning and improving the model's adaptability to missing test scenarios. The masking mechanism is specifically as follows: In the original multivariate time series data tensor, fill all positions with 0 for any consecutive missing length greater than T time steps. At the same time, create a binary mask matrix with the same shape as the data tensor to mark the state of each data point. If the original data is a true observation at that time step, the value of the corresponding position in the mask matrix is 1; if it is a time step that has been padded with 0, the value of the corresponding position in the mask matrix is 0. Data with missing values processed is input along with the data during forward propagation; In S1, the normalization process eliminates the differences in the dimensions of each variable and ensures that multivariate features participate fairly in the modeling. Specifically, it includes: To perform z-score standardization for each dimension: (1); In formula (1): This represents time series data after z-score standardization. This represents the raw numerical values of the input time series, where μ and σ are the mean and standard deviation on the training set, respectively. In S1, the specific method of detrending processing is as follows: If the original data has a clear long-term trend, first-order differencing is used for detrending, and zero-padding is performed at the beginning of the first-order differencing sequence. The first-order differencing operation can eliminate long-term trend interference, enabling the model to focus on data fluctuation patterns and improve the detection accuracy of non-stationary sequences. First-order differencing eliminates long-term trends in the original data by calculating the difference between two adjacent time steps, resulting in a first-order differencing sequence: (2); In formula (2): This represents the difference between time step t and the previous time step (t-1), i.e., the change in the original time series data between adjacent time steps. ,when At that time, because it did not exist The difference sequence will have a missing value at the beginning position. Therefore, in order to keep the difference sequence the same length as the original sequence, ... Missing values at a location are filled with zeros, i.e. , where n is the sequence length.
[0025] The above preprocessing can reduce input non-stationarity, eliminate the dimensional differences between different variables, and improve training convergence speed and make threshold determination more stable.
[0026] Preferably, step S2 includes the following steps: S2.1, the preprocessed input tensor:
[0027] Divided into continuous patches of length p according to the time dimension; In formula (3): This represents a real number data type, used to describe tensors. All elements stored in it are real numbers; Indicates batch size. Indicates the number of dimensions of the variable. : ; in: This represents the preprocessed time-series data ready to be input into the model in this instance. It is a three-dimensional tensor. This indicates that the input tensor will be... All continuous subsequences obtained after segmenting by the time dimension L, each patch being a local time segment of the original sequence. This represents the i-th segment extracted from the original data. It contains all B samples and all C variables, but the time length is only P. This indicates the number of patches that can be divided into within a time window. Represents the input time series Length, This represents the predefined duration of a single patch, where L is padded with zeros if it is not divisible by an integer. S2.2 flattens each patch into a one-dimensional vector and maps it to a fixed-length vector through a linear projection layer; After dimensional rearrangement, the patch becomes a one-dimensional vector: (4); In equation (4): Let represent the two-dimensional feature matrix obtained after flattening the i-th time series patch. This indicates that the flattened feature matrix is a two-dimensional real tensor; Then through a learnable linear transformation matrix The flattened patch vector is mapped to the latent space dimension d of the Transformer encoder: (5); In formula (5): , This represents the compressed vectorized representation of the i-th time series Patch after linear projection; is a learnable neural network weight matrix that is responsible for converting a flattened high-dimensional data slice vector into a fixed-dimensional latent feature vector. This conversion process extracts and compresses the core pattern information from the original data by learning the optimal mapping relationship, so that it can be processed by subsequent modules. b is a learnable bias term. S2.3, stack the projection results of all patches to form a sequence input; (6); In formula (6): This represents a batch processing sequence tensor formed by stacking the projection results of all patches. This represents the compressed vectorized representation of the i-th time series Patch after linear projection; express It is a three-dimensional real tensor containing B independent sequences, each of which consists of N elements, and each element is represented by a d-dimensional eigenvector; S2.4, in order to preserve chronological information and enable the model to not only model global dependencies but also distinguish the positions of different patches on the timeline, the specific implementation is as follows: For each Assign a unique time location index i, and then construct a location encoding matrix. Each line It is the position vector of the corresponding patch, parameter The model is randomly initialized at the start of training and automatically updated during training via gradient descent, enabling it to learn the optimal temporal representation. Add learnable positional encoding to the input sequence Z in S2.3 : (7); In equation (7): This represents a position-aware sequence tensor that simultaneously contains semantic content information of the original time segment and its position information within the entire sequence. It is a learnable positional code whose core function is to provide the model with explicit information about the order of each patch in the sequence; Structurally, Defined as a two-dimensional, trainable parameter matrix, its mathematical representation is: (8); In equation (8): the first dimension N represents the number of rows of the matrix, and its value corresponds to the length of the input sequence Z; the second dimension d represents the number of columns of the matrix, and its value is consistent with the dimension of the latent feature vector of each time slice. By using the position vector of the corresponding position content feature vectors of the corresponding time slices By adding them together, the model generates a position-aware sequence tensor. This injects the order of the sequence into the originally disordered set of features; S2.5 takes the sequence from S2.4 with the addition of learnable position encoding and inputs it into a multi-layer Transformer encoder. This part of the encoder structure includes a multi-head self-attention layer, a feedforward network, residual connections, and LayerNorm.
[0028] The core computation of the Transformer encoder is a self-attention mechanism: (9); In equation (9): This represents the attention output calculated using Q, K, and V. Each is derived from the input The query, key, and value obtained from a linear transformation; The calculation result is an attention weight matrix. In this part, it is first calculated by... Calculate the association score for each query pair across all keys in the sequence, and then... Perform numerical scaling, and finally... The function normalizes these scores to a probability distribution that sums to 1. This represents the transpose of the key matrix K. After transposing, the dot product similarity between the query matrix Q and all keys can be calculated. This represents the dimension of the key vector. After Transformer encoding, the output feature matrix is obtained: (10); In equation (10): the feature matrix H is a sequence representation that deeply integrates contextual information, and is related to the input. compared to, Although they have the same shape, H is a context-aware feature representation with a global perspective, formed by weighted aggregation of all other patch information in the sequence through a self-attention mechanism.
[0029] Preferably, in S3, the MLP decoding head consists of three fully connected layers, wherein each of the two hidden layers is followed by a non-linear activation function ReLU and Dropout. The multiple fully connected layers and non-linear activation functions enhance the model fitting ability and can accurately restore the global structure of the normal timing pattern. The fully connected dense layer, also known as the linear layer, is a fundamental component of neural networks. Its main function is to perform a linear transformation on the input vector. However, a network composed solely of stacked fully connected layers is essentially a single-layer linear network. Therefore, non-linearity is introduced through the ReLU activation function. This activation function not only enhances the network's expressive power, enabling it to learn and fit complex, non-linear mappings between input and output, but also alleviates gradient vanishing. Furthermore, in each training iteration, a portion of the neurons' outputs are temporarily set to zero using a preset probability p. This Dropout operation, which randomly shuts down neurons, forces each neuron to learn more independent and robust features, rather than overly relying on the presence of a few other neurons.
[0030] S3 further includes: S3.1, reshape the reconstruction result of each patch into the same shape as the original patch: (11); In equation (11): This represents the reconstruction result of the i-th patch, which is the flattened vector output by the MLP decoder head. The result obtained after the Reshape operation Represents a single Patch tensor after reconstruction. Mathematical space and three-dimensional shape, B indicates that the elements in the tensor are real numbers, C indicates the number of variable dimensions, and P indicates the time step length of each patch. S3.2, Reassemble all patches in chronological order: In PyTorch, directly... Input the data into the `concatenate` function to get the final refactoring result; The final splicing result is: (12); In equation (12): The final shape of the complete, end-to-end time series reconstruction result generated by the representative model in the first stage. Consistent with the shape of the initial input tensor of the model. This represents all the reconstructed independent time segments, each Both are three-dimensional tensors of shape B×C×P, representing the reconstruction result of the model decoder on the original i-th time segment. The goal is to map the PatchTST encoder output H back to the original dimensions to obtain the first reconstruction. This reconstruction primarily preserves the overall pattern of the sequence.
[0031] Preferably, in S4, the weighted fusion specifically generates the input fusion data for subsequent bi-branch modeling by using an element-wise weighted summation method. S4 retains the original input features while introducing reference information from the first reconstruction. In high-noise or sensor-drift environments, the normal benchmark provided by the reconstruction sequence can reduce the direct impact of abnormal noise. Furthermore, when the original input differs significantly from the reconstruction result, the fused input will strengthen the abnormal signal in subsequent modeling, making the abnormal points easier to distinguish in the final error space.
[0032] The original input sequence is The result of the first reconstruction is The element-wise weighted summation method is as follows: , (13); In equation (13): The fusion coefficient is a hyperparameter. To convert the original input and The first reconstruction result The result of linear combination preserves both the true details of the original signal and the underlying structure processed by the Transformer. In this embodiment, in order to emphasize the ability to model the normal pattern while ensuring that the model relies more on the reconstruction benchmark of the normal pattern in subsequent branch time series modeling, α=0.3 is set, that is, the weight of the original input is 0.3.
[0033] Preferably, in S5, the convolutional structure uses a one-dimensional convolutional kernel of size k that slides along the time dimension. If a missing span greater than T was used in S1 and a missing mask was applied, then in this part, the mask matrix is used as an additional channel and integrated with... The input is convolved together to further extract the correlation between local temporal patterns and multiple variables in the fused data. One-dimensional convolution sliding along the time dimension can efficiently capture local waveform features such as periodic breakpoints and rapid rises and falls. This operation provides a more expressive input for the subsequent GRU to capture long and short-term dependencies. The convolution operation is as follows: (14); In equation (14): It is a local temporal feature matrix generated after the Conv1D operation, which is a comprehensive representation of "local waveform features + multivariate correlation features" extracted by the convolutional layer. This represents a one-dimensional convolution kernel pair of size k. Slide along the time dimension, for Perform local feature extraction.
[0034] The shape of the output feature map is: (15); In equation (15): The number of output channels for the convolution. , The length of the time dimension after convolution. In this case, the convolution kernel k=3, the dilation rate d=1, the stride s=1, and the padding p=(k-1) / 2, therefore the output length is still L, i.e. ; Optionally, if a missing mask is used in S1, then in this part, the mask matrix is treated as an additional channel and combined with... Inputting them together into a convolutional layer allows the convolutional layer to learn different response strategies at locations where observations are missing.
[0035] Preferably, in this embodiment, in order to enhance the model's ability to model the temporal dependencies of multivariate time series, a two-branch temporal modeling based on convolution and gated recurrent units (GRUs) is adopted on the convolutional feature map obtained in S5 to obtain complementary temporal features.
[0036] Branch 1: Direct time series modeling is adopted. To facilitate GRU's acceptance of time series data, this part requires... Transpose ,Will Input GRU: (16); In equation (16): the hidden dimension of GRU is The output shape is (B, , This branch structure focuses on learning smooth, continuous temporal dependencies; To facilitate splicing with branch two, Transpose back to the original dimension: , (17); In equation (17): This represents the time-series feature matrix output after learning and transposing by the GRU. This is a tensor dimension rearrangement operation, representing the feature matrix output by the GRU. The core of dimensional rearrangement is adjusting the order of dimensions; Branch Two: First, check... Perform a second convolution to extract higher-order local patterns, then use GRU to model these more robust temporal signals, and finally use deconvolution to restore the same time dimension as branch one. This part combines the representation of local details and cross-time information. Secondary convolution: for Execute Conv1d to extract the local time pattern: (18); In formula (18): This represents the high-order local feature matrix obtained after performing a second one-dimensional convolution on the convolutional feature map F1 of branch one, with dimensions of... , This represents the number of output channels for the second convolution. This represents a one-dimensional convolution kernel pair of size k. Slide along the time dimension, for Perform a secondary feature extraction operation.
[0037] Then Input GRU: The hidden dimension of GRU is The output shape is (B, , ); To ensure alignment with the time dimension of branch one, the GRU output is transposed as follows: ; Next, ConvTranspose1D is used to perform deconvolution to smooth the high-dimensional representation of GRU and avoid excessive compression and loss of detail. The deconvolution yields: (19); In equation (19): This is the timing feature map of the final output of branch two. Indicates to Performing deconvolution operations, the core function is to... Upsampling and detail restoration are performed to alleviate the problem of excessive compression of timing information by GRU.
[0038] In S7, the splicing includes splicing along the feature dimension. : (20); In equation (20): It is The fused feature map is obtained by concatenating the features along the feature dimension. This indicates an operation that concatenates the features of the two branches along the H feature dimension; The First transpose to sequence format Then, the hidden features are remapped to the same dimension as the original input in the MLP decoder: (twenty one); In equation (21): Indicates the fusion of features The feature matrix obtained after mapping by the MLP decoder The feature mapping operation is represented by an MLP consisting of multiple fully connected layers. Each layer introduces non-linearity through the ReLU activation function, and finally maps the 2H dimension to the C dimension through the output layer. The purpose of transposition is to... The dimension from " "Transformed into the preprocessed input" Dimensions To maintain consistency, the permute operation is used to obtain the final secondary reconstruction result. ; The permute operation specifically refers to directly referencing the dimension rearrangement operation in the code.
[0039] Preferably, in S8, Anomaly scores are obtained based on the secondary reconstruction error and consistency error: Considering the differences in feature learning between the two branches, if the two reconstruction results deviate too much, it may cause the fused reconstruction result to drift and affect the detection accuracy. Therefore, consistency regularization constraints are introduced during the training process to avoid detection instability caused by excessive differences between the two reconstruction results. The first reconstruction error is defined as: (twenty two); In equation (22): The first reconstruction loss is represented by the squared Euclidean distance between the original sequence and the first reconstruction result, which quantifies the accuracy of the reconstruction. It represents the reconstruction capability of a branch pair of the original input. This represents the original input time series tensor after preprocessing. This represents the time series result of the first reconstruction. The second reconstruction error is defined as: (twenty three); In equation (23): The loss represents the second reconstruction, calculating the difference between the original input sequence and the reconstruction result after the two-branch fusion. This represents the global reconstruction capability of the fusion branch on the input. This represents the second reconstructed time series result generated after dual-branch time series modeling and the final decoder; Introducing a consistency regularization term: (twenty four); In equation (24): The consistency loss is used to quantify the difference between the two reconstruction results. This term acts as a regularization constraint, forcing the model in this instance to learn a consistent sequence representation on two different decoding paths, thereby enhancing the stability and robustness of the model. The ultimate training goal is: (25); In equation (25): The final loss function used for model training is a weighted sum with coefficients... To control the importance of the second reconstruction, a value ranging from 0.5 to 2.0 is recommended. The weights used to adjust the consistency regularization are recommended to be in the range of 0.01–0.2, serving as an auxiliary constraint. L represents the total loss function, ensuring that both branch one and branch two can accurately recover the original sequence features and avoiding extreme cases of single-branch collapse and excessive differences between the two branches, thereby improving the robustness of anomaly detection.
[0040] After the model training is complete, load the trained model for the test sequence. Calculate the error under each of the two reconstructions: , (26); In equation (26): This represents the outlier score calculated based on the first reconstruction. This represents the outlier score calculated based on the second reconstruction. The two outlier scores are then merged to obtain the final outlier score: (27); In equation (27): This represents the final fusion anomaly score at time step t. These are the weighting coefficients.
[0041] Preferably, in S8, the threshold setting uses the percentile method: A series of anomaly scores are calculated for normal samples on the training set. This forms a distribution; Next, select the q-percentile to set the threshold θ: (28); In equation (28): Percentile is a function for calculating percentiles, and q is a preset hyperparameter whose value defines the rarity of the anomaly; If the final anomaly score of the test sequence at time step t... If so, that moment is considered abnormal.
[0042] This embodiment is based on the PyTorc framework for model building, and is carried out in the Ubuntu 22.04 environment. The main hardware parameters are Intel(R) Xeon(R) Gold 6152 CPU, 10 CPU cores, RTX 3090, 24GB video memory.
[0043] This embodiment conducts experimental evaluations on four publicly available datasets, each described in Table 1: Table 1. Statistical Information of Dataset
[0044] MSL (Mars Science Laboratory) and SMAP (Soil Moisture Active Passivesatellite) are both remote sensing anomaly data from NASA's publicly available spacecraft detection system anomaly time reports, with 55 and 25 dimensions respectively; PSM (Pooled Server Metrics) is data collected from multiple application servers at eBay, with 25 dimensions; SMD (Server Machine Dataset) is server test data collected from a large internet company over a period of 5 weeks, with 38 dimensions.
[0045] This embodiment uses precision (P), recall (R), and F1 score as evaluation metrics, where F1 score is the harmonic mean of precision and recall.
[0046]
[0047]
[0048]
[0049] Wherein, TP represents an anomaly that is correctly detected as an anomaly, FP represents a normal that is incorrectly detected as an anomaly, and FN represents an anomaly that is incorrectly detected as a normal.
[0050] Some parameter settings are shown in Table 2, where L is the time window length and patch is the block length. The experiment uses the Adam optimizer with an initial learning rate of 0.0001. Table 2. Parameter settings for the four datasets.
[0051] The following table shows the performance analysis on different datasets in this embodiment: Table 3 Performance analysis on different datasets
[0052] This embodiment achieves excellent recall on PSM, SMAP, and SMD datasets, and its F1 score on the large SMD dataset is significantly better than the existing baseline. This proves that this dual reconstruction design is effective in handling high-dimensional and complex data, achieves robust anomaly detection, and achieves excellent recall while maintaining high precision.
Claims
1. A time series anomaly detection method based on PatchTST dual reconstruction consistency constraint, characterized by Comprising the following steps: S1, obtaining multivariate time series data, preprocessing the multivariate time series data, the preprocessing operation comprising missing value processing, normalization processing, detrending processing; S2, dividing the data after S1 preprocessing into several patches, each patch as a token input into the Transformer encoder, and obtaining global context features; S3, input the Transformer encoder output feature into the MLP decoding head to perform the first reconstruction to obtain a first reconstruction result X recon1 ; S4, original input is combined with the first reconstruction result X recon1 Weighted fusion, get fusion data X fuse ; S5, fusing data X fuse performing convolution to obtain a convolution feature map F1; S6, double-branch time series modeling: Branch one: the convolution feature map F1 inputs the gated recurrent unit GRU to obtain the time sequence feature map Feat A ; Branch two: the convolution feature map F1 is twice convolved, and then input into the gated recurrent unit GRU, and then the time dimension is recovered through deconvolution to obtain the time sequence feature map Feat B ; S7, the time sequence feature map Feat A with the time sequence feature map Feat B splicing, the input decoder obtains the final fusion reconstruction result X recon2 ; S8, obtaining an anomaly score based on the quadratic reconstruction error and the consistency error, and comparing the anomaly score with a threshold to detect time step anomalies.
2. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraint according to claim 1, characterized in that: In S1, the missing value processing specifically comprises: Taking the threshold T as 5 time steps, when the continuous missing length is less than the threshold T, a filling method based on a sliding window mean is used; when the missing span is greater than T, a mask mechanism is introduced, that is, zeros are filled in the data tensor, and a mask matrix of the same shape is constructed to mark the missing position; The mask mechanism specifically comprises: In the original multivariate time series data tensor, all positions with a continuous missing length greater than T time steps are filled with 0, and a binary mask matrix of the same shape as the data tensor is created to mark the state of each data point. If the original data is a true observation value at that time step, the value of the corresponding position of the mask matrix is 1, and if it is a time step filled with 0, the value of the corresponding position of the mask matrix is 0; The data after missing value processing is input together when propagating forward; In S1, the normalization processing specifically comprises: Z-score standardization is performed on each dimension: (1); In formula (1): denotes the time series data after z-score standardization, denotes the original numerical value of the input time series, and μ and σ are the mean and standard deviation on the training set, respectively; In S1, the detrending processing specifically comprises: If the original data has a clear long-term trend, a first-order difference operation is used for detrending, and zero padding is performed on the first-order difference sequence at the starting position; The first-order difference operation: First-order difference eliminates the long-term trend in the original data by calculating the difference between adjacent two time steps to obtain a first-order difference sequence: (2); In formula (2): denotes the difference between the t-th time step and the previous time step (t-1), i.e., the change amount of the original time series data at adjacent time steps, where When , because there is no , a missing value will occur at the starting position of the difference sequence, so in order to keep the difference sequence consistent with the length of the original sequence, the missing value at the position is zero-padded, i.e. , where n is the sequence length.
3. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraint according to claim 1, characterized in that: S2 comprises the following steps: S2.1, the input tensor after preprocessing: Divide into consecutive patches with a length of p according to the time dimension; In formula (3): represents a real data type, used to indicate that all elements stored in the tensor are real numbers; represents a batch size, represents a variable dimension number, ; S2.2, flatten each patch into a one-dimensional vector and map it to a fixed-length vector through a linear projection layer; The one-dimensional vector after dimension rearrangement of the patch is: (4); In formula (4): represents a two-dimensional feature matrix obtained after the i-th time sequence patch is flattened, represents that the flattened feature matrix is a two-dimensional real tensor; through a learnable linear transformation matrix mapping the flattened patch vectors to the hidden space dimensions d of the Transformer encoder: (5); In formula (5): , represents the compressed vectorized representation of the i-th time series patch after linear projection; is a learnable neural network weight matrix, which is responsible for converting a flattened high-dimensional data patch vector into a fixed-dimensional hidden feature vector. The conversion process extracts and compresses the most core pattern information from the original data by learning the optimal mapping relationship, so as to provide subsequent modules for processing, and b is a learnable bias term. S2.3, stack the projection results of all patches to form a sequence input; (6); In formula (6), denotes the batched sequence tensor formed by stacking the projection results of all patches, denotes the compressed vectorized representation of the i-th time sequence patch after linear projection, denotes is a three-dimensional real tensor containing B independent sequences, where each sequence consists of N elements, and each element is represented by a d-dimensional feature vector; S2.
4. Adding a learnable position encoding to the sequence Z input in S2.3 : (7); In formula (7): represents a position-aware sequence tensor that contains both the semantic content information of the original time segment and its position information in the entire sequence, is a learnable position encoding, and its core function is to provide the model with explicit information about the order of each patch in the sequence; In structure, is defined as a two-dimensional, trainable parameter matrix, mathematically represented as: (8); In formula (8), the first dimension N represents the number of rows of the matrix, the value of which corresponds to the length of the input sequence Z, and the second dimension d represents the number of columns of the matrix, the value of which is consistent with the dimension of the hidden feature vector of each time slice; by adding the position vector of the corresponding position to the content feature vector of the corresponding time slice The model generates a position-aware sequence tensor , thus injecting a sequential order to the originally unordered feature collection; S2.5, input the sequence after adding the learnable position encoding in S2.4 into the multi-layer Transformer encoder, and the encoder structure comprises a multi-head self-attention layer, a feedforward network, a residual connection and a LayerNorm.
4. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraints according to claim 3, characterized in that: The core operation of the Transformer encoder is the self-attention mechanism: (9); In equation (9): This represents the attention output calculated using Q, K, and V. Each is derived from the input The query, key, and value obtained from a linear transformation; The result of the computation is an attention weight matrix, in this part, first the relevance score of each query to all keys in the sequence is computed, then the scores are numerically scaled, and finally the scores are normalized to a probability distribution with sum 1 by the softmax function, denotes the transpose of the key matrix K, after transposing the dot product similarity of the query matrix Q to all keys can be computed denotes the dimension of the key vector; After Transformer encoding, an output feature matrix is obtained: (10); In formula (10), the feature matrix H is a sequence representation deeply fused with context information, and the input In contrast, Although the shapes are the same, H is a context-aware feature representation with a global view formed by weighting and aggregating all other patch information in the sequence through self-attention mechanisms.
5. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraints according to claim 1, characterized in that: In S3, the MLP decoding head is composed of 3 fully connected layers, wherein, after each fully connected layer in 2 hidden layers, a nonlinear activation function ReLU and Dropout are connected; The Dropout is an operation of randomly closing neurons, and a part of the output of the neurons is temporarily set to zero by a preset probability p; The S3 further includes: S3.1, reshaping the reconstruction result of each patch into the same shape as the original patch: (11); In formula (11): represents the reconstruction result of the i-th Patch, which is the flattened vector output by the MLP decoding head After the Reshape operation, represents the reconstructed single Patch tensor mathematical space and three-dimensional shape, represents that the elements in the tensor are real numbers, B represents the batch size, C represents the number of variable dimensions, and P represents the time step length of each Patch; S3.2, reassembling all patches in time sequence: In pytorch, directly put into the concatenate function to get the final reconstruction result; The final assembly result is: (12); In formula (12): The complete end-to-end time series reconstruction result generated by the representative model in the first stage, the final shape of which Consistent with the shape of the input tensor of the model at the beginning, Indicates all reconstructed independent time segments, each Is a three-dimensional tensor with a shape of BxCXP, which is the reconstruction result of the original ith time segment by the model decoder.
6. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraints according to claim 1, characterized in that: In S4, the weighted fusion is specifically an element-wise weighted sum to generate input fusion data for subsequent double-branch modeling; The original input sequence is The first reconstruction result is The element-wise weighted sum is as follows: , (13); In equation (13): The fusion coefficient is a hyperparameter. To convert the original input and The first reconstruction result The result of linear combination preserves both the true details of the original signal and the underlying structure processed by the Transformer.
7. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraints according to claim 1, characterized in that: In S5, a one-dimensional convolution kernel with size k is used to slide along the time dimension in the convolution structure part. When the missing span in S1 is greater than the threshold T, the missing mask is used. In this convolution part, the mask matrix is input into the convolution as an additional channel together with the fused data . The convolution operation is ; In equation (14): It is a local temporal feature matrix generated after the Conv1D operation, which is a comprehensive representation of local waveform features extracted by the convolutional layer and multivariate correlation features. This represents a one-dimensional convolution kernel pair of size k. Slide along the time dimension, for Perform local feature extraction; The shape of the output feature map is: (15); In formula (15): is the number of convolution output channels, , is the length of the time dimension after convolution, where the convolution kernel k = 3, the expansion rate d = 1, the stride s = 1, and the padding p = (k-1) / 2, so the output length is still L, that is .
8. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraints according to claim 7, characterized in that: In the S6, based on the convolution feature map obtained in S5, a double-branch time sequence modeling based on convolution and gated recurrent unit GRU is adopted to obtain complementary time sequence features; Branch 1: Direct time-series modeling, which is Transposed to , which is Input GRU: (16); In formula (16), the hidden dimension of the GRU is , , ) Convert back to original dimensions: , ; In formula (17): represents the time sequence feature matrix output after GRU learning and transposition, is a tensor dimension rearrangement operation, representing the feature matrix output by the GRU is rearranged in dimension, and the core is to adjust the dimension order; Branch two: first extract higher order local patterns by performing a second convolution, then model these more robust temporal signals by GRU, and finally recover the same time dimension as branch one by deconvolution, which represents both local details and cross-time information. Branch two: first extract higher order local patterns by performing a second convolution, then model these more robust temporal signals by GRU, and finally recover the same time dimension as branch one by deconvolution, which represents both local details and cross-time information. Secondary convolution: conv2d Performing Conv1d to extract local temporal patterns: (18); In formula (18): represents a high-order local feature matrix obtained after performing a second one-dimensional convolution on the convolution feature map F1 of the branch one, and the dimension is , is the output channel number of the second convolution, represents that a one-dimensional convolution kernel with a size k is used to slide along the time dimension to perform a second feature extraction operation on , . Again, we have input GRU: with hidden dimension of GRU , output shape of (B, , ). To ensure the alignment of the time dimension with the branch, the GRU output is transposed to: ; The deconvolution operation is performed using ConvTranspose1D, and the deconvolution result is: (19); In formula (19): is the timing feature map of the branch two final output, denotes performing a deconvolution operation on the input feature map 9. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraints according to claim 1, characterized in that: In S7, the concatenating comprises concatenating in the feature dimension : (20); In formula (20): is to After splicing in the feature dimension, a fusion feature map is obtained, represents an operation of splicing the features of the two branches in the H feature dimension. The Transposed into sequence format and re-mapped to the same dimension as the original input in the MLP decoder: (21); In formula (21): represents the fusion feature The feature matrix obtained after mapping by the MLP decoder, represents a feature mapping operation, and the MLP is composed of multiple fully connected layers, each layer introduces nonlinearity through a ReLU activation function, and finally maps 2H dimensions to C dimensions through an output layer. The purpose of transposition is to... The dimension from " "Transformed into the preprocessed input" Dimensions To maintain consistency, the permute operation is used to obtain the final secondary reconstruction result. ; The permute operation is specifically: directly referencing the dimension rearrangement operation in the code.
10. The time series anomaly detection method based on PatchTST dual reconstruction consistency constraints according to claim 1, characterized in that: In the S8, Based on the secondary reconstruction error and the consistency error, an anomaly score is obtained: In the training process, a consistency regularization constraint is introduced to avoid detection instability caused by too large difference between the two reconstruction results; The first reconstruction error is defined as: (22); In formula (22): represents the first reconstruction loss, which quantifies the accuracy of reconstruction by calculating the squared Euclidean distance between the original sequence and the first reconstruction result, and represents the reconstruction ability of branch one to the original input, represents the original input time sequence tensor after preprocessing, represents the first reconstruction time sequence result; The second reconstruction error is defined as: (23); In formula (23): represents the loss of the second reconstruction, which calculates the difference between the original input sequence and the reconstruction result after the fusion of the double branches, and represents the global reconstruction ability of the fusion branch to the input, represents the time series result of the second reconstruction generated after the double-branch time series modeling and the final decoder. The consistency regularization term is introduced: (24); In formula (24): represents the consistency loss, used to quantify the difference between the two reconstruction results, which is taken as a regularization constraint to force the model of the present example to learn consistent sequence representations on two different decoding paths, thereby enhancing the stability and robustness of the model; The final training target is: (25); In formula (25): represents the final loss function for model training, which is a weighted sum of coefficients for controlling the importance of the second reconstruction coefficients for adjusting the weight of consistency regularization, L is the total loss function After the model training is completed, the trained model is loaded, and for the test sequence , the error under the two reconstructions is calculated respectively: , (26); In formula (26): represents the abnormal score calculated based on the first reconstruction, represents the abnormal score calculated based on the second reconstruction, Two anomaly scores are fused to obtain the final anomaly score: (27); In formula (27): denotes the final fusion anomaly score at time step t, is a weight coefficient; The threshold setting selects the percentile method: a series of abnormal scores of normal samples are calculated on the training set , forming a distribution; Then, the q-percentile is selected to set the threshold θ: (28); In equation (28), Percentile is a function for calculating the percentile, and q is a preset hyperparameter, the value of which defines the rarity of the anomaly; If the test sequence has a final anomaly score at the tth time step then the time instant is determined to be anomalous.
Citation Information
Cited By
Industrial multi-element sensor signal anomaly detection method based on time-frequency-space three-level fusion
CN122113018A
A multi-element time sequence anomaly detection method based on a deep learning algorithm
CN122173906A