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

By using a time series similarity measurement method based on a twin neural network, using a pre-trained large model and Adapters layer for fine-tuning, and combining a multi-head attention mechanism and feature pooling technology, the problem that traditional methods have difficulty in capturing complex dependencies and insufficient generalization capabilities in small sample scenarios is solved, and high-precision time series similarity calculation and feature extraction are achieved.

CN119357707BActive Publication Date: 2025-09-16HUNAN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Traditional time series analysis methods have problems in capturing complex dependencies and insufficient generalization capabilities in small sample scenarios.

Method used

A time series similarity measurement method based on a twin neural network is adopted. By preprocessing and grouping time series data samples, fine-tuning with a pre-trained large model and Adapters layer, and combining the multi-head attention mechanism and feature pooling technology, the similarity of time series sample pairs is calculated.

Benefits of technology

It effectively solves the problems of complex dependency capture and insufficient generalization ability in small sample time series analysis, and achieves higher-precision similarity calculation and feature extraction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357707B_ABST
    Figure CN119357707B_ABST
Patent Text Reader

Abstract

The present invention discloses a time series similarity measurement method and terminal based on a twin neural network, which groups and pairs time series data samples into time series sample pairs and labels them, inputs the paired and labeled time series sample pairs into a twin neural network that uses the same pre-trained large model as a branch, obtains the similarity between time series as the final output of the network as a whole, and uses a loss function to update the network weights of the entire twin neural network combined with the fine-tuned pre-trained large model. The present invention targets the task of similarity measurement of time series data in small sample scenarios, utilizes the powerful capabilities of pre-trained large models in the field of time series, and combines the advantages of twin neural networks in small sample similarity measurement to perform similarity measurement of time series data. Only a small number of samples are needed to complete the measurement of time series similarity, and the characteristics of time series can be extracted in all directions as the basis for 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 for applications in small-sample scenarios. The analysis of time series data is a critical issue in multiple fields. Traditional sequence analysis methods such as ARIMA and LSTM face challenges when dealing with complex dependencies or small sample sizes. The ARIMA model relies on linearity and stationarity assumptions, making it suitable for predicting stationary time series. However, it struggles to capture complex nonlinear dependencies and, in small-sample scenarios, suffers from insufficient generalization due to data scarcity. While the LSTM model can handle long-term temporal dependencies, its complexity makes it prone to overfitting in small-sample scenarios and requires a relatively high amount of training data. To address these issues, advanced methods such as contrastive learning, twin neural networks, and self-attention mechanisms have emerged, demonstrating improved adaptability in handling 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 similarity in small-sample time series. Summary of the Invention

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

[0004] The present invention is implemented by the following technical solutions:

[0005] The present invention first discloses a time series similarity measurement method based on a twin neural network, which specifically includes the following steps:

[0006] S1. Pair the acquired time series data samples in pairs, and label each paired time series sample pair based on whether the time series data samples are similar;

[0007] 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 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.

[0008] 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;

[0009] S4. Use the Euclidean distance between the feature vectors after pooling the time series data samples as the final output of the similarity measurement of the time series sample pairs, combined with the label comparison loss function marked in step S1 to optimize the fine-tuned pre-trained large model.

[0010] In the time series similarity measurement method based on twin neural networks 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 the time series, filling of missing values ​​in the time series, and modification of outliers in the time series.

[0011] In the time series similarity measurement method based on the twin neural network 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.

[0012] In the time series similarity measurement method based on twin neural networks of the present invention, further, in step S2, the pre-trained large models all have a position embedding layer, and the position embedding layer first embeds the position of the input time series data sample into the time series, and uses Transformer sine and 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.

[0013] In the time series similarity measurement method based on the twin neural network of the present invention, further, in step S2, the multi-head attention layer outputs the feature vectors of data at different time steps in the time series data sample through the following sub-steps:

[0014] S21. Project the input time series data samples into query, key, and value spaces using different weight matrices:

[0015] ,

[0016] in, is the input time series data sample, Q 、 K 、 Vis the projection 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;

[0017] S22. Calculate the dot product of the query and key at each time step in the time series data sample using the following formula and obtain the attention weight through softmax normalization:

[0018] ,

[0019] 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;

