Time sequence similarity measurement method based on twin neural network and terminal

Based on the dual -based neural network similarity measurement method, combined with the pre -training large model and the Adaprs layer, the deficiencies of traditional methods in the analysis of the small sample time sequence have been solved, and the more efficient similarity and pan -in generalization are achieved. Ability.

CN119357707AActive Publication Date: 2025-01-24HUNAN UNIV
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411943130.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-01-24
Estimated Expiration
2044-12-27

AI Technical Summary

Technical Problem

Traditional sequence analysis methods have shortcomings in dealing with small sample time series analysis, and it is difficult to effectively capture complex dependencies and show good generalization capabilities.

Method used

Adopting a time sequence similarity method based on the twin neural network, through the bulls attention mechanism of the sharing right structure and pre -training large model through the twin neural network, combined with the Adaprs layer to fine -tune the pre -training large model, extract the global representation of the time series data indicating And use the distance between the Ou's distance for the similarity.

Benefits of technology

In the small sample scenario, effectively measure the similarity of time sequence data, improve the generalization ability and robustness of the model, reduce overfitting risks, and suitable for time sequence analysis in the field of data scarcity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357707A_ABST
    Figure CN119357707A_ABST
Patent Text Reader

Abstract

The invention discloses a time sequence similarity measurement method and terminal based on a twin neural network, and the method comprises the steps: carrying out the grouping and pairing of time sequence data samples into time sequence sample pairs, and labeling the time sequence sample pairs; and inputting the time sequence sample pairs after pairing and labeling into a twin neural network using the same pre-training large model as a branch, obtaining the similarity between the time sequences as the final output of the whole network, and updating the network weight of the combination of the whole twin neural network and the fine-tuning pre-training large model by using a loss function. According to the method, for a time series data similarity measurement task in a small sample scene, the similarity measurement of the time series data is carried out by utilizing the powerful capability of a pre-trained large model in the time series field and combining the advantages of a twin neural network in small sample similarity measurement; measurement of the similarity of the time series can be completed only through a small number of samples, and the features of the time series can be extracted in an omnibearing mode to serve as the basis of similarity measurement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention discloses a time series similarity measurement method and terminal based on a twin neural network, belonging to the field of similarity measurement of fine-tuned pre-trained deep learning models. Background Art

[0002] In recent years, time series similarity measurement methods based on twin neural networks and fine-tuning of pre-trained large models have gradually attracted attention, especially in small sample scenarios. The analysis of time series data is a key issue in many fields. Traditional sequence analysis methods such as ARIMA and LSTM face challenges when dealing with complex dependencies or small sample data. For the ARIMA model, it relies on linearity and stationarity assumptions and is suitable for the prediction of stationary time series. It is difficult to capture complex nonlinear dependencies. In the case of small samples, it also shows the problem of insufficient generalization ability caused by data scarcity. For the LSTM model, although it can handle long-term time dependencies, due to its complexity, it is prone to overfitting problems in small sample data, and the amount of data required for training is relatively high. In order to solve these problems, advanced methods such as contrastive learning, twin neural networks, and self-attention mechanisms continue to emerge, showing better adaptability in dealing with complex dependencies and small sample scenarios. Therefore, the combination of twin neural networks and pre-trained large models has become a new direction for solving the task of measuring the similarity of small sample time series. Summary of the invention

[0003] The technical problem solved by the present invention is: to provide a time series similarity measurement method and terminal based on a twin neural network in view of the defects of traditional sequence analysis methods in processing small sample time series analysis.

