A GPS trajectory representation method and device based on a dual-view encoder and a storage medium
Patent Information
- Application Number
- CN202510443011.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-09
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2045-04-09
AI Technical Summary
[0004]本发明的目的在于解决现有GPS轨迹表示方法因需提前对齐轨迹长度而引入误差,以及未能充分利用轨迹间结构特性的问题,通过构建结构和时序双视图编码器直接融合POI序列特征,无需对齐轨迹即可生成高精度轨迹表示向量
[0076]轨迹表示是利用城市车辆GPS数据分析城市交通的一项常见任务。现有的轨迹表示方法在预先对齐轨迹长度得到表示向量后有两类操作,一是从模型得到的表示向量中取原始轨迹长度的向量作为最终表示,二是直接将模型得到的表示向量作为最终表示向量,两种方法均在预处理时为轨迹增加了冗余信息,会导致最终轨迹之间的关系表示存在误差。与现有方法不同,本发明无需提前对齐轨迹长度,直接对轨迹序列进行表示,不仅避免了为轨迹引入冗余信息,还提高了数据预处理效率。本发明中首先将轨迹序列处理为兴趣点序列,保留了轨迹的关键特征。然后通过双视图编码器从结构和时序两个视角对轨迹进行表示,能够更全面地捕捉轨迹的特征,从而精确表示轨迹之间的关系。此外,双视图融合机制结合自注意力机制,能够有效整合结构和时序信息,增强模型的泛化能力,使其在不同场景下表现更加稳定。最后,通过带权重的InfoNCE损失函数对模型进行训练,进一步优化了轨迹表示向量,使相似轨迹在特征空间中靠近,不相似轨迹远离。这样做显著提高了轨迹表示的准确性和有效性。
Smart Images

