Taxi Trajectory Anomaly Detection Method Based on LSTM Network and Attention Mechanism
By using the LSTM network and attention mechanism in the taxi trajectory abnormal detection, the position, time and speed characteristics in the trajectory are extracted, and the problems of insufficient feature extraction and high time-consuming in the existing methods are solved, and higher detection accuracy and detection results are achieved that are closer to the real situation.
Patent Information
- Application Number
- CN202210213647.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-03
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2042-03-03
AI Technical Summary
The existing taxi trajectory abnormality detection methods are insufficient to extract the feature, which consumes a lot of time, and the trajectory preprocessing method is relatively simple, resulting in low detection accuracy.
The taxi trajectory anomaly detection method based on the LSTM network and attention mechanism is adopted to extract the position, time and speed features in the trajectory through the preprocessing, feature extraction, and model construction and training of the vehicle trajectory data, and improve the training effect of the model through the attention mechanism.
It improves data quality, mines out various features in the trajectory, improves the accuracy of detection, and makes the detection results closer to the real situation, which is of great significance in the fields of taxi fraud detection.
Smart Images

Figure CN114882069B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of taxi trajectory anomaly detection methods. More specifically, the present invention relates to a taxi trajectory anomaly detection method based on an LSTM network and an attention mechanism. Background Art
[0002] With the rapid expansion of the scale of the taxi industry, a large amount of taxi trajectory data has been generated and collected. The analysis of these trajectory data can help researchers obtain a lot of valuable information, such as implicit facts related to location prediction, interest patterns, etc. Among them, trajectory anomaly detection is one of the most popular research topics. Trajectory outliers refer to trajectories in a trajectory dataset that are significantly different from other data patterns or routes.
[0003] Traditional taxi trajectory anomaly detection algorithms include four categories: classification-based detection techniques, historical similarity-based detection techniques, distance-based detection techniques, and grid partition-based detection techniques. In the training stage of the classification-based detection technique, a classifier is learned and constructed through a manually selected feature dataset. In the testing stage, the trajectories are divided into normal and abnormal categories according to the classifier. The detection technique based on historical similarity mines all frequent patterns from a large amount of trajectory data collected historically to establish a feature model, and data different from the feature pattern is identified as an abnormal trajectory. The distance-based detection technique regards trajectories with a relatively large distance from most trajectories as abnormal. The grid partition-based detection technique identifies abnormal grid cell sequences from cells divided into equal-sized grids.
[0004] The existing methods have the following deficiencies:
[0005] 1. Only the location information of the taxi trajectory is considered, and the time and speed information contained in the taxi trajectory is not mined. Insufficient feature extraction will reduce the accuracy of anomaly detection.
[0006] 2. The distance-based matching method is very time-consuming. The time complexity of methods such as LCSS and EDR reaches O(m*n), and the Euclidean distance metric requires the same trajectory points, making it difficult to apply to real scenarios.
[0007] 3. The preprocessing process is relatively simple. The original taxi trajectory dataset includes a large number of redundant points and noise points, which must be removed before anomaly detection.
[0008] LSTM is a variant of the recurrent neural network (RNN) in deep learning, which can add or delete information through a gated network. Due to its special network structure characteristics, it shows excellent learning ability in sequence data. Many studies have shown that capturing the correlation features between trajectories through an LSTM network is a good choice for exploring and solving the problem of trajectory anomaly detection.
[0009] The attention mechanism draws on human visual attention. When humans observe external things, there is a selectivity, that is, they focus on the part of the area that they are interested in and ignore other irrelevant details, which is the so-called attention focus. During the training process of taxi trajectory data, the inflection points of the trajectory and the feature information should have a higher weight for the training of the model. Applying the attention mechanism to the LSTM network can capture the long-range dependencies in the features and can increase the weight of key trajectory points during the training process. Summary of the Invention
[0010] In order to overcome the above defects of the prior art, the present invention provides a taxi trajectory anomaly detection method based on the LSTM network and the attention mechanism. The technical problem to be solved by the present invention is: the technical problem that the feature extraction of the trajectory anomaly detection method in the prior art is insufficient, time-consuming, and the trajectory preprocessing method is relatively simple.
[0011] To achieve the above object, the present invention provides the following technical solutions:
[0012] A taxi trajectory anomaly detection method based on the LSTM network and the attention mechanism, comprising the following steps:
[0013] Step 1: Vehicle trajectory data preprocessing: Collect taxi trajectory data. The trajectory data is a trajectory sequence T composed of longitude, latitude, and timestamp triples p r : p1→p2→…p n , remove redundant points and noise points in the original dataset, and transform the map where it is located into a 100*100m grid, convert the trajectory into a grid sequence, convert the grid sequence into a vector representation through skip-gram, and calculate the speed of the trajectory points to convert them into corresponding road grade representations; Calculate and extract urban feature points according to the actual situation on the day of urban data collection, and divide the trajectory dataset into a training set, a validation set, and a test set;
[0014] Step 2: Feature extraction: Discretize the trajectory data, extract the position features from the grid cell ID sequence of the trajectory, discretize the continuous timestamp at an average time interval to extract time features, use the sliding window algorithm to obtain speed features, and splice the feature speed with the position features and time features. After being transformed into a word vector sequence through word2vec, construct an embedding layer;
[0015] Step 3: Model construction and training. Construct an LSTM-attention model, load the features extracted in Step 2 as input into the LSTM-attention model for training, extract features through the LSTM layer, and the attention layer differentiates the weights between inflection points and non-inflection points. After training is completed, input the features of the test dataset into the LSTM-attention model to verify the classification accuracy of the model;
[0016] Step 4: After the input data passes through the embedding layer, LSTM layer, attention layer, and output layer, the desired output is obtained. If this output is different from the actual category of the trajectory, the backpropagation algorithm will backpropagate the error to the output layer, and the neurons in each layer will update the parameters in the network structure according to this error, and visualize the anomaly detection results.
[0017] Furthermore, the preprocessing of the vehicle trajectory data includes the following steps:
[0018] Step 1.1: Collect taxi trajectory data through the vehicle networking data, and use the Douglas-Peucker algorithm to filter out redundant sampling point data records in the dataset; the specific steps are as follows: Connect the start and end points of a section of trajectory into a straight line, calculate the perpendicular distance from all points on this section of trajectory to this straight line, and find the maximum distance value d max , use d max Compare with the predefined threshold D: If d max < D, all the intermediate points on this curve are discarded; if d max ≥ D, retain the coordinate points corresponding to d max , and take this point as the boundary to divide the trajectory into two parts, and repeat the above steps for these two parts until all redundant sampling point data are filtered;
[0019] Step 1.2: Judge and remove noise points. Assume P i-1 , P i , P i+1 are three points arranged in the order of sampling time. If P i is a possible abnormal point, then the average speed difference between P i-1 to P i and P i to P i+1 is relatively large. Calculate the distance based on speed and time. If the path length from t i-1 to t i is less than the maximum reachable displacement r1 within this time period, and the path length from time t i to t i+1 is less than the maximum reachable displacement r2 within this time period, then P iThe possible area. If Pi appears within the area, Pi is set as a normal point; otherwise, it is a noise point that needs to be removed.
[0020] Step 1.3: Convert the original trajectory into a discrete sequence. Divide the entire map into grid cells of equal size of 100*100m. Each grid cell is marked with a separate ID. Each GPS point is converted into the ID of the grid cell it is in, and the trajectory sequence is converted into a grid cell ID sequence.
[0021] Step 1.4: Use the skip-gram model to learn the representation of the grid, so that adjacent grids have similar representations in the vector space, and convert the trajectory into a grid cell ID sequence into a vector.
[0022] Step 1.5: Calculate the speed of the trajectory points and use a graph to convert the speed of the trajectory points into the corresponding road grade. Convert the trajectory from the grid cell ID representation into a trajectory point speed sequence; and calculate and extract urban feature points according to the actual situation on the day of urban data collection.
[0023] Further, the said Step 2 includes the following steps:
[0024] Step 2.1: Sliding window feature extraction. Suppose the maximum offset value is w and the minimum is 1; the moving speed feature of each window has 3 dimensions: average speed, maximum speed, and minimum speed {mean, max, min}. The statistical data |max - min| represents the change in the window speed. If the statistical data |max - min| is not 0, then update the offset to half of the previous value until the offset is 1; if the statistical data |max - min| is 0, then update the offset to 2 times the previous value until the offset reaches the maximum value.
[0025] Step 2.2: Location information mining. The grid sequence represented by the vector includes the location information of the trajectory.
[0026] Step 2.3: Time information mining. Discretize the continuous timestamps at an average time interval, and use the skip-gram model to obtain the vector representation sequence TP of the trajectory points corresponding to the timestamps. i ;
[0027] Step 2.4: Speed information mining. Use the trajectory point speed sequence obtained in Step 2.1 to obtain the trajectory point speed sequence representation SP by the skip-gram model. i .
[0028] Further, the said Step 3 includes the following steps:
[0029] Step 3.1: Construct the embedding layer: Connect the urban feature points and the velocity sequence feature representations, initialize the weights with pre-trained vectors, and map the sequence into a unified low-dimensional vector by means of traditional word embedding methods;
[0030] Step 3.2: Construct the LSTM layer: Take the output feature matrix of the embedding layer as a time series, input the feature vector into the input layer at time t, and output the result through the activation function σ; Input the output result, the hidden layer output at time t-1, and the information stored in the cell unit at time t-1 into the LSTM node; Through the sorting of the input gate, output gate, forget gate, and cell unit, output the data to the attention layer; The calculation formula of LSTM is:
[0031] f t =σ g (W f x t +U f c t-1 +b f )
[0032] i t =σ g (W i x t +U i c t-1 +b fi )
[0033] o t =σ g (W o x t +U o c t-1 +b o )
[0034] c t =f t *c t-1 +i t *σ c (W c x t +b c )
[0035] h t =o t *σ h (c t )
[0036] Where x t is the state of the previous unit, f t is the forget gate, with a range of [0,1]; i t is the input gate, with a range of [0,1].
[0037] Step 3.3: Construct an attention layer. Input the hidden layer state sequence obtained in Step 3.2 into the attention layer, and use the Softmax function to normalize the attention scores to obtain a weight distribution. The calculation process formula can be expressed as:
[0038] a tj = v T tanh((W s s t-1 ) + W h h t )
[0039]
[0040] where T is the number of trajectory points, tanh is the hyperbolic tangent function, and v, W s , W h are learned parameters.
[0041] Step 3.4: Construct an output layer. The output layer consists of a fully connected layer, a Dropout layer, and a Softmax layer. The vector output after Step 3.3 is input into the fully connected layer, and the Dropout layer and Softmax layer convert it into probabilities; the label paper, that is, the category y to which the trajectory belongs, is output through the argmax function. When the parameter matrix is W and b is the bias, its calculation formula is as follows:
[0042] y = softmax(W·h i + b).
[0043] Furthermore, Step 4 includes the following steps:
[0044] Step 4.1: Take the obtained classification result y i and the current correct label value y'i as the two inputs of the cross-entropy loss function respectively, and calculate the loss value; transfer the error signal to the output of each layer, and then through the derivative of each layer's function with respect to the parameters, the gradient of the parameters can be obtained; then update and calculate the network parameters that affect model training and model output through the Stochastic Gradient Descent (SGD) optimizer to make it approach or reach the optimal value, so as to minimize the loss function. After obtaining the optimal model, input the validation set to detect abnormal trajectories and visualize them.
[0045] The beneficial effects of the present invention are as follows. The taxi trajectory anomaly detection method based on the LSTM network and the attention mechanism of the present invention removes the noise points and redundant points in the original trajectory, improving the quality of the data. It extracts the location, time, and speed features contained in the trajectory and maps the sequence into a unified low-dimensional vector. An attention mechanism module is proposed, making the impacts of different points (inflection points and non-inflection points) and different features (such as different speeds) on model training different, achieving a better training effect. The detected abnormal trajectories by this detection method are closer to the real situation and have a higher accuracy, which is conducive to the analysis of the causes of taxi abnormal trajectories and has great significance in the fields such as taxi fraud behavior detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 is the overall flowchart of the present invention;
[0047] Figure 2 is the detailed processing process of the sliding window module in step 2 of the present invention;
[0048] Figure 3 is the LSTM network structure diagram described in step 3 of the present invention;
[0049] Figure 4 is the overall network structure diagram described in step 3 of the present invention. DETAILED DESCRIPTION OF THE INVENTION
[0050] The present invention will be further described below with reference to the accompanying drawings.
[0051] As Figure 1 shown, the taxi trajectory anomaly detection method based on the LSTM network and the attention mechanism of the present invention includes the following steps:
[0052] Step 1: Vehicle trajectory data preprocessing: Collect taxi trajectory data, where the trajectory data is a trajectory sequence T composed of (longitude, latitude, timestamp) triples p r : p1 → p2 → … p n , removing the redundant points and noise points in the original dataset. And dividing the map into 100*100m grids, converting the trajectory into a grid sequence, converting the grid sequence into a vector representation through skip-gram, and calculating the speed of the trajectory points to convert them into corresponding road grade representations. Calculate and extract the urban feature points according to the actual situation on the day of urban data collection, and divide the trajectory dataset into a training set, a validation set, and a test set.
[0053] Specifically, in step 1, the vehicle trajectory data preprocessing includes the following steps:
[0054] Step 1.1: Collect taxi trajectory data through the vehicle networking. To address the data redundancy problem caused by road congestion, accidents, equipment failures, etc., the Douglas-Peucker algorithm is used to filter out redundant sampling point data records in the dataset. The specific steps are as follows: Connect the start and end points of a section of the trajectory to form a straight line, calculate the perpendicular distance from all points on this section of the trajectory to this straight line, and find the maximum distance value d max , use d max to compare with the predefined threshold D: If d max < D, all the intermediate points on this curve are discarded; if d max ≥ D, retain the coordinate points corresponding to d max , and take this point as the boundary to divide the trajectory into two parts. Repeat this method for these two parts until all redundant sampling point data are filtered out.
[0055] Step 1.2: Identify and remove noise points. Assume P i-1 , P i , P i+1 are three points arranged in the order of sampling time. If P i is a possible outlier, then the average speed difference between P i-1 to P i and P i to P i+1 is relatively large. Calculate the distance based on speed and time. If the path length from t i-1 to t i is less than the maximum achievable displacement r1 within this time period, and the path length from time t i to t i+1 is less than the maximum achievable displacement r2 within this time period, then the possible area where P i may appear can be projected according to the maximum driving speed v, r1, and r2 of the taxi. If Pi appears within the area, then Pi is set as a normal point; otherwise, it is a noise point and needs to be removed.
[0056] Step 1.3: Convert the original trajectory into a discrete sequence. Divide the entire map into 100*100m equal-sized grid cells, each grid cell is marked with a separate ID, and each GPS point is converted into the ID of the grid cell it is in, converting the trajectory sequence into a grid cell ID sequence.
[0057] Step 1.4: Use the skip-gram model to learn the representation of the grid, so that adjacent grids have similar representations in the vector space, and convert the trajectory into a sequence of grid cell IDs into a vector.
[0058] Step 1.5: Calculate the speed of the trajectory points and convert the speed of the trajectory points into the corresponding road grades using a graph, convert the trajectory represented by grid cell IDs into a sequence of trajectory point speeds. And calculate and extract urban feature points according to the actual situation on the day of urban data collection
[0059] Step 2: Feature extraction: Discretize the trajectory data, extract the location features from the sequence of grid cell IDs of the trajectory, discretize the continuous timestamps at an average time interval to extract time features, use the sliding window algorithm to obtain speed features, splice the urban feature speeds with the feature location features and time features, and convert them into a sequence of word vectors through word2vec to construct an embedding layer.
[0060] In Step 2, the trajectory feature embedding process includes the following steps:
[0061] Step 2.1: Sliding window feature extraction. Suppose the maximum offset value is w and the minimum is 1. Each window has three-dimensional average speed, maximum speed, and minimum speed {mean, max, min} for the moving speed feature. The statistical data |max - min| represents the change in the window speed. If the statistical data |max - min| is not 0, then update the offset to half of the previous value until the offset is 1. If the statistical data |max - min| is 0, then update the offset to twice the previous value until the offset reaches the maximum value.
[0062] As Figure 2 shown, the numerical values 1, 2, and 3 are the conversion of the trajectory point speed sequence into the corresponding road grades (1 is the highway, 2 is the main road, and 3 is the secondary road). Each circle represents the current window size. Assume that W and offset record the width and offset of the sliding window respectively. Make the maximum offset value W and the minimum value 1. The offset value of offset is adjusted according to the change in the speed interval in the sliding window. In this way, most of the speed changes are captured.
[0063] Step 2.2: Location information mining. The sequence vector LC of trajectory grid cells obtained from Step 1 i includes the location information of the trajectory.
[0064] Step 2.3: Time information mining. Discretize the continuous timestamps at an average time interval, and use the skip - gram model to obtain the vector representation sequence TP of the trajectory points corresponding to the timestamps i .
[0065] Step 2.4: Speed information mining. Use the trajectory point speed sequence obtained in Step 2.1 to obtain the sequence representation SP of the trajectory point speeds through the skip - gram model i .
[0066] Step 3: Model construction and training. Construct an LSTM-attention model, load the features extracted in Step 2 as inputs into the LSTM-attention model for training, extract features through the LSTM layer, and the attention layer differentiates the weights between inflection points and non-inflection points, where inflection points have higher weights for abnormal trajectories. The attention layer differentiates feature weights, and speed features have higher weights for classifying abnormal trajectories. After training, input the features of the test dataset into the LSTM-attention model to verify the classification accuracy of the model.
[0067] In Step 3, the process includes the following steps:
[0068] Step 3.1: Construct an embedding layer: Concatenate the city features obtained from Step 1.5 and the taxi spatio-temporal and speed sequence feature representations obtained from Step 2.1, initialize the weights with pre-trained vectors, and map the sequence to a unified low-dimensional vector by means of traditional word embedding methods.
[0069] Step 3.2: Construct an LSTM layer: As Figure 3 shown, o t is the output gate, and σ is the sigmoid function. Where h t-1 is the previous hidden layer state, f t is the forget gate, i t is the input gate, o t is the output gate, is the cell state after activation by the tanh function. q t is the updated cell state after forgetting. The long short-term memory neural network has the ability to capture long-distance dependence information. Take the output feature matrix of the embedding layer as a time series, input the feature vector into the input layer at time t, and output the result through the activation function σ. Input the output result, the hidden layer output at time t-1, and the information stored in the cell unit at time t-1 into the LSTM node. Through the sorting of the input gate, output gate, forget gate, and cell unit, output data to the attention layer. The calculation formula of LSTM is:
[0070] f t =σ g (W f x t +U f c t-1 +b f )
[0071] i t =σ g (W i x t +U i c t-1 +bfi )
[0072] o t =σ g (W o x t +U o c t-1 +b o )
[0073] c t =f t *c t-1 +i t *σ c (W c x t +b c )
[0074] h t =o t *σ h (c t )
[0075] where x t is the state of the previous unit, f t is the forget gate, which determines what information to discard from the cell state, ranging from [0, 1]. i t is the input gate, which determines how much information to select from the current state to enter the current c t , ranging from [0, 1].
[0076] Step 3.3: Construct the attention layer. Input the hidden layer state sequence obtained from Step 3.2 into the attention layer. In the attention layer, the influence of inflection points and non-inflection points, and velocity features are distinguished. Assign weights to more important points and more important features, and normalize the attention scores using the Softmax function to obtain the weight distribution. The calculation process formula can be expressed as:
[0077] a tj =v T tanh((W s s t-1 ) + W h h t )
[0078]
[0079] where T is the number of trajectory points, tanh is the hyperbolic tangent function, v, W s , W h are learned parameters.
[0080] Step 3.4: Construct the output layer: The output layer consists of a fully connected layer, a Dropout layer, and a Softmax layer. The Dropout layer is used to avoid overfitting, and the Softmax layer generates probabilities for abnormal trajectory classification. The vector output from step 3.3 is input to the fully connected layer, and the Dropout layer and the Softmax layer are converted into probabilities. The label paper is output through the argmax function, that is, the category y to which the trajectory belongs. When the parameter matrix is W and b is the bias, the calculation formula is as follows:
[0081] y=softmax(W·h i +b).
[0082] like Figure 4 As shown in the figure, the final model network result is obtained, where the input is the taxi trajectory vector representation after feature extraction, and it passes through the LSTM layer and the attention layer. The output to the attention layer is the hidden state F n As shown. To the output layer, the output layer consists of a fully connected layer, a Dropout layer, a Softmax layer, and a hidden state F n After the fully connected layer, it becomes a series M n The Dropout layer is used to avoid overfitting, and the Softmax generates probabilities for trajectory anomaly classification. The output of the model is the probability that the trajectory is an abnormal trajectory.
[0083] Step 4: After the input data passes through the embedding layer, LSTM layer, attention layer, and output layer, the expected output will be obtained. If this output is different from the actual category of the trajectory, the back propagation algorithm will propagate the error back to the output layer. The neurons in each layer will update the parameters in the network structure according to the error and visualize the anomaly detection results.
[0084] In step 4, the process includes the following steps:
[0085] Step 4.1: Get the classification result y i and the current correct label value y' i They are used as two inputs of the cross entropy loss function to calculate the loss value. The error signal is passed to the output of each layer, and the gradient of the parameter is obtained by taking the derivative of the function of each layer with respect to the parameter. The network parameters that affect model training and model output are then updated and calculated by the stochastic gradient descent (SGD) optimizer to approach or reach the optimal value, thereby minimizing the loss function. After obtaining the optimal model, the validation set is input to detect abnormal trajectories and visualize them.
[0086] The urban feature data includes: travel frequency feature, road segment feature, resident state transition feature, and resident area transition feature. The road segment feature represents the speed feature of the road segment under a given time period, which is characterized by the parameter average speed and variance. Let RS represent the road segment and TS represent the time period. The road segment feature is described as a Gaussian probability distribution X-N(μ,σ 2 ), where X = (RS,TS), μ,σ 2 represent the average speed and variance calculated statistically from the data layer.
[0087] The travel frequency feature represents the amount of vehicle trajectories starting from a given area and time period. The travel frequency feature is represented using the Poisson distribution X-π(λ), where X = (RE,TS), and λ represents the average amount of vehicle trajectories calculated statistically from the data layer. The resident state transition feature represents the transition relationship between various states of residents. The state refers to the category of POI points. Let OS and DS represent the starting state and the ending state respectively. The resident state transition feature is represented by a probability matrix, and each item in the matrix is the value of P(OS = os,DS = ds). The resident area transition feature represents the transition relationship between various areas of residents. Let OR and DR represent the starting area and the ending area respectively. The POI data are any meaningful points on the map that do not have geographical significance, including but not limited to stores, bars, gas stations, hospitals, and stations.
Claims
1. A taxi trajectory anomaly detection method based on the LSTM network and attention mechanism, comprising the following steps: Step 1: Preprocessing of vehicle trajectory data: Collect taxi trajectory data, where the trajectory data is a trajectory sequence T consisting of longitude, latitude, and timestamp triples p r : p1 → p2 → … p n , remove redundant points and noise points from the original dataset, transform the map into a 100*100m grid, convert the trajectory into a grid sequence, convert the grid sequence into a vector representation through skip-gram, and calculate the speed of the trajectory points to convert them into corresponding road grade representations; Calculate and extract urban feature points according to the actual situation on the day of urban data collection, and divide the trajectory dataset into training set, validation set, and test set; Step 2: Feature extraction: Discretize the trajectory data, extract the position features from the grid cell ID sequence of the trajectory, discretize the continuous timestamps at an average time interval to extract time features, use the sliding window algorithm to obtain speed features, splice the feature speed with the position features and time features, and convert them into a word vector sequence through word2vec to construct an embedding layer; Step 3: Model construction and training, construct an LSTM-attention model, load the features extracted from Step 2 as input into the LSTM-attention model for training, extract features through the LSTM layer, and the attention layer distinguishes the weights of inflection points and non-inflection points. After training is completed, input the features of the test data set into the LSTM-attention model to verify the classification accuracy of the model; Step 4: After the input data passes through the embedding layer, LSTM layer, attention layer, and output layer, the desired output is obtained. If this output is different from the actual category of the trajectory; then the backpropagation algorithm will backpropagate the error to the output layer, and the neurons in each layer will update the parameters in the network structure according to this error, and visualize the anomaly detection results; The preprocessing of the vehicle trajectory data includes the following steps: Step 1.1: Collect taxi trajectory data through the vehicle networking data, and use the Douglas-Peucker algorithm to filter out the redundant sampling point data records in the dataset; the specific steps are as follows: Connect the start and end points of a section of trajectory into a straight line, calculate the perpendicular distance from all points on this section of trajectory to this straight line, and find the maximum distance value d max , compare d max with the predefined threshold D: If d max < D, all the intermediate points on this curve are discarded; if d max ≥ D, retain the coordinate points corresponding to d max , and take this point as the boundary to divide the trajectory into two parts, and repeat the above steps for these two parts until all redundant sampling point data are filtered; Step 1.2: Determine and remove noise points. Assume P i-1 , P i , P i+1 are three points arranged in the order of sampling time. If P i is a possible abnormal point, then the average speed difference between P i-1 and P i and between P i and P i+1 is relatively large; the distance is obtained based on speed and time. If the path length from t i-1 to t i is less than the maximum achievable displacement r1 during this time period, and the path length from time t i to t i+1 is less than the maximum achievable displacement r2 during this time period, then the possible area where P i may appear can be projected based on the maximum driving speed v, r1, and r2 of the taxi. If Pi appears within the area, then Pi is set as a normal point; otherwise, it is a noise point and needs to be removed; Step 1.3: Convert the original trajectory into a discrete sequence, divide the entire map into grid cells of equal size of 100*100m, each grid cell is marked with a separate ID, each GPS point is converted into the ID of the grid cell where it is located, and the trajectory sequence is converted into a grid cell ID sequence; Step 1.4: Use the skip-gram model to learn the representation of the grid, so that adjacent grids have similar representations in the vector space, and convert the trajectory into a grid cell ID sequence into a vector; Step 1.5: Calculate the speed of the trajectory points and use the graph to convert the speed of the trajectory points into the corresponding road grade, convert the trajectory from the grid cell ID representation into a trajectory point speed sequence; and calculate and extract urban feature points according to the actual situation on the day of urban data collection; The said Step 2 includes the following steps: Step 2.1: Sliding window feature extraction, assuming that the maximum offset value is w and the minimum is 1; the moving speed feature of each window has 3 dimensions: average speed, maximum speed, and minimum speed {mean, max, min}, and the statistical data |max - min| represents the change in the window speed. If the statistical data |max - min| is not 0, then update the offset to half of the previous value until the offset is 1; if the statistical data |max - min| is 0, then update the offset to twice the previous value until the offset reaches the maximum value; Step 2.2: Location information mining, the grid sequence represented by the vector includes the location information of the trajectory; Step 2.3: Time information mining, discretize continuous timestamps at an average time interval, and use the skip-gram model to obtain a vector representation sequence TP of the timestamps corresponding to the trajectory points i ; Step 2.4: Speed information mining. Use the trajectory point speed sequence obtained in Step 2.1 to obtain the trajectory point speed sequence representation SP by skip-gram model i ; The said Step 3 includes the following steps: Step 3.1: Construct an embedding layer: Connect the urban feature points and the speed sequence feature representation, initialize the weights with pre-trained vectors, and map the sequence to a unified low-dimensional vector by means of traditional word embedding methods; Step 3.2: Construct the LSTM layer: Take the output feature matrix of the embedding layer as a time series. At time t, input the feature vector into the input layer, and output the result through the activation function σ; Input the output result, the hidden layer output at time t-1, and the information stored in the cell unit at time t-1 into the LSTM node; Through the sorting of the input gate, output gate, forget gate, and cell unit, output data to the attention layer; The calculation formula of LSTM is: f t = σ g (W f x t + U f c t-1 + b f ) i t = σ g (W i x t + U i c t-1 + b fi ) o t = σ g (W o x t + U o c t-1 + b o ) c t = f t * c t-1 + i t * σ c (W c x t + b c ) h t = o t * σ h (c t ) where x t is the state of the previous unit, f t is the forget gate, with a range of [0, 1]; i t is the input gate, with a range of [0, 1]; Step 3.3: Construct the attention layer. Input the hidden layer state sequence obtained in Step 3.2 into the attention layer, and use the Softmax function to normalize the attention scores to obtain the weight distribution. Its calculation process formula can be expressed as: a tj = v T tanh((W s s t-1 ) + W h h t ) where T is the number of trajectory points, tanh is the hyperbolic tangent function, v, W s , W h are the parameters to be learned; Step 3.4: Construct the output layer: The output layer consists of a fully connected layer, a Dropout layer, and a Softmax layer. The vector output after Step 3.3 is input into the fully connected layer, and the Dropout layer and Softmax layer are converted into probabilities; Output the label paper through the argmax function, that is, the category y to which the trajectory belongs. When the parameter matrix is W and b is the bias, its calculation formula is as follows: y = softmax(W·h i + b).
2. The taxi trajectory anomaly detection method based on the LSTM network and the attention mechanism according to claim 1, characterized in that: The said Step 4 includes the following steps: Step 4.1: Take the obtained classification result y i and the current correct label value y' i as the two inputs of the cross-entropy loss function respectively, and calculate the loss value; transmit the error signal to the output of each layer, and then through the derivative of the function of each layer with respect to the parameters, the gradient of the parameters can be obtained; then update and calculate the network parameters that affect model training and model output through the stochastic gradient descent optimizer to make it approach or reach the optimal value, so as to minimize the loss function. After obtaining the optimal model, input the validation set to detect abnormal trajectories and visualize them.
Citation Information
Patent Citations
Urban scale taxi track prediction method based on attention mechanism
CN110163439A
Vehicle trajectory prediction method based on generative adversarial network
CN112257850A