[0004] The present invention is implemented by the following technical solutions: The present invention first discloses a time series similarity measurement method based on a twin neural network, which specifically includes the following steps: S1. Pair the acquired time series data samples in pairs, and label each paired time series sample pair according to whether the time series data samples are similar; S2. Input the time series sample pair into the twin neural network for training. The two branches of the twin neural network use the same pre-trained large model to process the two time series data samples of the time series sample pair. The feature vector of each time step data in the time series data sample is obtained through the multi-head attention layer shared between the pre-trained large models. At the same time, the Adapters layer is added to the twin neural network to fine-tune the pre-trained large model. S3, using feature pooling to integrate the feature vectors of all time step data in the time series data sample to obtain the final global representation of the entire time series data sample; S4. Use the Euclidean distance between the feature vectors after pooling of the time series data samples as the final output of the similarity measurement of the time series sample pairs, and combine the label comparison loss function marked in step S1 to optimize the fine-tuned pre-trained large model.

[0005] In the time series similarity measurement method based on twin neural network of the present invention, further, before pairing the time series data samples in step S1, the original time series data is preprocessed, including alignment of time series, filling of missing values ​​of time series and modification of outliers of time series.

[0006] In the time series similarity measurement method based on twin neural networks of the present invention, further, in the step S1, the time series sample pairs are labeled according to the Euclidean distance between the time series data samples; the time series sample pairs whose Euclidean distance between the time series data samples is less than 0.2 are labeled as 1; the time series sample pairs whose Euclidean distance between the time series data samples is greater than 0.8 are labeled as 0; the labels of the remaining time series sample pairs are set to 0.5.

[0007] In the time series similarity measurement method based on twin neural network of the present invention, further, in the step S2, the pre-trained large model has a position embedding layer, and the position embedding layer first embeds the position of the time series for the input time series data sample, and uses Transformer sine-cosine position coding to encode the position of each time step of the time series data sample. The pre-trained large model perceives the different time steps of the time series through the position coding of each time step.

[0008] In the time series similarity measurement method based on twin neural network of the present invention, further, in step S2, the multi-head attention layer outputs the feature vectors of different time step data in the time series data sample through the following sub-steps: S21. Project the input time series data samples into query, key, and value spaces using different weight matrices: , in, is the input time series data sample, Q , K , V are the projections of time series data samples into query, key, and value spaces, respectively. W Q , W K, W V They are the query space weight matrix, key space weight matrix and value space weight matrix respectively; S22. Calculate the dot product of the query and key at each time step in the time series data sample by the following formula, and obtain the attention weight by softmax normalization: , in, Attention(Q,K,V) is the attention weight, is the dimension of the key, T Represents the projection transpose of time series data samples into the key space; S23. Projecting time series data samples into value space using attention weights V Perform weighted summation to get the output of different heads of the multi-head attention layer as follows: , represents the first Time series data output by each header, represents the first The attention weight of the head; S24. Concatenate the outputs of all heads in the multi-head attention layer and project them back to the original dimension. The final output of the multi-head attention layer is as follows: , in, It is the time series data feature vector finally output by the multi-head attention layer, which contains the dependencies of the time series data captured by all attention heads and constitutes the global dependencies between the data at different time steps in the time series data sample. It is a multi-head attention layer Output from different heads, W o is the output projection matrix.

[0009] In the time series similarity measurement method based on twin neural network of the present invention, further, the Adapters layer is inserted after the multi-head attention layer, which is a two-layer bottleneck structure. The time series data finally output by the multi-head attention layer is first reduced in dimension by the descent layer, then passed through a nonlinear activation function, and finally passed through the ascending layer to project the reduced-dimensional time series data features back to the high-dimensional space output; The output of the Adapters layer and the time series data finally output by the multi-head attention layer are added in the form of residual connection through the following formula: , in his the time series data finally output by the multi-head attention layer, Adapters(h) is the output of the Adapters layer, h’ It is the common output of the multi-head attention layer and the Adapters layer.