Figure CN120371930B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of GPS trajectory data processing, and in particular to a GPS trajectory representation method, apparatus, and storage medium based on a dual-view encoder. Background Technology
[0002] With the widespread adoption of GPS technology, GPS trajectory data has significant application value in fields such as traffic analysis and urban planning. Due to the varying lengths of trajectory data, existing methods typically require aligning variable-length trajectories to a uniform length before vector representation. This preprocessing not only increases computational complexity but also introduces noise due to padding or truncation operations, leading to inaccurate representations of relationships between trajectories. For example, current techniques often use recurrent neural networks to directly process the aligned trajectory sequences, but the length alignment process disrupts the spatiotemporal distribution characteristics of the original trajectories.
[0003] Specifically, existing trajectory representation methods involve two types of operations after pre-aligning the trajectory length to obtain the representation vector: one is to extract a vector of the original trajectory length from the model output as the final representation, and the other is to directly use the aligned vector from the model output. Both methods require forced alignment of the trajectory length during the preprocessing stage through padding or sampling, leading to the introduction of redundant information (such as invalid padding points or duplicate sampling points). This redundant information interferes with the model's extraction of the true features of the trajectory, causing deviations in the similarity calculation between trajectories, and ultimately resulting in significant errors in the representation of trajectory relationships. In addition, existing methods mostly focus on the temporal feature modeling of a single trajectory, failing to effectively mine the spatial structural associations of co-occurring points of interest (POIs) between trajectories, further limiting the accuracy of the representation model. Therefore, there is an urgent need for a trajectory representation method that does not require length alignment and can integrate spatiotemporal dual-view features to improve the accuracy and efficiency of traffic data analysis. Summary of the Invention
[0004] The purpose of this invention is to solve the problems of existing GPS trajectory representation methods, which introduce errors due to the need to pre-align trajectory lengths and fail to fully utilize the structural characteristics between trajectories. By constructing a dual-view encoder of structure and time sequence, the invention directly fuses POI sequence features, generating high-precision trajectory representation vectors without the need for trajectory alignment.
[0005] This invention solves the error problem caused by the pre-alignment of trajectory length in existing GPS trajectory representation methods by providing a method that eliminates the need for pre-alignment. The GPS trajectory is preprocessed into a sequence of points of interest (POIs), and a dual-view trajectory encoder is constructed. This encoder directly represents the POI sequence from both structural and temporal views without requiring pre-alignment. The dual-view fusion yields the final trajectory representation vector, which is then trained using a weighted InfoNCE loss function to optimize the vector. This achieves the goal of accurately representing the relationships between trajectories.
[0006] To achieve the above objectives, the present invention employs the following technical means:
[0007] A GPS trajectory representation method based on a dual-view encoder includes the following steps:
[0008] Step 1: GPS trajectory data preprocessing. Use the K-means clustering algorithm to cluster all trajectory points in the region to generate a set of Points of Interest (POIs). For each trajectory sequence, take the average of the longitude and latitude of the trajectory points in the POIs it passes through, and convert the trajectory sequence into a POI sequence.
[0009] Step 2: Construct a dual-view trajectory encoder to represent the POI sequence generated in Step 1 from both structural and temporal views, and then perform dual-view fusion to obtain the final trajectory representation vector;
[0010] Step 3: Implement the Structured View (StrucView), treating POIs as nodes and POI sequences as hyperedges, constructing a hypergraph and aggregating information through a graph attention mechanism to generate a vector H of uniform dimension. struc ;
[0011] Step 4: Implement the SeqView temporal view, calculate the probability distribution of the POI sequence as the cue vector, concatenate it with the original features, and input it into the Gated Recurrent Unit (GRU) model to generate a vector H of uniform dimension. seq ;
[0012] Step 5: Implement a dual-view fusion mechanism. The representation vectors of the two views generated in Step 3 and Step 4 are fused using a self-attention mechanism to obtain the final trajectory representation vector.
[0013] In the above technical solution, step 1 includes the following steps:
[0014] Step 1.1: Define the trajectory as TR = {p1, p2, ..., p i , ..., p l}, where p i It is a binary tuple p i = (long, lat), representing a GPS data point on the trajectory, where long represents longitude and lat represents latitude;
[0015] Step 1.2: For all trajectory points within the region, p1, p2, ..., p l The K-means clustering algorithm is used to cluster the points of interest, generating a set of points of interest POI = POI1, POI2, ..., POI... k};
[0016] Step 1.3: For the trajectory sequence TR i Pass it through Point of Interest (POI)k The average longitude and latitude of the inner trajectory points are used to obtain the trajectory sequence TR; at the point of interest... Original characteristics:
[0017]
[0018] Where M k For TR i exist The number of trajectory points within, long j and lat j Here, represents the longitude and latitude of the j-th trajectory point, and k is the POI number;
[0019] Step 1.4: Transfer the trajectory sequence TR i Convert to POI sequence in This indicates that the i-th trajectory passes through the point of interest numbered j.
[0020] In the above technical solution, step 3 includes the following steps:
[0021] Step 3.1: Construct a hypergraph, treating all points of interest within the region as nodes in the hypergraph, and the POI sequence as a hyperedge in the hypergraph, with the hyperedge connecting the points of interest traversed in the sequence;
[0022] Step 3.2: Extract node features for each point of interest (POI). k Calculate the average longitude and latitude of all trajectory points as the node features:
[0023]
[0024] Where N k Belongs to POI k The number of trajectory points, long i and lat i These are the longitude and latitude of the i-th trajectory point, respectively;
[0025] Step 3.3: Apply graph attention mechanism to the nodes and hyperedges in the hypergraph, specifically:
[0026] For each hyperedge E, compute the weighted sum of the representations of the nodes it connects to as the initial representation of the hyperedge:
[0027]
[0028] Where α E,k For the hyperedge E, pair node POI k Attention weights;
[0029] For each node POI kThe weighted sum of all the hyperedge representations it participates in is used as the update table of the node:
[0030]
[0031] Where ε k For the POI containing the node k The set of hyperedges, β k,E For node POI k Attention weights for the hyperedge E;
[0032] Step 3.4: For each hyperedge E, calculate the average value of the updated representations of the nodes it connects to generate the final representation H of the hyperedge. E ,Right now:
[0033]
[0034] Where H struc V is the representation vector output by the structure view. E Let |V be the set of nodes connected by the hyperedge E. E | represents the number of nodes.
[0035] In the above technical solution, step 4 includes the following steps:
[0036] Step 4.1: Construct the cue vector, calculated based on the POI sequence obtained in Step 1.4, specifically as follows:
[0037] For the POI sequence POI i Points of interest Calculate the corresponding trajectory TR i Passing through points of interest The number of trajectory points c j And calculate the POI based on the total number of trajectory points C of this trajectory. i Probability distribution of passing through each point of interest:
[0038]
[0039] in The hint vector Hhint = [Pr(POI1), Pr(POI2), ..., Pr(POIn)] is obtained;
[0040] Step 4.2: Set the cue vector H hint The feature vector of the POI sequence calculated in step 1.3 By concatenating the vectors, a new feature vector is formed:
[0041]
[0042] Where [;] denotes vector concatenation operation;
[0043] Step 4.3: Combine the concatenated feature vector F concat The data is fed into a GRU (Given Ratio Regulated Recurrent Unit) model to generate a representation vector with a uniform dimension.
[0044] H seq =GRU(F concat )
[0045] Where H seq This is the representation vector output by the time-series view.
[0046] In the above technical solution, step 5 includes the following steps:
[0047] Step 5.1: Convert the structural view representation vector H obtained in Step 3 into a vector. struc And the time-series view representation vector H obtained in step 4 seq Concatenate into matrix H:
[0048] H = [H] struc H seq ]
[0049] Where [;] denotes vector concatenation operation. d represents the feature dimension;
[0050] Step 5.2: Apply a linear transformation to each column of matrix H to calculate the self-attention weights:
[0051]
[0052] Where Linear(H) is the weight vector calculated through a linear layer;
[0053] Step 5.3: Use the self-attention weights W to perform a weighted summation on matrix H to obtain the final trajectory representation vector:
[0054]
[0055] Where H final This is the final trajectory representation vector.
[0056] The above technical solution also includes step 6, which involves training the model based on the weighted InfoNCE loss function and optimizing the trajectory representation vector. Step 6 includes the following steps:
[0057] Step 6.1: Calculate the predicted Euclidean distance matrix D pred Specifically:
[0058] The final trajectory representation vector obtained from step 5.3 Where N is the number of samples, d is the feature dimension, and the Euclidean distance between each pair of samples is calculated:
[0059] Dpred [i, j] = ||H i -H j ||2
[0060] Where H i and H j It is a trajectory representation vector. It is the predicted Euclidean distance matrix;
[0061] Step 6.2: Normalize the true distance matrix D true As the soft contrast weight w i,j :
[0062]
[0063] Where τ is a temperature coefficient that controls the smoothness of the distribution;
[0064] Step 6.3: Construct a weighted contrastive loss function based on InfoNCE, specifically as follows:
[0065] Constructing the loss function By minimizing the difference between the predicted distance and the true distance:
[0066]
[0067] The numerator represents the similarity weight of positive samples, and the denominator represents the sum of the similarity weights of all negative samples. By optimizing this loss function, similar trajectories are brought closer together in the feature space, while dissimilar trajectories are moved further apart.
[0068] This invention provides a GPS trajectory representation device based on a dual-view encoder, comprising:
[0069] The data preprocessing module is used to cluster all trajectory points in the region using the K-means clustering algorithm to generate a set of Points of Interest (POIs); for each trajectory sequence, the average longitude and latitude of the trajectory points in the POIs it passes through are taken to convert the trajectory sequence into a POI sequence.
[0070] The dual-view trajectory encoder construction module is used to obtain the final trajectory representation vector by fusing the POI sequence generated by the structural and temporal view representation data preprocessing module.
[0071] The structural view implementation module treats POIs as nodes and POI sequences as hyperedges, constructs a hypergraph, aggregates information through a graph attention mechanism, and generates a vector H of uniform dimension. struc ;
[0072] The time-series view implementation module calculates the probability distribution of the POI sequence as a cue vector, which is then concatenated with the original features and input into a gated recurrent unit (GRU) model to generate a vector H of uniform dimension. seq ;
[0073] The dual-view fusion mechanism implementation module is used to fuse the representation vectors of the two views generated by the structure view implementation module and the temporal view implementation module through a self-attention mechanism to obtain the final trajectory representation vector.
[0074] The present invention also provides a storage medium in which the processor executes a program, thereby implementing the aforementioned GPS trajectory representation method based on a dual-view encoder.
[0075] Because the present invention adopts the above-described technical solution, it has the following beneficial effects:
[0076] Trajectory representation is a common task in urban traffic analysis using urban vehicle GPS data. Existing trajectory representation methods involve two types of operations after pre-aligning the trajectory length to obtain the representation vector: one is to take the vector of the original trajectory length from the representation vector obtained from the model as the final representation; the other is to directly use the representation vector obtained from the model as the final representation vector. Both methods add redundant information to the trajectory during preprocessing, leading to errors in the representation of relationships between trajectories. Unlike existing methods, this invention does not require pre-aligning the trajectory length and directly represents the trajectory sequence, avoiding the introduction of redundant information and improving data preprocessing efficiency. In this invention, the trajectory sequence is first processed into a sequence of points of interest, preserving the key features of the trajectory. Then, a dual-view encoder is used to represent the trajectory from both structural and temporal perspectives, which can more comprehensively capture the features of the trajectory and thus accurately represent the relationships between trajectories. In addition, the dual-view fusion mechanism combined with the self-attention mechanism can effectively integrate structural and temporal information, enhance the model's generalization ability, and make it more stable in different scenarios. Finally, the model is trained using a weighted InfoNCE loss function to further optimize the trajectory representation vector, making similar trajectories closer together in the feature space and dissimilar trajectories farther apart. This significantly improves the accuracy and effectiveness of trajectory representation. Attached Figure Description
[0077] Figure 1 A block diagram of a GPS trajectory representation method based on a dual-view encoder is provided for the implementation of this invention. Detailed Implementation
[0078] The embodiments of the present invention will be described in detail below. Although the present invention will be described and illustrated in conjunction with some specific embodiments, it should be noted that the present invention is not limited to these embodiments. On the contrary, any modifications or equivalent substitutions made to the present invention should be covered within the scope of the claims of the present invention.
[0079] Furthermore, to better illustrate the present invention, numerous specific details are set forth in the following detailed embodiments. Those skilled in the art will understand that the present invention can be practiced without these specific details.
[0080] To achieve the above objectives, the present invention employs the following technical means:
[0081] A GPS trajectory representation method based on a dual-view encoder includes the following steps:
[0082] Step 1: GPS trajectory data preprocessing. Use the K-means clustering algorithm to cluster all trajectory points in the region to generate a set of Points of Interest (POIs). For each trajectory sequence, take the average of the longitude and latitude of the trajectory points in the POIs it passes through, and convert the trajectory sequence into a POI sequence.
[0083] Step 2: Construct a dual-view trajectory encoder to represent the POI sequence generated in Step 1 from both structural and temporal views, and then perform dual-view fusion to obtain the final trajectory representation vector;
[0084] Step 3: Implement the Structured View (StrucView), treating POIs as nodes and POI sequences as hyperedges, constructing a hypergraph and aggregating information through a graph attention mechanism to generate a vector H of uniform dimension. struc ;
[0085] Step 4: Implement the SeqView temporal view, calculate the probability distribution of the POI sequence as the cue vector, concatenate it with the original features, and input it into the Gated Recurrent Unit (GRU) model to generate a vector H of uniform dimension. seq ;
[0086] Step 5: Implement a dual-view fusion mechanism. The representation vectors of the two views generated in Step 3 and Step 4 are fused using a self-attention mechanism to obtain the final trajectory representation vector.
[0087] In the above technical solution, step 1 includes the following steps:
[0088] Step 1.1: Define the trajectory as TR = {p1, P2, ..., p} i ,…...,p l}, where p i It is a binary tuple p i= (long, lat), representing a GPS data point on the trajectory, where long represents longitude and lat represents latitude;
[0089] Step 1.2: For all trajectory points {p1, p2, ..., p} within the region... l The K-means clustering algorithm is used to cluster the points of interest, generating a set of points of interest POI = {POI1, POI2, ..., POI...}. k};
[0090] Step 1.3: For the trajectory sequence TR i Pass it through Point of Interest (POI) k The average of the longitude and latitude of the inner trajectory points is used to obtain the trajectory sequence TR. i Points of interest Original characteristics:
[0091]
[0092] Where M k For TR i exist The number of trajectory points within, long j and lat j Here, represents the longitude and latitude of the j-th trajectory point, and k is the POI number;
[0093] Step 1.4: Transfer the trajectory sequence TR j Convert to POI sequence in This indicates that the i-th trajectory passes through the point of interest numbered j.
[0094] In the above technical solution, step 3 includes the following steps:
[0095] Step 3.1: Construct a hypergraph, treating all points of interest within the region as nodes in the hypergraph, and the POI sequence as a hyperedge in the hypergraph, with the hyperedge connecting the points of interest traversed in the sequence;
[0096] Step 3.2: Extract node features for each point of interest (POI). k Calculate the average longitude and latitude of all trajectory points as the node features:
[0097]
[0098] Where N k Belongs to POI k The number of trajectory points, long i and lat i These are the longitude and latitude of the i-th trajectory point, respectively;
[0099] Step 3.3: Apply graph attention mechanism to the nodes and hyperedges in the hypergraph, specifically:
[0100] For each hyperedge E, compute the weighted sum of the representations of the nodes it connects to as the initial representation of the hyperedge:
[0101]
[0102] Where α E,k For the hyperedge E, pair node POI k Attention weights;
[0103] For each node POI k The weighted sum of all the hyperedge representations it participates in is used as the update table of the node:
[0104]
[0105] Where ε k For the POI containing the node k The set of hyperedges, β k,E For node POI k Attention weights for the hyperedge E;
[0106] Step 3.4: For each hyperedge E, calculate the average value of the updated representations of the nodes it connects to generate the final representation H of the hyperedge. F ,Right now:
[0107]
[0108] Where H struc V is the representation vector output by the structure view. E Let |V be the set of nodes connected by the hyperedge E. E | represents the number of nodes.
[0109] In the above technical solution, step 4 includes the following steps:
[0110] Step 4.1: Construct the cue vector, calculated based on the POI sequence obtained in Step 1.4, specifically as follows:
[0111] For the POI sequence POI i Points of interest Calculate the corresponding trajectory TR i Passing through points of interest The number of trajectory points c j And calculate the POI based on the total number of trajectory points C of this trajectory. i Probability distribution of passing through each point of interest:
[0112]
[0113] in Obtain the cue vector H hint =[Pr(POI1),Pr(POI2),…,Pr(POI n )];
[0114] Step 4.2: Set the cue vector H hint The feature vector of the POI sequence calculated in step 1.3 By concatenating the vectors, a new feature vector is formed:
[0115]
[0116] Where [;] denotes vector concatenation operation;
[0117] Step 4.3: Combine the concatenated feature vector F concat The data is fed into a GRU (Given Ratio Regulated Recurrent Unit) model to generate a representation vector with a uniform dimension.
[0118] H seq =GRU(F concat )
[0119] Where H seq This is the representation vector output by the time-series view.
[0120] In the above technical solution, step 5 includes the following steps:
[0121] Step 5.1: Convert the structural view representation vector H obtained in Step 3 into a vector. struc And the time-series view representation vector H obtained in step 4 seq Concatenate into matrix H:
[0122] H = [H] struc H seq ]
[0123] Where [;] denotes vector concatenation operation. d represents the feature dimension;
[0124] Step 5.2: Apply a linear transformation to each column of matrix H to calculate the self-attention weights:
[0125]
[0126] Where Linear(H) is the weight vector calculated through a linear layer;
[0127] Step 5.3: Use the self-attention weights W to perform a weighted summation on matrix H to obtain the final trajectory representation vector:
[0128]
[0129] Where H finalThis is the final trajectory representation vector.
[0130] The above technical solution also includes step 6, which involves training the model based on the weighted InfoNCE loss function and optimizing the trajectory representation vector. Step 6 includes the following steps:
[0131] Step 6.1: Calculate the predicted Euclidean distance matrix D pred Specifically:
[0132] The final trajectory representation vector obtained from step 5.3 Where N is the number of samples, d is the feature dimension, and the Euclidean distance between each pair of samples is calculated:
[0133] D pred [i, j] = ||H i -H j ||2
[0134] Where H i and H j It is a trajectory representation vector. It is the predicted Euclidean distance matrix;
[0135] Step 6.2: Normalize the true distance matrix D true As the soft contrast weight w i,j :
[0136]
[0137] Where τ is a temperature coefficient that controls the smoothness of the distribution;
[0138] Step 6.3: Construct a weighted contrastive loss function based on InfoNCE, specifically as follows:
[0139] Constructing the loss function By minimizing the difference between the predicted distance and the true distance:
[0140]
[0141] The numerator represents the similarity weight of positive samples, and the denominator represents the sum of the similarity weights of all negative samples. By optimizing this loss function, similar trajectories are brought closer together in the feature space, while dissimilar trajectories are moved further apart.
[0142] This invention provides a GPS trajectory representation device based on a dual-view encoder, comprising:
[0143] The data preprocessing module is used to cluster all trajectory points in the region using the K-means clustering algorithm to generate a set of Points of Interest (POIs); for each trajectory sequence, the average longitude and latitude of the trajectory points in the POIs it passes through are taken to convert the trajectory sequence into a POI sequence.
[0144] The dual-view trajectory encoder construction module is used to obtain the final trajectory representation vector by fusing the POI sequence generated by the structural and temporal view representation data preprocessing module.
[0145] The structural view implementation module treats POIs as nodes and POI sequences as hyperedges, constructs a hypergraph, aggregates information through a graph attention mechanism, and generates a vector H of uniform dimension. struc ;
[0146] The time-series view implementation module calculates the probability distribution of the POI sequence as a cue vector, which is then concatenated with the original features and input into a gated recurrent unit (GRU) model to generate a vector H of uniform dimension. seq ;
[0147] The dual-view fusion mechanism implementation module is used to fuse the representation vectors of the two views generated by the structure view implementation module and the temporal view implementation module through a self-attention mechanism to obtain the final trajectory representation vector.
[0148] The present invention also provides a storage medium in which the processor executes a program, thereby implementing the aforementioned GPS trajectory representation method based on a dual-view encoder.
[0149] Example 1
[0150] This embodiment uses the publicly available taxi GPS trajectory dataset GeoLife as an example to demonstrate the complete implementation process of the method described in this invention. This dataset contains 17,621 trajectories, each consisting of multiple GPS points, and each point contains longitude and latitude information.
[0151] like Figure 1 As shown, in one embodiment of the present invention, a GPS trajectory representation method based on a dual-view encoder is provided, comprising:
[0152] Step 1: GPS trajectory data preprocessing: Use the K-means clustering algorithm to cluster all trajectory points within the region, generating a set of Points of Interest (POIs). For each trajectory sequence, average the longitude and latitude of the trajectory points within the POIs it passes through, transforming the trajectory sequence into a POI sequence. This step specifically involves:
[0153] Step 1.1: Define the trajectory data structure, defining a single trajectory as:
[0154] TR = {p1, p2, ..., p} i , ..., p l}
[0155] Where p i= (long, lat) represents the longitude and latitude of the i-th GPS point. For example, if a trajectory contains 200 GPS points, then l = 200.
[0156] Step 1.2: Set the clustering parameter k = 1000 (adjust according to the area size; this example uses the area within the Fifth Ring Road of Beijing as an example). Cluster all GPS points within the area using the K-means clustering algorithm. Input the longitude and latitude data of all trajectory points, and output 1000 cluster categories. Each category is defined as a point of interest, generating a point of interest set POI = {POI1, POI2, ..., POI...}. 1000}
[0157] Step 1.3: For the trajectory sequence TR i Pass it through Point of Interest (POI) k The average of the longitude and latitude of the inner trajectory points is used to obtain the trajectory sequence TR. i Points of interest Original characteristics:
[0158]
[0159] Where M k For TR i exist The number of trajectory points within, long j and lat j Here, represents the longitude and latitude of the j-th trajectory point, and k is the POI number. For example, trajectory sequence TR1 passes through POIs. 20 If the trajectory points within the range are {p4, p5, p6, p7}, then TR1 lies in POI. 20 The characteristic in the data is the average longitude and latitude of the four points {p4, p5, p6, p7}.
[0160] Step 1.4: Transfer the trajectory sequence TR i Convert to POI sequence in This indicates that the i-th trajectory passes through the interest point numbered j. For example, the trajectory sequence TR1 can be transformed into...
[0161] Step 2: Construct a dual-view trajectory encoder to represent the POI sequence generated in Step 1 from both structural and temporal views, and then perform dual-view fusion to obtain the final trajectory representation vector.
[0162] Step 3: Implement the Structured View (StrucView), treating POIs as nodes and POI sequences as hyperedges, constructing a hypergraph and aggregating information through a graph attention mechanism to generate a vector H of uniform dimension. strucFor example, if the feature dimension of a POI node is (1000, 2), and StrucView encoding is performed, the H value is obtained. struc The dimensions are (17621, 128). This step specifically involves:
[0163] Step 3.1: Construct a hypergraph, treating all points of interest within the region as nodes in the hypergraph, and the POI sequence as a hyperedge in the hypergraph, with the hyperedge connecting the points of interest traversed in the sequence;
[0164] Step 3.2: Extract node features for each point of interest (POI). k Calculate the average longitude and latitude of all trajectory points as the node features:
[0165]
[0166] Where N k Belongs to POI k The number of trajectory points, long i and lat i These are the longitude and latitude of the i-th trajectory point, respectively;
[0167] Step 3.3: Apply graph attention mechanism to the nodes and hyperedges in the hypergraph, specifically:
[0168] For each hyperedge E, compute the weighted sum of the representations of the nodes it connects to as the initial representation of the hyperedge:
[0169]
[0170] Where α E,k For the hyperedge E, pair node POI k Attention weights;
[0171] For each node POI k Calculate the weighted sum of all the hyperedge representations it participates in as the updated representation of the node:
[0172]
[0173] Where ε k For the POI containing the node k The set of hyperedges, β k,E For node POI k Attention weights for the hyperedge E;
[0174] Step 3.4: For each hyperedge E, calculate the average value of the updated representations of the nodes it connects to generate the final representation H of the hyperedge. E ,Right now:
[0175]
[0176] Where H struc V is the representation vector output by the structure view. E Let |V be the set of nodes connected by the hyperedge E. E | represents the number of nodes.
[0177] Step 4: Implement the SeqView temporal view, calculate the probability distribution of the POI sequence as the cue vector, concatenate it with the original features, and input it into the Gated Recurrent Unit (GRU) model to generate a vector H of uniform dimension. seq For example, a POI sequence passes through 24 POIs (the exact number depends on the length of the POI sequence). The original feature dimension of this POI sequence is (1, 24, 3). After concatenating the constructed cue vector with the original features, the feature dimension of this POI sequence becomes (1, 24, 4). Inputting 17621 POI sequences of unequal length sequentially into a gated recurrent unit (GRU) model yields H... seq The dimension is (17621, 128). This step specifically involves:
[0178] Step 4.1: Construct the cue vector, calculated based on the POI sequence obtained in Step 1.4, specifically as follows:
[0179] For the POI sequence POI i Points of interest Calculate the corresponding trajectory TR i Passing through points of interest The number of trajectory points c j And calculate the POI based on the total number of trajectory points C of this trajectory. i Probability distribution of passing through each point of interest:
[0180]
[0181] in Obtain the cue vector H hint =[Pr(PoI1),Pr(POI2),…,Pr(POI n )];
[0182] Step 4.2: Set the cue vector H hint The feature vector of the POI sequence calculated in step 1.3 By concatenating the vectors, a new feature vector is formed:
[0183]
[0184] Where [;] denotes vector concatenation operation;
[0185] Step 4.3: Combine the concatenated feature vector F concatThe data is fed into a GRU (Given Ratio Regulated Recurrent Unit) model to generate a representation vector with a uniform dimension.
[0186] H seq =GRU(F concat )
[0187] Where H seq This is the representation vector output by the time-series view.
[0188] Step 5: Implement a dual-view fusion mechanism. The representation vectors of the two views generated in Steps 3 and 4 are fused using a self-attention mechanism to obtain the final trajectory representation vector. For example, the H generated in Step 3... struc The dimension is (17621, 128), and the H generated in step 4 is... seq The dimension is (17621, 128). After implementing the dual-view fusion mechanism, the final trajectory representation vector has a dimension of (17621, 128). This step specifically involves:
[0189] Step 5.1: Convert the structural view representation vector H obtained in Step 3 into a vector. struc And the time-series view representation vector H obtained in step 4 seq Concatenate into matrix H:
[0190] H = [H] struc H seq ]
[0191] Where [;] denotes vector concatenation operation. d represents the feature dimension;
[0192] Step 5.2: Apply a linear transformation to each column of matrix H to calculate the self-attention weights:
[0193]
[0194] Where Linear(H) is the weight vector calculated through a linear layer;
[0195] Step 5.3: Use the self-attention weights W to perform a weighted summation on matrix H to obtain the final trajectory representation vector:
[0196]
[0197] Where H final This is the final trajectory representation vector.
[0198] The above technical solution also includes step 6, which involves training the model based on the weighted InfoNCE loss function and optimizing the trajectory representation vector. Step 6 includes the following steps:
[0199] Step 6.1: Calculate the predicted Euclidean distance matrix D pred Specifically:
[0200] The final trajectory representation vector obtained from step 5.3 Where N is the number of samples, d is the feature dimension, and the Euclidean distance between each pair of samples is calculated:
[0201] D pred [i, j] = ||H i -H j ||2
[0202] Where H i and H j It is a trajectory representation vector. It is the predicted Euclidean distance matrix. For example, D pred The dimensions are (17621, 17621).
[0203] Step 6.2: Normalize the true distance matrix D true As the soft contrast weight w i,j :
[0204]
[0205] Where τ is a temperature coefficient that controls the smoothness of the distribution.
[0206] Step 6.3: Construct a weighted contrastive loss function based on InfoNCE, specifically as follows:
[0207] Constructing the loss function By minimizing the difference between the predicted distance and the true distance:
[0208]
[0209] The numerator represents the similarity weight of positive samples, and the denominator represents the sum of the similarity weights of all negative samples. By optimizing this loss function, similar trajectories are brought closer together in the feature space, while dissimilar trajectories are moved further apart. For example, the loss value is 7.93 in the first round of training, 7.77 in the second round, and 7.73 in the third round, with the loss continuously decreasing.
[0210] In summary, the present invention has the following characteristics:
[0211] 1. Avoid errors introduced by trajectory length alignment and improve representation accuracy.
[0212] Traditional methods require aligning variable-length trajectories to a fixed length, leading to redundancy or truncation and impairing spatial relationships. This invention directly processes POI sequences using a dual-view encoder, eliminating the need for preprocessing alignment and thus preventing information loss and errors. The structural view (StrucView) models spatial relationships between POIs using a hypergraph, while the temporal view (SeqView) enhances dynamic features of the sequence through probabilistic cue vectors. Both support variable-length inputs and preserve the integrity of the original trajectories, significantly improving representation accuracy.
[0213] 2. Enhanced trajectory relationship modeling capabilities through multi-view feature fusion
[0214] By capturing complex spatial interactions between Points of Interest (POIs) through a hypergraph attention mechanism (structural view) and combining it with GRU temporal modeling (temporal view) to capture dynamic changes in movement patterns, the complementary features of the two views cover the spatial and temporal attributes of the trajectory. Furthermore, a self-attention fusion mechanism dynamically weights the view contributions, adaptively strengthening key features, so that the final representation vector can more comprehensively characterize the similarity and differences between trajectories.
[0215] 3. Introduce soft-weighted contrastive learning to optimize the representation space distribution.
[0216] Based on the weighted InfoNCE loss function, soft contrast weights are generated using the true distance matrix to guide the model in distinguishing samples with different similarities. Compared to traditional binarized contrastive learning, this method smooths and optimizes the clustering of similar trajectories and the separation of dissimilar trajectories through probabilistic weights, enhancing the discriminative power of the feature space and giving the representation vector stronger generalization ability in downstream tasks such as traffic analysis and recommendation systems.
[0217] 4. Improve data processing efficiency and model scalability
[0218] K-means clustering is used to abstract the original trajectory points into POI sequences, reducing data complexity. The dual-view encoder processes structural and temporal features in parallel, reducing computational redundancy. In addition, the design of the hypergraph construction and GRU model takes scalability into account, enabling it to adapt to large-scale trajectory data and diverse POI distribution scenarios, providing an efficient and robust trajectory representation foundation for urban computing applications.
[0219] In summary, this invention overcomes the limitations of existing methods that rely on trajectory alignment through an innovative dual-view encoding architecture and fusion mechanism, achieving significant improvements in trajectory representation accuracy, feature richness, and model efficiency, and providing reliable technical support for intelligent applications based on GPS data.
Claims
1. A GPS trajectory representation method based on a dual-view encoder, characterized in that, Includes the following steps: Step 1: GPS trajectory data preprocessing. Use the K-means clustering algorithm to cluster all trajectory points in the region to generate a set of Points of Interest (POIs). For each trajectory sequence, take the average of the longitude and latitude of the trajectory points in the POIs it passes through, and convert the trajectory sequence into a POI sequence. Step 2: Construct a dual-view trajectory encoder to represent the POI sequence generated in Step 1 from both structural and temporal views, and then perform dual-view fusion to obtain the final trajectory representation vector; Step 3: Implement the Structured View (StrucView), treating POIs as nodes and POI sequences as hyperedges, constructing a hypergraph, and aggregating information through a graph attention mechanism to generate vectors of uniform dimension. ; Step 4: Implement SeqView to calculate the probability distribution of the POI sequence as a cue vector. Concatenate this vector with the original features and input it into the Gated Recurrent Unit (GRU) model to generate vectors of uniform dimension. ; Step 5: Implement a dual-view fusion mechanism. The representation vectors of the two views generated in Step 3 and Step 4 are fused using a self-attention mechanism to obtain the final trajectory representation vector. In the above scheme, step 3 includes the following steps: Step 3.1: Construct a hypergraph, treating all points of interest within the region as nodes in the hypergraph, and the POI sequence as a hyperedge in the hypergraph, with the hyperedge connecting the points of interest traversed in the sequence; Step 3.2: Extract node features for each point of interest. Calculate the average longitude and latitude of all trajectory points as node features: in Belonging to The number of trajectory points, and The first The longitude and latitude of each trajectory point; Step 3.3: Apply graph attention mechanism to the nodes and hyperedges in the hypergraph, specifically: For each superedge Calculate the weighted sum of the node representations connected to it as the initial representation of the hyperedge: in For super-edge For nodes Attention weights; For each node Calculate the weighted sum of all the hyperedge representations it participates in as the updated representation of the node: in For containing nodes The set of superedges For nodes For superedge Attention weights; Step 3.4: For each superedge Calculate the average of the updated representations of the connected nodes to generate the final representation of the hyperedge. ,Right now: in This is the representation vector output by the structure view. For super-edge The set of connected nodes The number of nodes; In the above scheme, step 4 includes the following steps: Step 4.1: Construct the hint vector, calculated based on the obtained POI sequence, specifically as follows: For POI sequences Points of interest Calculate the corresponding trajectory Passing through points of interest number of trajectory points And based on the total number of trajectory points of this trajectory. calculate Probability distribution of passing through each point of interest: in , obtain the hint vector ; Step 4.2: Set the cue vector The eigenvectors of the calculated POI sequence By concatenating the vectors, a new feature vector is formed: Where [;] represents vector concatenation operation; Step 4.3: Combine the concatenated feature vectors The data is fed into a GRU (Given Ratio Regulated Recurrent Unit) model to generate a representation vector with a uniform dimension. in This is the representation vector output by the time-series view.
2. The GPS trajectory representation method based on a dual-view encoder according to claim 1, characterized in that, Step 1 includes the following steps: Step 1.1: Define the trajectory as ,in It is a binary tuple. , representing a GPS data point on the trajectory, where Represents longitude, Represents latitude; Step 1.2: For all trajectory points within the region The K-means clustering algorithm is used to cluster data and generate a set of points of interest. ; Step 1.3: For the trajectory sequence Pass it through points of interest The trajectory sequence is obtained by averaging the longitude and latitude of the internal trajectory points. Points of interest Original characteristics: in for exist Number of trajectory points within, and The first The longitude and latitude of each trajectory point The POI number; Step 1.4: Translate the trajectory sequence Convert to POI sequence ,in Indicates the first The trajectory passes through the numbered Points of interest.
3. The GPS trajectory representation method based on a dual-view encoder according to claim 1, characterized in that, Step 5 includes the following steps: Step 5.1: Convert the structure view representation vector obtained in Step 3 into a vector. and the time-series view representation vector obtained in step 4 spliced into a matrix : Where [;] denotes vector concatenation operation. , For feature dimensions; Step 5.2: For the matrix For each column, a linear transformation is applied to calculate the self-attention weights: in The weight vector is calculated through a linear layer; Step 5.3: Use self-attention weights For matrix By performing a weighted summation, we obtain the final trajectory representation vector: in This is the final trajectory representation vector.
4. The GPS trajectory representation method based on a dual-view encoder according to claim 3, characterized in that, It also includes step 6, which trains the model based on the weighted InfoNCE loss function and optimizes the trajectory representation vector. Step 6 includes the following steps: Step 6.1: Calculate the predicted Euclidean distance matrix Specifically: The final trajectory representation vector obtained from step 5.3 ,in It is the sample size. For each pair of samples, calculate the Euclidean distance as the feature dimension: in and It is a trajectory representation vector. It is the predicted Euclidean distance matrix; Step 6.2: Normalize the true distance matrix As soft contrast weight : in It is the temperature coefficient, which controls the smoothness of the distribution; Step 6.3: Construct a weighted contrastive loss function based on InfoNCE, specifically as follows: Constructing the loss function By minimizing the difference between the predicted distance and the true distance: The numerator represents the similarity weight of positive samples, and the denominator represents the sum of the similarity weights of all negative samples. By optimizing this loss function, similar trajectories are brought closer together in the feature space, while dissimilar trajectories are moved further apart.
5. A GPS trajectory representation device based on a dual-view encoder, implementing the method as described in claim 1, characterized in that, include: The data preprocessing module is used to cluster all trajectory points within the region using the K-means clustering algorithm to generate a set of Points of Interest (POIs). For each trajectory sequence, the average longitude and latitude of the trajectory points in the POIs it passes through are taken to convert the trajectory sequence into a POI sequence. The dual-view trajectory encoder construction module is used to obtain the final trajectory representation vector by fusing the POI sequence generated by the structural and temporal view representation data preprocessing module. The structural view implementation module treats POIs as nodes and POI sequences as hyperedges, constructs a hypergraph, aggregates information through a graph attention mechanism, and generates vectors of uniform dimension. ; The time-series view implementation module calculates the probability distribution of the POI sequence as a cue vector, which is then concatenated with the original features and input into a gated recurrent unit (GRU) model to generate a vector of uniform dimension. ; The dual-view fusion mechanism implementation module is used to fuse the representation vectors of the two views generated by the structure view implementation module and the temporal view implementation module through a self-attention mechanism to obtain the final trajectory representation vector.
6. A storage medium, characterized in that, When the processor executes a program in the storage medium, it implements the method as described in any one of claims 1-4.
Citation Information
Patent Citations
Radar echo extrapolation method based on hypergraph neural network and related equipment
CN119471606A
Method and system for segmenting an image based on motion vanishing points
US9430840B1
