A method for calculating bus trajectory similarity based on twin neural networks
Through the method based on twin neural network, the bus lines are preprocessed and feature extraction, which solves the problem of similarity calculation of bus trajectory in the prior art, and achieves more accurate and efficient similarity calculation.
Patent Information
- Application Number
- CN202210394036.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-14
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2042-04-14
AI Technical Summary
The existing bus trajectory similarity calculation methods are difficult to process bus routes. Traditional methods such as LCSS and Hausdorff distances are not suitable for continuous scenarios of bus trajectory, and ignore the local direction information of the trajectory.
The bus trajectory similarity calculation method based on twin neural networks is adopted to perform line preprocessing on bus lines, including obtaining spatial coordinate point sequences, encrypting nodes, converting them into polar coordinates, and combining with neural networks for embedded vector expression. Then, the trajectory features are extracted by a bidirectional LSTM, and the loss calculation is performed using a twin neural network to compare the loss function, and the model is optimized to calculate the trajectory similarity.
This method can more accurately calculate the similarity of bus lines, enhance the characteristic distance between different lines, simplify the task framework and process, and have better generalization capabilities.
Smart Images

Figure CN114860859B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of public transportation, and in particular relates to a method for calculating bus trajectory similarity based on a twin neural network. Background Art
[0002] Bus routes are typical spatial data, which can be sourced from bus route planning or management systems, or from the actual running tracks of bus routes (collecting coordinate points through vehicle-mounted GPS). Measuring the similarity of bus routes in spatial location and spatial structure can provide a basis and reference for bus network optimization.
[0003] Similarity is a fundamental problem in artificial intelligence research. Image classification can be understood as calculating the similarity between the image to be classified and the known type, while text classification can be understood as the semantic similarity between the text to be classified and the known type. Similarity is the core research content of machine learning algorithms such as classification and clustering, and also plays an important role in image analysis and natural language understanding. Commonly used methods for measuring similarity include absolute deviation, root mean square error, cosine similarity, KL divergence, cross entropy, etc. These methods are all based on the quantitative expression of the research target. For example, images are expressed in vector form through CNN convolutional networks, and words and sentences are expressed through word2vec or various language models to form expression matrices. Language models such as CNN networks and Transformer have become the mainstream methods for replacing artificially designed features such as hog, sift, and tf-idf to achieve automatic feature extraction.
[0004] However, spatial data is usually represented as an ordered sequence of spatial points. Unlike text or images, their similarity includes both consistency in spatial position and consistency in spatial shape. Currently, representation learning based on deep learning is widely used in various tasks and scenarios of text and images. It is of pioneering significance to explore the feature representation and similarity measurement of spatial data and geometric figures.
[0005] The similarity of bus routes refers to the fact that the starting and ending points and overall directions of two bus routes are basically the same. For example, if the up and down directions of a bus route are similar, we consider the two bus routes to be similar. The following are the conditions for two bus routes to be similar:
[0006]
[0007] where p i and q j Represents any point on two routes. In simple terms, the distance from any point on the trajectory to the other trajectory is less than the set threshold. Because the number of points on the route is infinite, it is difficult to obtain the similarity of the routes according to this condition. It is necessary to use machine learning or reinforcement learning to judge the similarity of trajectories.
[0008] Traditionally, the method for trajectory similarity is LCSS (longest Common Subsequence). For example, Chen Shaoquan et al. used the improved LCSS method to analyze the similarity of user trajectories in "Research on Mobile User Trajectory Similarity Query Algorithm Based on Improved LCSS". However, the trajectory is a non-continuous and complex trajectory of users traveling to multiple destinations at multiple times, which is not suitable for continuous scenarios such as public transportation. In addition, Wang Pei et al. proposed a spatiotemporal trajectory segment distance measurement formula based on time synchronization in "Measuring Spatiotemporal Trajectory Similarity Using Hausdorff Distance", which converted the research object of trajectory measurement from trajectory points to trajectory segments, and verified the algorithm in the Internet Weibo check-in trajectory and taxi trajectory. In this method, the time attribute is obvious and it is not suitable for the scenario of public transportation trajectory similarity measurement. In order to solve the problem of slow trajectory matching calculation speed, Jiang Li et al. proposed a trajectory feature extraction method based on multiple rotations of spatial coordinates and then calculating the trajectory mean and variance in "An Efficient Trajectory Matching Algorithm Based on Spatial Coordinate System Rotation". The similarity of the trajectory is then calculated using methods such as the Pearson correlation coefficient. However, this method ignores the local direction information of the trajectory and has shortcomings in dealing with the similarity of multiple repeated bus routes. Summary of the invention
[0009] In view of the defects and problems existing in the current calculation of bus trajectory similarity, the present invention provides a bus trajectory similarity calculation method based on a twin neural network.
[0010] The solution adopted by the present invention to solve the technical problem is: a bus trajectory similarity calculation method based on a twin neural network, comprising the following steps:
[0011] Step 1: construct a bus route set, select two bus routes from the bus route set, and perform route preprocessing on the two bus routes respectively; the route preprocessing includes the following steps:
[0012] S1, obtain the spatial coordinate point sequence of the line;
[0013] S2, encrypt the nodes of the line;
[0014] S3, transform the spatial coordinate points from plane coordinates into polar coordinates, and then embed them with neural networks to complete the embedded vectorized expression of the data;
[0015] Step 2: Shift the bus routes, and use the shifted routes as similar trajectories and positive samples; randomly sample negative samples from the route set to obtain organized training samples, where each training sample includes two bus routes and labels of whether the two bus routes are similar;
[0016] Step 3: Use bidirectional LSTM to extract trajectory features of the route, add two fully connected layers to process the extracted trajectory features, and extract the feature vector of the route; use the twin neural network contrast loss function to calculate the loss of the feature vectors of the two extracted bus routes.
[0017]
[0018] Where: D represents the difference in feature expression of two samples, T∈[0,1] represents whether the samples are similar, T=0 represents dissimilarity; 1 represents similarity, closs only has the first term on the right side of the formula, and gradient descent minimizes the loss function, so the feature expression of the two samples tends to be consistent; when the two samples are dissimilar, closs only has the second term on the right side of the formula, and gradient descent minimizes the loss function, that is, it is necessary to make D tend to the hyperparameter c, that is, the feature differences of different categories tend to a certain prediction value;
[0019] Step 4: Train the model using the organized training data and the route features extracted after route preprocessing, and optimize the model through stochastic gradient descent to obtain a trained prediction model;
[0020] Step 5: Use the trained model to calculate the difference between the characteristics of the two routes and obtain the similarity between the two routes.
[0021] In the above-mentioned bus trajectory similarity calculation method based on the twin neural network, step 2 also includes processing the sampled data to ensure that the two routes are not similar, wherein the processing rules are:
[0022] ds i =Distance(p i ,line2)
[0023] p i ∈line1
[0024] Where: ds i Indicates p i Distance to line2; p i is any node of line1; if more than 50% of the nodes on line1 have a distance to line2 greater than β, it means that the two lines are not similar, where β is slightly larger than the road width.
[0025] In the above-mentioned bus trajectory similarity calculation method based on twin neural network, the absolute error is used in step 5 to calculate the similarity of two routes.
[0026] ∑feature vector2 -feature vector1 <ε
[0027] Where ε is the set threshold; vector1 represents the quantitative features of line 1; vector2 represents the quantitative features of line 2; when ε is less than the set threshold, the two input samples are considered similar, otherwise they are considered dissimilar.
[0028] Beneficial effects of the present invention: The present invention encrypts the bus track and aligns the characteristic length of the track while obtaining enough track points; the present invention converts the plane coordinates of the line track points into polar coordinates, which can make full use of the direction information of the bus line.
[0029] The present invention makes full use of the learning ability of deep learning algorithms, extracts features through route expressions converted by neural networks, and calculates similarities. This method is different from the original expression based on spatial coordinate point sequences and spatial geometric line graphics. It combines the two steps of quantitative expression and similarity calculation of bus routes, and integrates the two-stage task into a single-stage task. Using this method to obtain the similarity of bus routes can simplify the task framework and process. Compared with other similarity calculation methods, the twin neural network model structure of the present invention can increase the feature distance between dissimilar routes while reducing the feature distance between similar routes, making the similarity measurement of spatial linear units more accurate and with better generalization ability. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 The figure is a calculation flow chart of the present invention. DETAILED DESCRIPTION
[0031] The measurement of similarity has important applications in various fields. For example, in the field of computer vision, the task of pedestrian re-identification is to determine whether they are the same target by calculating the similarity of people in different pictures; in the field of NLP, text classification and sentiment analysis are also performed by measuring the semantic similarity of different sentences. There are many methods for quantifying similarity. Commonly used methods include Pearson correlation coefficient, KL divergence, root mean square error, absolute error, etc. The present invention provides a method for calculating the similarity of bus trajectories, which is further explained below in conjunction with the accompanying drawings and embodiments.
[0032] Embodiment 1: This embodiment provides a method for calculating bus trajectory similarity based on a twin neural network, the method comprising the following steps:
[0033] Step 1: construct a bus route set, select two bus routes from the bus route set, and perform route preprocessing on the two bus routes respectively; the route preprocessing includes the following steps:
[0034] S1. Get the spatial coordinate point sequence of the line
[0035] S2, encrypt the nodes of the line;
[0036] S3. Convert the spatial coordinate points from plane coordinates to polar coordinates
[0037] S4, combine neural network to complete the embedded vectorized expression of data;
[0038] Step 2: Sample data organization
[0039] The bus routes are translated, and the translated routes are used as similar trajectories and positive samples. Negative samples are randomly sampled from the route set to obtain organized training samples, where each training sample includes two bus routes and labels indicating whether the two bus routes are similar.
[0040] Step 3: Model construction
[0041] S1. Extract the trajectory features of the bus line through the bidirectional LSTM, add two fully connected layers to further process the extracted trajectory features, and extract the feature vector of the line;
[0042] S2, using the twin neural network contrast loss function to calculate the loss of the feature vectors of the two bus routes extracted;
[0043]
[0044] Where: D represents the difference in feature expression of two samples, T∈[0,1] represents whether the samples are similar, T=0 represents dissimilarity, and 1 represents similarity; closs only has the first term on the right side of the formula, and gradient descent minimizes the loss function, so the feature expressions of the two samples tend to be consistent; when the two samples are dissimilar, closs only has the second term on the right side of the formula, and gradient descent minimizes the loss function, that is, it is necessary to make D tend to the hyperparameter c, that is, the feature differences of different categories tend to a certain prediction value;
[0045] Step 4: Model training and prediction
[0046] The model is trained by using the organized training samples and the route features extracted after route preprocessing, and the model is optimized by stochastic gradient descent to obtain a trained prediction model;
[0047] Step 5: Calculate the route characteristics of the predicted samples through the trained prediction model, calculate the difference between the two route characteristics, and calculate the similarity between the two routes;
[0048] ∑feature vector2 -feature vector1 <ε
[0049] Where: ε is the set threshold; vector1 represents the quantitative characteristics of line 1; vector2 represents the quantitative characteristics of line 2.
[0050] Example 2: This example provides a method for calculating the similarity of bus trajectories based on a twin neural network. The following describes the calculation process and method of bus trajectory similarity through line preprocessing, sample data organization, model construction, model training and prediction.
[0051] 1. Line preprocessing
[0052] Points, lines, and surfaces are three core spatial data types, and bus routes are typical line spatial data types. In the GIS field, a line is composed of an ordered sequence of points. In this embodiment, the line spatial data type vector structure represented by the Well-known Text markup language formulated by the Open GIS Consortium (OGC) is used, such as LineString(((0,0),(1,1))), where ((0,0)(1,1)) is the sequence of spatial coordinate points representing the line.
[0053] This embodiment encrypts the nodes of the line space data. In addition, considering the particularity of the spatial coordinate points (the horizontal and vertical coordinates represent a point), this embodiment uses the position embedding in the transformer to convert the spatial coordinate points from plane coordinates to polar coordinates, and combines the neural network for embedding to complete the vector expression of the data. The quantitative expression process of the bus line is as follows:
[0054] Spatial structure LineString(((0,0),(10,10))) Node encryption (0,0),(2,2),(4,4),(6,6),(8,8),(10,10) Polar coordinate conversion (0,0),(2.83,pi / 4),(5.66,pi / 4),(8.49,pi / 4),(11.31,pi / 4),(14.14,pi / 4) Embedded Expression (0,0.98,1.17,1.35,1.50,1.63)
[0055] As an example, the reference formula for the embedded expression of polar coordinate conversion is: sin(length)+angle, which requires neural network operation.
[0056] 2. Sample data organization
[0057] Conventional bus routes include uplink and downlink. Generally, these two bus routes can be considered similar. In addition, in order to obtain more sample data, the bus routes are appropriately translated, and the routes before and after the translation are used as similar trajectories, i.e., positive examples; and negative samples are extracted from the route set by random sampling (the sampled data is simply processed, such as distance judgment, to ensure that the two routes are not similar. For example, the following rules can be referred to:
[0058] ds i =Distance(p i , line2)
[0059] p i ∈line1
[0060] Where: ds i Indicates pi Distance to line2; p i is any node of line1; if more than 50% of the nodes on line1 have a distance to line2 greater than β, and β is slightly greater than the road width, such as 50 meters, then it is confirmed that the two lines are not similar.
[0061] 3. Model construction
[0062] Since the similarity of bus routes focuses more on the repetitiveness of the spatial position and spatial structure of two trajectories, and has no requirements on the direction of the routes, in order to better capture this kind of information, the design uses bidirectional LSTM to extract trajectory features, and adds two fully connected layers Linear1 and Linear2. The trajectory features extracted by BiLSTM are successively passed to the two fully connected layers Linear for feature integration to obtain a more appropriate feature vector representation; then the model is built and optimized using stochastic gradient descent;
[0063] The loss of the two extracted line feature vectors is calculated using the twin neural network contrast loss function.
[0064]
[0065] Where: D represents the difference in feature expression between two samples, T∈[0,1] represents whether the samples are similar, T=0 represents dissimilar, and 1 represents similar.
[0066] From the comparison loss function, we can see that when two samples are similar, that is, T = 1, closs only has the first term on the right side of the formula, and gradient descent minimizes the loss function, so the feature expressions of the two samples tend to be consistent. When two samples are dissimilar, closs only has the second term on the right side of the formula, and gradient descent minimizes the loss function, that is, it is necessary to make D tend to the hyperparameter c, that is, the feature differences of different categories tend to a certain predicted value.
[0067] The loss calculation in this embodiment is based on the feature vectors of the two lines extracted after the neural network operation.
[0068] Model training: Through the organized training data, line preprocessing is performed, that is, line node encryption and polar coordinate conversion, line quantization is completed, and line feature extraction is completed through the LSTM layer and the fully connected layer. Then, the distance between the two features is calculated through the comparison loss function, and the error back propagation is performed to complete the update of the network weight.
[0069] Inference prediction: Compared with the training stage, there is no error back propagation process. After the prediction sample is calculated through the trained network to obtain the features, the difference between the two features is calculated to complete the prediction of whether they are similar, such as using absolute error, as follows:
[0070] ∑feature vector2 -feature vector1 <ε
[0071] Where ε is the set threshold; vector1 represents the quantitative features of line 1; vector2 represents the quantitative features of line 2; when ε is less than the set threshold (such as 0.2), the two input samples are considered similar, otherwise they are considered dissimilar.
Claims
1. A bus trajectory similarity calculation method based on twin neural network, characterized by: The following steps are involved: Step 1: construct a bus route set, select two bus routes from the bus route set, and perform route preprocessing on the two bus routes respectively; The line preprocessing comprises the following steps: S1, obtain the spatial coordinate point sequence of the line; S2, encrypt the nodes of the line; S3, transform the spatial coordinate points from plane coordinates into polar coordinates, and then embed them with neural networks to complete the embedded vectorized expression of the data; Step 2: Process the sampled data to ensure that the two lines are not similar, where the processing rules are: ds i =Distance(p i ,line2) p i ∈line1 Where: ds i Indicates p i Distance to line2; p i is any node of line1; if more than 50% of the nodes on line1 have a distance to line2 greater than β, it means that the two lines are not similar, where β is slightly larger than the road width; The bus routes are translated, and the translated routes are used as similar trajectories and as positive samples; negative samples are randomly sampled from the route set to obtain organized training samples, where each training sample includes two bus routes and labels of whether the two bus routes are similar; Step 3: Use bidirectional LSTM to extract trajectory features of the route, add two fully connected layers to process the extracted trajectory features, and extract the feature vector of the route; use the twin neural network contrast loss function to calculate the loss of the feature vectors of the two extracted bus routes. Where: D represents the difference in feature expression of two samples, T∈[0,1] represents whether the samples are similar, T=0 represents dissimilarity; 1 represents similarity, cLoss only has the first term on the right side of the formula, and gradient descent minimizes the loss function, so the feature expression of the two samples tends to be consistent; when the two samples are dissimilar, cLoss only has the second term on the right side of the formula, and gradient descent minimizes the loss function, that is, it is necessary to make D tend to the hyperparameter c, that is, the feature differences of different categories tend to a certain prediction value; Step 4: Train the model using the organized training data and the route features extracted after route preprocessing, and optimize the model through stochastic gradient descent to obtain a trained prediction model; Step 5: Use the trained model to calculate the difference between the characteristics of the two routes and obtain the similarity between the two routes.
2. The bus trajectory similarity calculation method based on twin neural network according to claim 1 is characterized in that: In step 5, the absolute error is used to calculate the similarity of the two routes. Σfeature vector2 -feature vector1 <ε Where: ε is the set threshold; feature vector1 Represents the quantitative characteristics of line 1; feature vector2 Represents the quantitative characteristics of line 2; when ε is less than the set threshold, the two input samples are considered similar, otherwise they are considered dissimilar.