[0010] In the time series similarity measurement method based on the twin neural network of the present invention, further, in the step S3, after the time series data sample is output by the multi-head attention layer and the Adapters layer, it is first input into a feedforward network composed of two layers of fully connected networks, and the feature representation of each time step data in the time series data sample is gradually nonlinearly transformed by the following formula: , in are the weights and bias parameters of the two fully connected layers in the feedforward network, h’ The common output of the multi-head attention layer and the Adapters layer for the time series data samples in step S2 is fitted by the nonlinear activation function ReLU to obtain is the output of the feedforward network; Then, the features of all time step data of the two time series data samples in the time series sample pair are integrated by the following formulas, and the final global representation of the time series data samples is extracted respectively: , in, Represents the feature vector generated by the average pooling operation of all time step data of the time series data sample, which is the time series data sample A global representation of all time-step data in ; The time series data sample output by the feedforward network is t The feature vector of the time step data, Represents the length of the time series data sample, that is, the number of time steps it contains.

[0011] In the time series similarity measurement method based on twin neural network of the present invention, further, in step S4, the pre-trained large model after fine-tuning is optimized by the following contrast loss function: , in represents the contrast loss function, A label indicating whether the time series sample in step S1 is similar to the annotated time series data sample, d is the similarity of a pair of time series samples measured by the Euclidean distance between the feature vectors of the time series data samples. m is a threshold used to distinguish the distance between similar and dissimilar time series sample pairs. mThe value range is a real number between 0 and 1.

[0012] In the time series similarity measurement method based on the twin neural network of the present invention, further, in the process of optimizing the fine-tuning pre-trained large model, the Adapters layer also needs to be optimized simultaneously through the loss function.

[0013] The present invention also discloses a terminal that adopts the above-mentioned time series similarity measurement method based on twin neural network, including a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor is used to execute the above-mentioned time series similarity measurement method based on twin neural network of the present invention when executing the program.

[0014] The twin neural network adopted in the present invention performs well in small sample tasks with its dual-branch structure with shared weights. By comparing paired input time series data samples, it can effectively measure similarity. At the same time, it uses a pre-trained large model as a branch of the twin neural network, and has powerful sequence modeling capabilities. Especially in the pre-training stage of unsupervised learning, it has accumulated rich feature expression capabilities and can capture complex long-distance dependency information in time series data samples through its self-attention mechanism, so that when they are migrated to specific fields, even if the amount of data is limited, they can show good generalization ability through fine-tuning.

[0015] In the time series similarity measurement method of the present invention, the two branches of the twin neural network use the same pre-trained large model to extract the features of the time series data samples. Each time series data sample is processed by the multi-head self-attention mechanism of the pre-trained large model to generate a feature vector for each time step data, and then the similarity between the time series sample pairs is calculated through the twin structure with shared parameters. Compared with traditional methods, this combined strategy can effectively cope with the time series similarity measurement task in small sample scenarios, and achieves higher-precision similarity calculation through the similarity learning of the twin neural network and the sequence modeling advantages of the pre-trained large model.

[0016] The present invention also introduces Adapters technology as a fine-tuning technology for pre-trained large models, which improves the flexibility of large models while giving full play to the advantages of pre-trained large models under small sample conditions. Adapters is a lightweight fine-tuning method that reduces the computational cost of the fine-tuning process by adding small adaptation modules to the pre-trained large model, which is suitable for the actual needs of small sample tasks. The fine-tuned pre-trained large model can adapt to the time series characteristics of specific fields and enhance the performance of the model in similarity measurement tasks.

[0017] The present invention adopts the above technical solution to achieve the following beneficial effects: (1) The pre-trained large model can be fine-tuned by introducing the Adapters layer, which can perform efficient parameter adjustment under small sample conditions. It is not necessary to adjust all the parameters of the training large model, which greatly reduces the amount of parameters to be adjusted, reduces the risk of overfitting, retains the original rich feature extraction capabilities of the pre-trained model, and reduces the demand for memory and computing resources. It is particularly suitable for time series analysis in data-scarce fields, such as time series analysis in power scenarios.

[0018] (2) By introducing the multi-head attention mechanism and the Adapters layer, the pre-trained large model can capture the complex dependencies and global context in the time series. In the pre-trained large model for time series of the present invention, the Adapters layer extracts the trends, seasonal fluctuations, periodic patterns and other features of the time series data, which is more advantageous than the traditional sequence analysis method. In addition, the fine-tuning of Adapters enhances the flexibility of feature representation, enabling the model to adjust the feature extraction capability according to specific fields and improve the accuracy of similarity measurement.