[0020] S23. Projecting time series data samples into value space using attention weights V Perform weighted summation to obtain the output of different heads of the multi-head attention layer as follows:

[0021] ,

[0022] represents the first Time series data output by each head, represents the first The attention weight of the individual;

[0023] 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:

[0024] ,

[0025] in, It is the time series data feature vector finally output by the multi-head attention layer, which contains the dependencies captured by all attention heads in the time series data and constitutes the global dependencies between different time step data in the time series data sample. It is a multi-head attention layer Output from different heads, W o is the output projection matrix.

[0026] In the time series similarity measurement method based on the twin neural network of the present invention, further, 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 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;

[0027] 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:

[0028] ,

[0029] 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.

[0030] In the time series similarity measurement method based on the twin neural network of the present invention, further, in step S3, after the time series data sample is output by the multi-head attention layer and the adapter 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:

[0031] ,

[0032] 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 sample in step S2 is fitted by the nonlinear activation function ReLU to obtain is the output of the feedforward network;

[0033] 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 formula to extract the final global representation of the time series data samples:

[0034] ,

[0035] in, Represents the feature vector generated after 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 tThe feature vector of the time step data, Indicates the length of the time series data sample, that is, the number of time steps it contains.

[0036] In the time series similarity measurement method based on the twin neural network of the present invention, further, in step S4, the fine-tuned pre-trained large model is optimized by the following contrast loss function:

[0037] ,

[0038] 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.

[0039] 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.

[0040] The present invention also discloses a terminal that adopts the above-mentioned time series similarity measurement method based on twin neural networks, including a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, it is used to execute the above-mentioned time series similarity measurement method based on twin neural networks of the present invention.

[0041] 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, which 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.

[0042] 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.

[0043] This paper also introduces Adapters technology as a fine-tuning technique for pre-trained large models. This improves the flexibility of large models while leveraging their advantages in small sample sizes. Adapters is a lightweight fine-tuning method that adds small adaptation modules to pre-trained large models, reducing the computational cost of fine-tuning and making it suitable for small sample size tasks. The fine-tuned pre-trained large models can adapt to the time series characteristics of specific domains and enhance their performance in similarity measurement tasks.

[0044] The present invention adopts the above technical solution to achieve the following beneficial effects:

[0045] (1) By introducing the Adapters layer for fine-tuning, the pre-trained large model can perform efficient parameter adjustment under small sample conditions, eliminating the need to adjust all parameters of the trained large model. This greatly reduces the number of parameters to adjust, 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. This is particularly suitable for time series analysis in data-scarce fields, such as time series analysis in power scenarios.

