Vehicle space-time trajectory similarity calculation method and device based on semantic information
By preprocessing and feature extraction of vehicle trajectory data, building a spatio-temporal relationship diagram with POI data, and using the T-LSTM model and a two-level comparison loss function for training, the problem of ignoring semantic information and poor generalization capabilities in the existing technology is solved, and a more accurate and adaptable vehicle trajectory similarity calculation is achieved.
Patent Information
- Application Number
- CN202510619442.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-14
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2045-05-14
AI Technical Summary
The existing vehicle trajectory similarity calculation method ignores semantic information when processing spatiotemporal data, resulting in inaccurate calculation results and poor generalization capabilities of the model, making it difficult to adapt to complex traffic scenarios.
By preprocessing the vehicle trajectory data, a similar matrix of spatiotemporal trajectory data is constructed, and a Tyson polygon is generated based on POI data to extract multi-dimensional features. Then, a spatio-temporal relationship diagram based on POI was constructed, and a random walk strategy with trajectory perception and a GAT algorithm learned node representation was used, and finally, a T-LSTM model and a two-level contrast loss function were used for training.
The accuracy and generalization ability of trajectory similarity calculation are improved, and the time, space and semantic information in trajectory data can be better captured and adapted to complex traffic scenarios.
Smart Images

Figure CN120123787A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of intelligent transportation, and particularly relates to a method for calculating the similarity of vehicle spatio-temporal trajectories based on semantic information. Background Art
[0002] With the acceleration of the urbanization process and the booming development of intelligent transportation systems, in-depth analysis and effective utilization of vehicle trajectory data in the field of intelligent transportation have become increasingly important. Vehicle spatio-temporal trajectory data contains rich information. Accurately calculating its similarity can play a key role in multiple aspects such as traffic flow prediction, travel pattern analysis, intelligent path planning, and traffic accident warning, thereby greatly improving the management efficiency and operation quality of urban traffic.
[0003] There are mainly two categories of existing trajectory similarity calculation methods: 1. Heuristic metric methods: Heuristic metric methods usually calculate based on the intuitive geometry of trajectories, using basic attributes of trajectories such as the position, order, and distance of points. Predefined similarity calculation rules or heuristic algorithms are used to evaluate the similarity between trajectories. For example, dynamic time warping (DTW) stretches or compresses the time dimension of two trajectories with different speeds on the time axis through time warping technology to find the optimal matching path, thereby calculating the similarity. This type of method usually does not require a large amount of training data, and the calculation process is relatively simple. However, it is sensitive to noise and sampling rate differences, has a high calculation complexity, and its adaptability to certain complex scenarios is also very limited; 2. Learning-based metric methods: The basic idea is to map trajectory data into a low-dimensional vector space through technologies such as deep learning, so that similar trajectories have similar representations in the vector space, and then trajectory similarity is represented by vector similarity. This type of method can automatically learn the complex features and patterns of trajectories and has good adaptability and generalization ability for different types of trajectories. However, traditional learning-based metric methods have significant defects. On the one hand, most existing methods only simply consider the spatial features of trajectories, ignoring the time characteristics and underlying semantic information contained in the trajectories. The driving trajectories of vehicles do not exist in isolation. The positions passed by at different time points are often closely related to the surrounding functional areas, such as shopping malls, schools, hospitals, etc. The semantic information carried by these functional areas is of great significance for calculating vehicle trajectory similarity. On the other hand, existing vehicle trajectory similarity calculation models involving spatio-temporal analysis need to separately set parameters for time and space during calculation, which not only makes the calculation process extremely cumbersome, but also the generalization ability of the model is poor and it is difficult to adapt to complex and changing actual traffic scenarios. Summary of the Invention
[0004] The object of the present invention is to solve the above problems, and a method for calculating the similarity of vehicle spatio-temporal trajectories based on semantic information is designed. By comprehensively integrating multi-dimensional information, it effectively solves the problems of insufficient generalization and insufficient data utilization existing in the current trajectory similarity calculation model, and improves the accuracy of trajectory similarity calculation.
[0005] The present invention provides a method for calculating the similarity of vehicle spatio-temporal trajectories based on semantic information, including the following steps: S1. Preprocess the vehicle trajectory data to obtain spatio-temporal trajectory data, construct a similarity matrix, divide the spatio-temporal trajectory data at 1-hour intervals, and simultaneously construct a Voronoi diagram based on the POI data to generate Thiessen polygons; S2. According to the spatio-temporal trajectory data and POI data, perform multi-dimensional feature extraction on the Thiessen polygon region containing the trajectory to obtain the spatial feature, time feature, and POI semantic feature of the region; S3. Construct a POI-based spatio-temporal relationship graph in the divided time interval, and sequentially adopt a spatio-temporal integrated random walk strategy with trajectory perception and the GAT algorithm to learn high-quality representations of nodes; S4. According to the spatio-temporal trajectory data and the learned node representations, construct a model T-LSTM that enhances the time expression ability to learn the final representation of the trajectory sequence; S5. Use the cosine similarity function to measure the similarity between nodes and between trajectories, and design a graph-based two-level contrast loss function to train the model using the pairwise sampling method.
[0006] Optionally, in the first implementation manner of the present invention, the preprocessing of the vehicle trajectory data to obtain spatio-temporal trajectory data, constructing a similarity matrix, dividing the spatio-temporal trajectory data at 1-hour intervals, and simultaneously constructing a Voronoi diagram based on the POI data to generate Thiessen polygons includes: Obtain vehicle trajectory data, preprocess the vehicle trajectory data to remove abnormal trajectory points and short trajectories, where the short trajectories have less than 5 trajectory points; Construct a similarity matrix for the preprocessed vehicle trajectory data through the longest common subsequence algorithm of the trajectory similarity calculation method; Divide the preprocessed spatio-temporal trajectory data at 1-hour intervals, and the data set constructed from the preprocessed spatio-temporal trajectory data is divided into a series of sub-data sets; Based on the position information of the POI points, use the Voronoi diagram to generate a series of Thiessen polygons, define the Thiessen polygons as the functional areas served by the corresponding POI points, and map the trajectory points in the sub-data sets to the Thiessen polygons.
[0007] Optionally, in the second implementation manner of the present invention, the multi-dimensional feature extraction of the POI Thiessen polygon region containing the trajectory based on the spatio-temporal trajectory data and the POI data to obtain the spatial feature, temporal feature, and POI semantic feature of the region includes: Normalize the longitude and latitude of the POI using the min-max normalization function, perform non-linear transformation using a multi-layer perceptron, and use the GPS coordinates recorded in the POI data as the location information of the region to obtain the spatial feature of the region; Transform the original timestamps of the trajectory sequence into sine and cosine feature representations, and perform normalization processing using the min-max normalization function to transform the one-dimensional linear representation of time into two-dimensional periodic features to obtain the temporal feature; Extract the semantic information of the POI through time frequency and text mining to obtain the POI semantic feature.
[0008] Optionally, in the third implementation manner of the present invention, the semantic information of the POI is extracted through time frequency and text mining to obtain the POI semantic feature, including: Taking 1 hour as the division unit, divide 1 day into 24 time intervals, traverse the spatio-temporal trajectory data, and for the time when each POI point appears in the trajectory, count the number of times it appears in the corresponding time interval to obtain the 24-dimensional temporal feature of each POI point, and perform normalization processing, replacing the value of each dimension with the percentage of the appearance frequency in the corresponding time interval in the whole-day appearance frequency, so that the sum of the values of the dimensions is 1, to obtain the temporal attribute of the POI, where the temporal attribute is the access heat distribution of the POI in different time intervals of 1 day.
[0009] Optionally, in the fourth implementation manner of the present invention, the semantic information of the POI is extracted through time frequency and text mining to obtain the POI semantic feature, and further includes: Adopt the TF-IDF algorithm for text mining, regard each POI point type as a word, the POI sequence passed by each trajectory sequence can be regarded as a document, and each trajectory can be represented as a word sequence; For each trajectory, calculate the word frequency and inverse document frequency of each POI point type, multiply the word frequency and inverse document frequency to obtain the TF-IDF value of each POI point type in each trajectory as the text attribute of the POI; Concatenate the TF-IDF values of all POI point types as additional dimensions with the temporal attribute to obtain the POI semantic feature.
[0010] Optionally, in the fifth implementation manner of the present invention, the spatio-temporal relationship graph based on the POI is constructed in the divided time intervals, and the spatio-temporal integrated random walk strategy with trajectory perception and the GAT algorithm are sequentially used to learn the high-quality representation of the nodes, including: Construct a spatio-temporal relationship graph based on POIs in the divided time intervals according to the spatial characteristics, temporal characteristics, and POI semantic characteristics of the region; Adopt a spatio-temporal integrated random walk strategy with trajectory awareness to learn the initial representation of vertices in the spatio-temporal relationship graph. In the sequence sampling stage, walk in the spatio-temporal relationship graph according to the time of the trajectory sequence sampling points to obtain the initial node vectors that can capture both temporal and spatial characteristics; Obtain the initial representation of vertices, and use the GAT algorithm for each spatio-temporal network in the time interval to capture the characteristics of the neighbor nodes of the trajectory.
[0011] Optionally, in the sixth implementation manner of the present invention, a model T-LSTM that enhances the time expression ability is constructed according to the spatio-temporal trajectory data and the learned node representation to learn the final representation of the trajectory sequence, including: According to the spatio-temporal trajectory data and the learned node representation, obtain the initial vector sequence of the trajectory, convert the time characteristics into sine and cosine characteristics, and use them as the input of the attention layer; Generate Q, K, and V vectors through matrix multiplication, calculate the attention scores through scaled dot-product attention, and perform weighted summation according to the attention scores to obtain the weighted feature representation; Use the high-quality node representation and the time characteristics with the attention mechanism as the input of the LSTM layer, and obtain the final input features through a multi-layer perceptron; Construct a model T-LSTM that enhances the time expression ability by combining time attention and the LSTM layer, and use the output of the last time step of T-LSTM as the trajectory embedding.
[0012] Optionally, in the seventh implementation manner of the present invention, the graph-based two-level contrast loss function includes a node-level semantic loss function and a trajectory-level contrast loss function, where the node-level semantic loss function is used to strengthen the learning of semantic information by the trajectory representation, and the trajectory-level contrast loss function is used to optimize the overall similarity of the trajectories.
[0013] Optionally, in the eighth implementation manner of the present invention, the node-level semantic loss function includes: Given nodes and , after obtaining the node representations through step S3, the corresponding embedding vectors are respectively and , and use the cosine similarity function as the function for measuring similarity: ; Adopt a strategy of positive and negative sampling for the nodes passed by the trajectory, calculate the point similarity loss, and use the contrast loss as the node-level semantic loss function.
[0014] Optionally, in the ninth implementation manner of the present invention, the contrast loss function at the trajectory level includes: In step S1, the similarity matrix is obtained as the true ground distance of the trajectory, the most similar trajectory of the trajectory in the similarity matrix is extracted as the positive sample, and the remaining trajectories are negative samples. The core of the model learning is to learn a mapping function to encode the trajectory sequence into a representation vector; Given the representation vectors obtained by any two trajectories through model learning, the cosine similarity function is used as the function to measure similarity. The goal is to maximize the cosine similarity between a given trajectory and its most similar trajectory, and minimize the cosine similarity with negative samples. The contrast loss is used as the contrast loss function at the trajectory level.
[0015] Compared with the prior art, the beneficial effects of the present invention include the following aspects: (1) The present invention deeply excavates dimensional features. By dividing the trajectory data according to time intervals and constructing the spatio-temporal structure of the trajectory based on the semantic information within the time interval, it realizes the simultaneous consideration of the temporality, spatiality, and semantic information of the trajectory data, and improves the expressive ability of the trajectory representation; (2) Aiming at the problem of weakened time features in the existing model, the present invention constructs a deep network model T-LSTM based on time attention. By introducing an attention mechanism to assign weights to different time importances, the model can better capture the dynamic change rules of the trajectory at different time stages, providing stronger support for trajectory similarity calculation in the time dimension; (3) In order to further enhance the expressive ability of the trajectory representation for functional semantic information, the present invention designs a two-level contrast loss function based on a graph to guide the training of the model. Among them, the loss function at the node level strengthens the expressive ability of the trajectory representation for POI semantic information by calculating node similarity; the loss function at the trajectory level is used to strengthen the global representation ability of the trajectory sequence representation. Compared with the traditional single loss function, the two-level contrast loss function of the present invention can simultaneously take into account the similarity losses of semantic nodes and trajectory sequences, which helps to improve the ability of the trajectory representation to capture functional semantic information and makes the model more targeted in identifying and understanding trajectory data. Description of the Drawings
[0016] By reading the detailed description of the preferred embodiments below, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only for the purpose of showing the preferred embodiments and are not considered to be a limitation of the present invention.
[0017] Figure 1 It is a schematic flowchart of a method for calculating the spatio-temporal trajectory similarity of vehicles based on semantic information proposed by the present invention; Figure 2 It is a schematic diagram of a spatio-temporal relationship graph constructed according to the spatio-temporal semantic association of the trajectory proposed by the present invention; Figure 3 It is a schematic diagram of a spatio-temporal integrated random walk strategy PTS-walk with trajectory perception proposed by the present invention; Figure 4 It is a schematic diagram of a model T-LSTM that enhances the time expression ability proposed by the present invention. Detailed implementation manners
[0018] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention, that is, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Usually, the components of the embodiments of the present invention described and illustrated herein can be arranged and designed in various different configurations.
[0019] Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative efforts belong to the scope of protection of the present invention.
[0020] The following describes the specific implementation manner of the present invention with reference to the accompanying drawings, a method for calculating the similarity of vehicle spatio-temporal trajectories based on semantic information. The present invention aims to divide the trajectory data by time, and construct the spatial structure of the trajectory based on the semantic information within the time interval, realizing the simultaneous consideration of the temporality, spatiality and semantic information of the trajectory data. Subsequently, deep learning technology is used to convert the trajectory data into a representation containing high-quality information, effectively solving the problems of insufficient generalization and insufficient data utilization existing in the current trajectory similarity calculation model, and improving the efficiency and accuracy of trajectory similarity calculation.
[0021] To achieve the above objective, the present invention provides a method for calculating the similarity of vehicle spatio-temporal trajectories based on semantic information. The overall process of this method refers to Figure 1 and specifically includes the following steps: S1. Preprocess the vehicle trajectory data to obtain spatio-temporal trajectory data, construct a similarity matrix, divide the spatio-temporal trajectory data at 1-hour intervals, and simultaneously construct a Voronoi diagram according to the POI data to generate Thiessen polygons; In this embodiment, the spatio-temporal trajectory data of the vehicle is preprocessed to screen and retain the valid trajectory data. The spatio-temporal trajectory data is divided with a one-hour span. At the same time, the Voronoi diagram is constructed using the points of interest (POI) data to generate the Thiessen polygon, and the Thiessen polygon is defined as the service area corresponding to the POI point, serving as the carrier of the functional semantic information of the vehicle trajectory. The trajectory points are mapped within the range of the divided Thiessen polygons.
[0022] In this embodiment, for the trajectory set , where , represents the longitude and latitude of the trajectory point, represents the time, represents the total number of trajectories, represents the trajectory length. The data preprocessing refers to removing the abnormal trajectory points and short trajectories (less than 5 trajectory points) caused by reasons such as the sampling rate, and constructing a distance matrix D for the retained valid data through the traditional trajectory similarity calculation method, the longest common subsequence algorithm (LCSS). Based on the distance matrix D, the distance between trajectories is normalized to obtain a similarity matrix S for the subsequent training of the supervised guidance model; It should be noted that the LCSS method is an algorithm commonly used to calculate the similarity between sequences. It measures the sequence similarity by finding the ordered and discontinuous similar subsequences from two sequences. For example, for the sequences "ABCD" and "ACBD", their longest common subsequence is "ACD" and the LCSS value is 3. This method has been widely used in fields such as trajectory similarity calculation. The present invention uses the LCSS method considering time similarity to construct the similarity matrix D, mainly aiming to provide the ground truth distance of the trajectory for the subsequent model training. Assume that two trajectories are given: the target trajectory and the candidate trajectory. The similarity between the trajectories is judged by setting a time threshold and a distance threshold. The calculation formula is as follows: ; Where, is the longest common subsequence value of the trajectories and , represents the remaining trajectory point sequence after removing the first trajectory point from the trajectory , represents the th trajectory point between the trajectories and represents the th trajectory point between the trajectories The time difference between trajectory points. From this, a distance matrix D is obtained, and after normalization, a similarity matrix S is obtained; Next, the spatio-temporal trajectory data is partitioned with 1 hour as the partition interval, and the dataset is divided into a series of sub-datasets. Therefore, the entire trajectory data representation problem is converted into a series of sub-data representation problems in different time intervals. It should be noted that in the present invention, only time-based segmentation of trajectory points is performed, and all POI points exist in the spatio-temporal map of each time interval; The use of POI data to construct a Voronoi diagram to obtain Thiessen polygons means mapping the POI data into the trajectory data and performing geometric processing on it to endow the trajectory data with semantic meaning. Specifically, first, the POI points are regarded as discrete points, and a triangular network is constructed by the Delaunay triangulation method. Subsequently, based on the position information of these discrete points, a Voronoi diagram is generated and Thiessen polygons are divided. These polygons are regarded as approximate regions of the POI service range. For the above-mentioned sub-datasets, the present invention maps the trajectory points into these Thiessen polygons. This process can not only effectively handle the problem of noise points existing in the trajectory data, but also endow the trajectory data with POI semantic information, providing a richer semantic basis for subsequent trajectory analysis and similarity calculation.
[0023] S2. According to the spatio-temporal trajectory data and POI data, perform multi-dimensional feature extraction on the POI Thiessen polygon region containing the trajectory to obtain the spatial feature, time feature, and POI semantic feature of the region; In this embodiment, according to the spatio-temporal trajectory data and POI data, perform multi-dimensional feature extraction on the POI Thiessen polygon region containing the trajectory to obtain the spatial feature, time feature, and POI semantic feature of the region.
[0024] In this embodiment, the above-mentioned divided polygons are used as POI regions, and region features are constructed for them. The specific steps are as follows: Spatial feature : Record the position information of the region, which is obtained by normalizing the longitude and latitude of the POI. The GPS coordinates recorded by the POI data are directly used as the position information of the region. First, use the min-max normalization function to normalize it, and use a multi-layer perceptron (MLP) for non-linear transformation. The spatial feature is represented as follows: ; Among them, represents the dimension of the POI point, represents the longitude of the POI point; Time feature : Record the time information of the region. First, convert the time representation of the original data, such as '08:00', into the corresponding minutes '480' starting from 0 o'clock in a day. Subsequently, to reflect the periodicity of time, convert the one-dimensional linear representation of time into two-dimensional periodic features. The original timestamps of the trajectory sequence need to be transformed into sine and cosine feature representations. Similarly, use the min-max normalization function to normalize it. The conversion process is as follows: ; ; ; Among them, 1440 refers to the time period of a day being 1440 minutes, is the min-max normalization function, is the sine feature representation, is the cosine feature representation.
[0025] Semantic features : Record the semantic information of the region. To better utilize the semantic information of POI data within the region, the present invention extracts the semantic information of POIs from two aspects: time frequency and text mining. Specifically as follows: 1. Time frequency: First, divide a day into 24 time intervals with 1 hour as the division unit. Subsequently, traverse the trajectory dataset. For the time when each POI point appears in the trajectory, count the number of times it appears in the corresponding time interval to obtain the 24-dimensional time feature of each POI point. Then, perform normalization processing on it, and replace the value of each dimension with the percentage of the appearance frequency in the corresponding time interval accounting for the total appearance frequency throughout the day, ensuring that the sum of the values of all dimensions is 1, to obtain , which can intuitively reflect the access heat distribution of POIs in different time intervals within a day and provides important time semantic information for trajectory analysis; 2. Text mining: Use the TF-IDF algorithm to further mine the information of POIs. Consider each POI point type as a "word", and the sequence of POIs passed by each trajectory sequence can be regarded as a "document", and each trajectory can be represented as a sequence of words. The calculation process is as follows: First, calculate the term frequency (TF). For each trajectory (i.e., "document"), the present invention calculates the term frequency of each POI point type (i.e., "word"). The calculation formula for the term frequency is: ; Among them, P represents the POI type, n is the number of times the POI appears in the trajectory, T represents the trajectory, and N is the total number of all POI types appearing in the trajectory.
[0026] Then calculate the inverse document frequency (IDF), which is used to measure the importance of a POI point type in the entire trajectory dataset. Its calculation formula is: ; D is the total number of trajectories, is the number of trajectories containing the POI type P.
[0027] Finally, calculate the TF-IDF value by multiplying the term frequency and the inverse document frequency to obtain the TF-IDF value of each POI point type in each trajectory, which is used as the text attribute of the POI : ; To comprehensively consider the semantics of the POI and its importance in the trajectory, the TF-IDF values of all POI point types are concatenated with P1 as an additional dimension to obtain the final POI representation ; ; The final regional feature consists of three parts, namely the spatial feature , the temporal feature and the semantic feature , and the formula is as follows: ; S3. Construct a spatio-temporal relationship graph based on POIs in the divided time intervals, and successively adopt a spatio-temporal integrated random walk strategy with trajectory awareness and the GAT algorithm to learn high-quality representations of nodes.
[0028] In this embodiment, through the spatio-temporal semantic association of trajectories, a spatio-temporal relationship graph based on POIs is constructed in the divided time intervals , where represents the POI spatial relationship graph from time to , the node represents the Thiessen polygon, that is, the POI semantic node, represents the edge between nodes, providing input for the subsequent trajectory similarity calculation model; for the above spatio-temporal relationship graph, a spatio-temporal integrated random walk strategy with trajectory awareness (POI and spatiotemporal random walk, PTS-walk) is adopted to learn the embedding of the nodes of the spatio-temporal relationship graph G. This strategy directly samples points in the graph according to the time of the trajectory sequence sampling points during the sequence sampling stage wanders in it to obtain the initial node vector that can capture both time and space features. Subsequently, the graph attention model (GAT) is used to learn the high-quality representation of the nodes, capture the features of the neighbor nodes of the nodes, and enhance the expression ability of the nodes.
[0029] In this embodiment, a spatio-temporal relationship graph based on POI is constructed , specifically, referring to constructing a spatio-temporal relationship graph based on POI in the divided time intervals according to the regional features obtained through the above process , the node represents a Thiessen polygon, that is, a POI region, and the connecting edge represents the connection between two POI regions and . Among them, the construction of the connecting edge e needs to meet one of the following conditions: 1) There is a trajectory sequence passing between them, and an edge is constructed for the two nodes. 2) The cosine similarity of the feature vectors , is the cosine similarity of the Kth similar node of 1) Trajectory connection: Given a node of a certain POI region, when a continuous trajectory passes through and reaches another node , an edge is constructed between the nodes. The node is 's neighbor node, that is, , which is used to represent the spatial relationship between the two nodes. The weight of the edge is obtained from the number of trajectories from node to node ; 2) Similarity: The spatial connection of nodes indicates their spatial similarity. There should also be an edge connection between POI nodes that are semantically similar. Here, the K-nearest neighbor (KNN) algorithm is used to find the semantically similar neighbors of the nodes and add an edge between them. For the POI region features obtained in the above steps, the cosine distance of the vectors is used to quantify the similarity of the nodes. Given nodes , the similarity calculation formula between the two is: ; Therefore, for node , the neighbor nodes of him can be obtained The weight of the edge From the node To the node Is obtained by the cosine similarity.
[0030] In each time interval, the above same construction process is carried out to obtain the spatio-temporal relationship graph based on POI , where Represents the time interval To The spatial graph, the node Represents the Thiessen polygon, that is, the POI node, Represents the edge between nodes, the initial feature vector , d is the dimension of the vector, the node To The weight , the obtained spatio-temporal relationship graph refers to Figure 2 .
[0031] In this embodiment, a spatio-temporal integrated random walk strategy with trajectory awareness, PTS-walk, is adopted to learn the embedding of vertex v in the spatio-temporal relationship graph G. In the sequence sampling stage, this strategy walks in the spatio-temporal relationship graph according to the time of the trajectory sequence sampling points, so as to obtain the initial node vector that can capture both time and space features. It is mainly realized through two steps. The first step is to use random walk to generate a node sequence to simulate the trajectory of vehicle objects in the time interval relationship graph. The second step takes the generated random walk sequence as the input and uses the Skip-gram model to learn the low-dimensional vector representation of the nodes. The spatio-temporal integrated random walk strategy with trajectory awareness, PTS-walk, can be referred to Figure 3 . The algorithm steps are as follows: (1) Random walk: Specifically, given the spatio-temporal relationship graph generated representing different time intervals , PTS-walk first starts walking from a certain vertex on the spatio-temporal relationship graph based on POI, and selects the next walking point according to a certain walking probability. In order to ensure that the generated random sequence is more in line with the vehicle trajectory walking law, the walking probability needs to combine the trajectory sequence. If the end time of the next walk exceeds the current spatio-temporal graph time limit, it will directly jump to the nearest vertex in the next spatio-temporal relationship graph. The walking probability is as follows: ; , Is the weight of the edge, Is a combination of DFS and BFS random walk strategies: ; Where Is the vertex and the vertex the shortest path distance between represents a set of trajectories, where p and q are parameters that determine whether the walking strategy is breadth-first search (BFS) or depth-first search (DFS). When is greater than or equal to , it indicates that the preferred walking strategy is BFS, otherwise DFS is preferred. Through these random walk strategies, a series of node sequences of length n for learning node representations are generated , as Figure 4 shown, as the input of the model
[0032] (2) Vector representation: Taking the generated random walk sequence as input, use the Skip-gram model to learn the low-dimensional vector representation of nodes , which aims to maximize the likelihood of the co-occurrence of words in a specified window in a sentence. All walks are regarded as a corpus, and each node in the walk is regarded as a word. The purpose of the Skip-gram model is to maximize the average probability: ; where is the encoder that maps nodes to d-dimensional space vectors, is the probability function, is the neighbor of node . To make the objective function easy to calculate, the present invention assumes that the probabilities of the neighborhood nodes appearing are independent of each other: ; Given node and , model the conditional likelihood of each source-neighborhood node pair as a Softmax unit: ; However, during the training process, the normalization factor is very time-consuming. Therefore, the present invention uses negative sampling to reduce the calculation time, and the model training obtains the low-dimensional vector representation of nodes .
[0033] In this embodiment, using GAT to learn high-quality representations of nodes means that, through the above steps, the initial representations of vertices are obtained. To better capture the spatial structure between trajectories, for the spatio-temporal network (V, E) in each time interval, use the graph attention network (GAT) to capture the neighbor node features of the trajectories, specifically as follows: Taking the spatio-temporal relationship graph G(V, E) as input, the vector learned by random walk is used as the initial feature vector of the node For each vertex , calculate the similarity coefficient between its neighbors and itself one by one: ; a is a single-layer feedforward neural network. Then, normalize the attention scores using the Softmax function to obtain the normalized attention coefficients: ; where represents the set of neighbor nodes of node .
[0034] According to the calculated attention coefficients, weight-aggregate the neighbor node features of the node to obtain the node update ; To improve the model fitting ability, a multi-head attention mechanism is adopted, so the formula is updated to: ; Thus, a high-quality representation of the node with neighbor features is obtained.
[0035] S4. According to the spatio-temporal trajectory data and the learned node representations, construct a model T-LSTM that enhances the temporal expression ability to learn the final representation of the trajectory sequence; In this embodiment, according to the spatio-temporal trajectory data and the learned node representations, the present invention designs a model T-LSTM (time-enhanced long short-term memory) that enhances the temporal expression ability to learn the final representation of the trajectory sequence. By embedding a temporal attention layer at the front end of the traditional LSTM structure, the model effectively distinguishes the importance of different time points in the trajectory, thereby finely depicting the temporal features in the trajectory data and improving the ability to learn the representation of the trajectory sequence.
[0036] In this embodiment, by designing a model T-LSTM that enhances the temporal expression ability to learn the final representation of the trajectory sequence, Figure 4 is the framework diagram of the T-LSTM model. To better utilize the time information, the model embeds a temporal attention layer at the front end of the traditional LSTM structure, effectively distinguishing the importance of different time points in the trajectory, thereby finely depicting the temporal features in the trajectory data and improving the learning effect of the trajectory sequence representation. Specifically as follows: 1. Input layer Input data: Through the above process, obtain the initial vector sequence of the trajectory points. For the time feature , the present invention separately converts it into sin and cos features by using the above method and uses them as the input of the attention layer; 2. Attention layer: Generation of Q, K, and V: For the time feature, Q, K, and V vectors are generated through matrix multiplication. Subsequently, the attention scores are calculated through scaled dot-product attention: ; Weighted summation is performed according to the attention scores to obtain the weighted feature representation: ; where a is the attention score. This residual connection helps the model better propagate gradients during training, avoid the problem of gradient vanishing, and enables the model to learn more complex features; 3. LSTM layer Through the above process, a high-quality representation of the node and the time feature with the attention mechanism are obtained. Both are used as the input of the LSTM model, and the final input feature is obtained through a multi-layer perceptron (MLP), ; The basic update equation of LSTM is as follows: ; ; where represents the input gate, represents the forget gate, is the candidate cell state, is the sigmoid function, and are the weight matrix and bias vector of the input gate, is the hidden state at the previous moment, is the input at the current moment, represents the output gate, and are the cell state and hidden state respectively.
[0037] By combining the time attention and the LSTM model, correspondingly, in the above update formula .
[0038] The present invention uses the output of the last time step of T-LSTM as the trajectory embedding .
[0039] S5. Use the cosine similarity function to measure the similarity between nodes and between trajectories, and adopt the pairwise sampling method to design a graph-based two-level contrast loss function to train the model.
[0040] In this embodiment, according to the node representation and the trajectory sequence representation, the present invention uses the cosine similarity function to measure the similarity between nodes and between trajectories. Finally, the pairwise sampling method is adopted to design a graph-based two-level contrast loss function to train the model. Among them, the loss function at the node level strengthens the expression ability of the trajectory representation for the semantic information of the POI by calculating the node similarity; the loss function at the trajectory level is used to strengthen the global representation ability of the trajectory sequence representation. Therefore, the model can take into account the similarity losses of both the POI semantic nodes and the trajectory sequences, and effectively improve the expression ability of the trajectory representation for the functional semantic information.
[0041] In this embodiment, the specific content of designing the graph-based two-level contrast loss function refers to: 1. The semantic loss function at the node level, which is used to strengthen the learning of the trajectory representation for semantic information. 2. The contrast loss function at the trajectory level, which is used to optimize the overall similarity of the trajectories. Therefore, the model can take into account the similarity losses of both the semantic nodes and the trajectory sequences, and effectively improve the expression ability of the trajectory representation for the functional semantic information.
[0042] 1. The semantic loss function at the node level To strengthen the learning of semantic information in the trajectory representation, the present invention proposes a node-level semantic loss function based on the POI points. Specifically, given nodes and , after obtaining the node representations through step S3, their corresponding embedding vectors are and respectively, and the cosine similarity function is used as the function to measure the similarity; ; Then, a positive and negative sampling strategy is adopted for the nodes passed by the trajectory to calculate their point similarity losses. Specifically, for the POI node , there is a trajectory sequence passing through to reach other POI nodes . The most similar node among these k nodes is used as the positive sample of , and at the same time, a node is randomly sampled from the set of other POI nodes that have never appeared in this trajectory as the negative sample . Based on this, the similarity loss function for the POI point pair is defined as follows: ; where represents the positive sample pair, Denotes a negative sample pair, is the cosine similarity function, denotes the temperature parameter, is the negative sample set.
[0043] 2. Trajectory-level contrast loss function In step S1, the trajectory similarity matrix S is obtained through the LCSS algorithm as the true ground distance of the trajectory. To train the model so that the learned trajectory vector representation can be closer to the true trajectory similarity calculation function, the present invention extracts the most similar trajectory of the trajectory in the similarity matrix S as the positive sample, and the remaining trajectories as negative samples. The core of the model learning is to learn a mapping function to make the trajectory sequence encoded into a representation vector , which needs to satisfy the following formula: ; is the positive sample similar to the trajectory , is the negative sample not similar to , denotes a function for measuring the similarity between samples. The goal of the model is to maximize the similarity score of the positive sample and minimize the similarity score of the negative sample. The present invention uses the cosine similarity function as the function for measuring similarity. Given any two trajectories and , their representation vectors obtained through model learning are and , ; In this calculation method, the goal of the present invention is to maximize the cosine similarity between a given trajectory and its most similar trajectory and minimize the cosine similarity with the negative sample. Therefore, the contrast loss is used here as the target loss function. Given the trajectory training set , the loss function is defined as: ; wherein, denotes the trajectory positive sample pair, denotes the trajectory negative sample pair, is the cosine similarity function, denotes the temperature parameter, is the negative sample set generated for the trajectory .
[0044] The accuracy of the model for calculating the spatio-temporal similarity of the trajectory is optimized by simultaneously considering the point similarity loss between the trajectory and the network node. The final loss function of the model is: ; During the training process, for the trajectory training set , for the trajectory All the POI nodes passed through in it, after calculating their similarities, the nearest POI node is used as the positive sample, and the remaining nodes not appearing in the trajectory are used as negative samples. The trajectory similarity matrix S is obtained through the LCSS algorithm, and the most similar trajectories in the matrix S are extracted as the positive samples of the target trajectory for calculation, and the last k trajectories are used as negative samples.
[0045] The trajectory data is first mapped in the POI nodes through partitioning, so the trajectory sequence is converted into a sequence data composed of POI nodes. These data are formed into a spatio-temporal relationship graph through time partitioning , PTS-walk captures the time and space characteristics of nodes by performing random walks in the spatio-temporal graph, and then aggregates the spatio-temporal neighbor features of nodes through GAT to learn the high-quality vector representation of nodes. Subsequently, the positive and negative trajectory samples used for training are converted into the form of a vector sequence and input into the model T-LSTM that enhances the time expression ability to learn the final vector representation of the trajectory. Finally, the graph-based two-level contrast loss function designed by the present invention is used to guide the update of the model weight parameters, and the new weight parameters are used for the next round of model training.
[0046] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments. The above embodiments and the descriptions in the specification are only preferred examples of the present invention and are not used to limit the present invention. Without departing from the spirit and scope of the present invention, the present invention will have various changes and improvements, and these changes and improvements all fall within the scope of the present invention claimed. The scope of protection claimed by the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information, characterized in that: The following steps are involved: S1. Preprocess the vehicle trajectory data to obtain spatiotemporal trajectory data, construct a similarity matrix, divide the spatiotemporal trajectory data into intervals of 1 hour, and construct a Voronoi diagram based on the POI data to generate Thiessen polygons; S2. Based on the spatiotemporal trajectory data and POI data, multi-dimensional feature extraction is performed on the POI Thiessen polygon area containing the trajectory to obtain the spatial features, temporal features and POI semantic features of the area; S3, construct a spatiotemporal relationship graph based on POI in the divided time interval, and use the spatiotemporal random walk strategy with trajectory perception and the GAT algorithm to learn high-quality representation of nodes; S4. Based on the spatiotemporal trajectory data and the learned node representation, a model T-LSTM with enhanced temporal expression ability is constructed to learn the final representation of the trajectory sequence; S5. Use the cosine similarity function to measure the similarity between nodes and trajectories, and adopt the paired sampling method to design a graph-based two-level contrastive loss function training model.
2. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information according to claim 1, characterized in that: The vehicle trajectory data is preprocessed to obtain spatiotemporal trajectory data, a similarity matrix is constructed, the spatiotemporal trajectory data is divided into intervals of 1 hour, and a Voronoi diagram is constructed according to the POI data to generate Thiessen polygons, including: Obtain vehicle trajectory data and pre-process the vehicle trajectory data to remove abnormal trajectory points and short trajectories, wherein the short trajectory is less than 5 trajectory points; The similarity matrix is constructed for the preprocessed vehicle trajectory data by using the longest common subsequence algorithm, a trajectory similarity calculation method; The preprocessed spatiotemporal trajectory data is divided into 1-hour intervals, and the dataset constructed by the preprocessed spatiotemporal trajectory data is divided into a series of sub-datasets; Based on the location information of the POI point, a series of Thiessen polygons are generated using the Voronoi diagram. The Thiessen polygons are defined as the functional areas served by the corresponding POI points, and the trajectory points in the sub-dataset are mapped to the Thiessen polygons.
3. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information according to claim 1, characterized in that: According to the spatiotemporal trajectory data and POI data, multi-dimensional feature extraction is performed on the POI Thiessen polygon area containing the trajectory to obtain the spatial features, temporal features and POI semantic features of the area, including: The latitude and longitude of POI are normalized using the minimum and maximum normalization function, and a multi-layer perceptron is used for nonlinear transformation. The GPS coordinates recorded in the POI data are used as the location information of the area to obtain the spatial characteristics of the area. The original timestamp of the trajectory sequence is transformed into sine and cosine feature representations, and normalized using the minimum and maximum normalization function to transform the one-dimensional linear representation of time into a two-dimensional periodic feature to obtain the time feature; The semantic information of POI is extracted through time frequency and text mining to obtain POI semantic features.
4. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information as claimed in claim 3, characterized in that: The semantic information of POI is extracted through time frequency and text mining to obtain POI semantic features, including: Taking 1 hour as the division unit, 1 day is divided into 24 time intervals. The spatiotemporal trajectory data is traversed. For the time when each POI point appears in the trajectory, the number of times it appears in the corresponding time interval is counted to obtain the 24-dimensional time feature of each POI point, and then normalized. The value of each dimension is replaced by the percentage of the frequency of appearance in the time interval to the frequency of appearance in the whole day, so that the sum of the dimension values is 1, and the time attribute of the POI is obtained, where the time attribute is the access heat distribution of the POI in different time intervals of 1 day.
5. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information as claimed in claim 4, characterized in that: The semantic information of POI is extracted through time frequency and text mining to obtain POI semantic features, including: The TF-IDF algorithm is used for text mining. Each POI point type is regarded as a word. The POI sequence passed by each trajectory sequence can be regarded as a document, and each trajectory can be represented as a word sequence. For each track, calculate the word frequency and inverse document frequency of each POI point type, multiply the word frequency and inverse document frequency to get the TF-IDF value of each POI point type in each track as the text attribute of the POI; The TF-IDF values of all POI point types are used as additional dimensions and concatenated with the time attribute to obtain the POI semantic features.
6. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information according to claim 1, characterized in that: The method of constructing a spatiotemporal relationship graph based on POIs in the divided time intervals and sequentially using a spatiotemporal random walk strategy with trajectory perception and a GAT algorithm to learn high-quality representation of nodes includes: According to the spatial characteristics, temporal characteristics and POI semantic characteristics of the region, a spatiotemporal relationship graph based on POI is constructed in the divided time interval; The initial representation of vertices in the spatiotemporal relationship graph is learned by using a trajectory-aware time-space integrated random walk strategy. In the sequence sampling stage, the time-space relationship graph is walked according to the sampling points of the trajectory sequence to obtain the initial node vector that can capture both time and space features. The initial representation of the vertex is obtained, and the GAT algorithm is used to capture the neighbor node characteristics of the trajectory in the spatiotemporal network in each time interval.
7. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information according to claim 1, characterized in that: According to the spatiotemporal trajectory data and the learned node representation, a model T-LSTM with enhanced temporal expression capability is constructed to learn the final representation of the trajectory sequence, including: According to the spatiotemporal trajectory data and the learned node representation, the initial vector sequence of the trajectory is obtained, and the time features are converted into sine and cosine features as the input of the attention layer; Generate Q, K, V vectors through matrix multiplication, calculate the attention score through scaled dot product attention, and perform weighted summation based on the attention score to obtain the weighted feature representation; The high-quality representation of nodes and the temporal features with attention mechanism are used as the input of the LSTM layer, and the final input features are obtained through a multi-layer perceptron. By combining the temporal attention and LSTM layers, a model T-LSTM with enhanced temporal expression ability is constructed, and the output of the last time step of T-LSTM is used as the trajectory embedding.
8. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information as claimed in claim 1, characterized in that: The graph-based two-level contrastive loss function includes a node-level semantic loss function and a trajectory-level contrastive loss function. The node-level semantic loss function is used to strengthen the learning of semantic information in trajectory representation, and the trajectory-level contrastive loss function is used to optimize the overall similarity of trajectories.
9. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information as claimed in claim 8, characterized in that: The node-level semantic loss functions include: Given a node and After obtaining the node representation in step S3, the corresponding embedding vectors are and , using the cosine similarity function as a function to measure similarity: ; A strategy for positive and negative sampling of nodes passed by the trajectory is used to calculate point similarity loss, and contrast loss is used as the semantic loss function at the node level.
10. The method for calculating the similarity of vehicle spatiotemporal trajectories based on semantic information as claimed in claim 8, characterized in that: The contrastive loss functions at the trajectory level include: In step S1, the similarity matrix is obtained as the true ground distance of the trajectory, and the trajectory with the most similarity in the similarity matrix is extracted as the positive sample, and the remaining trajectories are negative samples. The core of model learning is to learn a mapping function to encode the trajectory sequence into a representation vector; Given any two trajectories, the representation vectors are obtained through model learning, and the cosine similarity function is used as the function to measure the similarity. The goal is to maximize the cosine similarity between the given trajectory and its most similar trajectory, minimize the cosine similarity between the given trajectory and the negative sample, and use the contrast loss as the contrast loss function at the trajectory level.
Citation Information
Patent Citations
Semantic track similarity calculation system and method based on self-attention mechanism
CN112328721A
Method for discovering traveling vehicles based on natural semantic processing
CN114186582A
Network embedding method fusing community connection information and storage medium
CN114691934A
Truck path selection analysis method based on inverse reinforcement learning
CN117455330A
Trajectory prediction method based on comparative learning feature dimension reduction
CN117854597A
Cited By
Intelligent campus safety management early warning method and system based on big data
CN120564337A
Lane-level flow detection and prediction method, electronic equipment and storage medium
CN120808290A
Compact ground wave radar track association method and system
CN121765358A
Compact ground wave radar track association method and system
CN121765358B