[0019] (3) The twin neural network can effectively measure similarity by measuring the feature distance of time series sample pairs. The model uses the contrast loss function to expand the distance between different samples and reduce the distance between the same samples, making the similarity calculation more discriminative.

[0020] (4) The position embedding mechanism introduced by the Transformer in the pre-trained large model helps the model better understand the sequential information between time steps. Compared with the traditional RNN model, the parallel processing mechanism of the Transformer sine and cosine position encoding combined with position embedding effectively avoids the long-term dependency problem and improves the accuracy of time series feature extraction.

[0021] (5) By fine-tuning the large model, the adaptability to specific domain tasks (such as time series classification or prediction) can be enhanced, and the structure of the twin neural network enables the model to maintain good generalization performance when facing new samples, which makes the model not only able to be used for similarity measurement, but also applicable to subsequent classification or prediction tasks.

[0022] By combining the twin neural network and the pre-trained large model, the present invention can more accurately extract features in time series and improve the generalization and robustness of the model. It not only has significant advantages in the small sample similarity measurement task of time series data, but also shows broad application prospects in time series analysis in fields such as financial data, health monitoring, and fault detection.

[0023] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 It is a schematic diagram of the time series similarity measurement process based on the twin neural network of the present invention.

[0025] Figure 2 Schematic diagram of the twin neural network structure in the present invention.

[0026] Figure 3 This is a schematic diagram of the pre-trained large model in the present invention.

[0027] Figure 4 This is a schematic diagram of the Adapters layer in the present invention. DETAILED DESCRIPTION Example

[0028] See also Figure 1 In this embodiment, the similarity measurement of time series data of a wind turbine generator set is taken as an example to specifically illustrate the time series similarity measurement method based on a twin neural network of the present invention.

[0029] The time series data of the wind turbine generator set processed in this embodiment include the power generated by the wind turbine generator set, the wind speed of the wind turbine generator set at each height, the temperature and humidity of the wind turbine generator set. The power generated by the wind turbine generator set, the wind speed of the wind turbine generator set at each height, the temperature and humidity of the wind turbine generator set that need to be measured for time series similarity are collected by sensors, aligned according to time nodes, and merged into a set of original time series data containing the above parameters of the wind turbine generator set.

[0030] The specific steps of measuring the similarity of the time series data of the wind turbine generator set collected above are as follows: S1. The acquired time series data samples are grouped and paired in pairs, and each paired time series sample pair is labeled according to whether the time series data samples are similar.

[0031] Before pairing the time series data samples, the original time series data is preprocessed, including the alignment of the time series, the filling of the missing values ​​of the time series and the modification of the outliers of the time series, to obtain the time series data samples.

[0032] Merging the real-time parameters of the wind turbine generator set means aligning the time nodes of the original time series data. Processing the missing values ​​and outliers in the merged and aligned time series data. Taking the temperature data detected by the wind turbine generator set as an example, the missing values ​​in the original time series data are filled by linear interpolation using the following formula: ,in is the temperature value corresponding to the interpolation point, and are the temperature values ​​of two known data points, is the timestamp corresponding to the interpolation point, and are the timestamps corresponding to two known data points.

[0033] Taking the wind speed data detected by wind turbines as an example, the outliers in the original time series data are filled using the mean method using the following formula: , are the wind speed values ​​of the known data points, is the wind speed value corresponding to the outlier point.

[0034] The preprocessed time series data samples are grouped and paired, with two time series data samples as one group. The preprocessed time series data samples are grouped and paired in pairs to prepare for input into the subsequent twin neural network. The overall structure of the twin neural network in this embodiment is shown in the attached figure. Figure 2 As shown in Figure 1, the network combines the twin neural network with a fine-tuned pre-trained large model. The traditional twin neural network is composed of two neural networks with the same structure and shared weights. It takes paired data samples as input and outputs its representation embedded in a high-dimensional space to compare the similarity between the input paired data samples. In this embodiment, the two shared pre-trained large model structures process time series data samples respectively. and .

