Time series data anomaly detection method and device based on memory-enhanced autoencoder

By introducing the memory mechanism and LSTM encoder into the autoencoder, combined with the penalty term and the rectification function, the problem of over-generalization of the autoencoder in time series anomaly detection is solved and the accuracy of abnormal data identification is improved.

CN114298217BActive Publication Date: 2024-08-27SHANGHAI UNIV
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202111619238.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-27
Publication Date
2024-08-27
Estimated Expiration
2041-12-27

AI Technical Summary

Technical Problem

Autoencoders are prone to over-generalization in time series anomaly detection, resulting in abnormal data being reconstructed well and being unable to effectively distinguish abnormal and normal data, and measuring model complexity and data space magnitude is a long and inefficient process. process.

Method used

A memory-enhanced autoencoder is designed. By introducing a memory mechanism and an LSTM encoder-decoder, the relative distance between the potential representation and the memory item is used for matching and reorganization, and a penalty term and a rectification function are added to sparse the addressing vector to suppress Model generalization ability, extracting typical patterns for anomaly detection.

Benefits of technology

It effectively suppresses the over-generalization ability of the model, increases the anomaly score between abnormal data and normal data, and significantly improves the accuracy of anomaly identification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114298217B
    Figure CN114298217B
Patent Text Reader

Abstract

The present invention relates to a method and device for detecting anomalies in time series data based on a memory-enhanced autoencoder, the method comprising: obtaining original data, and obtaining original samples after processing; using an encoder to encode the original samples into potential representations; calculating the relative distance between the potential representations and each memory item to form an addressing vector; multiplying the addressing vector with each memory item respectively, and adding the multiplication results to obtain a new potential representation; using a decoder to decode the new potential representation to obtain a reconstructed sample; realizing anomaly detection according to the reconstruction error of the original sample and the reconstructed sample; the training of the memory item comprises: initializing the memory item, obtaining training data, and executing the above steps to obtain the reconstruction error, calculate the reconstruction loss, and continuously iterate the training to adjust the parameters in the memory item. Compared with the prior art, the present invention can suppress the over-generalization ability of the model, increase the anomaly score between abnormal data and normal data, and greatly improve the accuracy of identifying anomalies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of autoencoders, and in particular to a method and device for detecting anomalies in time series data based on a memory-enhanced autoencoder. Background Art

[0002] Autoencoders are a very efficient and commonly used method in anomaly detection algorithms. They use the samples themselves to train the model for reconstruction through unsupervised learning of the entire data set. In anomaly detection tasks, reconstruction error is generally used as an indicator to judge anomalies. Normal data with a large sample size naturally have a much greater impact on parameters than those with a small sample size. It is generally assumed that the reconstruction error of normal data is low because they are close to the original sample; while for abnormal data, the reconstruction error is high. However, this assumption is not always true in the anomaly detection task of time series. Autoencoders sometimes generalize well, allowing abnormal data to be reconstructed well. This results in abnormal samples also having a reconstruction error that is quite low compared to normal samples, and they cannot be distinguished. This is because the learning ability of the autoencoder is too strong and the parameter capacity is too large, so that the model can learn the patterns of normal samples while also learning the abnormal patterns. This phenomenon of "overgeneralization" caused by excessive generalization ability is very common in time series anomaly detection. However, measuring the complexity of the model and the magnitude of the data space is a long and inefficient process, so an unsupervised, end-to-end method that is not prone to overgeneralization is needed. Summary of the invention

[0003] The purpose of the present invention is to provide a method and device for detecting anomalies in time series data based on a memory-enhanced autoencoder in order to overcome the defect of the above-mentioned prior art that the autoencoder has excessive generalization ability for abnormal data.

[0004] The purpose of the present invention can be achieved by the following technical solutions:

[0005] A method for detecting anomalies in time series data based on a memory-enhanced autoencoder comprises the following steps:

[0006] Step 1: Get the original data, perform preprocessing to get the time series data, normalize the time series data to get the original sample;

[0007] Step 2: Use an encoder to encode the original sample into a latent representation;

