Vehicle trajectory anomaly detection method based on dynamic graph attention mechanism
By constructing a dynamic spatiotemporal graph sequence and a graph attention autoencoder model, the shortcomings of existing vehicle trajectory anomaly detection methods in processing vehicle interaction and contextual information are addressed. This achieves accurate identification and improved generalization capabilities for vehicle trajectory anomalies, enabling precise location of abnormal vehicles.
Patent Information
- Application Number
- CN202511977564.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-25
- Publication Date
- 2026-04-28
AI Technical Summary
Existing vehicle trajectory anomaly detection methods have shortcomings in processing vehicle interaction and contextual information, making it difficult to accurately identify abnormal behaviors caused by vehicle interaction, with limited generalization ability, and difficulty in distinguishing the root cause of anomalies.
A vehicle trajectory anomaly detection method based on dynamic graph attention mechanism is adopted. By constructing a dynamic spatiotemporal graph sequence and a graph attention autoencoder model, the dynamic interaction and contextual information between vehicles are captured by graph attention convolution operation. An unsupervised autoencoder framework is used to autonomously learn normal behavior patterns, and anomalies are identified by reconstructing the loss function.
It accurately identifies abnormal interactions, improves detection accuracy, and is suitable for dynamic interaction scenarios between vehicles. It does not require predefined rules and can accurately locate abnormal vehicles.
Smart Images

