A trajectory restoration method based on sequence similarity and dynamic mask training mechanism
Through the Similarmove model, combined with DTW similarity and self-attention mechanism and dynamic mask training, the problems of insufficient similarity learning and scarce training data in trajectory repair are solved, and the accuracy of trajectory repair and the generalization ability of the model are improved.
Patent Information
- Application Number
- CN202210877420.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-25
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2042-07-25
AI Technical Summary
Existing deep learning models for trajectory restoration cannot fully learn the similarities between trajectory sequences, and the use of static mask training leads to insufficient training data, which reduces the accuracy of the model.
A trajectory repair method based on sequence similarity and dynamic mask training mechanism is adopted. By constructing the Similarmove model, the gated graph embedding layer, the temporal embedding layer, the historical trajectory similarity feature extraction layer, the current day trajectory correlation feature extraction layer and the trajectory repair layer are used. In combination with the DTW similarity and self-attention mechanism, the dynamic mask training method is used to increase the amount of training data.
It improves the accuracy of trajectory repair, can better learn trajectory similarity, increase the amount of training data, and enhance the generalization ability of the model.
Smart Images

Figure CN115526225B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of data mining and deep learning, and relates to a trajectory repair method based on sequence similarity and dynamic mask training mechanism. Background Art
[0002] In recent years, with the development of GPS technology and the widespread adoption of mobile internet, real-time location information of mobile objects (people and vehicles) has become available for large-scale collection. This location information typically includes basic latitude and longitude data and timestamps, and may also include information such as direction and altitude. This massive amount of trajectory information holds significant research value, providing effective support for location-based social networks, smart urban transportation development, and urban planning. For example, analyzing taxi trajectories can reveal urban traffic flow, thereby assisting with urban road construction and citizen travel planning. However, due to anomalies such as weak GPS signals, transmission network congestion, and receiving device failures, conventional positioning technologies cannot provide reliable positioning accuracy, inevitably generating invalid data during the data collection and transmission process. Therefore, repairing trajectory data is crucial for the development of smart urban transportation.
[0003] Current solutions to the trajectory repair problem primarily rely on deep learning models based on RNN (recurrent neural networks) or Transformer architectures. These models can extract movement patterns from a large amount of historical data, thereby inferring missing trajectory locations. However, current deep learning models for trajectory repair suffer from two issues: first, they cannot fully learn the similarities between trajectory sequences; missing locations are related not only to the current day's travel trajectory but also to historical travel trajectories. Second, using static masks to train the model results in insufficient training data, reducing model accuracy. Summary of the Invention
[0004] One objective of this invention is to address the aforementioned issues by proposing a trajectory repair method based on sequence similarity and a dynamic mask training mechanism, and providing a trajectory repair model, Similarmove, based on this mechanism. This model can fully learn the similarity movement patterns of trajectories while also increasing the amount of training data, ultimately improving the accuracy of trajectory repair.
[0005] The technical solutions adopted in the present invention are as follows:
[0006] S1: Trajectory discretization
[0007] Obtain the missing trajectory sequence information and historical trajectory sequence information, discretize the above trajectory sequence, map it to a square grid, and convert the two-dimensional trajectory sequence into a one-dimensional trajectory sequence; split the trajectory sequence into two parts based on days: the historical trajectory sequence [h1, h2, …] and the current day trajectory sequence [c1].
[0008] S2: Build a trajectory repair model based on similar movement rules Similarmove
[0009] The trajectory restoration model Similarmove based on similarity movement rules includes a gated graph embedding layer, a time series embedding layer, a historical trajectory similarity feature extraction layer, a current day trajectory correlation feature extraction layer, and a trajectory restoration layer;
[0010] 1) Constructing a gated graph embedding layer
[0011] The gated graph embedding layer GGNN receives the historical trajectory sequence [h1, h2, ...] and the current day trajectory sequence [c1], learns the grid embedding vector representation based on the movement pattern of the user trajectory, makes the grid embedding vectors of adjacent positions more similar, and obtains the grid trajectory embedding vector. Then, the position encoding matrix is added to the grid trajectory embedding vector to finally obtain the grid embedding vector e i , historical trajectory sequence embedding vector matrix and the embedding vector matrix of the trajectory sequence of the day Specifically:
[0012] 1-1 Generate the in-degree matrix of the sequence data based on the historical trajectory sequence [h1,h2,…] and outdegree matrix Generate the in-degree matrix of the sequence data based on the trajectory sequence of the day [c1] and outdegree matrix The generated method is as follows:
[0013] Assume that there are n non-repeating grid numbers in [h1,h2,…], first generate two n*n two-dimensional matrices with all zeros and For the in-degree matrix, if there is a direct grid from [h1,h2,…] i to grid j The trajectory of , then the in-degree matrix The element in the jth row and ith column of is set to 1, then the out-degree matrix The element in row i and column j of is set to 1.
[0014] Assume that there are k non-repeated grid numbers in [c1], first generate two k*k two-dimensional matrices with all zeros and For the in-degree matrix, if there is a line in [c1] that goes directly from the grid i to grid j The trajectory of , then the in-degree matrix The element in the jth row and ith column of is set to 1, then the out-degree matrix The element in row i and column j of is set to 1.
[0015] 1-2 Generate the initial grid embedding vector matrix [e1,e2,…,e based on the node2vector algorithm n ]
[0016] The 1-3GGNN network layer learns the position embedding vector representation better through the neighbor information of the trajectory sequence, making the grid embedding vectors of adjacent positions more similar. When the GGNN network loops s times, the final output e s Denoted as the grid embedding vector e i According to the corresponding sequence number in the historical trajectory sequence [h1,h2,…], i Take out the corresponding embedding vector to generate the historical trajectory sequence embedding vector matrix According to the corresponding sequence number in the trajectory sequence [c1] of the day, i Take out the corresponding embedding vector to generate the historical trajectory sequence embedding vector matrix
[0017] The calculation process of the GGNN network is as follows:
[0018]
[0019] z s =sigmoid(W z a s +U z e s-1 ) (2)
[0020] r s =sigmoid(W r a s +U r e s-1 ) (3)
[0021] e' s =tanh(W h a s +U o (r s ⊙e s-1 )) (4)
[0022] e s =(1-z s )⊙es-1 +z s ⊙e' s (5)
[0023] Among them, M i and M o Represents the in-degree matrix and out-degree matrix of the input trajectory. When the historical trajectory sequence is input, M i and M o Corresponding respectively and When the trajectory sequence of the day is input, M i and M o Corresponding respectively and [e1,e2,…,e n ] is a two-dimensional matrix representing the initial grid embedding vector; with b I represents the parameters of the fully connected layer corresponding to the in-degree matrix, with b o Represents the fully connected layer parameters corresponding to the degree matrix; W z W r W h with U z U r U o They represent the parameters of the six fully connected layers in the network, which will be updated during the training process of the network. ⊙ represents the element-wise multiplication of the matrix, e s-1 represents the grid graph embedding vector obtained after the s-1th step; r s Represents the forget gate, which is used to control which information of the previous s-1 steps is "forgotten" during the update process of step s; e' s represents the candidate gating graph embedding vector generated in the sth step, z s Represents the update gate, used to weight e s-1 With e' s matrix and generates the gated graph embedding vector for the s-th step.
[0024] 2) Constructing the position encoding layer
[0025] The input of the position encoding layer is the output of the gated graph embedding layer Vector Sum Vector, by directly adding vectors to fuse the relative position features of the sequence data, and finally output the historical trajectory embedding vector matrix after position encoding and the day's trajectory embedding vector matrix Specifically:
[0026] First, the position encoding matrix e is generated by alternating sine and cosine functions. t , the calculation formula is as follows:
[0027]
[0028]
[0029] Where d represents the maximum dimension of the trajectory sequence embedding vector, e t (2i) represents the relative position feature of the 2ith dimension (even dimension) at the tth time step of the trajectory sequence data, e t (2i+1) represents the relative position feature of the 2i+1th dimension (odd dimension) at the tth time step of the trajectory sequence data.
[0030] According to formulas (6)-(7), the position encoding matrix e is obtained t , and then compare it with the input and The matrices are directly added to obtain the historical trajectory embedding vector matrix after position encoding and the day's trajectory embedding vector matrix
[0031] 3) Constructing the historical trajectory similarity feature extraction layer
[0032] The input of the historical trajectory similarity feature extraction layer is the output of the position encoding layer and This layer uses the attention mechanism to learn the similar movement patterns between the historical trajectory sequence matrix and the current day's trajectory sequence matrix, and then extracts the historical trajectory embedding vector of the day with the highest DTW (dynamic time warping) similarity. Specifically:
[0033] 3-1 Embed the position-encoded historical trajectory into a vector matrix The query matrix and value matrix are obtained through two fully connected layers, and the trajectory embedding vector matrix of the day after position encoding is obtained. The key matrix is obtained through a fully connected layer; the key matrix and the query matrix are calculated by matrix dot product to obtain the attention weight matrix, and then the attention weight matrix is normalized by softmax and matrix dot product is performed with the value matrix to obtain the historical trajectory sequence matrix after weight distribution. The details are as follows:
[0034]
[0035]
[0036]
[0037]
[0038] Where W q W k W v Represents the three fully connected layer parameters that can be learned; key T Represents the transpose of the key matrix.
[0039] 3-2 Perform DTW similarity feature extraction on the weighted historical trajectory sequence matrix to obtain the DTW extracted historical trajectory sequence matrix;
[0040] The calculation of DTW is based on the idea of dynamic programming. Assuming there are trajectory sequences a and b, the DTW similarity calculation formula is as follows:
[0041]
[0042] where dtw a,b (i, j) represents the DTW similarity between the first i trajectory points of trajectory sequence a and the first j trajectory points of trajectory sequence b. It represents the distance between the i-th trajectory point of trajectory sequence a and the j-th trajectory point of trajectory sequence b.
[0043] 3-3 Calculate the DTW similarity [s1,s2,…] between the historical trajectory sequence [h1,h2,…] and the current trajectory sequence [c1], from Extract the historical trajectory embedding vector of a certain day with the highest DTW similarity as the output of this layer.
[0044] 4) Construct the feature extraction layer related to the trajectory of the day
[0045] The day trajectory correlation feature extraction layer receives the day trajectory embedding vector Use the self-attention mechanism to learn the correlation of the trajectory sequence of the day, and finally output the correlation characteristics of the trajectory of the day Specifically:
[0046] Trajectory sequence matrix of the day The data is input into a self-attention network. The self-attention mechanism does not have the "forgetting" problem when learning the correlation between long sequence data. For the missing points in the trajectory of the day, the missing position can be inferred by the positions of the points around it. However, the importance of points at different positions for the inference is different. Therefore, the self-attention mechanism can be used to assign different weights to trajectory points at different positions. The specific calculation formula is as follows:
[0047]
[0048]
[0049]
[0050]
[0051] in Represents the position-encoded trajectory embedding vector matrix of the day W q W k W v They represent the parameters of the three fully connected layers in the model. Query represents a query matrix, key represents a key matrix, and the weight of each trajectory point can be obtained by dot product of the two matrices. Value represents a value matrix, and the weight of each trajectory point can be assigned by dot product calculation with the weight matrix. T represents matrix transpose. The final output Represents the correlation of the trajectory sequence of the day.
[0052] 5) Constructing the track repair layer
[0053] The input of the trajectory restoration layer is the historical trajectory similarity vector Current trajectory correlation vector and the grid graph embedding vector [e1,e2,…,e n ], the construction trajectory repair layer first and The trajectory sequence information is concatenated and fed into a three-layer fully connected network. The result is integrated with the grid graph embedding vector [e1,e2,…,e n ]Do the dot product and use the softmax function to normalize and get the probability of the missing trajectory position in each grid cell Finally, according to the probability The repair result is obtained, and the calculation formula is as follows:
[0054]
[0055]
[0056] in and Represents the historical trajectory similarity feature matrix and the current day trajectory correlation feature matrix respectively. Concat means concatenation on the last dimension of the vector, W u1 With W u2 Represents the parameters of two fully connected layers, tanh represents the activation function, e l represents the grid embedding vector, represents the probability that user u’s missing time t falls into each grid.
[0057] S3: Use dynamic mask training method to train the trajectory restoration model Similarmove based on similarity movement rules
[0058] The original trajectory data for the day is copied n times, and the trajectory points of t random time steps in each copy are set to 0. During the training process from round 0 to round n-1, the missing trajectory points of the same trajectory are always different, which increases the diversity of the training data, enables the model to learn more location information, and improves the repair accuracy.
[0059] S4: Use the trained trajectory repair model Similarmove based on similarity movement rules to achieve trajectory repair.
[0060] Since this method discretizes and preprocesses the trajectory data, the trajectory restoration problem can be regarded as a multi-classification problem. The cross entropy loss function is a commonly used loss function for multi-classification problems. The formula is as follows:
[0061]
[0062] in represents the actual grid cell where the missing position is located, is the probability of the grid cell where the missing location is located as predicted by the model.
[0063] The technical solution of the present invention will produce the following beneficial effects:
[0064] (1) This paper proposes an attention mechanism combined with DTW similarity. The attention mechanism calculates the similarity weight matrix between the historical trajectory sequence and the current day's trajectory sequence, allowing the model to focus on the trajectory segments in the historical trajectory sequence that are similar to the missing trajectory sequence. Then, based on the DTW similarity between the historical trajectory sequence and the missing trajectory sequence, the historical trajectory sequence matrix of the day with the highest similarity is extracted to repair the incomplete trajectory of the current day, thus solving the problem of extracting similar trajectory sequence information from an extremely long historical sequence.
[0065] (2) The present invention proposes a self-attention mechanism for trajectory sequences. The self-attention mechanism calculates a weight matrix through dot product similarity, allowing the model to automatically focus on a specific part of the missing trajectory and learn the correlation between the missing trajectory and the remaining trajectory of the day. On the other hand, the method of calculating similarity through dot product is not limited by the length of the trajectory sequence and can automatically find the remaining trajectory points that are more important for repair in a long sequence.
[0066] (3) This paper proposes a dynamic mask training method for trajectory data. With static masks, the hidden trajectory positions are fixed in each training iteration. With dynamic masks, the hidden positions are not repeated over a certain number of training iterations. This introduces multiple training information, increases the generalization capability of the network model, alleviates the problem of scarce training data in trajectory restoration tasks, and improves the accuracy of restoration. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] Figure 1 is the trajectory discretization graph of the present invention;
[0068] Figure 2 This is a model structure diagram of the present invention;
[0069] Figure 3 This is the attention mechanism diagram combined with DTW similarity of the present invention;
[0070] Figure 4 The dynamic mask training method proposed by the present invention. DETAILED DESCRIPTION
[0071] The specific embodiments of the present invention are described in further detail below with reference to the accompanying drawings.
[0072] A trajectory repair method based on sequence similarity and dynamic mask training mechanism includes the following steps:
[0073] S1: Trajectory sequence discretization. Figure 1 As shown, a square grid is used to divide the area where the vehicle's moving trajectory points are located. The grid sequence is numbered from left to right and from bottom to top, with the smallest number starting from 2. Number 1 indicates that the trajectory point is hidden, and number 0 indicates that the original trajectory point is missing. The two-dimensional trajectory sequence [(116.372936, 39.936349), (116.373367, 39.925062), (116.386878, 39.9239), (116.397514, 39.923955), (116.397729, 39.90608), (116.430787, 39.906467), (116.426475, 39.914658)] in the figure is mapped into a one-dimensional trajectory sequence traj = [224, 184, 186, 188, 68, 74, 134]. The discretized trajectory sequence traj is then split into the historical trajectory sequence [h1, h2, …] and the current day trajectory sequence [c1] on a daily basis.
[0074] S2: Build a trajectory repair model SimilarMove based on similar movement rules. Figure 2 As shown in the figure, the trajectory repair model Similarmove based on similarity movement law includes a gated graph embedding layer, a time series embedding layer, a historical trajectory similarity feature extraction layer, a current day trajectory correlation feature extraction layer, and a trajectory repair layer;
[0075] 1) Constructing a gated graph embedding layer
[0076] The gated graph embedding layer GGNN receives the historical trajectory sequence [h1, h2, ...] and the current day trajectory sequence [c1], learns the grid embedding vector representation based on the movement pattern of the user trajectory, makes the grid embedding vectors of adjacent positions more similar, and obtains the grid trajectory embedding vector. Then, the position encoding matrix is added to the grid trajectory embedding vector to finally obtain the grid embedding vector e i , historical trajectory sequence embedding vector matrix and the embedding vector matrix of the trajectory sequence of the day Specifically:
[0077] 1-1 Generate the in-degree matrix of the sequence data based on the historical trajectory sequence [h1,h2,…] and outdegree matrix Generate the in-degree matrix of the sequence data based on the trajectory sequence of the day [c1] and outdegree matrix The generated method is as follows:
[0078] Assume that there are n non-repeating grid numbers in [h1,h2,…], first generate two n*n two-dimensional matrices with all zeros and For the in-degree matrix, if there is a direct grid in [h1,h2,…] i to grid j The trajectory of , then the in-degree matrix The element in the jth row and ith column of is set to 1, then the out-degree matrix The element in row i and column j of is set to 1.
[0079] Assume that there are k non-repeated grid numbers in [c1], first generate two k*k two-dimensional matrices with all zeros and For the in-degree matrix, if there is a direct line from grid in [c1] i to grid j The trajectory of , then the in-degree matrix The element in the jth row and ith column of is set to 1, then the out-degree matrix The element in row i and column j of is set to 1.
[0080] 1-2 Generate the initial grid embedding vector matrix [e1,e2,…,e based on the node2vector algorithm n ]
[0081] The 1-3GGNN network layer learns the position embedding vector representation better through the neighbor information of the trajectory sequence, making the grid embedding vectors of adjacent positions more similar. When the GGNN network loops s times, the final output e s Denoted as the grid embedding vector ei According to the corresponding sequence number in the historical trajectory sequence [h1,h2,…], i Take out the corresponding embedding vector to generate the historical trajectory sequence embedding vector matrix According to the corresponding sequence number in the trajectory sequence [c1] of the day, i Take out the corresponding embedding vector to generate the historical trajectory sequence embedding vector matrix
[0082]
[0083] z s =sigmoid(W z a s +U z e s-1 ) (2)
[0084] r s =sigmoid(W r a s +U r e s-1 ) (3)
[0085] e′s=tanh(W h a s +U o (r s ⊙e s-1 )) (4)
[0086] e s =(1-z s )⊙e s-1 +z s ⊙e′ s (5)
[0087] Among them, M i and M o Represents the in-degree matrix and out-degree matrix of the input trajectory. When the historical trajectory sequence is input, M i and M o Corresponding respectively and When the trajectory sequence of the day is input, M i and M o Corresponding respectively and [e1, e2, ..., e n ] is a two-dimensional matrix representing the initial grid embedding vector. with b I represents the parameters of the fully connected layer corresponding to the in-degree matrix, with b o W represents the fully connected layer parameters corresponding to the degree matrix.z W r W h with U z U r U o They represent the parameters of the six fully connected layers in the network, which will be updated during the training process of the network. ⊙ represents the element-wise multiplication of the matrix, e s-1 Represents the grid graph embedding vector obtained after the s-1th step. s Represents the forget gate, which is used to control which information of the previous s-1 steps is "forgotten" during the update process of step s. s represents the candidate gating graph embedding vector generated in the sth step, z s Represents the update gate, used to weight e s-1 and e′ s matrix and generates the gated graph embedding vector for the s-th step.
[0088] 2) Constructing the position encoding layer
[0089] The input of the position encoding layer is the output of the gated graph embedding layer Vector Sum Vector, by directly adding vectors to fuse the relative position features of the sequence data, and finally output the historical trajectory embedding vector matrix after position encoding and the day's trajectory embedding vector matrix Specifically:
[0090] First, the position encoding matrix e is generated by alternating sine and cosine functions. t , the calculation formula is as follows:
[0091]
[0092]
[0093] Where d represents the maximum dimension of the trajectory sequence embedding vector, e t (2i) represents the relative position feature of the 2ith dimension (even dimension) at the tth time step of the trajectory sequence data, e t (2i+1) represents the relative position feature of the 2i+1th dimension (odd dimension) at the tth time step of the trajectory sequence data.
[0094] According to formulas (6)-(7), the position encoding matrix e is obtained t , and then compare it with the input and The matrices are directly added to obtain the historical trajectory embedding vector matrix after position encoding and the day's trajectory embedding vector matrix
[0095] 3) Constructing the historical trajectory similarity feature extraction layer
[0096] The input of the historical trajectory similarity feature extraction layer is the output of the position encoding layer and This layer uses the attention mechanism to learn the similar movement patterns between the historical trajectory sequence matrix and the current day's trajectory sequence matrix, and then extracts the historical trajectory embedding vector of the day with the highest DTW (dynamic time warping) similarity. like Figure 3 Specifically:
[0097] 3-1 Embed the position-encoded historical trajectory into a vector matrix The query matrix and value matrix are obtained through two fully connected layers, and the trajectory embedding vector matrix of the day after position encoding is obtained. The key matrix is obtained through a fully connected layer; the key matrix and the query matrix are calculated by matrix dot product to obtain the attention weight matrix, and then the attention weight matrix is normalized by softmax and matrix dot product is performed with the value matrix to obtain the historical trajectory sequence matrix after weight distribution. The details are as follows:
[0098]
[0099]
[0100]
[0101]
[0102] Where W q W k W v They represent the three fully connected layer parameters that can be learned. T Represents the transpose of the key matrix.
[0103] 3-2 Perform DTW similarity feature extraction on the weighted historical trajectory sequence matrix to obtain the DTW extracted historical trajectory sequence matrix;
[0104] The calculation of DTW is based on the idea of dynamic programming. Assuming there are trajectory sequences a and b, the DTW similarity calculation formula is as follows:
[0105]
[0106] where dtw a,b (i, j) represents the DTW similarity between the first i trajectory points of trajectory sequence a and the first j trajectory points of trajectory sequence b, It represents the distance between the i-th trajectory point of trajectory sequence a and the j-th trajectory point of trajectory sequence b.
[0107] 3-3 Calculate the DTW similarity [s1, s2, ...] between the historical trajectory sequence [h1, h2, ...] and the current trajectory sequence [c1], from Extract the historical trajectory embedding vector of a certain day with the highest DTW similarity As the output of the historical trajectory similarity feature extraction layer.
[0108] Step 4: Construct the feature extraction layer related to the trajectory of the day.
[0109] The day trajectory correlation feature extraction layer receives the day trajectory embedding vector Use the self-attention mechanism to learn the correlation of the trajectory sequence of the day, and finally output the correlation characteristics of the trajectory of the day Specifically:
[0110] The embedding vector of the trajectory map of the day obtained in step 2 is input into a self-attention network. For the missing points in the trajectory of the day, the missing position can be inferred by the positions of the surrounding points. However, the importance of points at different positions for inference is different. Therefore, the self-attention mechanism can be used to automatically learn which points are more important for repair. The specific calculation formula of the self-attention mechanism is as follows:
[0111]
[0112]
[0113]
[0114]
[0115] in Represents the position-encoded trajectory embedding vector matrix of the day W q W k W v They represent the parameters of the three fully connected layers in the model. Query represents a query matrix, key represents a key matrix, and the weight of each trajectory point can be obtained by dot product of the two matrices. Value represents a value matrix, and the weight of each trajectory point can be assigned by dot product calculation with the weight matrix. T represents matrix transpose. The final output Represents the correlation of the trajectory sequence of the day.
[0116] Step 5: Construct the trajectory repair layer.
[0117] The input of the trajectory restoration layer is the historical trajectory similarity vector Current trajectory correlation vector and the grid graph embedding vector [e1, e2, ..., e n ], the construction trajectory repair layer first and The trajectory sequence information is concatenated and fed into a three-layer fully connected network. The result is integrated with the grid graph embedding vector [e1, e2, ..., e n ]Do the dot product and use the softmax function to normalize and get the probability of the missing trajectory position in each grid cell Finally, according to the probability Get the repair result. The specific operations are as follows:
[0118]
[0119]
[0120] in and Represents the historical trajectory similarity feature matrix and the current day trajectory correlation feature matrix respectively. Concat means concatenation on the last dimension of the vector, W u1 With W u2 Represents the parameters of two fully connected layers, tanh represents the activation function, e l represents the grid embedding vector, represents the probability that user u’s missing time t falls into each grid.
[0121] S3: Use the dynamic mask training method to train the trajectory restoration model Similarmove based on similarity movement rules.
[0122] As attached Figure 4 As shown in the figure, in order to increase the amount of training data for the model, a dynamic mask mechanism is used to generate training data. In every three epochs of training, the position of the mask for the same trajectory of the dynamic mask is different (the white dots in the figure represent the mask), while the position of the mask for the same trajectory of the static mask is the same in every epoch.
[0123] Since the method of the present invention discretizes and preprocesses the trajectory data, the trajectory restoration problem can be regarded as a multi-classification problem. The cross entropy loss function is a commonly used loss function for multi-classification problems. The formula is as follows:
[0124]
[0125] in represents the actual grid cell where the missing position is located, is the probability of the grid cell where the missing location is located as predicted by the model.
[0126] This example was conducted on three datasets: Beijing taxi, Shenzhen taxi, and Brazilian bus datasets. The Beijing taxi dataset contains the running trajectories of approximately 1,400 taxis over a week, the Shenzhen taxi dataset contains the running trajectories of approximately 2,100 taxis over a month, and the Brazilian bus dataset contains the running trajectories of approximately 1,600 buses over a month. Before the experiment, it was necessary to define the regional scope and time range, and to exclude public transportation data with significantly insufficient data. The processed trajectory data is shown in the table below:
[0127]
[0128] The effect evaluation indicators used in this invention are recall@1, recall@5 and recall@10. The model will eventually output the probability prob that the missing position falls in each grid cell. u , the calculation index formula is as follows:
[0129]
[0130] In the formula, top@k represents prob u The K largest grids in the middle probability, loc u Indicates the actual grid unit where the missing position is located. In indicates that if the missing position can be found in the top@k(prob u ), returns 1 otherwise returns 0. The experimental results are shown as follows:
[0131]
[0132] The model proposed in this paper is the Similarmove model. The two compared methods are the attnmove model and the Periodicmove model. The attnmove model performs trajectory repair based on the attention mechanism, and the Periodicmove model performs trajectory repair based on the gated graph network. It can be seen that the model proposed in this paper has improvements over them on the three datasets.
Claims
1. A trajectory repair method based on sequence similarity and dynamic mask training mechanism, characterized by The following steps are involved: S1: Trajectory discretization Obtain the missing trajectory sequence and historical trajectory sequence of the vehicle, discretize the above trajectory sequence, map it to a square grid, and convert the two-dimensional trajectory sequence into a one-dimensional trajectory sequence to obtain the historical trajectory sequence [h1,h2,…] and the current day trajectory sequence [c1]. S2: Build a trajectory repair model based on similar movement rules Similarmove The trajectory restoration model Similarmove based on similarity movement rules includes a gated graph embedding layer, a position encoding layer, a historical trajectory similarity feature extraction layer, a current day trajectory correlation feature extraction layer, and a trajectory restoration layer; 1) Constructing a gated graph embedding layer 1-1 Generate the in-degree matrix of the sequence data based on the historical trajectory sequence [h1,h2,…] and outdegree matrix , based on the trajectory sequence of the day [c1], generate the in-degree matrix of the sequence data and outdegree matrix ; 1-2 Generate the initial grid embedding vector matrix based on the node2vector algorithm ; 1-3 The gated graph embedding layer GGNN learns the position embedding vector representation through the neighbor information of the trajectory sequence, making the grid embedding vectors of adjacent positions more similar. When the gated graph embedding layer GGNN cycles s times, the final output is Denoted as the grid embedding vector ; According to the corresponding sequence number in the historical trajectory sequence [h1,h2,…] Take out the corresponding embedding vector and generate the historical trajectory sequence embedding vector matrix , according to the corresponding sequence number in the trajectory sequence [c1] of the day Take out the corresponding embedding vector to generate the historical trajectory sequence embedding vector matrix ; 2) Constructing the position encoding layer The input of the position encoding layer is the output vector of the gated graph embedding layer. and , by directly adding vectors to fuse the relative position features of the sequence data, and finally output the historical trajectory embedding vector matrix after position encoding and the day's trajectory embedding vector matrix ; 3) Constructing a historical trajectory similarity feature extraction layer The input of the historical trajectory similarity feature extraction layer is the output of the position encoding layer and ; Use the attention mechanism to learn the similar movement patterns between the historical trajectory sequence matrix and the current day trajectory sequence matrix, and extract the historical trajectory embedding vector of the day with the highest dynamic time warping (DTW) similarity. ; 4) Construct the feature extraction layer for the trajectory correlation of the day The day trajectory correlation feature extraction layer receives the day trajectory embedding vector , using the self-attention mechanism to learn the correlation of the trajectory sequence of the day, and finally output the correlation characteristics of the trajectory of the day ; 5) Constructing the track repair layer The trajectory restoration layer is constructed to convert the historical trajectory similarity vector , current trajectory correlation vector The trajectory sequence information is spliced and input into a three-layer fully connected network, and the result is embedded in the initial grid vector matrix Do the dot product and use the softmax function for normalization to get the probability of the missing trajectory position in each grid cell , and finally according to the probability Get the repair result; S3: Use dynamic mask training method to train the trajectory restoration model Similarmove based on similarity movement rules; The original trajectory data of the day is copied n times and trained for n rounds respectively; during each round of training, the trajectory points of t random time steps in the trajectory data are set to 0; S4: Use the trained trajectory repair model Similarmove based on similarity movement rules to achieve trajectory repair.
2. The method according to claim 1, characterized in that The calculation process of the gated graph embedding layer GGNN is as follows: ; ; ; ; ; in and Represents the in-degree matrix and out-degree matrix of the input trajectory. When the input trajectory is a historical trajectory sequence, and Corresponding respectively and , when the input trajectory is the trajectory sequence of the day and Corresponding respectively and ; represents the fully connected layer parameters corresponding to the in-degree matrix, and Indicates the fully connected layer parameters corresponding to the degree matrix; and Represents the parameters of the fully connected layer in the gated graph embedding layer GGNN; represents element-wise matrix multiplication, represents the grid graph embedding vector obtained after the s-1th step; represents the forget gate; represents the candidate gating graph embedding vector generated in the s-th step, represents the update gate.
3. The method according to claim 2, characterized in that Step 1-1 is specifically: Assume that there are n non-repeated grid numbers in the historical trajectory sequence [h1,h2,…], first generate two n*n two-dimensional matrices with all zeros, namely the in-degree matrix and outdegree matrix ; For the in-degree matrix , if there is a path in the historical trajectory sequence [h1,h2,…] that goes directly from the grid To Grid The trajectory of , then the in-degree matrix The element in the jth row and ith column of is set to 1, and the degree matrix The element in row i and column j of is set to 1; Assume that there are k non-repeated grid numbers in the trajectory sequence [c1] of the day, first generate two k*k two-dimensional matrices with all zeros, namely the in-degree matrix and outdegree matrix ; For the in-degree matrix , if there is a path in the trajectory sequence [c1] that day that goes directly from the grid To Grid The trajectory of , then the in-degree matrix The element in the jth row and ith column of is set to 1, and the degree matrix The element in row i and column j of is set to 1.
4. The method according to claim 2, characterized in that The position encoding layer described in the trajectory restoration model Similarmove based on similarity movement rules is specifically: First, the position encoding matrix is generated by alternating sine and cosine functions. , the calculation formula is as follows: ; ; Where d represents the maximum dimension of the trajectory sequence embedding vector, Represents the relative position feature of the 2i-th dimension of the t-th time step of the trajectory sequence data, Represents the relative position feature of the 2i+1th dimension at the tth time step of the trajectory sequence data; According to formula (6)-(7), the position encoding matrix is obtained , then With input and The matrices are directly added to obtain the historical trajectory embedding vector matrix after position encoding and the day's trajectory embedding vector matrix .
5. The method according to claim 4, characterized in that The historical trajectory similarity feature extraction layer described in the trajectory restoration model Similarmove based on similar movement rules is specifically: 3-1 Embed the position-encoded historical trajectory into a vector matrix The query matrix and value matrix are obtained through two fully connected layers, and the trajectory embedding vector matrix of the day after position encoding is obtained. The key matrix is obtained through a fully connected layer; the key matrix and the query matrix are calculated by matrix dot product to obtain the attention weight matrix, and then the attention weight matrix is calculated by After normalization, the matrix dot product is performed with the value matrix to obtain the historical trajectory sequence matrix after weight distribution. ; The details are as follows: ; ; ; ; in Represent the three learnable fully connected layer parameters respectively; Represents the transpose of the key matrix; 3-2 Perform DTW similarity feature extraction on the weighted historical trajectory sequence matrix to obtain the DTW extracted historical trajectory sequence matrix; The calculation of DTW is based on the idea of dynamic programming. Assuming there are trajectory sequences a and b, the DTW similarity calculation formula is as follows: ; in represents the DTW similarity between the first i trajectory points of trajectory sequence a and the first j trajectory points of trajectory sequence b, represents the distance between the i-th trajectory point of trajectory sequence a and the j-th trajectory point of trajectory sequence b; 3-3 Calculate the DTW similarity [s1,s2,…] between the historical trajectory sequence [h1,h2,…] and the current trajectory sequence [c1], from Extract the historical trajectory embedding vector of a certain day with the highest DTW similarity As the output of the historical trajectory similarity feature extraction layer.
6. The method according to claim 5, characterized in that The trajectory restoration model Similarmove based on similar movement rules describes the following feature extraction layer for the trajectory correlation of the day: Trajectory sequence matrix of the day The data is input into a self-attention network. The self-attention mechanism does not have the "forgetting" problem when learning the correlation between long sequence data. For the missing points in the trajectory of the day, the missing position is inferred by the positions of the points around it. However, the importance of points at different positions for the inference is different. Therefore, the self-attention mechanism is used to assign different weights to trajectory points at different positions. The specific calculation formula is as follows: ; ; ; ; in Represents the position-encoded trajectory embedding vector matrix of the day , Represents three fully connected layer parameters respectively; query represents a query matrix, key represents a key matrix; value represents a value matrix; T represents matrix transpose; Represents the correlation of the trajectory sequence of the day.
7. The method according to claim 6, characterized in that The trajectory restoration layer described in the trajectory restoration model Similarmove based on similarity movement rules is specifically: ; ; in and Represent the historical trajectory similarity feature matrix and the current day trajectory correlation feature matrix respectively; Concat means concatenation on the last dimension of the vector. and Represents two fully connected layer parameters, tanh represents the activation function, represents the grid embedding vector, represents the probability that user u’s missing time t falls into each grid.
8. The method according to claim 1, characterized in that The loss function of the trajectory restoration model Similarmove based on similarity movement rules is as follows: ; in represents the actual grid cell where the missing position is located, It is the probability of the grid cell where the missing position is located predicted by the trajectory repair model Similarmove based on the similarity movement law.
9. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 8.
10. A computing device comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 8 is implemented.