[0008] Step 3: Calculate the relative distances between the potential representation and each pre-set and trained memory item to form an addressing vector;

[0009] Step 4: Multiply the addressing vector by each memory item to obtain a new potential representation;

[0010] Step 5: Using a decoder to decode the new potential representation to obtain a reconstructed sample;

[0011] Step 6: Perform time series data anomaly detection based on the reconstruction error between the original sample and the reconstructed sample;

[0012] The training process of the memory items includes: initializing each memory item, obtaining training data, and executing steps 1 to 6 in sequence to obtain the reconstruction error, thereby calculating the reconstruction loss, and adjusting the parameters in each memory item; repeating steps 1 to 6, adjusting the parameters in each memory item, and performing iterative training until a preset training stop condition is met.

[0013] Furthermore, step 3 also includes: performing rectification and standardization operations on the addressing vector in sequence.

[0014] Furthermore, the calculation expression of the rectification is:

[0015]

[0016] In the formula, is the addressing vector corresponding to the ith memory item after rectification, q i is the addressing vector corresponding to the i-th memory item, λ is the preset sparsification threshold, N is the total number of memory items;

[0017] The standardized calculation expression is:

[0018]

[0019] Where q is the standardized addressing vector, and ε is the preset standard threshold.

[0020] Furthermore, the calculation expression of the reconstruction loss is:

[0021]

[0022]

[0023] In the formula, To rebuild the losses, is the loss function between the original sample and the reconstructed sample, is the memory module sparsity metric index, q i is the addressing vector corresponding to the i-th memory item, N is the total number of memory items, and η is a preset adjustable hyperparameter.

[0024] Furthermore, the is the loss function based on MSE.

[0025] Furthermore, in step 3, the relative distance is calculated using the Softmax metric to form an addressing vector, and the calculation expression of the addressing vector is:

[0026] q i =Softmax(z T m i )

[0027] Where z is the potential representation generated by the encoder definition N memory items The memory modules composed of i represents the i-th memory item, q i is the addressing vector corresponding to the i-th memory item.

[0028] Furthermore, the computational expression of the new potential representation is:

[0029]

[0030] In the formula, is the new potential representation, q is the addressing vector combination, M is the memory item combination, q i is the addressing vector corresponding to the i-th memory item, m i is the i-th memory item, and N is the total number of memory items.

[0031] Furthermore, the calculation expression of the normalization process is:

[0032]

[0033] In the formula, x is the normalized data, D is the sample data after the original data is preprocessed, is a matrix containing n time series samples, the time series data d is the data point.

[0034] Furthermore, the encoder is an LSTM encoder, and the decoder is an LSTM decoder.

[0035] The present invention also provides a time series data anomaly detection device based on a memory-enhanced autoencoder, which is characterized in that it includes a memory and a processor, the memory stores a computer program, and the processor calls the computer program to execute the steps of the method described above.

[0036] Compared with the prior art, the present invention has the following advantages:

[0037] The present invention designs an unsupervised, end-to-end, and non-overgeneralized method for anomaly detection of IoT time series data. First, a memory mechanism is introduced to suppress the generalization ability of the model, and a memory-enhanced autoencoder for anomaly detection of time series data is designed. The latent representation encoded by the autoencoder is matched with the normal sample in the memory module, and a most similar latent representation of the sample with the anomaly eliminated is recombined, and then the latent representation is decoded to obtain the reconstructed sample and the original sample to calculate the outlier value; secondly, by adding a penalty term and a differentiable rectifier function to the Loss to sparse the addressing vector, the memory module is encouraged to extract a typical normal mode, thereby suppressing the generalization ability of the model; at the same time, for time series data, LSTM is introduced for decoding and encoding to obtain the contextual features of the time series data.

[0038] The method provided by the present invention can suppress the over-generalization ability of the model, increase the anomaly score between abnormal data and normal data, and greatly improve the accuracy of identifying anomalies. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 The overall structure diagram of an autoencoder of a method for detecting anomalies in time series data based on a memory-enhanced autoencoder provided in an embodiment of the present invention;

