Different-source city taxi track generation method and system based on time-space door mechanism migration
Through the spatio-temporal gate mechanism transfer learning and graph neural network, combined with the road network information of OpenStreetMap, the problem of sparse traffic trajectory data is solved, the quality of trajectory data is improved, and richer traffic planning support is provided.
Patent Information
- Application Number
- CN202410662563.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-08-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Due to the sparsity of traffic trajectory data, it is difficult for deep generative models to capture all possible traffic patterns, affecting the authenticity and quality of generated trajectory data, especially when the data is incomplete or cannot be obtained directly.
A heterogeneous city taxi trajectory generation method using spatiotemporal gate mechanism migration is used. Through transfer learning and graph neural network, combined with OpenStreetMap's road network information for data matching and preprocessing, a spatiotemporal encoder for public and target cities is constructed, using meta-learning and Transformer models share parameters to improve the learning effect of the model on sparse data.
It generates higher-quality traffic trajectory data, improves the learning effect of the model on sparse data, and provides richer data support for traffic planning and management.
Smart Images

Figure CN118569075A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent transportation technology, and in particular to a method and system for generating taxi trajectories in heterogeneous cities using a space-time gate mechanism migration. Background Art
[0002] Traffic trajectory data refers to the information about the movement path of a vehicle over a period of time, usually including a series of data points in fields such as longitude, latitude, and timestamp. These data points are connected in series to form the movement trajectory of individuals in space and time. In traffic planning, trajectory data helps to determine the priority of road construction, optimize traffic light scheduling, and provide real-time traffic information for navigation systems. For online car-hailing vehicle scheduling, trajectory data can help predict demand hotspots, thereby optimizing vehicle distribution, reducing passenger waiting time, and improving operational efficiency.
[0003] The significance of traffic trajectory generation for traffic trajectory data is that it can simulate and predict traffic trajectories that may occur in reality, especially when the data is incomplete or cannot be directly obtained. By generating graph neural networks (GNNs) under adversarial training, trajectory data similar to actual traffic conditions can be simulated, providing richer data support for traffic planning and management. However, due to privacy and commercial restrictions, we often only have access to limited trajectory samples, which leads to insufficient learning of deep generative models during training. This sparsity makes it difficult for the model to capture all possible traffic patterns, thus affecting the authenticity and quality of the generated trajectory data. Summary of the invention
[0004] In view of the sparsity of urban traffic trajectory data, the purpose of the present invention is to provide a method and system for generating heterogeneous urban taxi trajectories with a space-time gate mechanism migration, which improves the learning effect of the model on sparse data through transfer learning and other advanced technologies, thereby generating higher quality traffic trajectory data.
[0005] In order to achieve the above object, the technical solution adopted by the present invention is:
[0006] A method for generating taxi trajectories in heterogeneous cities with a space-time gate mechanism migration comprises the following steps:
[0007] S1: Data source collection and processing: Integrate taxi trajectory data from heterogeneous cities, perform data cleaning and preprocessing, match heterogeneous data to road networks, and use road network information in OpenStreetMap to convert longitude and latitude point sequences into continuous road sequences;
[0008] S2: Constructing a spatiotemporal migration meta-model for heterogeneous urban traffic trajectories: First, construct a spatiotemporal encoder T' for public transportation trajectories, where i represents the encoder of each city to capture the common features in traffic trajectory data; second, construct a spatiotemporal encoder T for each city. i , to learn the traffic characteristics of each city. In each round of meta-training, MAML is used to train the public encoder T' to the source city encoder T i After each round of meta-training, gradient descent is performed on the public encoder T' to optimize its parameters;
[0009] S3: Model transfer: The meta-model contains common features, and meta-learning is used to share parameters between multiple source cities to learn common features. The source model is trained on source cities with rich trajectory data, covering both common and specific features of the source cities. The target model is trained on target cities with relatively scarce data, and the features of the source cities are transferred to improve the prediction performance of the target cities. First, the shared parameters of the source model trained on the source city are copied to the target model to maintain the structural consistency of the two models. Then, the model is internally updated using the spatiotemporal coded trajectory data of the target city, and the private parameters of the model are adjusted and optimized to adapt to the specific traffic characteristics of the target city. On the target city’s data set, the model undergoes multiple iterations of training, and the model parameters are updated by gradient descent and back propagation methods to minimize the trajectory prediction error. At the same time, during the internal update process, the shared parameters of the target model are regularly synchronized with the shared parameters of the source model to ensure that the common knowledge of the source city can be transferred to the target city. During the process, the performance of the model is regularly evaluated using the average displacement error and the final displacement error as evaluation indicators to ensure that the performance of the model on the target city data continues to improve. After fine-tuning is completed, the model is finally tested using the target city test set to comprehensively evaluate the performance of the model in practical applications.
[0010] S4: Predict the next hop of the trajectory: Train the processed trajectory data through the Transformer model, use the trained model to predict the trajectory, predict the road of the next hop based on the current position, and use the mask mechanism of the adjacent topological structure of the road to constrain the prediction result and ensure the continuity of the trajectory.
[0011] Furthermore, in step S1, the data source collection and processing includes data acquisition and road network matching, and the specific steps are as follows:
[0012] Data acquisition: GPS trajectory data of taxis in different cities are obtained through data providers or open data platforms. The data includes: latitude and longitude coordinates of vehicle operation, timestamp, road section length, road section width, maximum speed limit, number of lanes, and road type;
[0013] Road network matching: Using the road network information provided by OpenStreetMap, a road network data model including road nodes, road sections and their topological relationships is established. The FastMM algorithm is used to match the GPS points of the taxi trajectory with the above road network data model, and the GPS point data is converted into a continuous trajectory. The specific operations include: converting the road network data into a graph structure and simplifying it, assigning a unique identifier to each edge and calculating the length and direction of the edge; for each GPS point, using the spatial index to quickly find the nearest edge or node, and generating a candidate set based on the distance and angle thresholds; using the error model to estimate the observation error of the GPS point, and calculating the probability density of each edge in the candidate set; using the dynamic programming Viterbi algorithm to search for the most likely path, considering the continuity and overall probability of the path; smoothing the matching results and correcting the error matching to improve the matching quality; and finally outputting the road sequence corresponding to the original GPS trajectory.
[0014] Furthermore, in step S2, the main body of meta-training can be divided into the following steps: First, initialize the model parameters, the public encoder T' and each city encoder T i The parameters of the public encoder T' are initialized to the same value; secondly, a meta-training cycle is performed. For each round of meta-training, a source city is randomly selected from all cities as the current task, and the parameters of the public encoder T' are cloned to the source city encoder T i In the example above, we get the initial city encoder parameters and use the city encoder T on the training data of the current source city. i Training is performed and the parameters of the city encoder are updated, the loss function of the current source city is calculated, and the loss value is recorded; finally, optimization is performed after the meta-training is completed. After each round of meta-training, gradient descent is performed on the public encoder T' to optimize its parameters so that it can better adapt to the traffic trajectory characteristics of each city. By using the training data and loss function of each city, the gradient of the public encoder T' is calculated, and the parameters of the public encoder are updated.
[0015] Furthermore, in step S2, the spatiotemporal encoder T' involves feature extraction and correlation modeling to generate accurate road representation and trajectory representation, and the specific steps include:
[0016] The road representation adopts a spatiotemporal embedding module, which encodes the characteristics of each road node while considering its spatial location and temporal attributes. The use of a graph attention network allows the model to dynamically focus on important road nodes according to the topological structure of the traffic network. The introduction of Fourier transform helps the model understand and predict periodic time patterns.
[0017] The trajectory representation described above uses a trajectory attention module to establish and strengthen the correlation between different positions in a single trajectory. The module identifies key points in the trajectory and captures the dynamic relationship between them. The causal attention mechanism is used to ensure that when calculating the trajectory representation, the model follows the time order, avoids the interference of future information on the past state, and generates a trajectory sequence representation that conforms to the time causal relationship.
[0018] Furthermore, a TrajEncoder, i.e., a spatiotemporal encoder T of the vehicle trajectory, is established. The encoder is a trajectory encoder that combines a graph neural network GNN and a Transformer. The specific implementation of TrajEncoder involves feature extraction and correlation modeling to generate accurate road representation and trajectory representation.
[0019] The road representation module mainly uses the graph neural network GNN: the spatiotemporal embedding module is used to encode the features of each node and integrate the time information into it through the semantically aware graph attention network and Fourier transform, so as to effectively embed the spatiotemporal semantics of the traffic trajectory;
[0020] The node features, including the length of the road section, the width of the road section, the maximum speed limit, the number of lanes, the road type, the GPS coordinates, and the road semantics including the edge are modeled, and the graph attention network GAT is used to encode the node features and their adjacent relations. Let R = {r k |k∈[N]} is a node set, A∈R N×N Represents their adjacency matrix, where N represents the number of roads, r k represents the kth road in the set. Define a trajectory as S = {x i |i∈[T]}, where x i =(r i , t i ), r i represents the i-th road in the trajectory, t i represents the timestamp of position i, T represents the length of the trajectory, specifically, for each r i , r i and Due to continuity, r i+1 = 1, the path r in the trajectory i Represented by the graph encoder, first, each road r i is embedded into a dense vector as the representation of the first layer, where is the i-th position x in the trajectory i The representation of is obtained by converting the MLP model:
[0021]
[0022] Using multi-head attention mechanism and multiple layers to aggregate messages from neighboring roads, we get node r from layer l-1 i The representation at level l is as follows, where It is the representation of the i-th road in the trajectory at the l-th layer by the graph attention network:
[0023]
[0024] Among them, C represents the number of heads, A i Indicates road r i Neighbors, represents the attention coefficient of node i and node j at head C, W c represents the weight matrix at head C, Represents the representation of the j-th road in the trajectory at the l-1 layer by the graph attention network;
[0025] For timestamp t i The goal is to obtain a continuous function mapping from the time domain to the d-dimensional vector space. In the time encoder, Fourier transform is used. The limited parameters can approximately express a powerful representation space. Characterize the time stamp t by Fourier transform i Mapped to a d-dimensional vector space, thus capturing temporal periodicity and trend information:
[0026]
[0027] Among them, the Fourier transform represents the periodic pattern in time through a linear combination of sine and cosine functions, ω l and ω d Indicates the frequency range, ω l represents the lowest frequency, ω d Indicates the highest frequency. The trajectory representation module of the trajectory spatiotemporal encoder mainly involves Trans: The trajectory attention module is used to establish the correlation between each position in a single trajectory and calculate the representation of the entire trajectory sequence through the causal attention mechanism;
[0028] In order to encapsulate the relationship of the entire traffic trajectory sequence, Transformer is used to capture the relevant semantics, and only its decoder is used to represent and generate trajectories, in which a multi-head causal attention mechanism is used to mask the impact of future points on historical points. First, the embeddings obtained by the above graph encoder and time encoder are concatenated as the roadmap in Transformer. i The original embedding of
[0029] Provides the position encoding of the model information for each point in the trajectory and is used together with Connect as input to Transformer;
[0030] Multiply the input embedding with three matrices to create query Q, key K, and value vector V, r respectively. i The query vector and r i The dot product is performed with the Key vector of its historical points to obtain the attention score, which is normalized by the Softmax operation until the value vector of each point up to the i-th position is multiplied by the normalized attention score, and the weighted value vectors are added to obtain the self-attention representation of the position:
[0031]
[0032] Among them, z i Represents node r i The self-attention representation of the Transformer encoder, c′ represents the number of attention heads, Characterization node r i and r j The attention coefficient at node c′, v ij Characterization node r i and r j The value vector, W o is the output matrix;
[0033] The representation of the current layer is added to the hidden representation of the previous layer, and LayerNorm (LN) is performed twice and Feed-Forward Network (FFN) is performed once to obtain the final hidden representation of the current layer. Therefore, the representation of layer l can be obtained from layer l-1 as follows:
[0034]
[0035] in, represents the hidden representation of the Transformer encoder at layer l, represents the hidden representation of the Transformer encoder at layer l-1, represents the self-attention representation of layer l.
[0036] Furthermore, in step S3, the shared parameters of the source model are initialized from the current meta-model, and the source model T' is first meta-cloned, and the steps are as follows:
[0037] For each source city model, clone the shared parameters from the current meta-model to obtain the parameters θ of the source city model src , using the source city training data through the TrajEncoder described in step S2 Optimize source city model parameters, perform internal updates, and use source city test data Calculate meta-gradients and update the parameters θ of the meta-modelmeta ;
[0038] For each city, the target city model clones the shared parameters from the updated meta-model to obtain the parameters θ of the target city model. tgt , using the target city training data Optimize the model parameters of the target city, perform internal updates, and repeat steps S1-S2. For each source city, use the trajectory data of that city for training to obtain the corresponding trajectory encoder model T i , the defined loss function is used during training:
[0039]
[0040] Where M represents the total number of trajectories in the training dataset, T represents the total number of positions in each trajectory, m represents the index of the trajectory, which is used to traverse all trajectories, and t represents the index of the position in the trajectory, which is used to traverse all positions in each trajectory. represents the true label of the mth trajectory at time step t+1, that is, the true next hop position, It represents the prediction result of the model at time step t for time step t+1 in the mth trajectory, that is, the probability distribution of the predicted next hop position.
[0041] Use the migrated track encoder model T target Perform trajectory prediction for other cities, use the trajectory data of the target city to test and evaluate the model, obtain its performance on the target city, transfer the knowledge of the model trained on the source city to the target city, and use the experience of the source city to improve the trajectory prediction performance of the target city to reduce the problem of insufficient data in the target city, and make full use of the data and knowledge of the source city to accelerate the training and optimization process of the target city model.
[0042] Furthermore, in step S4, the next hop path r i+1 With the current road i adjacent, to ensure the continuity of traffic trajectory, the destination road r T To determine the next path r i+1 It is of great significance, providing travel intention and avoiding deviation from multiple adjacent roads. i , BatchNorm is used to normalize the input of each layer to enhance the model's capabilities, and the Sigmoid function is used to calculate the spatiotemporal gate for the next road prediction
[0043]
[0044] in, Represents node r iThe calculation results of the spatiotemporal gating mechanism, Dist, BN, σ are the distance function, BatchNorm and Sigmoid function respectively;
[0045] Transformer A linear layer is applied to the hidden representation to obtain the original predicted logits, which are further gated with a spatiotemporal gate. Activate them to get the final predicted logits:
[0046]
[0047] in, represents the probability distribution of the next hop location, Mask represents the masking mechanism, which is used to ensure that the prediction result only contains candidate roads adjacent to the current road, and Linear represents the linear layer, which is used to transform the hidden state of the Transformer encoder. Convert to raw predicted logits.
[0048] After the trajectory prediction is completed, the Matplotlib visualization tool is used to visualize the results so that hidden features can be discovered. Further analysis of the results can be used to update and correct the vehicle trajectory prediction model.
[0049] A heterogeneous city taxi trajectory generation system with space-time gate mechanism migration, the system comprising:
[0050] Time series data processing module: used to process and clean taxi trajectory data in different cities;
[0051] Node feature extraction module: used to extract the features of road nodes from the processed trajectory data and construct the road network of the city;
[0052] Model training module: Use the extracted node features to train the model using the Transformer deep learning algorithm;
[0053] Node prediction execution module: used to perform node prediction based on the trained model and predict the next hop node based on the current node;
[0054] Prediction result optimization module: used to optimize the prediction results to ensure the continuity and accuracy of the trajectory;
[0055] Gradient update module: used to evaluate and migrate the MAML model and migrate trajectory data from source cities to target cities.
[0056] The beneficial effects of the present invention are: through transfer learning and other advanced technologies, the learning effect of the model on sparse data is improved, thereby generating higher quality traffic trajectory data and providing richer data support for traffic planning and management. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is the overall flow chart of the present invention;
[0058] Figure 2 It is a schematic diagram of the output of the FastMM algorithm for road network matching in the present invention. DETAILED DESCRIPTION
[0059] The technical solution of the present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0060] like Figure 1 As shown, the present invention proposes a method for generating taxi trajectories in heterogeneous cities using a space-time gate mechanism migration, comprising the following steps:
[0061] S1: Data source collection and processing;
[0062] Obtain taxi trajectory data from different cities, perform data cleaning and preprocessing to ensure data integrity and accuracy. Use the road network information in OpenStreetMap and convert GPS point data into continuous road trajectories through map matching technology, effectively integrate taxi trajectory data from different cities, and provide high-quality input data for subsequent modeling. The specific steps are as follows:
[0063] Data acquisition: Obtain GPS trajectory data of taxis in different cities through data providers or open data platforms. These data include latitude and longitude coordinates of vehicle operation, timestamp, road section length, road section width, maximum speed limit, number of lanes, road type, etc. Ensure that the acquired data has complete coverage and sufficient sampling rate for subsequent analysis and modeling.
[0064] Road network matching: Using the road network information provided by OpenStreetMap, QGIS open source software is used to build a road network data model that includes road nodes, road sections and their topological relationships. Then, the FastMM algorithm is used to match the GPS points of the taxi trajectory with the road network model, thereby converting the GPS point data into a continuous trajectory to ensure the consistency of the trajectory with the actual road direction. The output of the FastMM algorithm is a CSV file with exported fields such as Figure 2As shown in the figure: the orange circles represent the points on the original trajectory. These points are arranged in a certain order and represent the path the vehicle actually traveled. The points on the original trajectory correspond to specific nodes in the road network. These nodes are marked with green crosses, indicating that they are matching points. The path connecting the matching points is called the matching trajectory, which shows how to follow these matching points in the road network to reproduce the original trajectory. The matching trajectory is represented by a green solid line. The error refers to the difference between the original trajectory and the matching trajectory. The blue arrow indicates the error. The offset refers to the distance of the matching trajectory relative to the starting position of the original trajectory. The original path refers to the sequence passed by the original trajectory. The matching path refers to the sequence passed by the matching trajectory. The continuous path refers to the edges traversed between the matching points. The specific operations include: converting the road network data into a graph structure and simplifying it, assigning a unique identifier to each edge and calculating the length and direction of the edge; for each GPS point, using the spatial index to quickly find the nearest edge or node, and generating a candidate set based on the distance and angle thresholds; using the error model to estimate the observation error of the GPS point, and calculating the probability density of each edge in the candidate set; using the dynamic programming Viterbi algorithm to search for the most likely path, considering the continuity and overall probability of the path; smoothing the matching results and correcting the error matches to improve the matching quality; and finally outputting the road sequence corresponding to the original GPS trajectory.
[0065] S2: Constructing a spatiotemporal migration meta-model of heterogeneous urban traffic trajectories;
[0066] First, we combine graph neural networks and Transformer to build a public transportation trajectory spatiotemporal encoder T', which is designed to capture common features in traffic trajectory data. Then we build a traffic trajectory spatiotemporal encoder T for each city. i , where i∈{Beijing,Porto,Shanghai,Chengdu}, these city encoders can learn the unique traffic characteristics of their respective cities. In each round of meta-training, MAML is used to train the public encoder T' to the source city encoder T i After each round of meta-training, gradient descent is performed on the public encoder T' to optimize its parameters so that it can better adapt to the traffic trajectory characteristics of each city. Specifically, the main body of meta-training can be divided into the following steps: First, initialize the model parameters, the public encoder T' and each city encoder T i The parameters of the public encoder T' are initialized to the same value. Secondly, a meta-training cycle is performed. For each round of meta-training, a source city is randomly selected from all cities as the current task. The parameters of the public encoder T' are cloned to the source city encoder T i The initial city encoder parameters are obtained. Use the city encoder T on the training data of the current source city iTrain and update the parameters of the city encoder. Calculate the loss function of the current source city and record the loss value. Finally, optimize after the meta-training. After each round of meta-training, perform gradient descent on the public encoder T' to optimize its parameters so that it can better adapt to the traffic trajectory characteristics of each city. By using the training data and loss function of each city, calculate the gradient of the public encoder T' and update the parameters of the public encoder.
[0067] TrajEncoder, the spatiotemporal encoder T of the vehicle's trajectory, is a trajectory encoder that combines a graph neural network (GNN) and a Transformer. This combined encoding method combines the advantages of GNN in spatiotemporal relationship modeling and the advantages of Transformer in long-distance dependency modeling, so it can capture trajectory features more comprehensively. It can effectively process and analyze complex trajectory data and provide strong feature support for the task of predicting the next hop of the trajectory. The specific implementation of the spatiotemporal encoder TrajEncoder involves feature extraction and correlation modeling to generate accurate road representation and trajectory representation.
[0068] Among them, the road representation module of the trajectory spatiotemporal encoder TrajEncoder mainly applies GNN: the spatiotemporal embedding module is mainly used to encode the features of each node (i.e., road), and integrate the time information into it through the semantic-aware graph attention network and Fourier transform, thereby effectively embedding the spatiotemporal semantics of the traffic trajectory.
[0069] In order to model the road semantics including node features (including road section length, road section width, maximum speed limit, number of lanes, road type, GPS coordinates) and edges (topological structure), a graph attention network (GAT) is used to encode node features and their adjacent relationships. Let R = {r k |k∈[N]} is a node set, A∈R N×N is their adjacency matrix, where N is the number of roads, r k The kth road in the characterization set. Define a trajectory as S = {x i |i∈[T]}, where x i =(r i , t i ), r i Represents the i-th road in the trajectory, t i is the timestamp of position i, and T is the length of the trajectory. Specifically, for each r i , r i and Due to continuity, r i+1 = 1. The path r in the trajectory i Represented by a graph encoder. First, each road ri is embedded into a dense vector as the representation of the first layer, where is the i-th position x in the trajectory i The representation of is obtained by converting the MLP model:
[0070]
[0071] A multi-head attention mechanism and multiple layers are used to aggregate messages from neighboring roads. From the l-1 layer, we can get node r i The representation at level l is as follows, where It is the representation of the i-th road in the trajectory at the l-th layer by the graph attention network:
[0072]
[0073] Where C represents the number of heads, A i Indicates road r i Neighbors, represents the attention coefficient of node i and node j at head C, W c represents the weight matrix at head C, Represents the representation of the j-th road in the trajectory by the graph attention network at the l-1 layer.
[0074] For timestamp t i The goal is to obtain a continuous function mapping from the time domain to the d-dimensional vector space. Using Fourier transform in the time encoder, limited parameters can approximately express a powerful representation space. Characterize the time stamp t by Fourier transform i Mapped to a d-dimensional vector space, thus capturing temporal periodicity and trend information:
[0075]
[0076] Among them, the Fourier transform represents the periodic pattern in time through a linear combination of sine and cosine functions, ω l and ω d Indicates the frequency range, ω l represents the lowest frequency, ω d Indicates the highest frequency. The trajectory representation module of the trajectory spatiotemporal encoder mainly involves Trans: The trajectory attention module is used to establish the correlation between each position in a single trajectory and calculate the representation of the entire trajectory sequence through the causal attention mechanism.
[0077] In order to encapsulate the relationship of the entire traffic trajectory sequence, Transformer is used to capture the relevant semantics. Its decoder is used to represent and generate trajectories, in which a multi-head causal attention mechanism is used to mask the impact of future points on historical points. First, the embeddings obtained by the above graph encoder and time encoder are concatenated as the roadmap in Transformer. i The original embedding of .
[0078] Provides the position encoding of the model information for each point in the trajectory and is used together with Connect as input to Transformer.
[0079] Multiply the input embedding with three matrices to create query Q, key K, and value vector V, r respectively. i The query vector and r i The dot product is performed with the Key vector of its historical points to obtain the attention score, which is normalized by the Softmax operation until the value vector of each point up to the i-th position is multiplied by the normalized attention score, and the weighted value vectors are added to obtain the self-attention representation of the position:
[0080]
[0081] Among them, z i Represents node r i The self-attention representation of the Transformer encoder, c′ represents the number of attention heads, Characterization node r i and r j The attention coefficient at node c′, v ij Characterization node r i and r j The value vector, W o is the output matrix.
[0082] The representation of the current layer is added to the hidden representation of the previous layer, and LayerNorm (LN) is performed twice and Feed-Forward Network (FFN) is performed once to obtain the final hidden representation of the current layer. Therefore, the representation of layer l can be obtained from layer l-1 as follows:
[0083]
[0084] in, represents the hidden representation of the Transformer encoder at layer l, represents the hidden representation of the Transformer encoder at layer l-1, represents the self-attention representation of layer l.
[0085] S3: Model migration;
[0086] The shared parameters of the source model are initialized from the current meta-model. The process of cloning shared parameters from a meta-model is called meta-cloning. The source model T' is first meta-cloned, and the steps are as follows:
[0087] For each source city model, clone the shared parameters from the current meta-model to obtain the parameters Θsrc of the source city model. Use the source city training data through S2's TrajEncoder Optimize the source city model parameters and perform internal updates. Use the source city test data Calculate meta-gradients and update the parameters Θmeta of the meta-model.
[0088] For each city, the target city model clones the shared parameters from the updated meta-model to obtain the parameters of the target city model. Optimize the model parameters of the target city and perform internal updates. Repeat steps S1-S2. For each source city, use the trajectory data of that city for training to obtain a corresponding trajectory encoder model T i The loss function defined in the training process is:
[0089]
[0090] Where M represents the total number of trajectories in the training dataset, T represents the total number of positions in each trajectory, m represents the index of the trajectory, which is used to traverse all trajectories, and t represents the index of the position in the trajectory, which is used to traverse all positions in each trajectory. represents the true label of the mth trajectory at time step t+1, that is, the true next hop position, It represents the prediction result of the model at time step t for time step t+1 in the mth trajectory, that is, the probability distribution of the predicted next hop position.
[0091] Use the migrated track encoder model T target Perform trajectory prediction for other cities. Use the trajectory data of the target city to test and evaluate the model to see its performance on the target city. The purpose of model migration is to migrate the knowledge of the model trained on the source city to the target city, thereby using the experience of the source city to improve the trajectory prediction performance of the target city. Doing so can reduce the problem of insufficient data in the target city, and can make full use of the data and knowledge of the source city to accelerate the training and optimization process of the target city model.
[0092] Through model transfer, meta-learning is used to quickly adapt and promote between different cities, improving the generalization ability and performance of the model.
[0093] S4: predict the next hop of the trajectory;
[0094] The next path to choose i+1 Affected by the current road i To ensure the continuity of traffic trajectory, r i+1 With r i Adjacent. Destination road T To determine the next path r i+1 It is also of great significance to provide travel intentions and avoid deviating from multiple adjacent roads. i . BatchNorm is used to normalize the input of each layer to enhance the model's capabilities. Sigmoid function is used to calculate the spatiotemporal gate for the next road prediction.
[0095]
[0096] in, Represents node r i The calculation results of the spatiotemporal gating mechanism, Dist, BN, σ are the distance function, BatchNorm and Sigmoid function respectively.
[0097] Transformer A linear layer is applied to the hidden representation to obtain the original predicted logits, which are further gated with a spatiotemporal gate. Activate them to get the final predicted logits (the Mask function is used to filter non-adjacent roads to ensure trajectory continuity):
[0098]
[0099] in, represents the probability distribution of the next hop location, Mask represents the masking mechanism, which is used to ensure that the prediction result only contains candidate roads adjacent to the current road, and Linear represents the linear layer, which is used to transform the hidden state of the Transformer encoder. Convert to raw predicted logits.
[0100] After the trajectory prediction is completed, use visualization tools such as Matplotlib to visualize the results, making the results of model prediction and evaluation more obvious and considerable. Some hidden features will be magnified and discovered in this process. Further analysis of the results will be used to update and correct the vehicle trajectory prediction model.
[0101] An example of the present invention includes constructing a heterogeneous city taxi trajectory generation system with time-space gate mechanism migration, the system comprising:
[0102] Time series data processing module: responsible for processing and cleaning the taxi trajectory data of different cities to ensure the integrity and accuracy of the data. This module uses the road network information in OpenStreetMap and converts GPS point data into continuous road trajectories through map matching technology, thereby integrating the taxi trajectory data of different cities.
[0103] Node feature extraction module: Use T' to extract the features of road nodes from the processed trajectory data and build an academic heterogeneous network. This module mainly uses graph neural network GNN to encode and model node features and edges, and integrates time and space information through spatiotemporal embedding modules and Fourier transform.
[0104] Model training module: The model is trained using the extracted node features and the Transformer deep learning algorithm. In each round of meta-training, MAML is used to clone the parameters of the public encoder T' to the source city encoder Ti, and after each round of meta-training, gradient descent is performed on the public encoder T' to optimize its parameters.
[0105] Node prediction execution module: Use the trained model to predict nodes and predict the next hop node based on the current node. Train the processed trajectory data through the Transformer model and use the trained model to predict trajectories.
[0106] Prediction result optimization module: optimizes the prediction results to ensure the continuity and accuracy of the trajectory. BatchNorm is used to normalize the input of each layer, and the Sigmoid function is used to calculate the spatiotemporal gate of the next road prediction. The Mask mechanism is used to constrain the prediction results.
[0107] Gradient update module: Use the MAML method to evaluate and migrate the model and realize the migration of trajectory data from the source city to the target city.
[0108] The synergy of these modules ensures that the system can effectively process vehicle trajectory data and provide accurate trajectory next-hop prediction results.
[0109] The contents described in the embodiments of this specification are merely an enumeration of implementation forms of the inventive concept. The protection scope of the present invention should not be regarded as limited to the specific forms described in the embodiments. The protection scope of the present invention also extends to equivalent technical means that can be conceived by those skilled in the art based on the inventive concept.
Claims
1. A method for generating taxi trajectories in heterogeneous cities with a space-time gate mechanism migration, characterized in that: The following steps are involved: (S1): Data source collection and processing: Integrate taxi trajectory data from heterogeneous cities, perform data cleaning and preprocessing, match heterogeneous data to road networks, and use road network information in OpenStreetMap to convert longitude and latitude point sequences into continuous road sequences; (S2): Constructing a spatiotemporal migration meta-model of heterogeneous urban traffic trajectories: First, construct a spatiotemporal encoder T' for public transport trajectories to capture the common features in traffic trajectory data; Secondly, a traffic trajectory spatiotemporal encoder T is constructed for each city. i , where i represents the encoder of each city to learn the unique traffic characteristics of each city. In each round of meta-training, MAML is used to convert the public encoder T' to the source city encoder T i After each round of meta-training, gradient descent is performed on the public encoder T' to optimize its parameters to adapt it to the traffic trajectory characteristics of each city; (S3): Model migration: The source model is trained on a source city with rich trajectory data, and the target model is trained on a target city with scarce data. First, the shared parameters in the source model are copied to the target model to maintain the structural consistency of the two models. Then, the model is internally updated using the spatiotemporal encoded trajectory data of the target city, and the private parameters of the model are adjusted and optimized to adapt to the specific traffic characteristics of the target city. On the target city dataset, the model undergoes multiple iterative training, and the model parameters are updated by gradient descent and back propagation methods to minimize the trajectory prediction error. At the same time, during the internal update process, the shared parameters of the target model are regularly synchronized with the shared parameters of the source model to ensure that the common knowledge of the source city can be transferred to the target city. During the process, the performance of the model is regularly evaluated using the average displacement error and the final displacement error as evaluation indicators to ensure that the performance of the model on the target city data continues to improve. After fine-tuning is completed, the model is finally tested using the target city test set to comprehensively evaluate the performance of the model in practical applications. (S4): Predict the next hop of the trajectory: Train the processed trajectory data through the Transformer model, use the trained model to predict the trajectory, predict the road of the next hop based on the current position, and use the mask mechanism of the adjacent topological structure of the road to constrain the prediction result and ensure the continuity of the trajectory.
2. The method for generating taxi trajectories in heterogeneous cities with the space-time gate mechanism migration as claimed in claim 1, characterized in that: In the step (S1), the data source collection and processing includes data acquisition and road network matching, and the specific steps are as follows: Data acquisition: GPS trajectory data of taxis in different cities are obtained through data providers or open data platforms. The data includes: latitude and longitude coordinates of vehicle operation, timestamp, road section length, road section width, maximum speed limit, number of lanes, and road type. Ensure that the acquired data has complete coverage and sufficient sampling rate for subsequent analysis and modeling; Road network matching: Using the road network information provided by OpenStreetMap, a road network data model containing road nodes, road sections and their topological relationships is established. Then, the FastMM algorithm is used to match the GPS points of the taxi trajectory with the above road network data model, thereby converting the GPS point data into a continuous trajectory to ensure the consistency of the trajectory with the actual road direction. The specific operations include: converting the road network data into a graph structure and simplifying it, assigning a unique identifier to each edge and calculating the length and direction of the edge; for each GPS point, using the spatial index to quickly find the nearest edge or node, and generating a candidate set based on the distance and angle thresholds; using the error model to estimate the observation error of the GPS point, and calculating the probability density of each edge in the candidate set; using the dynamic programming Viterbi algorithm to search for the most likely path, considering the continuity and overall probability of the path; smoothing the matching results and correcting the error matching to improve the matching quality; and finally outputting the road sequence corresponding to the original GPS trajectory.
3. The method for generating taxi trajectories in heterogeneous cities with time-space gate mechanism migration as claimed in claim 1, characterized in that: In step (S2), the main body of meta-training can be divided into the following steps: First, initialize the model parameters, the public encoder T' and each city encoder T i The parameters of the public encoder T' are initialized to the same value; secondly, a meta-training cycle is performed. For each round of meta-training, a source city is randomly selected from all cities as the current task, and the parameters of the public encoder T' are cloned to the source city encoder T i In the example above, we get the initial city encoder parameters and use the city encoder T on the training data of the current source city. i Conduct training and update the parameters of the city encoder, calculate the loss function of the current source city, and record the loss value; finally, perform optimization after the meta-training is completed. After each round of meta-training, perform gradient descent on the public encoder T' to optimize its parameters. By using the training data and loss function of each city, calculate the gradient of the public encoder T' and update the parameters of the public encoder.
4. The method for generating taxi trajectories in heterogeneous cities with time-space gate mechanism migration as claimed in claim 1, characterized in that: In the step (S2), the spatiotemporal encoder T' involves feature extraction and correlation modeling to generate accurate road representation and trajectory representation, and the specific steps include: The road representation described herein: adopts a spatiotemporal embedding module that encodes the features of each road node while considering its spatial location and temporal attributes, uses a graph attention network to allow the model to dynamically focus on important road nodes based on the topological structure of the traffic network, and introduces Fourier transform to help the model understand and predict periodic temporal patterns; The trajectory representation described: uses the trajectory attention module to establish and strengthen the correlation between different positions in a single trajectory, identifies the key points in the trajectory through this module, and captures the dynamic relationship between them. The causal attention mechanism is used to ensure that when calculating the trajectory representation, the model follows the time order, avoids the interference of future information on the past state, and generates a trajectory sequence representation that conforms to the time causal relationship.
5. The method for generating taxi trajectories in heterogeneous cities with the space-time gate mechanism migration as claimed in claim 4 is characterized in that: The steps include: combining a graph neural network GNN and a Transformer to establish a TrajEncoder, i.e., a spatiotemporal encoder T of a vehicle trajectory, wherein the specific implementation of the TrajEncoder involves feature extraction and correlation modeling to generate accurate road representation and trajectory representation; Among them, the road representation module of the trajectory spatiotemporal encoder TrajEncoder mainly applies the graph neural network GNN: the spatiotemporal embedding module is used to encode the features of each node, and integrate the time information into it through the semantic-aware graph attention network and Fourier transform, effectively embedding the spatiotemporal semantics of the traffic trajectory; The node features, including the length of the road section, the width of the road section, the maximum speed limit, the number of lanes, the road type, the GPS coordinates, and the road semantics including the edge are modeled, and the graph attention network GAT is used to encode the node features and their adjacent relations. Let R = {r k |k∈[N]} is a node set, A∈R N×N represents the adjacency matrix, where N represents the number of roads, r k Represents the kth road in the set, and defines a trajectory as S = {x i |i∈[T]}, where x i =(r i , t i ), r i represents the i-th road in the trajectory, t i represents the timestamp of position i, T represents the length of the trajectory, specifically, for each r i , r i and Due to continuity, r i+1 = 1, the path r in the trajectory i Represented by the graph encoder, first, each road r i is embedded into a dense vector as the representation of the first layer, where is the i-th position x in the trajectory i The representation of is obtained by converting the MLP model: Using multi-head attention mechanism and multiple layers to aggregate messages from neighboring roads, we get node r from layer l-1 i The representation at level l is as follows, where It is the representation of the i-th road in the trajectory at the l-th layer by the graph attention network: Among them, C represents the number of heads, A i Indicates road r i Neighbors, represents the attention coefficient of node i and node j at head C, W c represents the weight matrix at head C, Represents the representation of the j-th road in the trajectory at the l-1 layer by the graph attention network; For timestamp t i The goal is to obtain a continuous function mapping from the time domain to the d-dimensional vector space, using Fourier transform in the time encoder. Characterize the time stamp t by Fourier transform i Mapped to a d-dimensional vector space, thus capturing temporal periodicity and trend information: Among them, the Fourier transform represents the periodic pattern in time through a linear combination of sine and cosine functions, ω l and ω d Indicates the frequency range, ω l represents the lowest frequency, ω d Indicates the highest frequency. The trajectory representation module of the trajectory spatiotemporal encoder involves Trans: The trajectory attention module is used to establish the correlation between each position in a single trajectory and calculate the representation of the entire trajectory sequence through the causal attention mechanism; Transformer is used to capture relevant semantics, and only its decoder is used to represent and generate trajectories to encapsulate the relationship of the entire traffic trajectory sequence; a multi-head causal attention mechanism is used to mask the impact of future points on historical points; first, the embeddings obtained by the above graph encoder and time encoder are concatenated as the roadmap in the transformer. i The original embedding of Next, the position encoding of the model information of each point in the trajectory is provided and compared with Connect as input to Transformer; Multiply the input embedding with three matrices to create query Q, key K, and value vector V, r respectively. i The query vector and r i The dot product is performed with the Key vector of its historical points to obtain the attention score, which is normalized by the Softmax operation until the value vector of each point up to the i-th position is multiplied by the normalized attention score, and the weighted value vectors are added to obtain the self-attention representation of the position: Among them, z i Represents node r i The self-attention representation of the Transformer encoder, c′ represents the number of attention heads, Characterization node r i and r j The attention coefficient at node c′, v ij Characterization node r i and r j The value vector, W o is the output matrix; The representation of the current layer is added to the hidden representation of the previous layer, and LN is performed twice and FFN is performed once to obtain the final hidden representation of the current layer. Therefore, the representation of layer l can be obtained from layer l-1 as follows: in, represents the hidden representation of the Transformer encoder at layer l, represents the hidden representation of the Transformer encoder at layer l-1, represents the self-attention representation of layer l.
6. The method for generating taxi trajectories in heterogeneous cities with time-space gate mechanism migration as claimed in claim 1, characterized in that: In the step (S3), the shared parameters of the source model are initialized from the current meta-model, and the source model T' is first meta-cloned, and the steps are as follows: For each source city model, clone the shared parameters from the current meta-model to obtain the parameters θ of the source city model src , using the source city training data through the TrajEncoder described in step (S2) Optimize source city model parameters, perform internal updates, and use source city test data Calculate meta-gradients and update the parameters θ of the meta-model meta ; For each city, the target city model clones the shared parameters from the updated meta-model to obtain the parameters θ of the target city model. tgt , using the target city training data Optimize the model parameters of the target city, perform internal updates, and repeat steps (S1)-(S2). For each source city, use the trajectory data of the city for training to obtain the corresponding trajectory encoder model T i , the defined loss function is used during training: Where M represents the total number of trajectories in the training dataset, T represents the total number of positions in each trajectory, m represents the index of the trajectory, which is used to traverse all trajectories, and t represents the index of the position in the trajectory, which is used to traverse all positions in each trajectory. represents the true label of the mth trajectory at time step t+1, that is, the true next hop position, It represents the prediction result of the model at time step t for time step t+1 in the mth trajectory, that is, the probability distribution of the predicted next hop position; Use the migrated track encoder model T target Perform trajectory prediction for other cities, use the trajectory data of the target city to test and evaluate the model, obtain its performance on the target city, transfer the knowledge of the model trained on the source city to the target city, use the experience of the source city to improve the trajectory prediction performance of the target city, so as to reduce the problem of insufficient data in the target city, and use the data and knowledge of the source city to accelerate the training and optimization process of the target city model.
7. The method for generating taxi trajectories in heterogeneous cities with space-time gate mechanism migration as claimed in claim 1, characterized in that: In the step (S4), the next hop path r i+1 With the current road i adjacent to ensure the continuity of traffic trajectory, the destination road r T To determine the next path r i+1 Provides travel intentions to avoid deviating from multiple adjacent roads i , BatchNorm is used to normalize the input of each layer to enhance the model's capabilities, and the Sigmoid function is used to calculate the spatiotemporal gate for the next road prediction in, Represents node r i The calculation results of the spatiotemporal gating mechanism, Dist, BN, σ are the distance function, BatchNorm and Sigmoid function respectively; Transformer A linear layer is applied to the hidden representation to obtain the original predicted logits, which are further gated with spatiotemporal gates. Activate them to get the final predicted logits: in, represents the probability distribution of the next hop location, Mask represents the masking mechanism, which is used to ensure that the prediction result only contains candidate roads adjacent to the current road, and Linear represents the linear layer, which is used to transform the hidden state of the Transformer encoder. Convert to original predicted logits; After the trajectory prediction is completed, the Matplotlib visualization tool is used to visualize the results so that hidden features can be discovered and the vehicle trajectory prediction model can be updated and corrected.
8. A heterogeneous city taxi trajectory generation system with space-time gate mechanism migration, characterized in that: The system includes: Time series data processing module: used to process and clean taxi trajectory data in different cities; Node feature extraction module: used to extract the features of road nodes from the processed trajectory data and construct the road network of the city; Model training module: Use the extracted node features to train the model using the Transformer deep learning algorithm; Node prediction execution module: used to perform node prediction based on the trained model and predict the next hop node based on the current node; Prediction result optimization module: used to optimize the prediction results to ensure the continuity and accuracy of the trajectory; Gradient update module: used to evaluate and migrate the MAML model and migrate trajectory data from source cities to target cities.
Citation Information
Cited By
Cross-city trajectory generation method combining deep learning and shortest path search
CN119829688A
Human space-time trajectory generation method and system
CN119885858A
Unknown trajectory travel time estimation method based on region division
CN121353025A