[0035] This embodiment labels time series sample pairs according to the Euclidean distance between the time series data samples. The Euclidean distance between the time series data samples satisfies the following formula: ,in For time series data samples =( ) and time series data samples =( ), For time series data samples The value at the i-th time step, For time series data samples The value at the i-th time step.

[0036] The specific labeling rules for time series sample pairs are as follows: the labels of time series sample pairs whose Euclidean distance between the time series data samples is less than 0.2 are marked as 1; the labels of time series sample pairs whose Euclidean distance between the time series data samples is greater than 0.8 are marked as 0; the labels of the remaining time series samples are set to 0.5.

[0037] In this step, the calculation of the Euclidean distance between time series data samples is performed directly using the original data that has not been processed by the neural network. In the subsequent steps, through deep learning of the time series data samples, according to the feature space suitable for measurement in the data, the time series data samples are extracted into complex feature vectors through the deep learning network. Based on this feature vector, the similarity of the time series samples is measured to represent a more accurate time series similarity.

[0038] S2. Input the time series sample pair into the twin neural network for training. The two branches of the twin neural network use the same pre-trained large model to process the two time series data samples of the time series sample pair. The pre-trained large model of this embodiment uses GPT2, and its structure is as follows: Figure 3 As shown in the figure, the feature vector of each time step data in the time series data sample is obtained through the multi-head attention layer shared between the pre-trained large models, capturing the global dependency between data at different time steps. At the same time, the Adapters layer is added to the twin neural network to fine-tune the pre-trained large model.

[0039] The twin neural network has a position embedding layer, and both pre-trained large models are configured with a position embedding layer. The position embedding layer first embeds the position of the input time series data samples, encodes the position of each time step data in the time series data samples, and helps the pre-trained large model perceive the order of the input time series data samples, that is, the time order of the time series. The pre-trained large model perceives the different time steps of the time series through the position encoding of each time step, and understands the relative position relationship between the data of each time step.

[0040] This embodiment specifically uses Transformer sine and cosine position encoding to encode the position of each time step of the time series data sample. The non-learnable encoding in the form of sine and cosine in Transformer can reduce the parameter burden when fine-tuning the model. Its calculation satisfies the following formula: , ; in, They are the positional encoding Quantity, t is the index of the time step, that is, the time series data sample is encoded t time steps, i is the dimension index, i.e. the number of variables in the time series, d model It is the original dimension of the input time series data sample, that is, the dimension size of each input vector in the Transformer model. Common values ​​are 512 or 1024.

[0041] The multi-head attention mechanism captures the global dependencies between different time steps of the time series data sample through a parallel multi-head design. This parallel mechanism enables some heads to focus on short-term dependencies and other heads to focus on long-term dependencies. The short-term dependencies and long-term dependencies together constitute the global dependencies of different time steps of the time series. Specifically, the multi-head attention layer captures the global dependencies between different time steps in the time series data sample through the following sub-steps.

[0042] S21. First, for each input time series data sample, the query, key, and value are calculated, and different weight matrices are used to project the input time series data sample into the query, key, and value space, as shown in the following formula: , in, is the input time series data sample, Q , K , V are the projections of time series data samples into query, key, and value spaces, respectively. W Q , W K , W V They are the query space weight matrix, key space weight matrix and value space weight matrix respectively.

[0043] S22. Calculate the attention weight. Calculate the dot product of the query and key at each time step in the time series data sample by the following formula, and obtain the attention weight by softmax normalization: , in, Attention(Q,K,V) is the attention weight, is the dimension of the key, used for normalization to avoid gradient explosion.

[0044] S23. Projecting time series data samples into value space using attention weights V Perform weighted summation to get the output of different heads of the multi-head attention layer as follows: , represents the first Time series data output by each header, represents the first The attention weight of each head.