[0040] Figure 2 An autoencoder data flow diagram of a method for detecting anomalies in time series data based on a memory-enhanced autoencoder provided in an embodiment of the present invention;

[0041] Figure 3 A schematic diagram of an addressing vector without any thinning operation provided in an embodiment of the present invention;

[0042] Figure 4 A schematic diagram of an addressing vector induced by sparseness provided in an embodiment of the present invention;

[0043] Figure 5 A schematic diagram of a final vector after sparse induction and rectification provided in an embodiment of the present invention;

[0044] Figure 6 It is a schematic diagram of the result of a normal sample on ECG5000 heartbeat data provided in an embodiment of the present invention, and the shaded part represents the error between the original sample and the reconstructed sample;

[0045] Figure 7 A schematic diagram of the results of an abnormal sample on ECG5000 heartbeat data provided in an embodiment of the present invention, wherein the shaded portion represents the error between the original sample and the reconstructed sample;

[0046] In the figure, batch is batch and LSTM Cell is LSTM cell. DETAILED DESCRIPTION

[0047] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0048] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0049] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0050] Example 1

[0051] This embodiment provides a method for detecting anomalies in time series data based on a memory-enhanced autoencoder, comprising the following steps:

[0052] Step 1: Get the original data, perform preprocessing to get the time series data, normalize the time series data to get the original sample;

[0053] Step 2: Use an encoder to encode the original sample into a latent representation;

[0054] Step 3: Calculate the relative distances between the potential representation and each pre-set and trained memory item to form an addressing vector;

[0055] Step 4: Multiply the addressing vector with each memory item to obtain a new potential representation;

[0056] Step 5: Use the decoder to decode the new potential representation to obtain the reconstructed sample;

[0057] Step 6: Perform time series data anomaly detection based on the reconstruction error between the original sample and the reconstructed sample;

[0058] The training process of the memory items includes: initializing each memory item, obtaining training data, and executing steps 1 to 6 in sequence to obtain the reconstruction error, thereby calculating the reconstruction loss, and adjusting the parameters in each memory item; repeating steps 1 to 6, adjusting the parameters in each memory item, and performing iterative training until the preset training stop condition is met.

[0059] In order to solve the problem of over-generalization of traditional autoencoders and avoid learning and reconstruction of abnormal data, this solution first introduces a memory mechanism and sets multiple memory items. After the encoder is used to encode the sample, the relative distance between the encoded potential representation and each memory item, that is, the similarity, is calculated, and the result of multiplying the similarity with the memory item data is decoded to obtain the reconstructed sample; during the continuous training process in advance, each memory item will gradually match the normal data in the original sample, so that the autoencoder decodes with normal data, so that the reconstructed sample does not have generalized decoding of abnormal data, avoiding the generalization problem of the autoencoder.

[0060] As a preferred implementation, step 3 further includes: performing rectification and standardization operations on the addressing vectors in sequence, and rectifying and standardizing the addressing vectors make the addressing combination more effective.

[0061] Specifically, the calculation expression for rectification is:

[0062]

[0063] In the formula, is the addressing vector corresponding to the ith memory item after rectification, q i is the addressing vector corresponding to the i-th memory item, λ is the preset optional sparsification threshold, N is the total number of memory items;

[0064] The standardized calculation expression is:

[0065]

[0066] Where q is the standardized addressing vector, and ε is the preset standard threshold.

[0067] As a preferred implementation, the calculation expression of the reconstruction loss is:

[0068]

[0069]

[0070] In the formula, To rebuild the losses, is the loss function between the original sample and the reconstructed sample, is the memory module sparsity metric index, q i is the addressing vector corresponding to the i-th memory item, N is the total number of memory items, and η is a preset adjustable hyperparameter. is the loss function based on MSE.

[0071] The loss value consists of two parts: MSE reconstruction loss and sparsification metric index. There is an adjustable hyperparameter η to control the influence of the sparsification metric index to achieve the sparsification of the addressing vector.

