A time series similarity search method, recording medium and system
Through Min-Max standardization and early termination strategy optimization dynamic time regularization algorithm, the problem of high computational complexity in time series similarity search is solved, and the efficiency and accuracy of large-scale time series search is improved.
Patent Information
- Application Number
- CN202210097848.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-27
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2042-01-27
AI Technical Summary
Existing time series similarity search methods, especially the dynamic time regularization (DTW) algorithm, have high computational complexity when processing large-scale data, resulting in inefficient efficiency and cannot effectively respond to the similarity search requirements of large-scale time series.
The Min-Max standardization method is used to perform linear transformation of the time series data, construct the cumulative distance matrix, and reduce redundant calculations through the early termination strategy, dynamically plan to find the minimum bending path, and terminate the conditions early to improve efficiency.
It greatly reduces the overhead of DTW, improves the efficiency of time series similarity search, reduces redundant calculations and comparison operations, and ensures the accuracy of search results.
Smart Images

Figure CN114547139B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of data mining, and discloses a time series similarity search method, a recording medium storing a program capable of executing the method, and a system. Background Art
[0002] With the rapid development of computer science and technology, the data generated in the fields of Internet, meteorology, astronomy, industry and commerce, and medical care has exploded. How to transform data into organized knowledge to provide guidance and assistance for people's production, life, and even decision-making activities has become an extremely urgent need in the era of big data. Time series is one of many data types, which refers to an ordered sequence of data formed over time. Time series are widely used in different application fields, such as electrocardiogram data of patients in the medical field, real-time stock prices in the financial field, and real-time monitoring data of temperature and humidity in the meteorological field.
[0003] Similarity search of time series means, given a query sequence, finding one or more sequences from a set of time series whose similarity with the query sequence meets the set threshold requirement. Similarity search of time series is a basic problem in the study of time series data mining, and it is also one of the core problems. Clustering and association rule mining in time series data mining are inseparable from similarity search.
[0004] Early research on fast similarity search of time series was mostly based on Euclidean distance. The calculation of Euclidean distance is simple, intuitive and easy to understand, but it is sensitive to the expansion and distortion of the time axis. A small deformation on the time axis will cause a large change in the Euclidean distance, resulting in serious distortion. In addition, the Euclidean distance requires a one-to-one correspondence between the elements of the two time series, that is, it can only be applied to the similarity measurement between time series of equal length.
[0005] Dynamic Time Warping (DTW) is a more robust similarity measurement method that first appeared in the field of speech recognition. The DTW algorithm adopts the idea of dynamic programming, defines the optimal alignment and matching relationship between sequences, supports the similarity measurement of time series of unequal lengths, and is insensitive to the expansion and distortion of the time axis. However, the computational complexity of DTW is relatively high, and the computational cost is huge compared to the Euclidean distance. In particular, when DTW is applied to similarity search of large-scale time series, the efficiency is very low.
[0006] There are currently two main approaches to solving the problem of high computational complexity of DTW: one is to limit the range of finding the minimum curved path in the cumulative distance matrix through some constraints, such as Sakoe-Chiba constraints and Itakra-Parallelogram constraints; the other is to use a distance metric method with lower complexity (called a "lower bound function") to replace DTW for calculation, filter out sequences that do not meet the similarity requirements, and thus reduce the number of DTW algorithm runs. However, the principles of the above two methods are to simplify the algorithm. Although they can effectively delete redundant calculations, they cannot avoid the complex and time-consuming calculation of precise dynamic time warping distances. Therefore, the efficiency improvement is very limited when dealing with large-scale time series. Summary of the invention
[0007] In view of the above problems, the present invention provides a time series similarity search method, and the specific scheme includes the following steps:
[0008] S1. Obtain multiple time series data sets that need to be searched for similarity;
[0009] S2. The Min-Max standardization method is used to perform linear transformation on the data in the time series data set so that the result value is mapped between (0, 1);
[0010] S3. taking a group of the linearly transformed time series data sets and naming them as query sequences, and the rest as index sequences, pairing the query sequences with the index sequences one by one, and calculating the dynamic time warping distance by constructing a cumulative distance matrix to measure the similarity between the query sequences and the index sequences;
[0011] S4. Taking any of the cumulative distance matrices, performing a preliminary calculation of the similarity between the index sequence and the query sequence;
[0012] S5. Each number in the cumulative distance matrix is defined as a basic unit as a square, and an initial early termination threshold ε is set according to the result of the preliminary calculation in step S4;
[0013] S6. Calculate the cumulative distance of the squares in each group of the cumulative distance matrix one by one. When the early termination threshold ε is exceeded, the square is judged to overflow. When the set early termination condition is reached, the subsequent calculation of the cumulative distance matrix is stopped;
[0014] S7. Calculate the cumulative distance matrix using a dynamic time warping algorithm, and return the query sequence in the cumulative distance matrix with the smallest value. The original time series data corresponding to the query sequence is the most similar matching result.
[0015] Preferably, the order of calculation one by one in step S6 is to first calculate the first and last squares in the cumulative distance matrix, then calculate all the squares in the first row and all the squares in the first column of the cumulative distance matrix, and finally calculate the remaining squares row by row. When the cumulative distances of a row exceed the early termination threshold ε during the calculation process, it is judged that the early termination condition is met, the subsequent calculation of the cumulative distance matrix is terminated, and the current calculation result is assigned to ∞.
[0016] Specifically, for the query sequence X={x1,x2,…,x m} and index sequence Y = {y1,y2,…,y n}, if the base distance d of the starting point (1,1) in the cumulative distance matrix W base (1,1) exceeds the early termination threshold ε, then the two sequences can be judged to be dissimilar;
[0017] If the base distance d of the starting point (1,1) in the cumulative distance matrix W base (1,1) does not exceed the early termination threshold ε, but the sum of the base distances between the starting point (1,1) and the end point (m,n) exceeds the early termination threshold ε, which also means that the two sequences are not similar.
[0018] Furthermore, in the dynamic time warping distance calculation, the dynamic programming to find the minimum curved path is from the starting point (1,1) of the cumulative distance matrix to the end point (m,n), and there is w(1,1=)d base (1, w(m,n)=d base (m,n)+min{w(m-1,n),w(m,n-1),w(m-1,n-1)}, if d ba ( s 1 e ,>ε1ord base (1,1)+d base (m,n)>ε, then w(m,n)>ε holds. At this point, we can stop calculating all the remaining squares and determine that the two sequences are not similar.
[0019] If the above steps still cannot determine that the two sequences are not similar, calculate the first row of squares in the cumulative distance matrix W: the cumulative distance w(1,j) of the current square (1,j) is equal to the cumulative distance w(1,j-1) of the previous square and the base distance d of the current square base(1,j); if the cumulative distance w(1,j-1) of the previous square exceeds the set threshold ε, it is determined that the current square and the subsequent squares in the row are overflowed, and the two sequences are not similar; or calculate the first column of the squares in the cumulative distance matrix W: the cumulative distance w(i,1) of the current square (i,1) is equal to the cumulative distance w(i-1,1) of the previous square and the base distance d of the current square base If the cumulative distance w(i-1,1) of the previous square exceeds the set threshold ε, it is determined that the current square and all subsequent squares in the column have overflowed, and the two sequences are not similar.
[0020] If the above cannot determine that the two sequences are not similar, the remaining squares are calculated according to the above principle, and the current square (i, j) can also be used, where i, j ≥ 2. If the minimum value of its adjacent squares w(i-1, j-1, w(i-1, j), w(i, j-1) exceeds the threshold ε, it can be determined that the current square overflows; otherwise, the cumulative distance w(i, j) of the current square (i, j) is equal to the minimum value of its adjacent squares w(i-1, j-1), w(i-1, j), w(i, j-1) plus the base distance d of the current square base (i, j), if w(i, j) exceeds the threshold ε, the current square (i, j) is judged to overflow. When it is judged that all the squares in a row of the cumulative distance matrix overflow, the early termination condition is met, and the calculation of the remaining squares can be skipped, and the two sequences are judged to be dissimilar.
[0021] Furthermore, if w(i-1,j)>ε, w(i,j-1)>ε, and w(i-1,j-1)>ε all hold, then min{w(i-1,j),w(i,j-1),w(i-1,j-1)}>ε. base (i,j)≥0, then w(i,j)>ε, that is, w(i,j) also overflows;
[0022] If w(i-1,j), w(i,j-1), and w(i-1,j-1) all overflow, then regardless of the base distance d base For what value of (i,j) must be w(i,j)>ε, so d base The specific value of (i,j) has no effect on the overflow judgment of w(i,j), and the calculation can be omitted. In addition, if the subsequent calculation of w(i',j')(i'≥i,j'≥j) uses the value of w(i,j), because w(i,j)>ε, the square (i,j) overflows. Replacing w(i,j) with any value greater than the threshold ε will not change the overflow state of the square, nor will it affect the subsequent overflow judgment of w(i',j')(i'≥i,j'≥j).
[0023] Preferably, the method of returning the most similar matching result in S7 is:
[0024] If the query sequence and an index sequence are terminated prematurely in step S6 and are determined to be dissimilar, the index sequence is discarded and the next one is calculated; otherwise, the index sequence is added to the candidate set, and dynamic time warping calculation is performed on the candidate set to obtain the index sequence with the smallest value as the matching result.
[0025] The beneficial technical effects of the present invention are:
[0026] The present invention reduces a large number of redundant calculations and comparison operations by proposing an improved DTW early termination strategy, greatly reduces the computational overhead of DTW, and effectively improves the efficiency of time series similarity search while ensuring that no underreporting occurs.
[0027] Another embodiment of the present invention is to provide a non-transitory readable recording medium for storing one or more programs including a plurality of instructions. When the instructions are executed, the processing circuit will execute the above-mentioned time series similarity search method.
[0028] Another embodiment of the present invention is to provide a time series similarity search system, including a processing circuit and a memory electrically coupled thereto, wherein the memory is configured to store at least one program, wherein the program includes a plurality of instructions, and the processing circuit runs the program to execute the above-mentioned time series similarity search method. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 Schematic diagram of DTW early termination in an embodiment of the present invention;
[0030] Figure 2 is a schematic diagram of preliminary similarity judgment in an embodiment of the present invention;
[0031] Figure 3 is a schematic diagram of initializing the boundary of the cumulative distance matrix W in an embodiment of the present invention;
[0032] Figure 4 Schematic diagram of calculation of the remaining squares of the cumulative distance matrix W in an embodiment of the present invention;
[0033] Figure 5 4 is a flow chart of a similarity search method in an embodiment of the present invention. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be described below in conjunction with the drawings in the embodiments of the present invention. The described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making innovative efforts are within the scope of protection of the present invention.
[0035] Refer to the instruction manual Figure 1-5 This embodiment provides a specific implementation process of a time series similarity search method, and the steps are as follows:
[0036] We select the subdataset OliveOil from the famous large-scale time series dataset UCR archive as an example. OliveOil is collected from the field of food safety, with 30 sequences in the training set and 30 sequences in the test set. Each sequence is 570 long and contains 4 categories.
[0037] Perform data preprocessing on all 60 time series in the OliveOil dataset;
[0038] Since the data types in the OliveOil dataset are consistent and there are no missing values, the Min-Max standardization method is directly used to perform a linear transformation on the original sequence and map it to (0,1). The formula for linear transformation is:
[0039]
[0040] Among them, x max =3.74 is the maximum value among all sample data in the OliveOil dataset; min =-1.01 is the minimum value of all sample data in the OliveOil dataset.
[0041] The 30 sequences in the divided Train of the OliveOil dataset are used as index sequences, and a sequence is randomly selected from the divided Test as the query sequence. The similarity between the query sequence and the 30 index sequences is calculated in turn using the DTW metric.
[0042] Construct the cumulative distance matrix W and first make a preliminary judgment on the similarity of the two sequences;
[0043]
[0044] In order to more intuitively illustrate the specific operation steps of the early termination strategy through drawing, a simple example is given. For the query sequence Q = {2, 5, 2, 5, 3} and the index sequence C = {0, 3, 6, 0, 6, 1}, after calculation, the early termination threshold ε = 9 is set, and a cumulative distance matrix W with a dimension of [5, 6] can be constructed. The DTW distance is calculated by finding the minimum curved path, as shown in Figure 2 shown.
[0045] According to the beginning-end judgment lemma, if the base distance of the starting point (1,1) in the cumulative distance matrix exceeds the early termination threshold ε, the DTW calculation can be terminated and the two sequences are determined to be dissimilar; because w(1,1) = d base (1,1)=4 is less than the threshold ε, and the early termination condition is not met, so the subsequent calculation continues.
[0046] According to the beginning-end judgment lemma, if the sum of the base distances between the starting point (1,1) and the end point (5,6) in the cumulative distance matrix exceeds the early termination threshold ε, the DTW calculation can be terminated and the two sequences are determined to be dissimilar. However, it is found through calculation that d base (1,1)+d base (5,6)=8 is less than the threshold ε and does not meet the overflow condition, so the subsequent calculation continues.
[0047] Among them, the Euclidean distance is used to calculate the base distance d between two sequence elements. base , since the representation method of the base distance does not affect the measurement result, in order to improve the calculation efficiency, the square root operation can be omitted, that is:
[0048] d base (i,j)=(x i -y j ) 2 25(26)
[0049] Among them, the dynamic programming method is used to calculate the minimum curved path in the cumulative distance matrix, as shown in the following formula:
[0050]
[0051] The matrix composed of dtw(i,j) is called the cumulative distance matrix, and the end point value dtw(5,6) is the exact calculated value of DTW.
[0052] Initialize the boundaries of the cumulative distance matrix, such as Figure 3 The shaded part indicates that the base distance calculation and comparison operation are omitted and the overflow square is directly determined.
[0053] First, calculate the first row of squares in the cumulative distance matrix W: the cumulative distance w(1,j) of the current square (1,j) is equal to the cumulative distance w(1,j-1) of the previous square and the base distance d of the current square base If the cumulative distance w(1,j-1) of the previous square exceeds the threshold ε, the current square and the subsequent squares in the row are considered to have overflowed, and the value ∞ can be directly assigned, omitting the base distance calculation and comparison operations.
[0054] Similarly, calculate the first column of the cumulative distance matrix W: the cumulative distance w(i,1) of the current square (i,1) is equal to the cumulative distance w(i-1,1) of the previous square and the base distance d of the current square base If the cumulative distance w(i-1,1) of the previous square exceeds the threshold ε, the current square and the subsequent squares in the column are considered to have overflowed, and the value ∞ can be directly assigned, omitting the base distance calculation and comparison operations.
[0055] Calculate the cumulative distances of the remaining squares in the cumulative distance matrix row by row to determine whether the squares overflow and whether the early termination conditions are met, such as Figure 4 As shown in the figure, the shaded part indicates that the base distance calculation and comparison operation are omitted and the overflow square is directly determined; the arrow indicates the position where the early termination condition is reached.
[0056] For the current square (i, j), where i, j ≥ 2. If the minimum value of its adjacent squares w(i-1, j-1), w(i-1, j), and w(i, j-1) exceeds the threshold ε, the current square can be judged to be overflowed according to the overflow propagation lemma. According to the omitted substitution lemma, the current square and all subsequent squares in the row can be assigned ∞, omitting the base distance calculation and comparison operations;
[0057] Otherwise, the cumulative distance w(i,j) of the current square (i,j) is equal to the minimum value of its adjacent squares w(i-1,j-1, w(i-1,j), w(i,j-1) plus the base distance d of the current square base (i,j). If w(i,j) exceeds the threshold ε, the current square (i,j) overflows and can be assigned a value of ∞.
[0058] When it is determined that all the squares in a row of the cumulative distance matrix have overflowed, the early termination condition is reached, and the calculation of the remaining squares can be skipped, and the two sequences are determined to be dissimilar.
[0059] If the query sequence and the index sequence are determined to be dissimilar through the above early termination strategy, the index sequence is discarded and the next one is calculated; otherwise, the index sequence is added to the candidate set C, and the index sequence with the smallest DTW value in the candidate set C is returned as the final search matching result.
[0060] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computers, available storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer program code.
[0061] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0062] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0063] These computer program instructions can also be loaded into a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing one or more processes and / or blocks in the flowchart. Figure 1 The steps for the functions specified in one or more boxes.
[0064] Compiling the above method steps into a program and then storing it on a hard disk or other non-transitory storage medium constitutes the technical solution of "a non-transitory readable recording medium" of the present invention; and electrically connecting the storage medium to a computer processor and obtaining a set of most similar time series through data processing constitutes the technical solution of "a time series similarity search system" of the present invention.
[0065] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A time series similarity search method, It is characterized in that The real-time monitoring of temperature and humidity in the meteorological field includes the following steps: S1. Obtain multiple time series data sets that need to be searched for similarity; S2. The Min-Max standardization method is used to perform linear transformation on the data in the time series data set so that the result value is mapped between (0, 1); S3. taking a group of the linearly transformed time series data sets and naming them as query sequences, and the rest as index sequences, pairing the query sequences with the index sequences one by one, and calculating the dynamic time warping distance by constructing a cumulative distance matrix to measure the similarity between the query sequences and the index sequences; S4. Taking any of the cumulative distance matrices, performing a preliminary calculation of the similarity between the index sequence and the query sequence; S5. defining each number in the cumulative distance matrix as a basic unit as a square, and setting the initial early termination threshold ε according to the result of the preliminary calculation in step S4; S6. Calculate the cumulative distance of the squares in each group of the cumulative distance matrix one by one. When the early termination threshold ε is exceeded, the square is judged to overflow. When the set early termination condition is reached, the subsequent calculation of the cumulative distance matrix is stopped; S7. Calculate the cumulative distance matrix using a dynamic time warping algorithm, and return the query sequence in the cumulative distance matrix with the smallest value. The original time series data corresponding to the query sequence is the most similar matching result.
2. A time series similarity search method according to claim 1, It is characterized in that The method of calculating one by one in step S6 is that: the order of calculating one by one is to first calculate the first and the last squares in the cumulative distance matrix, then calculate all the squares in the first row and all the squares in the first column of the cumulative distance matrix, and finally calculate the remaining squares row by row. When the cumulative distances of a row exceed the early termination threshold ε during the calculation process, it is judged that the early termination condition is met, the subsequent calculation of the cumulative distance matrix is terminated, and the current calculation result is assigned to ∞.
3. A time series similarity search method according to claim 2, It is characterized in that The method of returning the most similar matching result in S7 is: If the query sequence and an index sequence are terminated prematurely in step S6 and are determined to be dissimilar, the index sequence is discarded and the next one is calculated; otherwise, the index sequence is added to the candidate set, and dynamic time warping calculation is performed on the candidate set to obtain the index sequence with the smallest value as the matching result.
4. A non-transitory readable recording medium for storing one or more programs comprising a plurality of instructions, It is characterized in that When the instruction is executed, the processing circuit is caused to execute a time series similarity search method according to any one of claims 1 to 3.
5. A time series similarity search system, comprising a processing circuit and a memory electrically coupled thereto, It is characterized in that The memory configuration stores at least one program, wherein the program includes a plurality of instructions, and the processing circuit runs the program to execute a time series similarity search method as claimed in claim 3.