[0045] S24. For the multi-head attention mechanism of the multi-head attention layer, the outputs of all heads of the multi-head attention layer are concatenated and projected back to the original dimension, that is, the original dimension of the input time series data sample d model , the final output of the multi-head attention layer is as follows: , in, is the time series data feature vector finally output by the multi-head attention layer, It is a multi-head attention layer The multi-head attention layer extracts the dependencies of the time series and outputs the time series data samples with dependencies. W o is the output projection matrix, which is used to project the high-dimensional representation of the concatenated time series data samples back to the original dimension of the input d model .

[0046] After the multi-head attention calculation, the Adapters layer is inserted after the multi-head attention layer. The Adapters layer is a two-layer bottleneck structure, such as Figure 4 As shown, the time series data samples finally output by the multi-head attention layer are first reduced in dimension by the descending layer, reducing the dimension of the input time series data from a high dimension to a smaller dimension, and then passed through a nonlinear activation function. In this embodiment, the ReLU function is selected as the activation function, and finally the time series data features after dimension reduction are projected back to the high-dimensional space output by the ascending layer. The above process satisfies the formula: , Adapters(h) is the output of the Adapters layer, W down Represents the linear transformation matrix of the descending layer, which is used to compress the dimension of the feature vector into a low-dimensional space. W up Represents the linear transformation matrix of the ascending layer, which is used to restore the feature vector compressed to the low-dimensional space back to the high-dimensional space.

[0047] Adapters The output of the layer and the time series data finally output by the multi-head attention layer are added in the form of residual connection through the following formula, and the final output can be expressed as: , in h is the time series data finally output by the multi-head attention layer, Adapters(h) for Adapters The output of the layer, h’ It is the common output of the above two.

[0048] During the training process, by freezing the main parameters of the pre-trained large model, only the Adapters layer is allowed to participate in the training, and then only the parameters of the Adapters layer are updated to achieve overall fine-tuning of the pre-trained large model.

[0049] S3. Feature pooling is used to integrate the feature vectors of all time step data in the time series data sample, and the final global representation of the entire time series data sample is obtained through the feature vectors of all time step data in the time series data sample.

[0050] In step S3, after the time series data sample is output by the multi-head attention layer and the Adapters layer, it is first input into a feedforward network consisting of two layers of fully connected networks. Each time step data of the time series data sample passes through the same feedforward network, and the feature representation of each time step data in the time series data sample is gradually nonlinearly transformed by the following formula: , in are the weights and bias parameters of the two fully connected layers in the feedforward network, h’ The common output of the multi-head attention layer and the Adapters layer for the time series data samples in step S2 is fitted through the nonlinear activation function ReLU, so that the network can fit complex patterns, and finally the output of the feedforward network is obtained , that is, the feature vector of each time step of the time series data sample after being processed by the feedforward network.

[0051] Then, feature pooling is used to extract the final global representation of the time series data sample by integrating the features of all time step data of the time series data sample. The feature pooling method adopts average pooling. The time series data sample of the time series sample pair and Satisfy the following formulas respectively: , , in, , Represents time series data samples respectively and The feature vector generated by the average pooling operation of all time step data in , is a time series data sample A global representation of all time-step data in , Represents a sample of time series data In the t The feature vector of the time step, In the time series data sample A global representation of all time-step data in , Represents a time series data sample In the t The feature vector of each time step, Represents the length of the time series data sample, that is, the number of time steps it contains.

[0052] S4. Use the Euclidean distance between the feature vectors of the time series data samples as the final output of the similarity measure of the time series sample pairs, which satisfies the formula: , in, d Two time series data samples in a time series sample pair and The Euclidean distance between the eigenvectors of , Represents time series data samples respectively and The feature vector generated after the average pooling operation of all time step data in .

