Time sequence anomaly detection method based on mask attention network and generative model
By using the mask attention network and generative model in time series anomaly detection, combined with the graph attention network and normalized flow, the problem of complex interactions of multivariate variables and complex temporal dependencies is solved, achieving efficient anomaly detection and enhancing the detection of time series anomalies. Ability to handle incomplete data.
Patent Information
- Application Number
- CN202410849094.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-10-29
AI Technical Summary
Existing time series anomaly detection methods are difficult to accurately identify anomalies when faced with complex interactions of multivariate variables and complex temporal dependencies, and missing data and noise interference affect detection accuracy and reliability.
Using a method based on mask attention network and generative model, the spatial and temporal relationships of time series are captured through graph attention network, and the probability density is calculated by combining normalized flow and variational autoencoder to detect and judge outliers.
This method can effectively capture the spatial dependencies and temporal dependencies of multivariate time series, improve the model's robustness and flexibility to incomplete data, and improve anomaly detection performance, especially when data is missing or noise exists. sex and flexibility.
Smart Images

Figure CN118861918A_ABST
Abstract
Description
Technical Field
[0001] The present invention provides a time series anomaly detection method based on a masked attention network and a generative model, and belongs to the technical field of time series anomaly detection based on a masked attention network and a generative model. Background Art
[0002] With the rapid development of the Internet of Things and big data technologies, more and more network sensors are deployed in many automated information systems to monitor and control various operational processes, which are often deployed in critical infrastructures such as servers, water treatment systems, and spacecraft. Over time, sensors on various devices will generate a large amount of multivariate time series data that interact in time and space. Mining useful information from these data can improve production control capabilities and has become an important issue of common concern in the industry and academia. Anomaly detection is an important research topic in time series analysis, which helps monitor system behavior and enables staff to take targeted actions on abnormal events in advance, check and solve potential problems, thereby avoiding potential risks and economic losses. At present, anomaly detection has been widely used in fields such as healthcare, aerospace, and industrial production.
[0003] In recent years, time series data anomaly detection methods have been widely studied. Existing anomaly detection algorithms can be roughly divided into the following categories: statistical-based methods, clustering-based methods, distance-based methods, density-based methods, and deep learning-based methods. Deep neural networks are widely used in multivariate time series anomaly detection due to their effective automatic feature extraction capabilities. Since labels for anomaly data are relatively rare and their acquisition costs are usually high, unsupervised learning is often considered a suitable solution in this case.
[0004] In recent years, recurrent neural networks (RNN), convolutional neural networks (CNN), graph neural networks (GNN), transformers, and autoencoders (AE) have been widely used in unsupervised anomaly detection models. RNN is a type of neural network that is very suitable for sequence data analysis. It captures the temporal dependencies in data through a cyclic structure. However, standard RNNs have weak memory for long sequences and may suffer from gradient vanishing or gradient exploding problems. To address these problems, various RNN variants have been developed, including long short-term memory networks (LSTM) and gated recurrent units (GRU), which provide enhanced memory and gradient flow and can more effectively model complex sequence data. Su et al. constructed a random RNN using GRU and variational autoencoder (VAE) to capture temporal dependencies and generate new random representations. On this basis, the time-dependent relationship is converted into a new expression using a flat normalization flow, and then the anomaly is judged based on the reconstruction probability. Zhang et al. constructed a signature matrix based on the correlation of each time series, and used convolution and convolutional LSTM combined with attention mechanism to encode the signature matrix to obtain time information. Then the new representation is decoded into a signature matrix and compared with the previous signature matrix to judge anomalies. Tuli et al. proposed a Transformer-based encoder-decoder network, which adaptively extracts features by adjusting attention scores and adversarial training processes, and calculates reconstruction errors for anomaly detection. In the past few years, researchers have proposed extracting spatial information from multivariate time series and forming graph structures, and then detecting anomalies in time series based on their graph structures, and have used GNNs to model these graphs. Deng et al. introduced graph structures to express the relationship between multivariate time series, captured the correlation and features between sensors based on GNN, predicted time series for anomaly detection. Normalizing Flow is a class of deep generative models for learning the underlying distribution of data samples. Its core idea is to transform complex data distributions into standard simple distributions (such as Gaussian distributions) through a series of reversible transformations. In this process, each step of the transformation is reversible and has a clear Jacobian determinant, which allows the model to accurately calculate the probability density function of the data, thereby effectively identifying anomalies with significantly different data distributions.Dai et al. used a Bayesian network to decompose time series along the sequence dimension, and used conditional normalization flow to decompose along the time dimension, and used a graph-based dependency encoder to perform anomaly detection on the conditional density produced by the decomposition.
[0005] However, due to the diverse interactions of real systems, signal-based anomaly detection has the following defects:
[0006] (1) Complex interactions of multiple variables: Data generated by different sensors often interact in a complex nonlinear way, which makes the correlation of spatial features difficult to discover and utilize;
[0007] (2) Complex temporal dependencies: Different historical moments have different impacts on current data, making it particularly difficult to find reliable temporal dependencies from historical data to identify anomalies;
[0008] (3) Missing data and noise interference: Due to errors from equipment, improper operation or changes in the external environment, as well as uncertainties in the data collection and transmission process, the collected data may contain missing values and be interfered by noise, affecting the accuracy and reliability of anomaly detection. Summary of the invention
[0009] In order to overcome the deficiencies in the prior art, the present invention aims to solve the technical problem of providing a time series anomaly detection method based on a masked attention network and a generative model.
[0010] In order to solve the above technical problems, the technical solution adopted by the present invention is: a time series anomaly detection method based on a masked attention network and a generative model, comprising the following detection steps:
[0011] Step 1: Mask the nodes and time dimensions in the time series respectively, and use the graph attention network to capture the spatial and temporal relationships of the time series;
[0012] Step 2: Combine the probability estimation ability of the standardized flow and the deep potential feature extraction ability of the variational autoencoder VAE to capture the complex distribution in the sequence, and use the standardized flow and variational autoencoder to calculate the probability density;
[0013] Step 3: Obtain anomaly scores based on the calculated probability density, and detect and judge outliers in the time series.
[0014] The specific method of using the graph attention network to capture the spatial and temporal relationship of the time series in step 1 is:
[0015] Step 1.1: Build a spatial mask map attention module:
[0016] Mask the time series: each sensor (i.e., each dimensional time series) is regarded as a node, forming a node set U; in the sliding window, each node x in the node set U i is a sequence vector x i ={x i,t |t∈[0,w]}, a total of N nodes, that is, N-dimensional time series, where x i,t is the value of sensor i at time t, w is the sliding window size;
[0017] Random sampling selects a subset of nodes Mask each node in the subset using the mask token MASK;
[0018] Subset the mask proportionally It is divided into and right The nodes in are assigned a learnable mask vector right The nodes in are randomly assigned data of other nodes, and the masked nodes are represented as follows:
[0019]
[0020] in, Indicates that the mask mark is a d-dimensional real vector, u i and u j is a node in the node set U, x i and x j are time series nodes u respectively i and u j The value of
[0021] Then, a directed graph is constructed with each dimension of sensor data as a node. Each node in the graph represents a one-dimensional time series, and each edge represents the relationship between two corresponding time series;
[0022] Each sensor is given a learnable embedding vector to build the graph structure and participate in the operation of the attention mechanism. The expression is:
[0023] v i ∈R n ,i∈{1,2,...,N};
[0024] Among them, v i represents the embedding vector of the i-th sensor, R n represents an n-dimensional real vector, where N is the dimension of the time series, i.e. the number of sensors;
[0025] The adjacency matrix A is used to represent the directed graph. ijRepresenting an edge from i to j, we first calculate the normalized dot product of the embedding vectors between the two nodes, then for each node, calculate the cosine similarity between the nodes, and select the P nodes most similar to each node as its neighbors to construct the adjacency matrix A∈R N×N , the expression is:
[0026]
[0027] Among them, v i and v j represents the embedding vector of the i-th sensor and the j-th sensor, sim(·) is the cosine similarity function, and Top m (·) is to select the first m maximum values;
[0028] The graph attention network is introduced to fuse node information and neighbor information, process the dependency relationship of nodes in the graph, and represent the aggregate of node i as z. i The expression is:
[0029]
[0030] Where N(i) = {j|A ij >0} is the neighbor set of node i obtained by adjacency matrix A, α i,j is the attention coefficient, W is a learnable parameter;
[0031] Calculate the attention coefficient α i,j The calculation formula is:
[0032]
[0033] Among them, a T is the transpose of the learnable coefficient vector a of the attention mechanism, Indicates splicing, g i Indicates that sensor i fuses the masked data and the embedding vector v i The representation of g j represents the representation of sensor j fused with masked data and embedded vector, π(i, j) represents the attention score between node i and node j, ∑ k∈N(i)∪{i} exp(π(i, k)) represents the sum of the exponential functions of the attention scores of node i and all its neighboring nodes, N(i) represents the neighbor set of node i, {i} represents the node itself, and W is a learnable parameter;
[0034] The output of the graph attention network is masked again, and the features of the masked nodes are set to zero:
[0035]
[0036] Among them, z i is the aggregate representation of node i after the graph attention network, is the node representation after mask operation, represents the set of masked nodes, u i Represents node i, which is used to identify whether the current node is in the mask set;
[0037] Finally, the matrix form of the spatial mask image attention module output is expressed as: z∈R N×n ;
[0038] Among them, R represents a real number set, N represents the number of nodes, and n represents the feature dimension;
[0039] Step 1.2: Build the temporal mask map attention module:
[0040] In the sliding window, the data of N sensors at the same time t are regarded as a time node x t ={x i,t |i∈[0,N)}, construct a complete graph;
[0041] Use a masking strategy similar to that in the spatial mask graph attention module to mask the time node data and obtain the masked time series Then we use the graph attention network to capture the relational dependencies in the time dimension, where node x t The updated feature is represented as c t , the expression is:
[0042]
[0043] Among them, σ represents the sigmoid activation function, and are the values of node t and node s after masking, represents splicing, α t,s represents the attention weight between node t and node s, e t,s represents the correlation score between time nodes t and s, e t,l represents the correlation score between time nodes t and l, and W is a learnable parameter;
[0044] Using the re-masking strategy in the spatial mask map attention module, the matrix form of the output of the temporal mask map attention module is expressed as:
[0045] C∈R n×N ;
[0046] Among them, R represents a real number set, N represents the number of nodes, and n represents the feature dimension;
[0047] Step 1.3: The spatial dependency between variables is captured by the established spatial mask graph attention module, and the temporal dependency pattern of the time series is captured by the established temporal mask graph attention module;
[0048] The spatial features captured by the spatial mask map attention module are concatenated with the temporal features captured by the temporal mask map attention module, and the features of the two modalities of space and time are fused as follows:
[0049] H∈R n×2N ;
[0050]
[0051] The specific method of using the standardized flow and the variational autoencoder to calculate the probability density in step 2 is:
[0052] Step 2.1: Reconstruct the probability density estimation module:
[0053] The variational autoencoder VAE is modeled as an encoder-decoder architecture, where the encoder network q φ (z|x) encodes the input data x into a latent variable z that obeys a certain probability distribution, where φ is the parameter of the encoder; the decoder network p established θ (x|z) then according to q φ (z|x) The latent variable z obtained by sampling reconstructs the output data close to the input data x Where θ is the parameter of the decoder;
[0054] Variational Autoencoder VAE introduces the evidence lower bound ELBO through variational inference:
[0055]
[0056] Among them: the first term is the reconstruction term, which represents the expectation of the log-likelihood of the decoder generating the input data, reflecting the ability of the decoder to reconstruct the input data; the second term D KL is the KL divergence, which acts as a regular term to limit q φ (z|x) deviates from the prior p(z);
[0057] By maximizing ELBO, the variational autoencoder VAE can indirectly maximize the log-likelihood of the data ln p θ (x), to achieve the effect of probability density estimation, p θ (x) is the probability density estimation of data based on the parameter-based generative model;
[0058] In the training phase, given an input x, the encoder q of the variational autoencoder φ (z|x) first maps x to mean μ and variance σ 2 , characterizing its parameters;
[0059] Using the heavy parameter technique From q φ (z|x) where represents noise from a standard normal distribution;
[0060] Decoder p θ (x|z) reconstructs the output x based on the latent variable z, and optimizes the VAE parameters φ and θ through the above ELBO objective function;
[0061] Get the reconstruction loss Loss Reconsitution , the expression is:
[0062]
[0063] By pre-training the variational autoencoder VAE on normal data, the reconstruction-based probability density estimation module provides the key reconstruction probability density for subsequent anomaly detection Used to identify abnormal samples;
[0064] Step 2.2: Adopt the normalized flow probability generation model through the reversible differentiable transformation f(·): R d →R d , standardize the complex data distribution p(x) into a simple benchmark distribution q(f(x)), and realize the modeling of p(x) and the estimation of probability density:
[0065] Specifically, through reversible and differentiable transformation, the logarithmic density of x is expressed as:
[0066]
[0067] in, is the Jacobian matrix of the transformation f, is the determinant of the Jacobian matrix;
[0068] The standardized flow probability generation model further expands the variable transformation into a conditional transformation f(x; H t ),
[0069] The fused spatiotemporal features at time step t represent H t The conditional x t The logarithmic density logp(x t |H t ), the expression is:
[0070]
[0071] Among them, p(x t |H t ) is based on the condition H tThe probability density function of the target data distribution is is the Jacobian matrix of the conditional transformation, is the determinant of the Jacobian matrix;
[0072] Through the conditional transformation f(·), the complex conditional target data distribution p(x t |H t ) is mapped to a simple conditional benchmark distribution to achieve modeling and probability density estimation of target data;
[0073] The masked autoregressive flow MAF is used to learn a potentially complex normalized flow transformation, with the goal of t Under the condition of maximizing the input data x t The logarithmic probability density under the current MAF model is expressed as:
[0074]
[0075] Among them, φ and θ are the normalized flow and the conditional distribution q θ The parameters of (·), The time series x t Under the given condition H t The following is mapped to the latent variable space through flow transformation, q θ (·) is the probability density of the latent variable after mapping under the benchmark distribution, is the Jacobian matrix, which is used to calculate the logarithmic determinant of the transformation flow;
[0076] The calculation formula of its loss function is:
[0077] Loss Flow = -O log p;
[0078] The two modules are based on two different density estimation paradigms, reconstruction and transformation, and jointly output the probability density to obtain the total model loss, which is calculated as follows:
[0079] Loss=Loss Reconsitution +Loss Flow .
[0080] The specific method for detecting and judging outliers in the time series in step 3 is:
[0081] Based on the probability density estimation obtained by the hybrid generation model, anomaly detection is performed on time series data, and the anomaly score at time t is t VAE and Normalizing Flow are used to calculate x respectively. t The probability density of is:
[0082] scoret =1-p VAE (x t )+1-p flow (x t );
[0083] Among them, p VAE (x t ) is the probability density calculated by the variational self-encoder, p flow (x t ) is the probability density calculated by the normalized flow;
[0084] After obtaining the anomaly score at time t, if the score is greater than the threshold K, time t is marked as anomaly. The expression is:
[0085]
[0086] The threshold K is automatically selected using the peak over threshold method.
[0087] The beneficial effects of the present invention compared with the prior art are as follows: the time series anomaly detection method provided by the present invention combines the masking mechanism, the graph attention network and the hybrid generation model by considering multi-sensor signals, and simultaneously captures the spatial dependency and temporal dependency of multivariate time series, and efficiently models the distribution of complex industrial time series data for anomaly detection; the masking strategy designed by the present invention enables the model to capture sufficient information from the input data, explore the deeper structure and relationship within the data, and enhance the ability of the model to process incomplete data, thereby improving the robustness and flexibility of the model when facing missing or noisy data; as an unsupervised learning method, it provides a suitable solution for actual anomaly detection situations where abnormal data labels are rare or the label acquisition cost is high, and is advanced, stable and practical, with high anomaly detection performance, and has achieved significant performance improvement on public data sets. BRIEF DESCRIPTION OF THE DRAWINGS
[0088] The present invention will be further described below in conjunction with the accompanying drawings:
[0089] Figure 1 is a flow chart of the steps of the detection method of the present invention;
[0090] Figure 2 It is a structural schematic diagram of the multivariate time series anomaly detection model of the present invention. DETAILED DESCRIPTION
[0091] The present invention provides a time series anomaly detection method based on a masked attention network and a generative model. The method simultaneously considers the spatial and temporal correlations in the time series, uses a graph neural network with a mask strategy to explicitly model the correlation between different features, and models the temporal dependency within each time series. By introducing standardized flow and variational autoencoder to calculate probability density, the probability estimation capability of the standardized flow and the deep potential feature extraction capability of VAE are combined to capture the complex distribution in the sequence, thereby performing effective multivariate time series anomaly detection.
[0092] The present invention captures rich information about the spatial and temporal dependencies between multiple variables in a time series by designing a graph attention mechanism with a masking strategy, and explores the complex distribution of data through a hybrid generative model, thereby performing effective time series anomaly detection; the present invention designs a spatiotemporal feature capture module based on masking and graph attention, which explicitly captures the spatial and temporal dependencies of multiple variables in a multivariate time series, and fully explores the spatiotemporal contextual information; and by designing a masking strategy for space and time, the model is enabled to capture sufficient information from the input data, explore deeper structures and relationships within the data, improve the model's depth of understanding of the data, and also enhance the model's ability to process incomplete data; the hybrid generative model provided by the present invention combines the advantages of the powerful deep feature extraction capability of the variational autoencoder (VAE) and the efficient density estimation of the normalizing flow model, thereby being able to accurately capture the inherent complex distribution of time series data, providing a reliable basis for anomaly detection.
[0093] In order to more clearly illustrate and explain the purpose, measures and key points of the present invention, the method proposed by the present invention is described in detail below with reference to the accompanying drawings:
[0094] The main purpose of this invention is to achieve accurate and efficient multivariate time series anomaly detection. Figure 1 The flowchart of the multivariate time series anomaly detection algorithm of the present invention is shown as follows: Figure 2 The structure diagram of the multivariate time series anomaly detection algorithm model is as follows: In the multivariate time series anomaly detection problem, given a historical multivariate time series X = {x1, x2, ..., x t , ..., x T}∈R N×T , where x t is the value of the sensor at timestamp t, N is the number of variables, T is the length of the time series, and the task is to determine the state of the input time series Y = {y1, y2, ..., y t , ..., y T}, where y t∈{0,1} indicates whether the time series is normal (0) or abnormal (1) at timestamp t.
[0095] This paper designs a graph attention mechanism with a mask strategy to capture rich information about the spatial and temporal dependencies between multiple variables in the time series, and explores the complex distribution of data through a hybrid generative model, thereby performing effective time series anomaly detection. The detection method mainly includes three steps:
[0096] Step 1: Capture spatiotemporal features based on mask and graph attention; mask the nodes and time dimensions in the time series respectively, and use the graph attention network to capture the spatial and temporal relationships of the time series.
[0097] Step 2: Probability density estimation based on the hybrid generative model; use the standardized flow and variational autoencoder to calculate the probability density, combining the probability estimation ability of the standardized flow and the deep potential feature extraction ability of VAE to capture the complex distribution in the sequence.
[0098] Step 3: Time series anomaly detection; combine the two probability densities to obtain the anomaly score, so as to judge the outliers.
[0099] Furthermore, the computational model used in step one mainly consists of two parts: a spatial mask map attention module and a temporal mask map attention module, which process data of different dimensions respectively to capture the spatiotemporal relationship in time series data.
[0100] Among them, the spatial mask map attention module used is specifically:
[0101] Since multivariate time series data usually have complex dependencies between variables, it is necessary to capture the spatial dependency characteristics between variables in the sequence. In order to enhance the robustness and flexibility of the model when facing missing or noisy real data, a graph attention network with a mask strategy is designed to enable the model to capture enough information from the input data, explore the deeper structure and relationship within the data, improve the model's understanding of the data, and enhance the model's ability to handle incomplete data. To this end, a spatial mask graph attention module is designed.
[0102] First, the time series is masked and each sensor (i.e., each dimensional time series) is regarded as a node to form a node set U. In the sliding window, each node x in the node set U i is a sequence vector x i ={x i,t |t∈[0,w]}, a total of N nodes, that is, N-dimensional time series. Among them, x i,t is the value of sensor i at time t, and w is the sliding window size.
[0103] Random sampling selects a subset of nodes And mask each node in the subset with the mask token [MASK]. BERT proposes not to always replace the masked word with the actual [MASK] token, but to keep its small probability unchanged or replace it with another random token. Therefore, the mask subset is divided into It is divided into and right The nodes in are assigned a learnable mask vector right The nodes in are randomly assigned data of other nodes. Through the learnable mask vector, the model can adaptively adjust the feature representation of the masked node so that it can provide reasonable context features for the masked variable. The masked node representation is:
[0104]
[0105] in, Indicates that the mask mark is a d-dimensional real vector, u i and u j is a node in the node set U, x i and x j are time series nodes u respectively i and u j The value of
[0106] Then, a directed graph is constructed with each dimension of sensor data as a node. Each node in the graph represents a one-dimensional time series, and each edge represents the relationship between two corresponding time series.
[0107] In multivariate time series data, there may be complex relationships between different sensors. In order to capture the relevant dependency features, an embedding vector is assigned to each sensor to build the graph structure and participate in the operation of the attention mechanism:
[0108] v i ∈R n ,i∈{1,2...,N};
[0109] Among them, v i represents the embedding vector of the i-th sensor, R n represents an n-dimensional real vector, where N is the dimension of the time series, i.e. the number of sensors;
[0110] The adjacency matrix A is used to represent the directed graph. ijRepresents an edge from i to j. First, the normalized dot product of the embedding vectors between the two nodes is calculated. Then, for each node, the cosine similarity between the nodes is calculated, and the P nodes most similar to each node are selected as its neighbors to construct the adjacency matrix A∈R N×N :
[0111]
[0112] Among them, v i and v j represents the embedding vector of the i-th sensor and the j-th sensor, sim(·) is the cosine similarity function, and Top m (·) is the first m maximum values selected. Through adaptive graph construction, the model can flexibly model the spatial dependencies between nodes. The constructed graph structure is used to participate in the attention operation.
[0113] The graph attention network is introduced to fuse node information and neighbor information to process the dependency relationship of nodes in the graph and learn the high-order representation of nodes. The aggregate representation z of node i i The calculation is as follows:
[0114]
[0115] Where N(i) = {j|A ij >0} is the neighbor set of node i obtained by adjacency matrix A, α i,j is the attention coefficient and W is a learnable parameter.
[0116] Calculate the attention coefficient α i,j The calculation is as follows:
[0117]
[0118]
[0119] Among them, a T is the transpose of the learnable coefficient vector a of the attention mechanism, Indicates splicing, g i Indicates that sensor i fuses the masked data and the embedding vector v i The representation of g j represents the representation of sensor j fused with masked data and embedded vector, π(i, j) represents the attention score between node i and node j, ∑ k∈N(i)∪{i} exp(π(i, k)) represents the sum of the exponential functions of the attention scores of node i and all its neighboring nodes, N(i) represents the neighbor set of node i, {i} represents the node itself, and W is a learnable parameter.
[0120] In order to further encourage the model to learn the modeling ability of time series, the output of the graph attention network is masked again to encourage the model to pay attention to the masked data, thereby further improving the ability to capture spatial dependent features. Specifically, the features of the masked nodes are set to zero:
[0121]
[0122] Among them, z i is the aggregate representation of node i after the graph attention network, is the node representation after mask operation, represents the set of masked nodes, u i Represents node i, which is used to identify whether the current node is in the mask set;
[0123] Finally, the matrix form of the spatial mask image attention module output is expressed as: Z∈R N×n ;
[0124] Among them, R represents a real number set, N represents the number of nodes, and n represents the feature dimension.
[0125] The temporal mask graph attention module used is specifically:
[0126] In time series data, there are complex dependencies between different time steps. This module aims to capture the dependencies in the time dimension through the graph attention network and extract rich time series features. In the sliding window, the data of N sensors at the same time t is regarded as a time node x t ={x i,t |i∈[0,N)}, construct a complete graph.
[0127] First, we use a masking strategy similar to that in the spatial mask graph attention module to mask the time node data and obtain the masked time series. Then we use the graph attention network to capture the relational dependencies in the time dimension, where node x t The updated feature is represented as c t :
[0128]
[0129] Among them, σ represents the sigmoid activation function, and are the values of node t and node s after masking, represents splicing, α t,s represents the attention weight between node t and node s, e t,s represents the correlation score between time nodes t and s, e t,lrepresents the correlation score between time nodes t and l, and W is a learnable parameter;
[0130] Then, the re-masking strategy in the spatial mask map attention module is adopted, and finally the matrix form of the output of the temporal mask map attention module is obtained as follows:
[0131] C∈R n×N ;
[0132] Among them, R represents a real number set, N represents the number of nodes, and n represents the feature dimension.
[0133] The spatial mask attention module captures the spatial dependencies between variables, while the temporal mask attention module captures the temporal dependency patterns of time series. Spatial and temporal dependencies reflect different semantics of data, and there are certain differences and complementarities between them. The spatial features captured by the spatial mask attention module and the temporal features captured by the temporal mask attention module are concatenated, and the features of the two modalities of space and time are fused as follows:
[0134] H∈R n×2N ;
[0135]
[0136] The fused features are more comprehensive and have better spatiotemporal expression capabilities, and can describe the detailed features of the data more finely, thereby enhancing the feature expression capabilities of the entire model and facilitating the capture of more complex and abstract patterns in the data.
[0137] Furthermore, in step 2, the specific method for estimating the probability density based on the mixed generation model is:
[0138] The probability density distribution can be regarded as a "fingerprint" describing the data, which can characterize various subtle features of the data. For normal time series, the true probability distribution is often concentrated and smooth; when an anomaly occurs, the probability density distribution will also be significantly offset or distorted due to changes in the data distribution. Therefore, by comparing the probability distribution of the current data with the pre-modeled normal distribution, abnormal deviations can be discovered in a timely manner. In addition, the probability distribution can not only reveal the statistical characteristics of the data, but also reflect the inherent structure and generation mechanism of the data. For complex time series, its probability distribution often implies rich patterns such as time dynamics, periodicity, and multivariate correlation. High-quality modeling and estimation of this true probability distribution can deeply explore the essential properties of time series data and fundamentally improve the robustness and generalization ability of anomaly detection.
[0139] In view of this, the present invention proposes a probability density estimation of a hybrid generative model, which integrates a variational autoencoder and a flow model, and is committed to accurately and efficiently estimating the probability density of complex time series data. The two modules are based on two different density estimation paradigms, reconstruction and transformation, and jointly output probability density clues, providing a reliable basis for subsequent anomaly detection analysis.
[0140] When performing reconstruction-based probability density estimation:
[0141] The variational autoencoder (VAE) used has powerful generative modeling capabilities and an end-to-end reconstruction training framework. This module introduces VAE to perform reconstruction-based probability density estimation and uses VAE's reconstruction mechanism to capture the true distribution of data. VAE is modeled as an encoder-decoder architecture, where the encoder network q φ (z|x) encodes the input data x into a latent variable z that obeys a certain probability distribution, where φ is the parameter of the encoder; the decoder network p θ (x|z) then according to q φ (z|x) The latent variable z obtained by sampling, reconstructs the output as close to x as possible Where θ is the parameter of the decoder. The basic goal of VAE is to maximize the marginal log-likelihood ln p θ (x), but since the posterior distribution p θ (z|x) is difficult to calculate directly, and VAE introduces the Evidence Lower Bound (ELBO) through variational inference:
[0142]
[0143] The first term is the reconstruction term, which represents the expectation of the log-likelihood of the decoder generating the input data, reflecting the ability of the decoder to reconstruct the input data; the second term D KL is the KL divergence, which acts as a regular term to limit q φ (z|x) deviates from the prior p(z); by maximizing ELBO, the variational autoencoder VAE can indirectly maximize the log-likelihood of the data ln p θ (x), to achieve the effect of probability density estimation, p θ (x) is the probability density estimate of the data based on the parameter-based generative model.
[0144] In the training phase, given an input x, the VAE encoder q φ (z|x) first maps x to mean μ and variance σ 2 , characterize its parameters. Using the re-parameterization technique From q φ (z|x) where represents the noise from the standard normal distribution. Decoder p θ (x|z) reconstructs the output x according to z, and optimizes the VAE parameters φ and θ through the above ELBO objective function. The reconstruction loss Loss is obtained. Reconsitution , the expression is:
[0145]
[0146] By pre-training the variational autoencoder VAE on normal data, the reconstruction-based probability density estimation module can provide the key reconstruction probability density for subsequent anomaly detection. Used to identify abnormal samples. For normal data x, the reconstruction probability is high; for abnormal samples, since their distribution deviates from the training data, the reconstruction probability will drop significantly.
[0147] When performing probability density estimation based on flow models:
[0148] Normalization flow is a probabilistic generative model that learns the underlying distribution of data samples through a series of reversible and differentiable transformations f(·): R d →R d The complex data distribution p(x) is standardized into a simple benchmark distribution q(f(x)), thereby achieving efficient modeling and accurate probability density estimation of p(x). Through transformation, the logarithmic density of x can be expressed as:
[0149]
[0150] in, is the Jacobian matrix of the transformation f, is the determinant of the Jacobian matrix.
[0151] The conditional normalized flow model further expands the variable transformation into a conditional transformation f(x; H t ), the fused spatiotemporal features at time step t represent H t The conditional x t The logarithmic density log p(x t |H t ), the expression is:
[0152]
[0153] Among them, p(x t |H t ) is based on the condition H t The probability density function of the target data distribution is is the Jacobian matrix of the conditional transformation, is the determinant of the Jacobian matrix.
[0154] Through the conditional transformation f(·), the complex conditional target data distribution p(x t |H t ) is mapped to a simple conditional benchmark distribution to achieve modeling and probability density estimation of the target data.
[0155] Masked Autoregressive Flow (MAF) is a classic form of flow model, in which the transformation layer is constructed as an autoregressive neural network. This module uses MAF to learn potentially complex normalized flow transformations. The goal is to t Under the condition of maximizing the input data x t The logarithmic probability density under the current MAF model is maximized:
[0156]
[0157] Among them, φ and θ are the normalized flow and the conditional distribution q θ The parameters of (·), The time series x t Under the given conditions H t The following is mapped to the latent variable space through flow transformation, q θ (·) is the probability density of the latent variable after mapping under the benchmark distribution (Gaussian), is the Jacobian matrix used to compute the logarithmic determinant of the transformed flow.
[0158] Its loss function is:
[0159] Loss Flow = -O log p;
[0160] The two modules are based on two different density estimation paradigms, reconstruction and transformation, and jointly output probability density. The total model loss is:
[0161] Loss=Loss Reconsitution +Loss Flow .
[0162] Furthermore, when the present invention performs anomaly detection based on probability density:
[0163] Based on the probability density estimation obtained by the hybrid generation model, this module performs anomaly detection on time series data, and the anomaly score at time t is t VAE and Normalizing Flow are used to calculate x respectively. t The probability density of is:
[0164] score t =1-p VAE(x t )+1-p flow (x t );
[0165] Among them, p VAE (x t ) is the probability density calculated by the variational self-encoder, p flow (x t ) is the probability density calculated by the normalized flow;
[0166] After obtaining the anomaly score at time t, if the score is greater than the threshold K, time t is marked as anomaly:
[0167]
[0168] The threshold K is automatically selected using the Peak Over Threshold (POT) method.
[0169] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A time series anomaly detection method based on masked attention network and generative model, characterized by: The detection steps include the following: Step 1: Mask the nodes and time dimensions in the time series respectively, and use the graph attention network to capture the spatial and temporal relationships of the time series; Step 2: Combine the probability estimation ability of the standardized flow and the deep potential feature extraction ability of the variational autoencoder VAE to capture the complex distribution in the sequence, and use the standardized flow and variational autoencoder to calculate the probability density; Step 3: Obtain anomaly scores based on the calculated probability density, and detect and judge outliers in the time series.
2. The time series anomaly detection method based on masked attention network and generative model according to claim 1, characterized in that: The specific method of using the graph attention network to capture the spatial and temporal relationship of the time series in step 1 is: Step 1.1: Build a spatial mask map attention module: Mask the time series: each sensor (i.e., each dimensional time series) is regarded as a node, forming a node set U; in the sliding window, each node x in the node set U i is a sequence vector x i ={x i,t |t∈[0,w]}, a total of N nodes, that is, N-dimensional time series, where x i,t is the value of sensor i at time t, w is the sliding window size; Random sampling selects a subset of nodes Mask each node in the subset using the mask token MASK; Subset the mask proportionally It is divided into and right The nodes in are assigned a learnable mask vector right The nodes in are randomly assigned data of other nodes, and the masked nodes are represented as follows: in, Indicates that the mask mark is a d-dimensional real vector, u i and u j is a node in the node set U, x i and x j are time series nodes u respectively i and u j The value of Then, a directed graph is constructed with each dimension of sensor data as a node. Each node in the graph represents a one-dimensional time series, and each edge represents the relationship between two corresponding time series; Each sensor is given a learnable embedding vector to build the graph structure and participate in the operation of the attention mechanism. The expression is: v i ∈R n ,i∈{1,2,...,N}; Among them, v i represents the embedding vector of the i-th sensor, R n represents an n-dimensional real vector, where N is the dimension of the time series, i.e. the number of sensors; The adjacency matrix A is used to represent the directed graph. ij Representing an edge from i to j, we first calculate the normalized dot product of the embedding vectors between the two nodes, then for each node, calculate the cosine similarity between the nodes, and select the P nodes most similar to each node as its neighbors to construct the adjacency matrix A∈R N×N , the expression is: Among them, v i and v j represents the embedding vector of the i-th sensor and the j-th sensor, sim(·) is the cosine similarity function, and Top m (·) is to select the first m maximum values; The graph attention network is introduced to fuse node information and neighbor information, process the dependency relationship of nodes in the graph, and represent the aggregate of node i as z. i The expression is: Where N(i) = {j|A ij >0} is the neighbor set of node i obtained by adjacency matrix A, α i,j is the attention coefficient, W is a learnable parameter; Calculate the attention coefficient α i,j The calculation formula is: Among them, a T is the transpose of the learnable coefficient vector a of the attention mechanism, Indicates splicing, g i Indicates that sensor i fuses the masked data and the embedding vector v i The representation of g j represents the representation of sensor j fused with masked data and embedded vector, π(i, j) represents the attention score between node i and node j, ∑ k∈N(i) ∪ {i} exp(π(i, k)) represents the sum of the exponential functions of the attention scores of node i and all its neighboring nodes, N(i) represents the neighbor set of node i, {i} represents the node itself, and W is a learnable parameter; The output of the graph attention network is masked again, and the features of the masked nodes are set to zero: Among them, z i is the aggregate representation of node i after the graph attention network, is the node representation after mask operation, represents the set of masked nodes, u i Represents node i, which is used to identify whether the current node is in the mask set; Finally, the matrix form of the spatial mask image attention module output is expressed as: Z∈R N×n ; Among them, R represents a real number set, N represents the number of nodes, and n represents the feature dimension; Step 1.2: Build the temporal mask map attention module: In the sliding window, the data of N sensors at the same time t are regarded as a time node x t ={x i,t |i∈[0,N)}, construct a complete graph; Use a masking strategy similar to that in the spatial mask graph attention module to mask the time node data and obtain the masked time series Then we use the graph attention network to capture the relational dependencies in the time dimension, where node x t The updated feature is represented as c t , the expression is: Among them, σ represents the sigmoid activation function, and are the values of node t and node s after masking, represents splicing, α t,s represents the attention weight between node t and node s, e t,s represents the correlation score between time nodes t and s, e t,l represents the correlation score between time nodes t and l, and W is a learnable parameter; Using the re-masking strategy in the spatial mask map attention module, the matrix form of the output of the temporal mask map attention module is expressed as: C∈R n×N ; Among them, R represents a real number set, N represents the number of nodes, and n represents the feature dimension; Step 1.3: The spatial dependency between variables is captured by the established spatial mask graph attention module, and the temporal dependency pattern of the time series is captured by the established temporal mask graph attention module; The spatial features captured by the spatial mask map attention module are concatenated with the temporal features captured by the temporal mask map attention module, and the features of the two modalities of space and time are fused as follows: H∈R n×2N ; 3. The time series anomaly detection method based on masked attention network and generative model according to claim 2, characterized in that: The specific method of using the standardized flow and the variational autoencoder to calculate the probability density in step 2 is: Step 2.1: Reconstruct the probability density estimation module: The variational autoencoder VAE is modeled as an encoder-decoder architecture, where the encoder network q φ (z|x) encodes the input data x into a latent variable z that obeys a certain probability distribution, where φ is the parameter of the encoder; the decoder network p established θ (x|z) then according to q φ (z|x) The latent variable z obtained by sampling reconstructs the output data close to the input data x Where θ is the parameter of the decoder; Variational Autoencoder VAE introduces the evidence lower bound ELBO through variational inference: Among them: the first term is the reconstruction term, which represents the expectation of the log-likelihood of the decoder generating the input data, reflecting the ability of the decoder to reconstruct the input data; the second term D KL is the KL divergence, which acts as a regular term to limit q φ (z|x) deviates from the prior p(z); By maximizing ELBO, the variational autoencoder VAE can indirectly maximize the log-likelihood of the data ln p θ (x), to achieve the effect of probability density estimation, p θ (x) is the probability density estimation of data based on the parameter-based generative model; In the training phase, given an input x, the encoder q of the variational autoencoder φ (z|x) first maps x to mean μ and variance σ 2 , characterizing its parameters; Using the heavy parameter technique From q φ (z|x) where represents noise from a standard normal distribution; Decoder p θ (x|z) reconstructs the output x according to the latent variable z, and optimizes the parameters φ and θ of the VAE through the above ELBO objective function; Get the reconstruction loss Loss Reconsitution , the expression is: By pre-training the variational autoencoder VAE on normal data, the reconstruction-based probability density estimation module provides the key reconstruction probability density for subsequent anomaly detection Used to identify abnormal samples; Step 2.2: Adopt the normalized flow probability generation model through the reversible differentiable transformation f(·): R d →R d , standardize the complex data distribution p(x) into a simple benchmark distribution q(f(x)), and realize the modeling of p(x) and the estimation of probability density: Specifically, through reversible and differentiable transformation, the logarithmic density of x is expressed as: in, is the Jacobian matrix of the transformation f, is the determinant of the Jacobian matrix; The standardized flow probability generation model further expands the variable transformation into a conditional transformation f(x; H t ), The fused spatiotemporal features at time step t represent H t The conditional x t The logarithmic density log p(x t |H t ), the expression is: Among them, p(x t |H t ) is based on the condition H t The probability density function of the target data distribution is is the Jacobian matrix of the conditional transformation, is the determinant of the Jacobian matrix; Through the conditional transformation f(·), the complex conditional target data distribution p(x t |H t ) is mapped to a simple conditional benchmark distribution to achieve modeling and probability density estimation of target data; The masked autoregressive flow MAF is used to learn a potentially complex normalized flow transformation, with the goal of t Under the condition of t The logarithmic probability density under the current MAF model is expressed as: Among them, φ and θ are the normalized flow and the conditional distribution q θ The parameters of (·), The time series x t Under the given condition H t The following is mapped to the latent variable space through flow transformation, q θ (·) is the probability density of the latent variable after mapping under the benchmark distribution, is the Jacobian matrix, which is used to calculate the logarithmic determinant of the transformation flow; The calculation formula of its loss function is: The two modules are based on two different density estimation paradigms, reconstruction and transformation, and jointly output the probability density to obtain the total model loss, which is calculated as follows: Loss=Loss Reconsitution +Loss Flow 。 4. The time series anomaly detection method based on masked attention network and generative model according to claim 3 is characterized in that: The specific method for detecting and judging outliers in the time series in step 3 is: Based on the probability density estimation obtained by the hybrid generation model, anomaly detection is performed on time series data, and the anomaly score at time t is t VAE and Normalizing Flow are used to calculate x respectively. t The probability density of is: score t =1-p VAE (x t )+1-p flow (x t ); Among them, p VAE (x t ) is the probability density calculated by the variational self-encoder, p flow (x t ) is the probability density calculated by the normalized flow; After obtaining the anomaly score at time t, if the score is greater than the threshold K, time t is marked as anomaly. The expression is: The threshold K is automatically selected using the peak over threshold method.
Citation Information
Cited By
Method and system for extracting advanced semantic information from hierarchical power utilization sequence
CN119557698A
Industrial production anomaly detection method based on information mask and related device
CN119646574A
Water pipeline operation state anomaly detection method combining reconstruction and prediction model
CN119807970A
Unsupervised time sequence anomaly detection method and system based on frequency domain enhancement
CN119939380A
Activity identification method based on variational auto-encoder and sequential network
CN119939469A
