Multivariate time sequence identification method combined with shape representation
By combining Transformer and shapelets methods, the global and local features of the time series are extracted, and the problem of insufficient classification accuracy in the prior art is solved, and higher classification accuracy and stronger recognition capabilities are achieved.
Patent Information
- Application Number
- CN202411545669.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-01
- Publication Date
- 2025-02-18
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art has insufficient accuracy in time series classification and cannot effectively extract local features of time series.
Combining Transformer's self-attention module and shapelets method, the global and local features of the time series are extracted, and the double attention layer and shapelets encoder are spliced for timing modeling.
The accuracy of time series classification is improved, and noise interference is reduced by extracting global and local features, and the classification recognition ability of the network is enhanced.
Smart Images

Figure CN119474976A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of social data governance, and specifically relates to a multivariate time series recognition method combined with shapelets shape representation. Background Art
[0002] Time series plays an important role in real life and is widely used in various fields, such as weather forecasting, missing data interpolation in data mining, and anomaly detection in industry. The continuous recording of time series means that each time point contains only some scalar data. Since a single time point usually lacks sufficient information for analysis, many studies focus on the changes and trends of time series, which can better reveal the characteristics of time series. The multivariate time series classification (MTSC) task aims to assign labels to time series through supervised learning so that supervised learning can be used to give appropriate labels to time series. This task has attracted much attention from academia and industry in the field of time series analysis.
[0003] Nowadays, extracting effective features from multivariate time series has become a major challenge for time series classification and recognition. People have made great efforts for time series classification and recognition. The recently proposed Transformer architecture has shown good ability in capturing the global context of language modeling tasks. Inspired by this, the powerful sequence modeling ability of Transformer is transferred from natural language processing to time series classification and recognition. However, there is still a key problem in using Transformer for time series classification and recognition: the lack of key local features. Multivariate time series are usually continuous data with high noise, periodicity, and different semantics. The unique complexity of time series makes it impossible to accurately identify different time series with global features captured only by Transformer, while local features will be captured in key time windows. Combining global features and local features for classification effectively avoids the interference of external noise. The shapelets method extracts a subsequence in a time series, which is the most prominent feature in this time series, and uses it to perform time series classification and recognition. Shapelets-based methods focus on extracting local features within a significant time range to reduce the noise interference that is common in time series. Some shapelets-based classification and recognition methods focus on finding the best candidate shapes or using different subsets of discriminant features to represent different classes, etc. These are important manifestations of local feature extraction. Therefore, how to extract key local features in combination with shapelets has become a problem that must be solved in time series classification and recognition. Summary of the invention
[0004] One purpose of the present invention is to address the problem that the accuracy of time series classification in the prior art is insufficient and the time series classification model cannot effectively extract the local features of the time series. A time series recognition method combined with shapelets local feature extraction is proposed. The global features are extracted through the self-attention model of Transformer, and shapelets are combined to extract the local features of the time series salient subsequences, and the two are combined for time series modeling.
[0005] The present invention utilizes Transformer network, self-attention module (Attention), and shapelets to extract global features and local features, and constructs a complete time series classification model combined with shapelets shape representation to improve the accuracy of time series classification.
[0006] The technical solution adopted by the present invention is as follows:
[0007] Step 1: Obtain multivariate time series data to construct a data set, standardize the multivariate time series data in the data set, and perform digital coding mapping on the labels.
[0008] Step 2: The standardized time series data is passed through several cascaded local feature extraction units to obtain local features.
[0009] The specific implementation process of the local feature extraction unit is: rearrange the input time series data, then input it into the dual attention layer to extract features.
[0010] The dual attention layer implementation process is as follows: the time series vector y after feature mapping passes through the squeeze excitation layer and the sparse self-attention layer successively. The squeeze excitation layer obtains the weights of different window information. In the process of capturing global features, the sparse self-attention layer selects top-u vectors through KL divergence for self-attention calculation, thereby reducing a certain amount of time and space complexity.
[0011] Step 3: Extract local features of time series data: The standardized multivariate time series data from step 1 is fed into the encoder combined with shapelets, and different similarity metrics are used to match patterns from short-term to long-term, thereby extracting local features of prominent subsequences.
[0012] Step 4: Concatenate the global features and local features output from Step 2 and Step 3, obtain the predicted distribution of each label class of the input time series through the classifier, combine the labels after digital coding mapping, and perform end-to-end training by minimizing the cross entropy loss.
[0013] The technical implementation scheme provided by the present invention has the following beneficial effects:
[0014] The present invention introduces a squeeze excitation layer and a sparse self-attention layer as a global feature learning method for time series data, which not only supplements the global feature representation of time series data, but also selects the representative tensor of top-u for calculation through KL divergence, thereby completing the extraction of global features while reducing the required resources and improving the accuracy of time series classification and recognition.
[0015] The present invention introduces a shapelet encoder as a local feature modeling method for time series data. By learning time series of separated shapes of different lengths, the short-term to long-term patterns of the time series are calculated to extract local features, thereby solving the problem of lack of local features in the classification and recognition process of time series data and improving the classification accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is the overall flow chart of the method of the present invention;
[0017] Figure 2 This is a schematic diagram of the network structure of the present invention. DETAILED DESCRIPTION
[0018] The present invention will be further analyzed below in conjunction with the accompanying drawings.
[0019] A time series recognition method combined with shapelets shape representation, such as Figure 1 and Figure 2 As shown, the following steps are included:
[0020] Step (1), obtain multivariate time series data to construct a training set and a test set, standardize the multivariate time series data and perform digital coding mapping on the labels. Figure 2 This paper shows an overview of the time series classification and recognition method combined with shapelets shape representation. The entire model input is a set of multivariate time series involving multiple dimensions (channels). For each dimension, the time series has the same sequence length. First, the features and labels of the training set and test set are obtained from the original data. At the same time, the null values in the data set are replaced, and then the StandardScaler object is created to fit and standardize the training data, and the labels are mapped to data encoding.
[0021] Step (2), the time series data after the normalization process is passed through a number of cascaded local feature extraction units to obtain local features. The specific implementation process of the local feature extraction unit is: the input time series data is rearranged, and then input into the dual attention layer to extract features. In order to obtain time series data of different time series patterns, the present invention layers the network architecture, and the time series vectors of different stages are input into the layered module and then into the dual attention layer, thereby generating feature maps of different time scales.
[0022] The rearrangement process is as follows: let the input vector be X∈RB* (P*F)*C , where B represents the batch size, P represents the number of each batch, F represents the length feature after stratification, and C represents the number of channels; the vector is rearranged, and the vector with a scale of B*(P*F)*C is rearranged to B*F*(P*C). The specific formula is as follows:
[0023] x′=rearrange(x,B*(P*F)*C->P*F*(P*C))
[0024] Among them, rearrange represents the rearrangement operation, and the other variables are consistent with the input vector representation. The feature mapping of the rearranged vector x′ is then performed as follows:
[0025] y=Wx′+b
[0026] Where W is the weight of the linear layer, b is the bias term, and the output y is in the shape of (B, F, O), where O is the number of output channels. Assume that the length and dimension of the time series data in each stage will be reduced to T / 4 and 4C respectively, and then it will be put into the linear layer for dimension alignment, so that time series patterns of different lengths can be extracted. The layered vectors will then be put into the dual attention layer to extract global features.
[0027] The rearranged time series vector is input into the dual self-attention layer to extract global features. Global time series data modeling is mainly completed by the self-attention layer in Transformer. The self-attention layer is used to establish the relationship between each element in the input sequence, so that when the model processes a certain token or position, it can "pay attention" to other tokens or positions in the sequence, thereby better understanding the context information.
[0028] In the self-attention layer, each element of the input is weighted and summed with other elements in the sequence by calculating the attention weight. These weights reflect the degree of "attention" of an element to other elements, helping the model to dynamically adjust the representation of the input based on global information. This mechanism allows the self-attention layer to capture long-range dependencies in the sequence without being restricted by the order of the input.
[0029] The present invention introduces a dual attention mechanism to replace the traditional time self-attention, which will effectively reduce the temporal and spatial complexity. It is divided into a squeeze excitation layer and a sparse self-attention layer. The squeeze excitation layer enables the network to capture the local features of each stage through a global window. The input time series vector of this module is in the shape of (B, L, C), where B represents the batch size, L is the number of time blocks, and C represents the channel dimension. The squeeze excitation layer is mainly divided into two steps: squeeze and excitation:
[0030] Squeeze: It aims to use global average pooling to aggregate the information of each stage and generate a context description for each stage based on the information of different stages of long-range dependencies. The squeeze operation is defined as follows:
[0031] Z = Avg pool (x)
[0032] AvgPool represents the average pooling operation on the input vector.
[0033] Motivation: The vector after global average pooling is reshaped and the context weights are learned by using two linear projections.
[0034] H = W2ReLU(W1Z′)
[0035] Where W1 and W2 represent the weight parameters that need to be learned for linear projection, Z′ is the vector after global average pooling and reshaping, and ReLU is the activation function.
[0036] Finally, the squeeze layer applies the trained window description to the original time series vector. The normalized weights are added to the original features. The specific formula is as follows:
[0037] S=XSigmod(H)
[0038] Where X is the original feature and Sigmod is the activation function.
[0039] At the same time, in order to capture the global features of the time series, the multi-head self-attention mechanism will calculate each dot product pair. Increasing the window size can effectively enhance the sequence representation and improve the network classification results, but as the window size increases, the spatiotemporal complexity will also increase. And most of the dot product pairs cannot play an active role, only a very small part of the dot product pairs play an active role. Therefore, the present invention introduces a sparse self-attention layer to overcome the current problem. The top-u vectors are selected for self-attention calculation through KL divergence, rather than all vectors, where u is the sampling frequency. The sparse self-attention layer accepts Among them, M Q , M K , M V The present invention first randomly selects several keys as K, and then respectively uses q i ,k i To represent the i-th row in Q, K, and calculate the specific score under the i-th query according to the following formula:
[0040]
[0041] where q i ,k i is the i-th row in Q, K, LK is the length of K, is the scale, usually the dimension of query and key vectors. This formula includes calculating the maximum value and the mean. Subtracting the two is to give priority to the score dominated by top-u. Top-u is defined as:
[0042]
[0043] Finally, The dot product with V is used as a partial sparse self-attention feature map, where the top-u queries are selected for corresponding calculations, and the average value of V is used as the calculation score for the rest, which will greatly reduce the amount of calculation. The specific formula is as follows:
[0044]
[0045] Score2=Mean(V)
[0046] Among them, Score1 is the score obtained after self-attention calculation. For the above formula top u The selected vectors, K and V, are the key and value of the input self-attention module. Mean is the mean processing, and Score2 is supplemented by calculating the average of V.
[0047] Step (3), extracting local features of time series data, after extracting global features in step (2), local features still need to be combined for time series classification. The standardized data from step (1) is input into an encoder combined with shapelets. After splitting it to different degrees, different similarity metrics are used to match patterns from short-term to long-term, thereby extracting local features of prominent subsequences. The existing Transformer-based encoder design may be more suitable for natural language processing, but may not be suitable for time series data. For example: Some studies have shown that subsequences that are far apart in time should not be similar. However, time series data often has periodicity, which causes some time series data to still have certain similarities when they are far apart, which is often in the opposite direction of this conclusion. In order to solve the above problems, the present invention considers introducing an encoder combined with shapelets, which will extract local features of prominent time series subsequences of different lengths to reduce time series noise interference.
[0048] The time series classification and recognition method based on shapelets was initially developed by extracting representative shape features of univariate time series. Due to the limitations of multivariate time series data classification and recognition, this paper extends it to a more general multivariate case. Given a standardized vector x∈R C×T, where C represents the dimension and T represents the time block length; initialize a sequence s ∈ R with the same dimension C C×L , L < T, calculate the distance between all segments of length L in the vector x and s, and find the segment most similar to s. The final output dist is the minimum of these distances, representing the degree of the most similar match. The specific formula is expressed as:
[0049]
[0050] where x[t, L] represents the subsequence starting from timestamp t and lasting for length L, calculate the similarity between the subsequence x[t, L] and s through the Euclidean metric, and take the minimum value as the local feature. Usually, s is used as a trainable parameter, that is, the optimal shape feature can be learned through the optimization algorithm. However, this method is difficult to capture features other than shape, such as the potential frequency domain features and trend features of time series data, which will limit the learning ability of the encoder to a certain extent. To solve the above problems, the present invention extends the calculation of similarity to:
[0051]
[0052] where (x j [t, L], s j ) represents the sequence of the j-th dimension, and agg d is an aggregator of different similarity measurement methods, and C is the channel dimension of the time series vector x. Calculate in the most similar dimension (x j [t, L], s j ) to generate the final result, and d(·) is the similarity measurement method. When d is the similarity measurement method of the Euclidean norm, the extended equation is the single-variable calculation formula.
[0053] To capture the local features calculated by different time scales and different similarity measurement methods, a shapelets encoder is added. This encoder is a combination of multiple different sub-modules. There are M different similarity measurement methods inside the sub-module, and the input is the time series vectors of R different time scales. The reason for doing this is that: time series will show different time patterns at different lengths, and at the same time, different similarity measurement methods can supplement additional features.
[0054] The input time series vector passes through the similarity calculation, and the obtained g(x, s, d) forms the prominent sequence feature f r,m , the prominent sequence feature f r,m The subsequence length is L r 、the similarity measurement method is d m , and f r,m has prominent subsequence features, where T is the length of the input time series; the same similarity metric d m , the same subsequence length L r The N different prominent subsequence features in f r,m (x i ), x i is one of the dimensions in the time series; all subsequence features of the input time series vector are connected as the local features of the time series vector. The formula of the shapelets encoder is specifically expressed as:
[0055] z i =z i,1 ⊕z i,2 ⊕···⊕z i,R
[0056] z i,r =f r,1 (x i )⊕f r,2 (x i )⊕···⊕f r,M (x i )
[0057] f r,m (x i )=[f r,m,1 (x i ),f r,m,2 (x i ),···,f r,n,N (x i )]
[0058] Where ⊕ represents the concatenation operator, z i,r Represents x i In the time length L r The local features on the , including the local feature results calculated by M different similarity metrics, z i Represents the local features of the current sample input, and connects the local feature vectors of different time series lengths.
[0059] By configuring the shapelets encoder, three widely used similarity metrics are adopted for salient subsequences: Euclidean distance, cosine similarity and cross-correlation, which effectively brings out the local features of the time series.
[0060] By introducing a general configuration of shapelets encoders, which considers three widely adopted similarity metrics including Euclidean distance, cosine similarity and cross-correlation, we automatically determine the encoder architecture to match short-term to long-term temporal patterns.
[0061] Step (4) concatenates and linearly projects the output feature vectors of step 2 and step 3 to obtain the predicted distribution of each possible label class of the input time series. End-to-end training is then performed by minimizing the cross entropy loss.
[0062] The calculation method of cross entropy loss for a single-label n-classification task is as follows:
[0063]
[0064] where y i Represents the i-th element of the actual category label, represents the i-th element of the probability distribution predicted by the model, and K represents the number of time series categories.
[0065] The proposed method is evaluated on 13 datasets from the latest multivariate time series classification archive. The archive includes real-world multivariate time series data collected from different applications such as human activity recognition, motion classification, ECG / EEG signal classification, etc. The datasets have different characteristics in terms of the number of sequences, sequence length, number of sequence dimensions, and number of categories.
[0066] For each data set, the present invention calculates the classification accuracy as an evaluation indicator, and also calculates average and other indicators to compare different methods. The present invention compares the proposed method with a variety of different benchmark methods.
[0067] Table 1: Details of the results achieved
[0068]
[0069]
[0070] It can be concluded from Table 1 that compared with many previous results, the results of the present invention are better, mainly in small data. According to the results provided in the table, it can be intuitively observed that the present invention has won 11 times in 13 data sets, with an average accuracy of avg acc: 0.815, which is 13%, 11.6%, 10%, and 7.5% higher than the average accuracy of the previously released DTW-1NN-D, MLSTM-FCN, SMATE, and DANET. The experimental results show that the application of the present invention in the multivariate time series classification and recognition method is feasible. It extracts global features through dual attention layers and combines different similarity metrics of shapelets to extract local features of different lengths, so that the features available for learning are increased, which effectively enhances the network classification and recognition capabilities.
Claims
1. A multivariate time series recognition method combined with shapelets shape representation, characterized in that: The process includes: Step 1: Obtain multivariate time series data to construct a data set, standardize the multivariate time series data in the data set, and perform digital coding mapping on the labels; Step 2: The time series data after the normalization process is passed through several cascaded local feature extraction units to obtain local features; Step 3: The standardized multivariate time series data is fed into the encoder combined with shapelets, and the local features of the prominent subsequences are extracted through different similarity metrics; Step 4: Concatenate the global features and local features, obtain the predicted distribution of each label class of the input time series through the classifier, combine the labels after digital coding mapping, and perform end-to-end training by minimizing the cross entropy loss.
2. The multivariate time series recognition method combined with shapelets shape representation according to claim 1 is characterized in that: The specific implementation process of the local feature extraction unit is: rearrange the input time series data, then input it into the dual attention layer to extract features.
3. The multivariate time series recognition method combined with shapelets shape representation according to claim 2 is characterized in that: The rearrangement implementation process is as follows: Let the input vector be X∈R B*(P*F)*C , where B represents the batch size, P represents the number of each batch, F represents the length feature after stratification, and C represents the number of channels; the vector is rearranged, and the vector with a scale of B*(P*F)*C is rearranged to B*F*(P*C); Perform feature mapping on the rearranged vector x′, the formula is as follows y=Wx′+b Where W is the weight of the linear layer, b is the bias term, and the shape of the output y is (B, F, O), where O is the number of output channels.
4. The multivariate time series recognition method combined with shapelets shape representation according to claim 3 is characterized in that: The dual attention layer implementation process is as follows: the time series vector y after feature mapping passes through the squeeze excitation layer and the sparse self-attention layer successively, the squeeze excitation layer obtains the weights of different window information, and the sparse self-attention layer selects the top-u vectors for self-attention calculation through KL divergence in the process of capturing global features.
5. The multivariate time series recognition method combined with shapelets shape representation according to claim 4 is characterized in that: The specific implementation process of step 3 is as follows: Given a normalized vector \(x\in\mathbb{R}\) C×T , where \(C\) represents the dimension and \(T\) represents the time block length; initialize a sequence \(s\in\mathbb{R}\) with the same dimension \(C\) C×L , \(L < T\), calculate the distance between all segments of length \(L\) in the vector \(x\) and \(s\), and find the segment that is most similar to \(s\); The similarity is calculated as: Where (x j [t,L],s j ) represents the sequence of the jth dimension, agg d is an aggregator of different similarity measures, d(·) is the similarity measure; Add a shapelets encoder, which is a combination of multiple different submodules. There are M different similarity metrics inside the submodule, and the input is R time series vectors of different time scales; The input time series vector is similarity calculated, and the obtained g(x,s,d) constitutes the prominent sequence feature f r,m , highlighting the sequence feature f r,m The length of the subsequence is L r , the similarity measure is d m , f r,m In prominent subsequence features, where T is the length of the input time series; the same similarity metric d m , the same subsequence length L r The N different prominent subsequence features in f r,m (x i ), x i is one of the dimensions in the time series; all subsequence features of the input time series vector are connected as the local features of the time series vector; The formula of the shapelets encoder is specifically expressed as: f r,m (x i )=[f r,m,1 (x i ),f r,m,2 (x i ),···,f r,m,N (x i )] in Represents the concatenation operator, z i,r Represents x i In the time length L r The local features on the , including the local feature results calculated by M different similarity metrics, z i Represents the local features of the current sample input, connecting the local feature vectors of different time series lengths.
Citation Information
Patent Citations
DTW-former-based time sequence prediction model and method
CN116227560A
Supervised contrast learning network model training multivariate time series data classification method and system
CN117407772A