[0053] Then, the label comparison loss function of the time series sample pairs annotated in step S1 is combined to optimize the fine-tuned pre-trained large model, and the comparison loss function L as follows: , in Indicates whether the time series sample is the same as the labeled time series data sample. If it is similar, it is 1, and if it is not similar, it is 0. d is the similarity of a pair of time series samples measured by the Euclidean distance between the feature vectors of the time series data samples. m It is a threshold used to distinguish the distance between similar and dissimilar time series samples. Its value is generally taken as the average of the Euclidean distance of similar time series data samples and the Euclidean distance of dissimilar time series data samples. m The value range is a real number between 0 and 1. For the same time series data samples, it is expected that the distance between the two is small, and the loss function attempts to minimize the distance. At this time, the loss function satisfies the formula: , for different time series data samples, the expected distance is larger, and the loss function is smaller than the threshold m When the loss increases, the real function satisfies the formula: .

[0054] In addition to the loss of the twin neural network, since the pre-trained large model introduces the Adapters layer to fine-tune the large model, the loss function calculation of the Adapters layer must be added during the optimization of the fine-tuned pre-trained large model, and the Adapters layer must be optimized at the same time. The loss function of the Adapters layer satisfies the following formula: , in, is the regularization coefficient, which is used to adjust the weight of the regularization loss. W up represents the linear transformation matrix of the ascending layer, W down represents the linear transformation matrix of the descending layer, and It is the L2 norm of the linear transformation matrix of the ascending and descending layers in the Adapters layer.

[0055] This embodiment also discloses a device terminal that applies the above-mentioned time series similarity measurement method based on twin neural network, including a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor is used to execute the above-mentioned time series similarity measurement method of this embodiment when executing the program.

[0056] In this document, the terms "comprises," "comprising," or any other variations thereof, are intended to cover a non-exclusive inclusion of elements other than those listed and may also include additional elements not expressly listed.

[0057] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A time series similarity measurement method based on twin neural networks, characterized in that: The steps include: S1. Pair the acquired time series data samples in pairs, and label each paired time series sample pair according to whether the time series data samples are similar; S2. Input the time series sample pair into the twin neural network for training. The two branches of the twin neural network use the same pre-trained large model to process the two time series data samples of the time series sample pair. The feature vector of each time step data in the time series data sample is obtained through the multi-head attention layer shared between the pre-trained large models. At the same time, the Adapters layer is added to the twin neural network to fine-tune the pre-trained large model. S3, using feature pooling to integrate the feature vectors of all time step data in the time series data sample to obtain the final global representation of the entire time series data sample; S4. Use the Euclidean distance between the feature vectors after pooling of the time series data samples as the final output of the similarity measurement of the time series sample pairs, and combine the label comparison loss function marked in step S1 to optimize the fine-tuned pre-trained large model.

2. The method for measuring time series similarity based on twin neural networks according to claim 1 is characterized in that: Before pairing the time series data samples in step S1, the original time series data is preprocessed, including alignment of the time series, filling of missing values ​​of the time series, and modification of abnormal values ​​of the time series.

3. The method for measuring time series similarity based on twin neural networks according to claim 2 is characterized in that: In the step S1, the time series sample pairs are labeled according to the Euclidean distance between the time series data samples; The time series sample pairs whose Euclidean distance between the time series data samples is less than 0.2 are labeled as 1; The time series sample pairs whose Euclidean distance between the time series data samples is greater than 0.8 are labeled as 0; The labels of the remaining time series sample pairs are set to 0.

5.

4. The method for measuring time series similarity based on twin neural networks according to claim 1, characterized in that: In step S2, the pre-trained large model has a position embedding layer, which first embeds the position of the time series data sample into the input time series data sample, and uses Transformer sine-cosine position coding to encode the position of each time step of the time series data sample. The pre-trained large model perceives the different time steps of the time series through the position coding of each time step.