Figure CN121935774A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of vehicle trajectory anomaly detection. Specifically, this invention relates to a vehicle trajectory anomaly detection method based on dynamic graph attention mechanism. Background Technology
[0002] With the rapid development of Internet of Things (IoT) technology and intelligent transportation systems, massive amounts of high-precision vehicle trajectory data (such as those from highway surveillance cameras and radar) have brought unprecedented opportunities to traffic management. In these applications, trajectory anomaly detection is a core task because it is crucial for improving traffic efficiency, preventing traffic accidents, and ensuring road safety. Existing trajectory anomaly detection methods mainly include three types: clustering-based trajectory anomaly detection methods, graph-based trajectory anomaly detection methods, and deep learning-based trajectory anomaly detection methods.
[0003] While existing methods for detecting abnormal vehicle behavior have achieved some success in specific scenarios, they suffer from three main drawbacks: First, they neglect vehicle interaction. Most traditional methods analyze vehicles as independent entities, such as... Figure 1 As shown, these methods do not consider dynamic interactions between vehicles (such as the impact of the vehicle in front on the vehicle behind, and speed coordination among vehicles within a lane) and the context of the traffic scene (such as lane function and traffic flow status). Therefore, they cannot accurately identify abnormal behaviors caused by vehicle interactions, such as slow driving on a highway obstructing vehicles behind. Second, they rely on predefined rules, resulting in limited generalization ability. Many methods rely on pre-set rules (such as speed thresholds, acceleration thresholds) or supervised learning for specific anomaly types (such as speeding, rear-end collisions). This makes it difficult for them to detect unforeseen and diverse anomaly patterns, resulting in poor generalization ability and robustness in new scenarios. Third, they struggle to distinguish the root cause of anomalies. When an abnormal event occurs (such as a car suddenly stopping), its impact quickly spreads to surrounding vehicles, causing a chain reaction (such as a following vehicle braking suddenly or changing lanes). Existing methods may mark all affected vehicles as abnormal, forming an "abnormal scenario," but they cannot accurately identify the root cause vehicle that initially caused the problem.
[0004] Therefore, this invention proposes a vehicle trajectory anomaly detection method based on dynamic graph attention mechanism. Summary of the Invention
[0005] This invention aims to overcome the shortcomings of existing technologies and proposes a vehicle trajectory anomaly detection method based on dynamic graph attention mechanism to achieve the following objectives: realize vehicle trajectory anomaly detection and improve detection accuracy, applicable to dynamic interaction scenarios between vehicles.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is: a vehicle trajectory anomaly detection method based on a dynamic graph attention mechanism, the method comprising the following steps:
[0007] Step S1: Obtain vehicle trajectory data;
[0008] Step S2: Preprocess the vehicle trajectory data and construct time window samples;
[0009] Step S3: Construct a dynamic spatiotemporal graph sequence for each time window sample;
[0010] Step S4: Construct a model based on graph attention autoencoder, using dynamic spatiotemporal graph sequences as input;
[0011] Step S5: Perform probabilistic reconstruction on the model to output the probability distribution parameters of each vehicle state variable under the current dynamic graph sequence, and define the reconstruction loss function;
[0012] Step S6: Train the model;
[0013] Step S7: Use the trained model to detect vehicle trajectory anomalies.
[0014] Preferably, in step S2, the preprocessing includes:
[0015] Normalize the vehicle trajectory data;
[0016] Continuous vehicle trajectory data is segmented into fixed-length, overlapping time window samples.
[0017] For each time window sample, filtering or linear interpolation is performed. The filtering includes retaining only vehicle trajectories with valid observation data within the entire time step of the time window; the linear interpolation includes linear extrapolation of the missing parts of the vehicle trajectory data.
[0018] Preferably, step S3 includes:
[0019] Construct a dynamic spatiotemporal graph sequence for each time window sample ;
[0020] Where: the node set V represents all vehicles within the time window, and at each discrete time step t∈T, each vehicle node i has a state vector. At each discrete time step t∈T, an edge is established between adjacent vehicles i and j. ; Let represent the set of edges formed by all adjacent vehicles at time step t.
[0021] Preferably, in step S4, the graph attention-based autoencoder model adopts an autoencoder architecture that includes an encoder and a decoder, wherein each encoder or decoder employs an improved gated loop unit.
[0022] Preferably, the improved gated loop unit updates the gate of the original gated loop unit. Reset door and candidate states The matrix multiplication in the algorithm is replaced by graph attention convolution operations. Correspondingly, at each time step, the improved gated recurrent unit updates the hidden state using the following formula. :
[0023] ;
[0024] ;
[0025] ;
[0026] ;
[0027] in, Indicates the activation function; This represents the state vector at time t; This represents the output state vector at time t; This represents the output state vector at time t-1; , , , , , Represents the weights during the training process; , , Indicates the bias coefficient; (·) indicates the graph attention convolution operation.
[0028] Preferably, the graph attention convolution operation includes:
[0029] Calculate attention coefficient and normalized attention score :
[0030] Formula 1: ;
[0031] Formula 2: ;
[0032] in, For activation functions; and Indicates learnable parameters; , These represent the current state vectors of vehicle nodes i and j, respectively. Let represent the set of neighboring nodes of vehicle node i at time t;
[0033] Then, the node state is updated using the following formula:
[0034] Formula 3: ;
[0035] Finally, the state vector of vehicle node i at time t is obtained after graph attention convolution operation. .
[0036] Preferably, the graph attention convolution operation further includes: introducing a multi-head attention mechanism, that is: setting K groups in parallel, each group having independent learnable parameters a and W, and performing the operations of formulas 1-3 to obtain K output features, and averaging or concatenating the K output features to obtain the final output state vector of vehicle node i at time t after the graph attention convolution operation.
[0037] Preferably, step S5 includes: performing probabilistic reconstruction on each encoder, that is, in each decoding step, the decoder generates an estimate of the probability distribution parameters of the vehicle state at the current moment based on its current hidden state and the output of the previous step. For continuous vehicle state variables, each is assumed to follow a univariate Gaussian distribution. Correspondingly, the probability distribution parameters output by the decoder include the mean and log-variance of each vehicle state variable based on the Gaussian distribution. For discrete vehicle state variables, each is assumed to follow a class distribution. Correspondingly, the probability distribution parameters output by the decoder include a probability vector representing the probability that the vehicle belongs to each class.
[0038] Preferably, in step S5, a weighted sum of negative log-likelihood loss and cross-entropy loss is used as the reconstruction loss function.
[0039] Preferably, in step S7, after the model training is completed, for any input trajectory, the magnitude of its reconstruction loss directly reflects the degree of deviation of its behavior from the normal pattern, i.e., its degree of abnormality; when detecting abnormal vehicles, for vehicle i, its abnormality score... Defined as the average of its various losses over the entire time window T:
[0040] ;
[0041] in, This represents the magnitude of the reconstruction loss for vehicle i at time t;
[0042] In anomaly detection, for a road segment scenario S, its anomaly score is... Defined as the maximum reconstruction loss that occurs for all vehicles across all time steps within the entire time window T in this scenario:
[0043] ;
[0044] in, This represents the magnitude of the reconstruction loss for vehicle i at time t.
[0045] The technical effects of this invention are as follows:
[0046] 1) Accurate identification of interaction anomalies: By constructing a dynamic spatiotemporal graph and utilizing the graph attention mechanism, this invention can effectively capture the dynamic interactions and contextual information between vehicles, thereby accurately identifying abnormal behaviors that violate local traffic rules, which is something that traditional single-vehicle analysis methods cannot achieve.
[0047] 2) No predefined rules required, strong generalization ability: This invention adopts an unsupervised autoencoder framework, which learns "normal" behavior patterns autonomously from a large amount of data. This enables it to detect various unexpected abnormal behaviors without the need for manually setting cumbersome rules, and has a strong generalization ability;
[0048] 3) Precisely locate abnormal vehicles: By calculating the independent abnormal score of each vehicle, this invention can directly locate the root vehicle that caused the abnormality, rather than just marking a vague abnormal area or scene, providing more accurate decision support for traffic management. Attached Figure Description
[0049] Figure 1 This is a schematic diagram of traditional vehicle trajectory anomaly types;
[0050] Figure 2 This is a schematic diagram of the dynamic spatiotemporal graph construction process provided in an embodiment of the present invention;
[0051] Figure 3 This is a schematic diagram of the model structure based on graph attention autoencoder provided in an embodiment of the present invention. Detailed Implementation
[0052] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. This is to help those skilled in the art to have a more complete, accurate, and in-depth understanding of the inventive concept and technical solutions of the present invention, and to facilitate its implementation. It should be noted that the terms "first," "second," etc., used in this application are only for the convenience of describing the technical solutions and to distinguish components; the corresponding component configurations may be the same or different, and are not intended to limit the scope of this application. To make the technical solutions of the present invention clearer, the present invention will be explained and illustrated through the following embodiments.
[0053] This embodiment provides a vehicle trajectory anomaly detection method based on a dynamic graph attention mechanism, the method comprising the following steps:
[0054] Step S1: Obtain vehicle trajectory data;
[0055] Step S2: Preprocess the vehicle trajectory data and construct time window samples;
[0056] Step S3: Construct a dynamic spatiotemporal graph sequence for each time window sample;
[0057] Step S4: Construct a model based on graph attention autoencoder, using dynamic spatiotemporal graph sequences as input;
[0058] Step S5: Perform probabilistic reconstruction on the model to output the probability distribution parameters of each vehicle state variable under the current dynamic graph sequence, and define the reconstruction loss function;
[0059] Step S6: Train the model;
[0060] Step S7: Use the trained model to detect vehicle trajectory anomalies.
[0061] Referring to step S1, the vehicle trajectory data obtained in this embodiment is a set of trajectory data for N vehicles observed within a time window T. For any vehicle i, the observation value at time t... Includes its status information, specifically: vertical position Horizontal position Lane number Longitudinal velocity and longitudinal acceleration .
[0062] Referring to step S2, in order to transform the raw, continuous vehicle trajectory data into structured samples suitable for deep learning model processing, the following preprocessing operations are required:
[0063] Normalize the vehicle trajectory data;
[0064] Continuous vehicle trajectory data is segmented into fixed-length, overlapping time window samples.
[0065] For each time window sample, filtering or linear interpolation is performed. The filtering includes retaining only vehicle trajectories with valid observation data within the entire time step of the time window; the linear interpolation includes linear extrapolation of the missing parts of the vehicle trajectory data.
[0066] Specifically, to eliminate the influence of different physical quantity ranges and make the model training process more stable and efficient, it is first necessary to normalize the numerical features of the vehicles in the dataset. This embodiment uses the Min-Max Normalization method to linearly scale the value of each feature to the [0,1] interval. For any numerical feature F, its normalized value... The calculation formula is as follows:
[0067] ;
[0068] in, and These are the maximum and minimum values of the feature in the entire training dataset, respectively. These features include, but are not limited to, the vehicle's longitudinal position, speed, acceleration, and mileage.
[0069] To capture the temporal dependence and dynamic evolution of vehicle behavior, this embodiment divides continuous trajectory data into fixed-length, overlapping time window samples. In this embodiment, a 300-second segment of vehicle trajectory data can be divided into multiple 30-second time window samples with a sliding step of 1 second. Each time window sample contains continuous trajectory information of all vehicles on the highway within that time period, constituting an independent analysis unit.
[0070] Vehicles may enter or leave the monitored area, resulting in incomplete trajectories for some vehicles within a certain time window. To ensure the consistency of the graph structure across the time dimension in each sample, this embodiment filters samples for each time window. Specifically, this embodiment only retains vehicle trajectories that have valid observation data throughout the entire time step of the time window (e.g., every second within 30 seconds). Vehicle trajectories that do not meet this condition are removed from the current time window sample. For datasets with short road segments and a high proportion of incomplete trajectories, an alternative approach can be adopted: linear extrapolation of the missing parts is performed, and these padding values are ignored during subsequent loss calculations using a masking mechanism. For each processed valid sample, its node features, adjacency relationships, and other information at each time step are stored in separate files for efficient subsequent retrieval.
[0071] Referring to step S3, this embodiment constructs a dynamic spatiotemporal graph sequence for each time window sample. ;
[0072] Where: the node set V represents all vehicles within the time window, and at each discrete time step t∈T, each vehicle node i has a state vector. The feature vector consists of two parts: first, normalized features of the vehicle's numerical observations, such as speed, acceleration, and miles per hour; and second, a low-dimensional dense vector obtained by embedding the categorical observations (lane IDs). For example, through a series of embedding layers, each discrete lane ID (e.g., 0, 1, 2, 3) is mapped to a continuous, learnable vector. Finally, the numerical feature vector and the lane embedding vector are concatenated to form the final node feature vector, which is the state vector. It contains both the vehicle's kinematic information and its discrete position information.
[0073] Vehicle behavior is primarily influenced by its neighboring vehicles. To reduce unnecessary computation and focus on key interactions, edges are constructed based on the principle of spatial proximity, such as... Figure 2 As shown. At each discrete time step t∈T, an edge is established between adjacent vehicles i and j. ; This represents the set of edges connecting all adjacent vehicles at time step t. This proximity is defined by two configurable thresholds: a longitudinal distance less than the threshold `max_gap` (e.g., 0.1 miles) and a lateral lane distance less than the threshold `attend_lane_dist` (e.g., one lane). Because the relative positions of vehicles change over time, the set of edges... It is also dynamic and changing.
[0074] Referring to step S4, in this embodiment, the graph attention-based autoencoder model adopts an autoencoder architecture that includes an encoder and a decoder, such as... Figure 3 As shown, each encoder or decoder employs an improved gated recurrent unit (VDGA). Compared to traditional LSTM, the gated recurrent unit has a simpler structure. It combines the forget gate and input gate into a single "update gate," omitting the output gate. This simplified structure results in fewer parameters and higher computational efficiency for the gated recurrent unit. This embodiment further improves upon this by proposing an improved gated recurrent unit (VDGA).
[0075] In this embodiment, the improved gated loop unit (VDGA) updates the gate of the original gated loop unit. Reset door and candidate states The matrix multiplication in the algorithm is replaced with graph attention convolution operations to capture interactions between vehicles. This method effectively leverages the advantages of GRU in handling temporal dependencies. Correspondingly, at each time step, the improved gated recurrent unit updates the hidden state using the following formula. :
[0076] ;
[0077] ;
[0078] ;
[0079] ;
[0080] in, Indicates the activation function; This represents the state vector at time t; This represents the output state vector at time t; This represents the output state vector at time t-1; , , , , , Represents the weights during the training process; , , Indicates the bias coefficient; (·) indicates the graph attention convolution operation.
[0081] The core of graph attention convolution lies in its attention mechanism, which dynamically calculates the importance of neighbors based on the characteristics of the current vehicle node and its neighboring nodes. The graph attention convolution operation includes:
[0082] Calculate attention coefficient and normalized attention score :
[0083] Formula 1: ;
[0084] Formula 2: ;
[0085] in, For activation functions; and Indicates learnable parameters; , These represent the current state vectors of vehicle nodes i and j, respectively. Let represent the set of neighboring nodes of vehicle node i at time t;
[0086] Then, the node state is updated using the following formula:
[0087] Formula 3: ;
[0088] Finally, the state vector of vehicle node i at time t is obtained after graph attention convolution operation. This mechanism enables the model to learn complex, asymmetric interactions (e.g., the influence of the preceding vehicle on the following vehicle is much greater than the influence of the following vehicle on the preceding vehicle), making it far more powerful than weight allocation based on fixed physical distance. Furthermore, this embodiment introduces a multi-head attention mechanism: K groups are set up in parallel, each with independent learnable parameters a and W, and the operations described in formulas 1-3 are executed to obtain K output features. These K output features are averaged or concatenated to obtain the final output, which is the state vector of vehicle node i at time t after graph attention convolution. This allows the model to capture neighborhood information from different perspectives.
[0089] The encoder is used to compress the input dynamic graph sequence into a low-dimensional vector that can express its core semantics, while the decoder is used to receive the low-dimensional vector and use it as the initial state to reconstruct the original trajectory sequence in reverse time order.
[0090] Specifically, after the dynamic spatiotemporal graph sequence is input, it is first encoded layer by layer by a multi-layer encoder to obtain the encoded vector, which is the hidden state at the end of the final output time window of the encoder. As an encoding vector, the encoding vector is transformed into the decoder's initial hidden state after passing through a fully connected layer and a ReLU activation function; then, the decoder's initial hidden state is decoded layer by layer through multiple decoders. To improve computational efficiency, the decoder uses a fixed set of edges in all decoding steps. This edge set is the union of all edge sets at all time steps during the encoding phase, and is generated by a custom function.
[0091] Referring to step S5, to better handle the inherent randomness in normal driving behavior (such as slight speed fluctuations), this embodiment does not directly predict the deterministic state of the vehicle, but rather reconstructs it probabilistically. Specifically, in each decoding step, the decoder generates an estimate of the probability distribution parameters of the vehicle state at the current moment based on its current hidden state and the output of the previous step. Finally, the decoded output sequence is inverted to match the original time order. This is especially important for continuous vehicle state variables (e.g., longitudinal position). ,speed and acceleration (etc.), each of them is made to follow a univariate Gaussian distribution. Correspondingly, the probability distribution parameters output by the decoder include the mean of each vehicle state variable based on the Gaussian distribution. and logarithmic variance For discrete vehicle state variables (e.g., lanes) (etc.), each of which is ordered to follow a class distribution. Correspondingly, the probability distribution parameters output by the decoder include a probability vector. , which represents the probability that a vehicle belongs to each category (each lane).
[0092] Based on the above probabilistic reconstruction, the training objective of the model is now to maximize the log-likelihood of the observed data under the predicted distribution. In this embodiment, the reconstruction loss function... The reconstruction loss function is a weighted sum of negative log-likelihood loss and cross-entropy loss.
[0093] ;
[0094] ;
[0095] ;
[0096] ;
[0097] ;
[0098] in, , , , Representing the vertical position respectively Longitudinal velocity Longitudinal acceleration Lane number The preset weights are used to balance the importance of the four different sub-losses in the total loss; q(·) represents the probability density function; Indicates vertical position Follow the mean Logarithmic variance is Gaussian distribution, longitudinal velocity Longitudinal acceleration And so on; Indicates the indicator function, lane The function evaluates to 1 if the value is true, and 0 otherwise. This indicates that the model outputs the current vehicle belonging to the lane. The probability of.
[0099] Referring to step S6, the model in this embodiment uses the Adam optimizer for end-to-end training. The initial learning rate is set to a relatively high value (e.g., 0.05), and a learning rate decay strategy is employed, such as halving the learning rate every 50 training epochs, to help the model converge better in the later stages of training. To prevent gradient explosion, gradient pruning is also introduced during training. The model is trained on large-scale "normal" traffic data that does not contain specific abnormal scenarios.
[0100] Referring to step S7, after the model training is complete, it has mastered the inherent patterns of normal traffic behavior. For any input trajectory, the magnitude of its reconstruction loss directly reflects the degree to which its behavior deviates from the normal pattern, i.e., its degree of anomalousness. When detecting anomalous vehicles, for vehicle i, its anomalousness score is... Defined as the average of its various losses over the entire time window T:
[0101] ;
[0102] in, This represents the reconstruction loss of vehicle i at time t; averaging is used to obtain a smoother and more robust anomaly assessment over time, as anomalous behavior typically persists for a period of time. A high anomaly score means that the vehicle's driving behavior has a very low reconstruction probability and is therefore classified as anomalous.
[0103] In anomaly detection, for a road segment scenario S, its anomaly score is... Defined as the maximum reconstruction loss that occurs for all vehicles across all time steps within the entire time window T in this scenario:
[0104] ;
[0105] in, This represents the reconstruction loss of vehicle i at time t. Maximum aggregation is used to ensure that even if only a brief but severe anomalous event occurs, the scenario can be effectively labeled, avoiding the anomalous signal being "averaged out" by the low losses of a large number of normal vehicles.
[0106] To evaluate the detection performance of the proposed vehicle trajectory anomaly detection method based on dynamic graph attention mechanism (DynaTAD), experiments were conducted on the TransModeler simulation dataset and the German HighD highway dataset.
[0107] For the TransModeler simulation dataset, due to its large data volume and controllable data source, this invention directly discards all incomplete vehicle trajectories. For the real-world HighD dataset, due to its uncontrollable data source, containing a large number of incomplete road segments, and short sampling intervals, this invention completes the incomplete vehicle trajectories using linear extrapolation, assuming that the vehicle speed in the extrapolated portion is constant. During the loss calculation process, this invention masks these parts to prevent them from affecting the experimental results.
[0108] This invention uses the following benchmark models to evaluate the performance of the DynaTAD model. LTI uses linear interpolation between the first and last vehicle positions to reconstruct the trajectory. CVM assumes the velocity recorded at the first observation time step remains constant to reconstruct the trajectory. Seq2Seq uses two LSTM networks to encode and decode the time series, using the mean squared error (MSE) as the reconstruction error. STAGE uses a convolutional network temporally and a graph convolutional network spatially, employing a bivariate Gaussian reconstruction loss to construct the encoder-decoder pair, thus deriving anomaly scores. DSAB is an autoencoder composed of RGAT blocks, where important vehicles are assigned attention coefficients through an attention mechanism.
[0109] This invention uses the following three commonly used metrics to compare the performance of this invention with the benchmark model: ROC-AUC value, precision (Precision@k), and average precision.
[0110] To verify the effectiveness of the DynaTAD model in trajectory anomaly detection, this invention was first compared with classic models on a comprehensive scene test set across two datasets. The comparative experimental results for anomaly vehicle detection are shown in Tables 1 and 2. Besides DSAB, our method is the only model capable of identifying specific vehicles exhibiting abnormal behavior within traffic flow.
[0111]
[0112] Table 1
[0113]
[0114] Table 2
[0115] Next, this embodiment compares the performance of all classic models and DynaTAD in different scenarios, including slow speed, speeding, following too closely, and engine stalling. The results are shown in Tables 3-6. From the metrics of pre@100 and Ave Pre, it can be seen that most methods fail to identify the patterns of slow-moving and stalled vehicles. Only by deeply modeling the dynamic interaction relationships between vehicles can their anomalies be effectively detected. In both cases, the method in this embodiment achieves optimal performance in 4 out of 6 metrics.
[0116] Clearly, almost all methods, including the nonparametric CVM method specifically designed for speeding and rear-end collision scenarios, perform exceptionally well in speeding scenarios. Although DSAB achieves an impressive ROC-AUC of 0.995, the performance gap of our model remains within acceptable limits, and it is best or tied for best in the other two metrics.
[0117]
[0118] Table 3
[0119]
[0120] Table 4
[0121]
[0122] Table 5
[0123]
[0124] Table 6
[0125] These experimental results demonstrate that the present invention can provide a more in-depth study of the dynamic interaction relationships between vehicles.
[0126] The present invention has been described above by way of example with reference to the accompanying drawings. Obviously, the specific implementation of the present invention is not limited to the above-described manner. Any non-substantial improvements made using the inventive concept and technical solution; or the direct application of the inventive concept and technical solution to other situations without modification, are all within the protection scope of the present invention.
Claims
1. A vehicle trajectory anomaly detection method based on dynamic graph attention mechanism, characterized in that: The method includes the following steps: Step S1: Obtain vehicle trajectory data; Step S2: Preprocess the vehicle trajectory data and construct time window samples; Step S3: Construct a dynamic spatiotemporal graph sequence for each time window sample; Step S4: Construct a model based on graph attention autoencoder, using dynamic spatiotemporal graph sequences as input; Step S5: Perform probabilistic reconstruction on the model to output the probability distribution parameters of each vehicle state variable under the current dynamic graph sequence, and define the reconstruction loss function; Step S6: Train the model; Step S7: Use the trained model to detect vehicle trajectory anomalies.
2. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 1, characterized in that: In step S2, the preprocessing includes: Normalize the vehicle trajectory data; Continuous vehicle trajectory data is segmented into fixed-length, overlapping time window samples. For each time window sample, filtering or linear interpolation is performed. The filtering includes retaining only vehicle trajectories with valid observation data within the entire time step of the time window. The linear interpolation includes performing linear extrapolation on the missing parts of the vehicle trajectory data.
3. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 1, characterized in that: Step S3 includes: Construct a dynamic spatiotemporal graph sequence for each time window sample ; Where: the node set V represents all vehicles within the time window, and at each discrete time step t∈T, each vehicle node i has a state vector. At each discrete time step t∈T, an edge is established between adjacent vehicles i and j. ; Let represent the set of edges formed by all adjacent vehicles at time step t.
4. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 1, characterized in that: In step S4, the graph attention-based autoencoder model adopts an autoencoder architecture that includes an encoder and a decoder, wherein each encoder or decoder employs an improved gated loop unit.
5. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 4, characterized in that: The improved gated loop unit will update the gate of the original gated loop unit. Reset door and candidate states The matrix multiplication in the algorithm is replaced by graph attention convolution operations. Correspondingly, at each time step, the improved gated recurrent unit updates the hidden state using the following formula. : ; ; ; ; in, Indicates the activation function; This represents the state vector at time t; This represents the output state vector at time t; This represents the output state vector at time t-1; , , , , , Represents the weights during the training process; , , Indicates the bias coefficient; (·) indicates the graph attention convolution operation.
6. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 5, characterized in that: The graph attention convolution operation includes: Calculate attention coefficient and normalized attention score : Official 1: ; Official 2: ; in, For activation functions; and Indicates learnable parameters; , These represent the current state vectors of vehicle nodes i and j, respectively. Let represent the set of neighboring nodes of vehicle node i at time t; Then, the node state is updated using the following formula: Official 3: ; Finally, the state vector of vehicle node i at time t is obtained after graph attention convolution operation. .
7. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 6, characterized in that: The graph attention convolution operation further includes: introducing a multi-head attention mechanism, that is: setting K groups in parallel, each group having independent learnable parameters a and W, and executing the operations of formulas 1-3 to obtain K output features, and averaging or concatenating the K output features to obtain the final output, which is the state vector of vehicle node i at time t after the graph attention convolution operation.
8. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 1, characterized in that: Step S5 includes: performing probabilistic reconstruction on each encoder, that is, in each decoding step, the decoder generates an estimate of the probability distribution parameters of the vehicle state at the current moment based on its current hidden state and the output of the previous step. For continuous vehicle state variables, each is assumed to follow a univariate Gaussian distribution. Correspondingly, the probability distribution parameters output by the decoder include the mean and log-variance of each vehicle state variable based on the Gaussian distribution. For discrete vehicle state variables, each is assumed to follow a class distribution. Correspondingly, the probability distribution parameters output by the decoder include a probability vector representing the probability that the vehicle belongs to each class.
9. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 1, characterized in that: In step S5, a weighted sum of negative log-likelihood loss and cross-entropy loss is used as the reconstruction loss function.
10. The vehicle trajectory anomaly detection method based on dynamic graph attention mechanism according to claim 1, characterized in that: In step S7, after the model training is complete, for any input trajectory, the magnitude of its reconstruction loss directly reflects the degree of deviation of its behavior from the normal pattern, i.e., its degree of abnormality; when detecting abnormal vehicles, for vehicle i, its abnormality score is... Defined as the average of its various losses over the entire time window T: ; in, This represents the magnitude of the reconstruction loss for vehicle i at time t; In anomaly detection, for a road segment scenario S, its anomaly score is... Defined as the maximum reconstruction loss that occurs for all vehicles across all time steps within the entire time window T in this scenario: ; in, This represents the magnitude of the reconstruction loss for vehicle i at time t.