[0072] Working principle: The autoencoder uses reconstruction error to judge data anomalies, but for time series data in the Internet of Things, sometimes it can reconstruct anomalies very well without accurately measuring the model complexity and data dimension, resulting in a low reconstruction error of the anomaly. However, measuring the model complexity and the magnitude of the data space is a long and inefficient process. This embodiment designs an unsupervised, end-to-end, and non-overgeneralized method for anomaly detection of time series data in the Internet of Things. First, a memory mechanism is introduced to suppress the generalization ability of the model, and a memory-enhanced autoencoder TSMAE (Time Series Memory Autoencoder) for anomaly detection of time series data is designed. The potential representation encoded by the autoencoder is matched with the normal sample in the memory module, and a most similar potential representation of the sample with the anomaly eliminated is recombined, and then the potential representation is decoded to obtain the reconstructed sample and the original sample to calculate the anomaly value. Secondly, by adding a penalty term and a differentiable rectifier function to the Loss to sparse the addressing vector, the memory module is encouraged to extract a typical normal mode, thereby suppressing the generalization ability of the model. At the same time, for time series data, LSTM is introduced for decoding and encoding to obtain the contextual features of the time series data. The method provided in this embodiment can suppress the over-generalization ability of the model, increase the anomaly score between abnormal data and normal data, and greatly improve the accuracy of identifying anomalies.

[0073] A more optimal implementation can be obtained by arbitrarily combining the above preferred implementations. The implementation process of an optimal implementation is described in detail below.

[0074] In response to the demand for anomaly detection of time series data in the Internet of Things, this embodiment designs a memory-enhanced autoencoder model, such as Figure 1 The overall structure of the model, the specific numerical calculation and flow mode are as follows Figure 2 shown.

[0075] Step 1: First, preprocess the raw data to obtain computable time series data, and normalize it according to the context data of the sensor at the same time point every time from the entire time dimension. As input, the entire raw data is a matrix containing n time series samples, each sample length is T, representing the data collected by T acquisition actions. For each data point d, find the maximum and minimum values ​​of the column where the data is located as the normalization parameters of the data point. The specific normalization method is:

[0076]

[0077] Step 2: Use LSTM encoder to encode the normalized data into latent representation z.

[0078] Step 3: Use Softmax to calculate the relative distance between the potential representation and each memory item to form an addressing vector. The inner product is used to calculate the matching degree between the potential representation and each memory item, and then a relative similarity distance is obtained by comparing it with other memory items through Softmax.

[0079] q i =Softmax(z T m i )

[0080] In the formula, the potential representation generated by the encoder is definition N memory items The memory modules composed of i represents the i-th memory item, the attention addressing vector

[0081] Rectify the addressed vector.

[0082]

[0083] Normalize the rectified addressing vector.

[0084]

[0085] λ is an optional sparsification threshold that satisfies

[0086] like Figure 3-5 As shown, the results of rectifying and normalizing the addressing vector are compared.

[0087] Step 4: Combine the memory items according to the weights of the addressing vector to form a new potential representation

[0088]

[0089] In the formula, is the new potential representation, q is the addressing vector combination, M is the memory item combination, q i is the addressing vector corresponding to the i-th memory item, m i is the i-th memory item, and N is the total number of memory items.

[0090] Step 5: Use the LSTM decoder to decode the new combined latent representation to obtain the reconstructed sample.

[0091] Step 6: Use L2 distance to represent the reconstruction error between the original sample and the reconstructed sample as the anomaly score. At the same time, use MSE as the loss function to calculate the reconstruction loss of the model, combined with the memory module sparsity metric index as the loss value

[0092]

[0093] in The specific measurement methods are:

[0094]

[0095] The addressing vector result of combining the rectification in step 3 and the induced sparse operation in step 6 is as follows Figure 3 As shown in Figure 2, the addressing vector has an obvious sparse trend, and there is no complex combination of low-value weights.

[0096] Step 7: Figure 6 and Figure 7 The results clearly show the difference in the size of the model's direct reconstruction error for normal samples and abnormal samples, that is, the difference in the size of the shadow area. According to the data distribution of the abnormal score, the optimal threshold is traversed to find the criterion for judging normal and abnormal results in the task.

