Anomaly detection method and device for time series data based on spatiotemporal feature representation differences
Through a deep learning model based on the difference in spatio-temporal feature representations, time and space angles are used to extract feature representations and calculate similarity, which solves the problem of failing to effectively utilize multi-dimensional time series data associated information in the existing technology, and achieves label-free Time series data anomaly detection is applicable to multiple fields and improves detection efficiency.
Patent Information
- Application Number
- CN202410969151.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2024-06-06
- Filing Date
- 2024-07-19
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2044-07-19
AI Technical Summary
Existing deep learning methods fail to effectively utilize the correlation information between different dimensions of multi-dimensional time series data in time series data anomaly detection, making it difficult to achieve efficient anomaly detection without abnormal labels, and the model complexity and training time are long. .
Using a deep learning model based on differences in spatiotemporal feature representations, feature representations are extracted from time angles and spatial angles, and the similarity between the two is calculated. KL divergence is used to construct a loss function to optimize the feature representation module to achieve anomaly detection of time series data. .
Anomaly detection of time series data is realized without labels. The model structure is simple, suitable for medical, meteorological, transportation and other fields, and has strong migration and detection efficiency.
Smart Images

Figure CN118503893B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data mining, and in particular relates to a method and device for detecting anomalies in time series data based on differences in temporal and spatial feature representations. Background Art
[0002] The application of deep learning to anomaly detection in time series data has always been a popular research direction. In recent years, deep learning applied to representation learning of time series has received a lot of attention. The use of representation learning methods has lower requirements on the quality of the data itself and data labels, and is more suitable for application in actual time series data scenarios. In recent years, some methods have emerged for anomaly detection using representation learning of time series data.
[0003] The AnomalyTransformer model proposed by Tsinghua University is based on the intuitive observation that abnormal points only have strong feature associations with their surrounding points and have low feature associations with global time series points, while normal points have relatively stable association patterns with their surrounding and global data points. It uses the Encoder of Tranformer to model two association representations, SeriesAssociation (global association) and Prior Association (local association), and judges time series abnormal points based on the difference between these two associations. However, this method only considers the association pattern of the time series direction of each time point, and does not consider the association between the channels that naturally exist in time series data.
[0004] The DCDetector model proposed by Alibaba is also based on the architecture of the above model. The difference is that the DCDetector model divides the input data into patches of equal length, constructs a patch-by-patch representation of the data and a point-by-point embedding representation within the patch, and compares the difference between the two representations after simple copy upsampling to find anomalies. Similar to the above method, this method does not take into account the natural correlation between channels of time series data, and simple copy upsampling is prone to information loss. At the same time, the above two models are not simple enough and require a long time to train.
[0005] The above two methods are both examples of using deep representation learning methods to detect anomalies in time series data. However, in the process of representing and modeling time series data, neither of them takes advantage of the rich correlation information that naturally exists between different dimensions of multidimensional time series data. Instead, they only use the correlation in the time dimension of time series data to model. Summary of the invention
[0006] In view of the above, the purpose of the present invention is to provide a method and device for anomaly detection of time series data based on differences in spatiotemporal feature representation, which can be used without abnormal labels and detect possible anomalies in time series data. The method is simple to use and efficient.
[0007] To achieve the above-mentioned purpose of the invention, an embodiment provides a method for detecting anomalies in time series data based on differences in spatiotemporal feature representation, comprising the following steps:
[0008] Obtain time series data and perform preprocessing to construct sample data;
[0009] The sample data is used to train a deep learning model based on the difference in spatiotemporal feature representation to obtain an anomaly detection model;
[0010] The anomaly detection model is used to infer and calculate the sample data to be detected to obtain the anomaly score of the data at each time point, including: determining the anomaly score of the data at each time point in the sample based on a first similarity between a time feature representation extracted from a time perspective of the sample data to be detected and a spatial feature representation extracted from a spatial perspective;
[0011] The data at the time point when the screening abnormality score is higher than the abnormality threshold is judged as abnormal.
[0012] Preferably, the preprocessing of the time series data includes: removing outliers in the time series data, backfilling missing values, and normalizing the data.
[0013] Preferably, the deep learning model based on spatiotemporal feature representation differences is trained using sample data to obtain an anomaly detection model, including:
[0014] The sample data is organized in the form of equal-length time windows, and the sample data in each time window is divided into patches of equal length in chronological order, obtaining input data of shape , where numPatchs represents the number of patches after the sample data in a single time window is divided into patches, patchSize represents the length of each patch, and C represents the number of dimensions in the multidimensional time series data;
[0015] The input data in each time window is input into the feature representation modules corresponding to each angle according to the time angle and the space angle for feature representation to obtain the time feature representation and the space feature representation. The first similarity between the time feature representation and the space feature representation is calculated in the anomaly detection module, and the loss function is constructed with the first similarity to optimize the feature representation module. The optimized feature representation module and the anomaly detection module constitute an anomaly detection model.
[0016] Preferably, the feature representation modules corresponding to the time angle and the space angle have the same structure, and both include a linear representation layer, an attention layer, and a size mapping layer;
[0017] The input data is linearly mapped in the linear representation layer to extract an embedded representation. The embedded representation obtains an important representation by focusing on important features through the attention mechanism in the attention layer. The second similarity between each row is calculated based on the important representation to reconstruct the similarity representation. The similarity representation is upsampled in the size mapping layer to obtain a temporal association representation of the same dimension as the input data. In the temporal association representation, each row of data is regarded as the association pattern between the data at a certain time point in the time window and the data at all time points in the window.
[0018] The temporal correlation representation output by the feature representation module corresponding to the time angle is used as the temporal feature representation, and the temporal correlation representation output by the feature representation module corresponding to the spatial angle is used as the spatial feature representation.
[0019] Preferably, the second similarity adopts cosine similarity.
[0020] Preferably, the embedding representation obtains an important representation by focusing on important features through an attention mechanism in the attention layer, including:
[0021] A temporal embedding representation different from the embedding representation output by the linear representation layer is used as the query vector Q. The embedding representation output by the linear representation layer is used as the key vector K and the value vector V. Based on K, Q, and V, an attention mechanism is used to focus on important features to obtain important representations.
[0022] Preferably, a representation of the data at each time point in the Patch is constructed through MLP as a query vector Q.
[0023] Preferably, the first similarity adopts KL divergence. During training, a loss function is constructed based on KL divergence to optimize the feature representation module with the goal of minimizing the loss.
[0024] During prediction and reasoning, the KL divergence between each row of data is calculated based on the temporal feature representation and the spatial feature representation. The KL divergence can represent the difference between the data at each time point obtained from the two feature representations, and the anomaly score of the data at each time point is obtained from the KL divergence.
[0025] Preferably, the abnormal threshold is constructed in the following manner:
[0026] When training a deep learning model, the anomaly scores of the time point data in the sample data used for training are saved, and the anomaly detection model is used to calculate the anomaly scores of the time point data in the sample data used for verification, and the anomaly scores of the time point data in the training sample data and the verification sample data are combined to obtain the overall anomaly score. Then, based on the knowledge of the anomaly ratio in the training sample set and the verification sample set, the anomaly score corresponding to the anomaly ratio sorting position in the overall anomaly score is selected as the anomaly threshold when sorting by high and low.
[0027] To achieve the above-mentioned object of the invention, an embodiment of the present invention provides an anomaly detection device in time series data based on spatiotemporal feature representation differences, comprising:
[0028] A data preprocessing module, which is used to obtain time series data and perform preprocessing to construct sample data;
[0029] A model training module is used to train a deep learning model based on spatiotemporal feature representation differences using sample data to obtain an anomaly detection model;
[0030] An inference calculation module is used to use the anomaly detection model to perform inference calculation on the sample data to be detected to obtain an anomaly score of the data at each time point, including: determining the anomaly score of the data at each time point in the sample based on a first similarity between a time feature representation extracted from a time perspective of the sample data to be detected and a spatial feature representation extracted from a spatial perspective;
[0031] The abnormality judgment module is used to screen the time point data whose abnormality score is higher than the abnormality threshold and is judged as abnormal.
[0032] Compared with the prior art, the present invention has the following beneficial effects:
[0033] (1) Since time series data generally lacks abnormal labels, supervised learning methods are difficult to apply. The anomaly detection method proposed in this invention uses deep representation learning technology to learn the correlation between the input data at each time point in each time window. Since the correlation between abnormal data points and other normal points is relatively fragile, it is difficult to model a stable correlation representation between abnormal points and other data points in the window from different embedded representations, thereby realizing anomaly judgment and working without labels.
[0034] (2) The anomaly detection model proposed in the present invention has a simple structure, reliable effect, and does not require complex data preprocessing;
[0035] (3) The anomaly detection method proposed in the present invention is applicable to monitoring time series data in the fields of medicine, meteorology, transportation, etc., and has strong portability. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0037] Figure 1 is a flow chart of an anomaly detection method provided by an embodiment;
[0038] Figure 2 is a schematic diagram of the structure of an anomaly detection model provided in an embodiment;
[0039] Figure 3 It is the organization form of time series data used in model training and reasoning provided by the embodiment;
[0040] Figure 4 is a schematic diagram of the structure of the attention layer MHA provided in the embodiment;
[0041] Figure 5 is a schematic diagram of anomaly scoring values provided in an embodiment;
[0042] Figure 6 is a visualization diagram of the reconstructed feature representation extracted from the determination result provided by the embodiment, wherein the upper left is the timing correlation CorrWinT of the timing window with abnormality, the upper right is the timing correlation CorrWinC of the timing window with abnormality, the lower left is the timing correlation CorrWinT of the timing window without abnormality, and the lower right is the timing correlation CorrWinT of the timing window without abnormality;
[0043] Figure 7 It is a schematic diagram of the structure of the abnormality detection device provided in the embodiment. DETAILED DESCRIPTION
[0044] To make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation methods described herein are only used to explain the present invention and do not limit the scope of protection of the present invention.
[0045] In time series data in the fields of medicine, meteorology, transportation, etc., since the correlation between abnormal data points and other normal points is relatively fragile, it is difficult to model a stable correlation representation between abnormal points and other data points in the window from different embedding representations, which can be used for subsequent abnormality judgment. Specifically, time series data naturally has correlations between dimensions and correlations in time order. Time series data can be embedded from the above two perspectives, and then a series of reconstruction methods are used to model the correlation between points in a certain time window from these two representations. For the vast majority of normal points in time series data of a certain length, no matter which of the above embedding representations is used to model, the correlation between normal points is small, and because abnormal points do not have a stable correlation dependency with other points, the correlation between abnormal points and normal points will be greatly different in the two point-to-point representations modeled from the two embedding representations, which can be used to judge abnormalities.
[0046] Based on this, an embodiment of the present invention provides an anomaly detection method for time series data based on the difference in spatiotemporal feature representation, which realizes anomaly detection of time series data in the fields of medical, meteorological, and transportation through the difference in spatiotemporal feature representation. Among them, the time series data in the medical field includes ECG time series data and EEG time series data, the time series data in the meteorological field includes rainfall time series data and various gas concentration time series data, and the time series data in the transportation field includes vehicle flow time series data.
[0047] like Figure 1 As shown, the anomaly detection method for time series data based on spatiotemporal feature representation differences provided by an embodiment of the present invention includes the following steps:
[0048] S1, obtain time series data and perform preprocessing to construct sample data.
[0049] In the embodiment, the acquired time series data can be collected by sensors, and the collected time series data is preprocessed, including removing abnormal points of monitoring data, backfilling missing values, normalizing data, and eliminating the dimensional influence between different dimensions of time series data. Specifically, the maximum and minimum normalization method is selected, which is expressed as:
[0050] ;
[0051] in, is the original value of the sequence, is the normalized value of the sequence, is the sequence length, and represents the time point data in the time series data, i and j Both represent the data index at a time point. From the sequence Find the minimum value in From the sequence Find the maximum value among
[0052] S2, using sample data to train a deep learning model based on spatiotemporal feature representation differences to obtain an anomaly detection model.
[0053] The preprocessed sample data is organized in the form of equal time windows and fed into the deep learning model. Subsequently, the time series data is embedded in the dimension level and time order level. In order to reduce the overall number of model parameters, the time series data is divided into equal blocks in time order. Specifically, Figure 3 As shown in the figure, let the time window length be winSize, the sample data organized in the form of time windows will be divided into several patches of equal size in chronological order, and the final divided data is used as the input data, and its shape is numPatchs×patchSize×C. It is easy to know that numPatchs×patchSize=winSize, where numPatchs represents the number of patches after the sample data in a single time window is divided into patches, patchSize represents the length of each patch, and C represents the number of dimensions in the multidimensional time series data.
[0054] After dividing the time window and patch, Figure 2 As shown, the input data in each time window is extracted with dimensions of patchSize*C and numPatchs*patchSize, and input into the feature representation modules corresponding to each angle respectively according to the time angle (patch order) and the space angle for feature representation to obtain the time feature representation CorrWinT and the space feature representation CorrWinC of the shape of [winSize, winSize]. The feature representation modules corresponding to the time angle and the space angle have the same structure, and both include a linear representation layer, an attention layer, and a size mapping layer.
[0055] The reason for using patch-by-patch embedding representation from a temporal perspective is that the time series patches are divided according to chronological order, which naturally maintains the position information of the original time series data, and after dividing the patches, the number of parameters of the subsequent model can be reduced.
[0056] Specifically, the input data of the time angle and the spatial angle are linearly mapped in the linear representation layer to extract the embedded representations ReprT and ReprC with the shapes of [numPatchs, reprDim] and [C, reprDim] respectively. Subsequently, the association representation between each time point of the time series data is reconstructed from the two embedded representations ReprT and ReprC, where reprDim is a model hyperparameter and the linear representation layer can be implemented using MLP.
[0057] Specifically, the embedded representations ReprT and ReprC are respectively represented by focusing on important features in the attention layer MHA through the attention mechanism. Figure 4 As shown, taking the embedded representation ReprT as an example, the embedded representation in the attention layer obtains important representations by focusing on important features through the attention mechanism, including: using a temporal embedded representation different from the embedded representation ReprT output by the linear representation layer as the query vector Q, denoting the number of query vectors Q as n, and using the embedded representation ReprT output by the linear representation layer as the key vector K and the value vector V, and based on K, Q, and V and using the attention mechanism to focus on important features to obtain an important representation with a shape of [n, reprDim].
[0058] It should be noted that the query vector Q can be obtained using a variety of different time series data embedding representations. The shape of the query vector Q depends on the specific embedding representation, and the shape of the query vector Q finally obtained depends on the construction method. Specifically, it includes: using the MLP structure to model the representation of the data at each time point in the patch as the query vector Q, that is, using a linear layer with an input dimension of numPatchs * C and an output dimension of reprDim to map the input time series data, and the resulting query vector shape Q is [patchSize, reprDim].
[0059] Specifically, the second similarity (for example, cosine similarity) between each row is calculated based on the important representation to reconstruct a similarity representation with a shape of [n,n]. Since what is needed later is the association representation between each point in the time window, the similarity representation is upsampled in the size mapping layer to obtain the temporal association representations CorrWinT and CorrWinC of the same dimension as the input data (that is, [winSize, winSize]). In the temporal association representation, each row of data is regarded as the association pattern between the data at a certain time point in the time window and the data at all time points in the window, wherein the temporal association representation output by the feature representation module corresponding to the time angle is used as the time feature representation CorrWinT, and the temporal association representation output by the feature representation module corresponding to the spatial angle is used as the spatial feature representation CorrWinC.
[0060] After obtaining the time feature representation CorrWinT and the space feature representation CorrWinC, the first similarity between the two is calculated in the anomaly detection module according to the time feature representation CorrWinT and the space feature representation CorrWinC, and a loss function is constructed based on the first similarity to optimize the feature representation module. The optimized feature representation module and the anomaly detection module constitute an anomaly detection model.
[0061] The first similarity adopts KL divergence. In the time feature representation CorrWinT and the spatial feature representation CorrWinC, the physical meaning of each row is the correlation of the data at a certain time point relative to the data at each time point in the time window, which can be regarded as a distribution, and KL divergence is an indicator to measure the similarity between two distributions. For two distributions P1 and P2, the KL divergence between the two is The calculation is as follows:
[0062] ;
[0063] in, represents the i-th data point in distribution P1, represents the i-th data point in distribution P2;
[0064] Since the abnormal data in the training data only accounts for a small part and the training data is generally unlabeled, the training data can be regarded as having no anomalies during the training process. The training goal is to minimize the KL divergence loss between CorrWinT and CorrWinC to optimize the feature representation module. The optimized feature representation module and the anomaly detection module constitute the anomaly detection model.
[0065] S3, using the anomaly detection model to perform inference calculations on the sample data to be detected to obtain the anomaly score of the data at each time point.
[0066] When testing reasoning, the sample data to be tested is preprocessed, organized in time windows, and divided into patches, and then input into the anomaly detection module to calculate the first similarity (i.e., KL divergence) between the time feature representation CorrWinT extracted from the time perspective and the spatial feature representation CorrWinC extracted from the spatial perspective. The KL divergence can represent the difference between the data at each time point obtained from the two feature representations (i.e., the time series association representation). It can be seen from the above that the association pattern of normal points is easier to reconstruct, while the association pattern of abnormal points is difficult to reconstruct and thus shows a larger KL divergence difference. Therefore, the anomaly score of the data at each time point is obtained from the KL divergence, and the shape is [winSize,1].
[0067] The anomaly scores of each time window above are finally concatenated together to obtain the shape of The point-by-point anomaly score of the dataset is is the length of the dataset used.
[0068] S4, the time point data with a screening anomaly score higher than the anomaly threshold is judged as abnormal.
[0069] In the embodiment, the data at the time point with an abnormal score higher than the abnormal threshold is screened according to the abnormal threshold and is determined to be abnormal. The abnormal threshold is defined by assuming that the training data (past monitoring data) and the verification data (currently collected data) are distributed in the same way, and therefore have the same abnormal ratio. The abnormal ratio can be determined based on past experience, and the abnormal threshold is subsequently determined based on the abnormal ratio. That is, if the abnormal ratio is 1%, the abnormal threshold is determined to be the first percentile of the abnormal score after descending order, and so on. It is specifically constructed in the following way:
[0070] When training a deep learning model, the anomaly scores of the time point data in the sample data used for training are saved, and the anomaly detection model is used to calculate the anomaly scores of the time point data in the sample data used for verification, and the anomaly scores of the time point data in the training sample data and the verification sample data are combined to obtain the overall anomaly score. Then, based on the knowledge of the anomaly ratio in the training sample set and the verification sample set, the anomaly score corresponding to the anomaly ratio sorting position in the overall anomaly score is selected as the anomaly threshold when sorting by high and low.
[0071] Specifically, the anomaly score of the data at each time point obtained in the training sample data is recorded as ScoreTrain, whose shape is [trainLength, 1], and the anomaly score of the data at each time point obtained in the validation sample data is recorded as ScoreTest, whose shape is [testLength, 1]. The two are concatenated. The anomaly score Score of all data is obtained, and its shape is [trainLength+testLength,1]. Let the anomaly ratio in the training sample set and the validation sample set be δ. Then the anomaly score Score corresponding to the δ percentile sorting position after the anomaly scores of all data are arranged from large to small is used as the anomaly threshold threshold:
[0072] ;
[0073] ;
[0074] ;
[0075] in, Indicates abnormal proportion Corresponding sort position The anomaly score, Represents the overall length. Assume that there are 10 anomaly scores in total, and the specific order is {a, b, c, d, e, f, g, h, i, j}. The anomaly ratio is 30%. Then the anomaly score c corresponding to the 30% order position is used as the anomaly threshold.
[0076] The embodiment also takes the PSM public data set as an example, uses the above model for training and testing, and finally obtains the abnormal score value of a certain segment of the test set as follows: Figure 5 As shown, Figure 5 The straight line parallel to the x-axis in the figure is the anomaly threshold. As mentioned above, since the time series data is input in the form of a time window during training and validation, if there are anomalies in the window, not only is it difficult to reconstruct the relationship between the anomaly and other normal points from different embedding representations, but the anomaly will also affect the reconstruction of the association pattern between the normal point and the rest of the time points in the window, so the anomaly score will often appear in a rectangular peak shape.
[0077] In the judgment result of the PSM data set, the reconstruction results of two data segments with a length of 60 are respectively taken, wherein the first segment of data has an anomaly, and the second segment of data does not have an anomaly. The two reconstruction results of the first segment of data are recorded as RecAT and RecAC, and the two reconstruction results of the second segment of data are recorded as RecT and RecC. According to the above, the distribution difference between RecAT and RecAC will be greater than the difference between RecT and RecC. Figure 6 The four figures in the middle (from left to right, from top to bottom) are RecAT, RecAC, RecT, and RecA. It can be seen from the figures that the results support the above analysis.
[0078] like Figure 7 As shown, the embodiment also provides an anomaly detection device 70 in time series data based on the difference in spatiotemporal feature representation, including a data preprocessing module 71, a model training module 72, an inference calculation module 73, and an anomaly judgment module 74, wherein the data preprocessing module 71 is used to obtain time series data and perform preprocessing to construct sample data; the model training module 72 is used to use the sample data to train a deep learning model based on the difference in spatiotemporal feature representation to obtain an anomaly detection model; the inference calculation module 73 is used to use the anomaly detection model to perform inference calculation on the sample data to be detected to obtain an anomaly score for the data at each time point; the anomaly judgment module 74 is used to screen the time point data whose anomaly score is higher than the anomaly threshold and judged as abnormal.
[0079] It should be noted that the anomaly detection device in time series data based on the difference in spatiotemporal feature representation provided in the above embodiment should be illustrated by the division of the above functional modules when detecting anomalies. The above functional distribution can be completed by different functional modules as needed, that is, the internal structure of the terminal or server is divided into different functional modules to complete all or part of the functions described above. In addition, the anomaly detection device in time series data based on the difference in spatiotemporal feature representation provided in the above embodiment and the anomaly detection construction method embodiment in time series data based on the difference in spatiotemporal feature representation belong to the same concept. The specific implementation process is detailed in the anomaly detection method embodiment of time series data based on the difference in spatiotemporal feature representation, which will not be repeated here.
[0080] The specific implementation methods described above provide a detailed description of the technical solutions and beneficial effects of the present invention. It should be understood that the above is only the most preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for detecting anomalies in time series data based on differences in spatiotemporal feature representation, characterized in that: The anomaly detection of medical time series data is achieved by expressing differences in spatiotemporal features, including the following steps: Acquire time series data in the medical field and perform preprocessing to construct sample data, wherein the time series data in the medical field includes ECG time series data or EEG time series data; The deep learning model based on the difference of spatiotemporal feature representation is trained by using the sample data to obtain an anomaly detection model, including: organizing the sample data in the form of equal time windows, and dividing the sample data in each time window into equal-length patches in chronological order, and obtaining input data of the shape of , where numPatchs represents the number of patches after the sample data in a single time window is divided into patches, patchSize represents the length of each patch, and C represents the number of dimensions in the multidimensional time series data; Input data in each time window is input into the feature representation modules corresponding to each angle according to the time angle and the space angle for feature representation to obtain the time feature representation and the space feature representation, and the first similarity between the time feature representation and the space feature representation is calculated in the anomaly detection module, and the loss function is constructed with the first similarity to optimize the feature representation module, and the optimized feature representation module and the anomaly detection module constitute an anomaly detection model; Among them, the feature representation modules corresponding to the time angle and the space angle have the same structure, both of which include a linear representation layer, an attention layer and a size mapping layer; the input data is linearly mapped in the linear representation layer to extract an embedded representation, and the embedded representation obtains an important representation by focusing on important features through the attention mechanism in the attention layer, and the second similarity between each row is calculated based on the important representation to reconstruct the similarity representation, and the similarity representation is upsampled in the size mapping layer to obtain a temporal association representation of the same dimension as the input data, in which each row of data is regarded as a correlation pattern between data at a certain time point in the time window and data at all time points in the window; the temporal association representation output by the feature representation module corresponding to the time angle is used as the temporal feature representation, and the temporal association representation output by the feature representation module corresponding to the space angle is used as the spatial feature representation; The anomaly detection model is used to infer and calculate the sample data to be detected to obtain the anomaly score of the data at each time point, including: determining the anomaly score of the data at each time point in the sample based on a first similarity between a time feature representation extracted from a time perspective of the sample data to be detected and a spatial feature representation extracted from a spatial perspective; The data at the time point when the screening abnormality score is higher than the abnormality threshold is judged as abnormal.
2. The anomaly detection method for time series data based on spatiotemporal feature representation differences according to claim 1 is characterized in that: The preprocessing of time series data includes: removing outliers in the time series data, backfilling missing values, and normalizing the data.
3. The anomaly detection method for time series data based on spatiotemporal feature representation differences according to claim 1, characterized in that: The second similarity adopts cosine similarity.
4. The anomaly detection method for time series data based on spatiotemporal feature representation differences according to claim 1, characterized in that: The embedded representation obtains important representations by focusing on important features through the attention mechanism in the attention layer, including: A temporal embedding representation different from the embedding representation output by the linear representation layer is used as the query vector Q. The embedding representation output by the linear representation layer is used as the key vector K and the value vector V. Based on K, Q, and V, an attention mechanism is used to focus on important features to obtain important representations.
5. The anomaly detection method for time series data based on spatiotemporal feature representation differences according to claim 4 is characterized in that: The representation of the data at each time point in the patch is constructed through MLP as the query vector Q.
6. The anomaly detection method for time series data based on spatiotemporal feature representation differences according to claim 1, characterized in that: The first similarity uses KL divergence. During training, a loss function is constructed based on KL divergence to optimize the feature representation module with the goal of minimizing the loss. During prediction and reasoning, the KL divergence between each row of data is calculated based on the temporal feature representation and the spatial feature representation. The KL divergence can represent the difference between the data at each time point obtained from the two feature representations, and the anomaly score of the data at each time point is obtained from the KL divergence.
7. The anomaly detection method for time series data based on spatiotemporal feature representation differences according to claim 1, characterized in that: The anomaly threshold is constructed in the following way: When training a deep learning model, the anomaly scores of the time point data in the sample data used for training are saved, and the anomaly detection model is used to calculate the anomaly scores of the time point data in the sample data used for verification, and the anomaly scores of the time point data in the training sample data and the verification sample data are combined to obtain the overall anomaly score. Then, based on the knowledge of the anomaly ratio in the training sample set and the verification sample set, the anomaly score corresponding to the anomaly ratio sorting position in the overall anomaly score is selected as the anomaly threshold when sorting by high and low.
8. An anomaly detection device for time series data based on time-space feature representation differences, characterized in that: The anomaly detection of time series data in the medical field is achieved by expressing differences in spatiotemporal features, including: A data preprocessing module, which is used to obtain time series data and perform preprocessing to construct sample data, wherein the time series data in the medical field includes ECG time series data or EEG time series data; A model training module is used to train a deep learning model based on spatiotemporal feature representation differences using sample data to obtain an anomaly detection model, including: organizing sample data in the form of equal time windows, and dividing the sample data in each time window into equal-length patches in chronological order to obtain input data of shape , where numPatchs represents the number of patches after the sample data in a single time window is divided into patches, patchSize represents the length of each patch, and C represents the number of dimensions in the multidimensional time series data; Input data in each time window is input into the feature representation modules corresponding to each angle according to the time angle and the space angle for feature representation to obtain the time feature representation and the space feature representation, and the first similarity between the time feature representation and the space feature representation is calculated in the anomaly detection module, and the loss function is constructed with the first similarity to optimize the feature representation module, and the optimized feature representation module and the anomaly detection module constitute an anomaly detection model; Among them, the feature representation modules corresponding to the time angle and the space angle have the same structure, both of which include a linear representation layer, an attention layer and a size mapping layer; the input data is linearly mapped in the linear representation layer to extract an embedded representation, and the embedded representation obtains an important representation by focusing on important features through the attention mechanism in the attention layer, and the second similarity between each row is calculated based on the important representation to reconstruct the similarity representation, and the similarity representation is upsampled in the size mapping layer to obtain a temporal association representation of the same dimension as the input data, in which each row of data is regarded as a correlation pattern between data at a certain time point in the time window and data at all time points in the window; the temporal association representation output by the feature representation module corresponding to the time angle is used as the temporal feature representation, and the temporal association representation output by the feature representation module corresponding to the space angle is used as the spatial feature representation; An inference calculation module is used to use the anomaly detection model to perform inference calculation on the sample data to be detected to obtain an anomaly score of the data at each time point, including: determining the anomaly score of the data at each time point in the sample based on a first similarity between a time feature representation extracted from a time perspective of the sample data to be detected and a spatial feature representation extracted from a spatial perspective; The abnormality judgment module is used to screen the time point data whose abnormality score is higher than the abnormality threshold and is judged as abnormal.
Citation Information
Patent Citations
Power dispatching monitoring data anomaly detection method based on time-space anomaly Transform
CN117056839A
Ocean observation data anomaly detection method based on space-time correlation of adjacent sites
CN117972604A
Internet of Things time series data anomaly detection method and system based on dynamic graph attention
CN118094427A
Determine Spatiotemporal Causal Interactions In Data
US20130166188A1
MEA-BP neural network-based WSN abnormality detection method
WO2018126984A2