[0046] (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 time series. In the pre-trained large model for time series of this invention, the Adapters layer extracts features such as trends, seasonal fluctuations, and periodic patterns in time series data, which is more advantageous than traditional sequence analysis methods. In addition, fine-tuning of the Adapters enhances the flexibility of feature representation, enabling the model to adjust its feature extraction capabilities according to specific domains and improve the accuracy of similarity measurement.

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

[0048] (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.

[0049] (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 suitable for similarity measurement, but also for subsequent classification or prediction tasks.

[0050] By combining twin neural networks and pre-trained large models, the present invention can more accurately extract features from time series and improve the generalization and robustness of the model. It not only has significant advantages in small sample similarity measurement tasks 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.

[0051] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

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

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

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

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

[0056] 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.

[0057] The time series data of wind turbines processed in this embodiment includes wind turbine power generation, wind speed at various heights, temperature, and humidity. The wind turbine power generation, wind speed at various heights, temperature, and humidity for which time series similarity measurement is required are collected by sensors, aligned by time nodes, and merged into a set of raw time series data containing the aforementioned wind turbine parameters.

[0058] The specific steps of measuring the similarity of the time series data of the wind turbine generator sets collected above are as follows:

[0059] S1. Pair the acquired time series data samples in pairs, and label each paired time series sample pair based on whether the time series data samples are similar.

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

[0061] Merging the real-time parameters of wind turbines means aligning the time nodes of the original time series data. Missing values ​​and outliers in the merged and aligned time series data are processed. Taking the temperature data detected by wind turbines as an example, the missing values ​​in the original time series data are filled using the linear interpolation method as follows:

[0062] ,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.

[0063] 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:

[0064] , are the wind speed values ​​of the known data points, is the wind speed value corresponding to the outlier point.

[0065] The pre-processed time series data samples are grouped and paired, with two time series data samples as a group, and the pre-processed 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 a 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 .

[0066] This embodiment labels time series sample pairs based on 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.

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

[0068] In this step, the Euclidean distance between time series data samples is calculated 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, the time series data samples are passed through the deep learning network to extract complex feature vectors based on the feature space suitable for measurement in the data. Based on this feature vector, the similarity of the time series samples is measured to represent a more accurate time series similarity.

[0069] 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 multi-head attention layer shared between the pre-trained large models is used to obtain the feature vector of each time step data in the time series data sample, 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.

[0070] 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 performs position embedding of the time series on 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.

[0071] 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 of the sine and cosine form in the Transformer can reduce the parameter burden when fine-tuning the model. Its calculation satisfies the following formula:

[0072] 、 ;

[0073] in, They are positional encoding A 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, that is, 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.

[0074] The multi-head attention mechanism captures the global dependencies between data at different time steps in a time series data sample through a parallel multi-head design. This parallel mechanism enables some heads to focus on short-term dependencies while others focus on long-term dependencies. Together, these short-term and long-term dependencies constitute the global dependencies at different time steps in the time series. Specifically, the multi-head attention layer captures the global dependencies between data at different time steps in a time series data sample through the following substeps.

[0075] S21. First, for each input time series data sample, the query, key, and value calculations are used, and different weight matrices are used to project the input time series data sample into the query, key, and value spaces, as shown in the following formula:

[0076] ,

[0077] in, is the input time series data sample, Q 、 K 、 V is the projection 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.

[0078] S22. Calculate the attention weight by calculating the dot product of the query and key at each time step in the time series data sample using the following formula and normalize it using softmax to obtain the attention weight:

[0079] ,

[0080] in, Attention(Q,K,V) is the attention weight, is the dimension of the key, used for normalization to avoid gradient explosion.

[0081] S23. Projecting time series data samples into value space using attention weights V Perform weighted summation to obtain the output of different heads of the multi-head attention layer as follows:

[0082] ,

[0083] represents the first Time series data output by each head, represents the first The attention weight of the head.

[0084] 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 spliced ​​together 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:

[0085] ,

[0086] 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 spliced ​​time series data samples back to the original dimension of the input d model .

[0087] 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 descent 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. Finally, the features of the reduced time series data are projected back to the high-dimensional space for output by the ascending layer. The above process satisfies the formula:

[0088] ,

[0089] 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.

[0090] 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. The final output can be expressed as:

[0091] ,

[0092] 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.

[0093] 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.

[0094] 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.

[0095] In step S3, after the time series data sample is output by the multi-head attention layer and the adapter 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:

[0096] ,

[0097] 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 data of the time series data sample after being processed by the feedforward network.

[0098] 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:

[0099]

[0100] ,

[0101] 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 time series data sample In the t The feature vector of each 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, Indicates the length of the time series data sample, that is, the number of time steps it contains.

[0102] 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:

[0103] ,

[0104] in, d Two time series data samples within a time series sample pair and The Euclidean distance between the eigenvectors of 、 Represents time series data samples respectively and The feature vector generated by the average pooling operation of all time step data in .

[0105] Then, the label comparison loss function of the time series sample pairs in step S1 is combined to optimize the fine-tuned pre-trained large model, and the comparison loss function L as follows:

[0106] ,

[0107] 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 large, and the loss function is less than the threshold m When the loss increases, there is a real function that satisfies the formula: .

[0108] 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 included in the process of optimizing 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:

[0109] ,

[0110] 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 rising 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 layer and the descending layer in the Adapters layer.

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

[0112] As used herein, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion of elements other than the listed elements and may also include additional elements not specifically listed.

[0113] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.

Claims

1. A time series similarity measurement method based on a twin neural network is used to measure the similarity of time series data of wind turbines. The time series data includes the power generated by the wind turbines, the wind speed of the wind turbines at various heights, the temperature and humidity of the wind turbines. The method is characterized by: The steps include: S1. Pair the acquired time series data samples in pairs, and label each paired time series sample pair based on whether the time series data samples are similar; S2. The time series sample pairs are input 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 models all have a position embedding layer. The position embedding layer first embeds the position of the input time series data sample into the time series, and uses Transformer sine and cosine position encoding 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 encoding of each time step, and obtains the feature vector of each time step data in the time series data sample through the multi-head attention layer shared between the pre-trained large models. The multi-head attention layer outputs the feature vectors of the data of 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: Q=W Q ·τ, J=W K ·τ,V=W V ·t, Where τ is the input time series data sample, Q, K, V are the projections of the time series data sample to the query, key and value spaces respectively, and 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 using the following formula and obtain the attention weight by softmax normalization: Among them, Attention(Q,K,V) is the attention weight, is the dimension of the key, and T represents the projection transpose of the time series data sample to the key space; S23. Use the attention weights to perform weighted summation on the projection V of the time series data samples into the value space, and obtain the output of different heads of the multi-head attention layer as follows: Z ι =Attention(Q,K,V) ι ·V, Z ι Represents the time series data output by the ι-th head of the multi-head attention layer, Attention(Q, K, V) ι represents the attention weight of the ith head of the multi-head attention layer; 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: h=MultiHead(Q,K,V)=Concat(Z1,Z2,...,Z ι )·W o , Among them, h = MultiHead (Q, K, V) is the time series data feature vector finally output by the multi-head attention layer, which contains the dependency of all attention heads capturing the time series data, and constitutes the global dependency between the data at different time steps in the time series data sample, Z1, Z2, ..., Z ι is the output of ι different heads of the multi-head attention layer, W o is the output projection matrix; The Adapters layer is added to the twin neural network to fine-tune the pre-trained large model. 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 down-drop layer, then passed through a nonlinear activation function, and finally passed through the up-drop layer to project the reduced time series data features back into the high-dimensional space for 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: h′=h+Adapters(h), Where h is the time series data finally output by the multi-head attention layer, Adapters(h) is the output of the Adapters layer, and h' is the common output of the multi-head attention layer and the Adapters layer; S3. Feature pooling is used to integrate the feature vectors of all time-step data in the time series data sample. After the time series data sample is output by the multi-head attention layer and the adapter layer, it is first input into a feedforward network consisting of two layers of fully connected networks. The feature representation of each time-step data in the time series data sample is gradually nonlinearly transformed. Then, the features of all time-step data of the two time series data samples in the time series sample pair are respectively integrated using the following formula to extract the final global representation of the time series data sample: Among them, Γ 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 h t ″ is the feature vector of the time series data sample output by the feedforward network at the tth time step, Indicates the length of the time series data sample, that is, the number of time steps included; S4. Use the Euclidean distance between the feature vectors after pooling the time series data samples as the final output of the similarity measurement of the time series sample pairs, and combine it with 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 a twin neural network according to claim 1, 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 ​​in the time series, and modification of outliers in the time series.

3. The time series similarity measurement method based on a twin neural network according to claim 2, characterized in that: In step S1, 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 a twin neural network according to claim 1, characterized in that: In step S3, the feature representation of each time step data in the time series data sample is gradually nonlinearly transformed by the following formula: h″=ReLU(h′·Θ1+b1)·Θ2+b2, Where Θ1, Θ2, b1, and b2 are the weights and bias parameters of the two fully connected layers in the feedforward network. h' is the common output of the multi-head attention layer and the Adapters layer for the time series data samples in step S2. It is fitted by the nonlinear activation function ReLU, and h" is the output of the feedforward network.

5. The method for measuring time series similarity based on a twin neural network 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: Where L represents the contrast loss function, ε represents the label of whether the time series data samples annotated by the time series sample pair in step S1 are similar, d is the similarity of the time series sample pair measured by the Euclidean distance between the feature vectors of the time series data samples, and m is a threshold used to distinguish the distances between similar and dissimilar time series sample pairs. The value of m ranges from 0 to 1.

6. The method for measuring time series similarity based on a twin neural network according to claim 5, 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.

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

Citation Information

Patent Citations

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

    CN117192378A

  • Aircraft multi-sensor data fault prediction method

    CN118332291A