[0097] This embodiment provides a time series data anomaly detection device based on a memory-enhanced autoencoder, including a memory and a processor, the memory stores a computer program, and the processor calls the computer program to execute the steps of the above method.

[0098] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.

Claims

1. A method for detecting anomalies in time series data based on a memory-enhanced autoencoder, characterized in that: The following steps are involved: Step 1: Get the original data, perform preprocessing to get the time series data, normalize the time series data to get the original sample; Step 2: Use an encoder to encode the original sample into a latent representation; Step 3: Calculate the relative distances between the potential representation and each pre-set and trained memory item to form an addressing vector; Step 4: Multiply the addressing vector by each memory item to obtain a new potential representation; Step 5: Using a decoder to decode the new potential representation to obtain a reconstructed sample; Step 6: Perform time series data anomaly detection based on the reconstruction error between the original sample and the reconstructed sample; The training process of the memory items includes: initializing each memory item, obtaining training data, and executing steps 1 to 6 in sequence to obtain the reconstruction error, thereby calculating the reconstruction loss, and adjusting the parameters in each memory item; repeating steps 1 to 6, adjusting the parameters in each memory item, and performing iterative training until a preset training stop condition is met.

2. According to claim 1, a method for detecting anomalies in time series data based on a memory-enhanced autoencoder is characterized in that: Step 3 also includes: performing rectification and standardization operations on the addressing vector in sequence.

3. The method for detecting anomalies in time series data based on a memory-enhanced autoencoder according to claim 2, characterized in that: The calculation expression of the rectification is: In the formula, is the addressing vector corresponding to the ith memory item after rectification, q i is the addressing vector corresponding to the i-th memory item, λ is the preset sparsification threshold, N is the total number of memory items; The standardized calculation expression is: Where q is the standardized addressing vector, and ε is the preset standard threshold.

4. The method for detecting anomalies in time series data based on a memory-enhanced autoencoder according to claim 2, characterized in that: The calculation expression of the reconstruction loss is: In the formula, To rebuild the losses, is the loss function between the original sample and the reconstructed sample, is the memory module sparsity metric index, q i is the addressing vector corresponding to the i-th memory item, N is the total number of memory items, and η is a preset adjustable hyperparameter.

5. The method for detecting anomalies in time series data based on a memory-enhanced autoencoder according to claim 4, characterized in that: Said is the loss function based on MSE.

6. The method for detecting anomalies in time series data based on a memory-enhanced autoencoder according to claim 1, characterized in that: In step 3, the relative distance is calculated using the Softmax metric to form an addressing vector, and the calculation expression of the addressing vector is: q i =Softmax(z T m i ) Where z is the potential representation generated by the encoder definition N memory items The memory modules composed of i represents the i-th memory item, q i is the addressing vector corresponding to the i-th memory item.

7. The method for detecting anomalies in time series data based on a memory-enhanced autoencoder according to claim 1, characterized in that: The computational expression of the new potential representation is: In the formula, is the new potential representation, q is the addressing vector combination, M is the memory item combination, q i is the addressing vector corresponding to the i-th memory item, m i is the i-th memory item, and N is the total number of memory items.

8. The method for detecting anomalies in time series data based on a memory-enhanced autoencoder according to claim 1, characterized in that: The calculation expression of the normalization process is: In the formula, x is the normalized data, D is the sample data after the original data is preprocessed, is a matrix containing n time series samples, the time series data 1≤t≤T, d is a data point.

9. The method for detecting anomalies in time series data based on a memory-enhanced autoencoder according to claim 1, characterized in that: The encoder is an LSTM encoder, and the decoder is an LSTM decoder.

10. A time series data anomaly detection device based on a memory-enhanced autoencoder, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor calls the computer program to execute the steps of any one of the methods according to claims 1 to 9.

Citation Information

Patent Citations

  • Semi-supervised time sequence anomaly detection method and system

    CN113067754A

  • Video anomaly detection method based on memory enhanced automatic encoder

    CN113807178A

  • System and method for training an autoencoder to detect anomalous system behaviour

    GB202113180D0

  • Topology-inspired neural network autoencoding for electronic system fault detection

    US20190286506A1