5. The method for measuring time series similarity based on twin neural networks according to claim 4 is characterized in that: In step S2, the multi-head attention layer outputs feature vectors of data at different time steps in the time series data sample through the following sub-steps: S21. Project the input time series data samples into query, key, and value spaces using different weight matrices: , in, is the input time series data sample, Q , K , V are the projections of time series data samples into query, key, and value spaces, respectively. W Q , W K , W V They are the query space weight matrix, key space weight matrix and value space weight matrix respectively; S22. Calculate the dot product of the query and key at each time step in the time series data sample by the following formula, and obtain the attention weight by softmax normalization: , in, Attention(Q,K,V) is the attention weight, is the dimension of the key, T Represents the projection transpose of time series data samples into the key space; S23. Projecting time series data samples into value space using attention weights V Perform weighted summation to get the output of different heads of the multi-head attention layer as follows: , represents the first Time series data output by each header, represents the first The attention weight of the head; S24. Concatenate the outputs of all heads in the multi-head attention layer and project them back to the original dimension. The final output of the multi-head attention layer is as follows: , in, It is the time series data feature vector finally output by the multi-head attention layer, which contains the dependencies of the time series data captured by all attention heads and constitutes the global dependencies between the data at different time steps in the time series data sample. It is a multi-head attention layer Output from different heads, W o is the output projection matrix.

6. The method for measuring time series similarity based on twin neural networks according to claim 5 is characterized in that: The Adapters layer is inserted after the multi-head attention layer, forming a two-layer bottleneck structure. The time series data finally output by the multi-head attention layer is first reduced in dimension by the descending layer, then passed through a nonlinear activation function, and finally passed through the ascending layer to project the reduced-dimensional time series data features back to the high-dimensional space output; The output of the Adapters layer and the time series data finally output by the multi-head attention layer are added in the form of residual connection through the following formula: , in h is the time series data finally output by the multi-head attention layer, Adapters(h) is the output of the Adapters layer, h’ It is the common output of the multi-head attention layer and the Adapters layer.

7. The method for measuring time series similarity based on twin neural networks according to claim 1, characterized in that: In step S3, after the time series data sample is output by the multi-head attention layer and the Adapters layer, it is first input into a feedforward network consisting of two layers of fully connected networks, and the feature representation of each time step data in the time series data sample is gradually nonlinearly transformed by the following formula: , in are the weights and bias parameters of the two fully connected layers in the feedforward network, h’ The common output of the multi-head attention layer and the Adapters layer for the time series data samples in step S2 is fitted by the nonlinear activation function ReLU to obtain is the output of the feedforward network; Then, the features of all time step data of the two time series data samples in the time series sample pair are integrated by the following formulas, and the final global representation of the time series data samples is extracted respectively: , in, Represents the feature vector generated by the average pooling operation of all time step data of the time series data sample, which is the time series data sample A global representation of all time-step data in ; The time series data sample output by the feedforward network is t The feature vector of the time step data, Represents the length of the time series data sample, that is, the number of time steps it contains.

8. The method for measuring time series similarity based on twin neural networks according to claim 1, characterized in that: In step S4, the fine-tuned pre-trained large model is optimized by the following contrast loss function: , in represents the contrast loss function, A label indicating whether the time series sample in step S1 is similar to the annotated time series data sample, d is the similarity of a pair of time series samples measured by the Euclidean distance between the feature vectors of the time series data samples. m is a threshold used to distinguish the distance between similar and dissimilar time series sample pairs. m The value range is a real number between 0 and 1.

9. The method for measuring time series similarity based on twin neural networks according to claim 8 is characterized in that: In the process of optimizing the fine-tuned pre-trained large model, the Adapters layer also needs to be optimized through the loss function.

10. A terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, it can be used to perform the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Time sequence and CNN-based unsafe behavior identification method and system

    CN107862331A

  • Aero-engine small sample fault diagnosis method based on deep twin self-attention network

    CN115545092A

  • Lithium battery SOH estimation method based on coupling of attention mechanism and Bayesian network

    CN117192378A

  • Gait recognition model training method, gait recognition method and device

    CN117253281A

  • Multivariable time sequence anomaly detection method and system based on graph neural network

    CN117786374A