Traffic trajectory anomaly detection method and device based on neighborhood reconstruction and graph contrastive learning
By abstracting traffic trajectory data into a graph structure, and using graph neural networks to reconstruct neighborhood information and perform graph comparison learning, the complexity and dynamic changes of traditional methods when processing large-scale traffic data are solved, and efficient identification and accurate detection of traffic anomalies are achieved.
Patent Information
- Application Number
- CN202510013887.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-06
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2045-01-06
AI Technical Summary
Traditional traffic trajectory anomaly detection methods face challenges of high complexity and dynamic changes when processing large-scale traffic data. They are difficult to adapt to diverse anomaly patterns and the dynamic nature of traffic flow, and computational resource limitations lead to insufficient detection accuracy and real-time performance.
This paper adopts a method based on neighborhood reconstruction and graph contrastive learning to abstract traffic trajectory data into a graph structure, reconstruct neighborhood information using graph neural networks, extract features through graph convolutional networks, and identify abnormal behavior through graph contrastive learning. By combining multiple contrast modes and dynamic threshold adjustment, efficient anomaly detection can be achieved.
It achieves efficient identification of complex traffic behavior patterns, accurately captures abnormal behaviors at the vehicle and vehicle interaction levels, reduces false alarms and false negatives, improves the accuracy and stability of detection, and adapts to various traffic scenarios.
Smart Images

Figure CN119939465B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of data mining and artificial intelligence, in particular to an abnormality detection method in traffic trajectory, and specifically to a traffic trajectory abnormality detection method and device based on neighborhood reconstruction and graph contrastive learning. BACKGROUND
[0002] Under the background of current intelligent transportation systems and digital transformation, traffic trajectory anomaly detection has become an important tool for traffic management and public safety maintenance. With the continuous increase of urban traffic flow and the surge in the number of vehicles, the transportation system faces complex and hidden abnormal behaviors such as traffic accidents, traffic congestion, traffic violations, etc. These problems not only threaten public safety, but also can lead to a decrease in social efficiency, waste of resources, and even legal liability. If the traffic management department fails to detect and respond to these abnormal behaviors in a timely manner, it may lead to more serious accidents or safety hazards. Therefore, the importance of traffic trajectory anomaly detection is increasingly prominent. Traditional detection methods face high complexity and dynamic changes when dealing with large-scale traffic data, and the lack of a powerful and intelligent anomaly detection system may result in some malicious behavior or traffic violation behavior being missed, further endangering the safety and smoothness of the transportation system. Therefore, it is urgent to build a powerful and intelligent traffic trajectory anomaly detection mechanism. By effectively detecting and preventing traffic accidents, traffic violations, and abnormal traffic patterns, the safety of the transportation system can be effectively maintained, the efficiency of traffic management can be improved, and the safety of citizens traveling can be ensured, reducing social problems caused by traffic accidents. This not only helps to ensure the healthy operation of the transportation system, but also creates a safer and more reliable transportation environment for society.
[0003] With the continuous growth of urban traffic data and the increasing complexity of data, traffic trajectory anomaly detection faces the following main challenges:
[0004] 1) High dimensionality and sparsity of data: Traffic trajectory data usually has high-dimensional characteristics, such as vehicle speed, position, and driving route, etc. At the same time, the driving trajectory of the vehicle is relatively sparse in some time periods and areas, which makes it difficult for traditional feature-based statistical methods to fully characterize the data characteristics.
[0005] 2) Diverse abnormal patterns: Abnormal behaviors in traffic trajectories can manifest as vehicle illegal lane changes, speeding, and reverse driving, etc., which are diverse and hidden, increasing the difficulty of detection.
[0006] 3) Dynamic nature of traffic flow and trajectory: Traffic trajectories have a high degree of dynamicity, with vehicle driving routes, traffic flow, and speed changing in real time. Traditional static detection methods are difficult to adapt to these real-time changes, so more dynamically adaptive algorithms are needed.
[0007] 4) Computing resource limitation: Processing large-scale traffic trajectory data requires efficient algorithm design and computing resources, otherwise it may be too expensive to calculate and affect practical application.
[0008] Overall, traditional traffic trajectory anomaly detection methods have certain limitations in the face of complex and variable traffic environments, and there is an urgent need for more adaptable and intelligent methods to improve the accuracy and real-time performance of anomaly detection. New traffic trajectory anomaly detection methods should be able to adapt to changes in different traffic scenarios, process high-dimensional, heterogeneous data through intelligent algorithms, and more comprehensively and accurately identify bad or abnormal behavior involving multiple vehicles or traffic points, so as to better maintain the safety and smoothness of the traffic system.
[0009] Thanks to the development of graph neural network (GNN) technology, traffic trajectory anomaly detection has ushered in a new breakthrough. GNN can effectively capture the complex relationships between different vehicles and traffic points (such as intersections and road segments) in the traffic system, and more comprehensively analyze the dynamic changes of traffic flow, path and behavior. Its powerful feature learning ability enables the detection system to adapt to changing traffic anomaly patterns, and compared to traditional methods, it has higher flexibility and intelligence. By learning the spatio-temporal correlation between vehicles and driving trajectories, GNN can identify abnormal behaviors in traffic trajectories, such as speeding, illegal lane changes, and reverse driving. In addition, GNN helps detect potential traffic anomalies through node and edge embedding representation, and timely discovers traffic safety hazards and emergencies. These technological innovations have promoted the progress of traffic trajectory anomaly detection and provided a powerful tool for intelligent traffic management. By improving the safety of the traffic system, reducing the impact of traffic accidents and violations on society, and providing a safer and smoother traffic environment for the city. SUMMARY
[0010] The present application is aimed at complex data of traffic trajectory, in order to overcome the above-mentioned shortcomings of the prior art, a traffic trajectory anomaly detection method and device based on neighborhood reconstruction and graph contrastive learning are provided to realize accurate detection of abnormal data in the field of traffic trajectory.
[0011] The application first abstracts traffic trajectory data into graph structure data, wherein nodes represent vehicles or traffic points (such as intersections, road segments), and edges represent the relationship between vehicles or traffic flow. The application introduces a neighborhood reconstruction module to reconstruct the traffic trajectory graph structure using the feature information of vehicles and their surrounding traffic points, and assesses potential abnormal vehicles or traffic points through reconstruction error. Secondly, positive and negative sample pairs are generated through subgraph sampling so that the model can learn the patterns of normal and abnormal behaviors. Then, subgraph data is input into a graph convolution network (GCN) layer to obtain the hidden layer information and potential representation of the subgraph, and the features of nodes and edges are gradually extracted. Then, three contrast modes of graph contrast learning (node and node contrast, node and subgraph contrast, and subgraph and subgraph contrast) are used to learn the differences between normal trajectories and abnormal trajectories in traffic trajectory graph data. Finally, the abnormal information learned by each contrast mode is integrated for anomaly recognition. During the training process, the model compares the similarity of embedding vectors to determine positive and negative samples, and is optimized through a triplet loss function and the like to ensure that the similarity of positive sample pairs is higher than that of negative sample pairs. Ultimately, in a large and complex traffic trajectory data, the identification of abnormal behaviors (such as speeding, illegal lane changing, and reverse driving) or abnormal traffic patterns is completed.
[0012] The application achieves the above-mentioned purpose by the following technical solutions: a traffic trajectory anomaly detection method based on neighborhood reconstruction and graph contrast learning, comprising the following implementation steps:
[0013] S1: Select a widely used traffic trajectory dataset, preprocess the original data, and define corresponding graph structure data;
[0014] S2: Reconstruct the neighborhood information of graph structure data to capture the similarity and difference in attribute space;
[0015] S3: Subgraph and node sampling to obtain positive and negative sample pairs, and extract the potential representation of subgraph embedding vectors;
[0016] S4: Graph contrast learning network to capture the similarity and difference of embedding vectors;
[0017] S5: Define an abnormal score function;
[0018] S6: Perform traffic trajectory data anomaly detection.
[0019] Among them, step S1 specifically includes:
[0020] S1.1: Selecting a suitable traffic trajectory dataset is crucial for anomaly detection. To simulate real-world traffic behavior, the Porto dataset, which originates from taxi trajectory data in the city of Porto, Portugal, is chosen. In the dataset, vehicles are treated as nodes, and the position information (latitude and longitude), speed, timestamp, and other features of the vehicles are considered as node features. The movement trajectories between vehicles and the intersection relationships are represented as edges in the graph. This dataset contains a large amount of taxi trajectory data, covering traffic flow in different time periods, regions, and road types. By using these data, it is possible to effectively simulate both normal and abnormal driving patterns in the traffic system, which helps to identify potential traffic violations or abnormal patterns, such as speeding, reverse driving, and illegal lane changes. This dataset provides rich information on actual traffic behavior and is an important reference for traffic trajectory anomaly detection.
[0021] S1.2: Data cleaning. When processing the Porto dataset, first, remove noise points and redundant points, which may be caused by weak signals from the positioning system or GPS accuracy problems. These points not only increase the size of data storage, but also may have a significant impact on the accuracy of anomaly detection. Next, handle missing values and fill in missing node feature data. Mean interpolation or filling by analyzing similar vehicle features can be used to ensure that each vehicle's trajectory data is complete and consistent. Finally, perform data conversion to convert non-numeric features into numeric features to facilitate model processing. This includes feature encoding operations, such as converting timestamps into time intervals, or converting categorical features such as different road types and traffic states into numeric features, to facilitate subsequent model training and analysis.
[0022] S1.3: Constructing graph structure data. When processing the Porto dataset, traffic trajectory data is abstracted into a graph structure. Each taxi's trajectory data is treated as a node in the graph, and the node's features include the vehicle's position information (latitude and longitude), speed, timestamp, and other features. The edges in the graph represent the relationship between vehicles, usually consisting of the movement trajectories of vehicles driving on the same road segment or adjacent intersections within the same time period. By treating road networks (such as intersections and road segments) as nodes and the relationships between vehicles as edges, a graph structure data based on traffic flow can be established. In addition, the weight of the edge can be defined according to the distance or travel time between vehicles, so as to better reflect the dynamic characteristics of the traffic network. Ultimately, this graph structure data provides an effective input for subsequent anomaly detection and pattern recognition.
[0023] S1.4: Define graph data and anomaly detection problem. For a given undirected graph G = (V, E), where {V1, V2, V3 … Vn} represents the set of nodes, n represents the number of nodes, and E represents the set of edges. In addition, the node feature matrix X ∈ Rnxd is used, where d represents the number of node features. The goal of anomaly detection is to identify abnormal nodes or edges in the graph based on the given node features and edge relationships. This can be achieved by training a machine learning model on the graph data and then using the trained model to detect anomalies in new data. N} represents the set of nodes, n represents the number of nodes, and E represents the set of edges. In addition, the node feature matrix X ∈ R N×DRepresenting node feature information, the adjacency matrix A∈R N×N This represents graph structure information. Simultaneously, x is used. i ∈R D Represents node v i Features, using d i This represents the degree of each node. For an adjacency matrix A, if A... ij =1, then it means node v i and v j There exists an edge between them, otherwise A ij =0. The goal of this invention is to detect all anomalous nodes in a given graph that contain anomalous nodes. The solution to this problem is as follows: A model of G = (V, E), with adjacency matrix A, measures the anomalousness of each node in G by learning an anomaly scoring function S(·). S(v i The larger the value, the better the node v i The higher the probability of an anomaly, the better. Then, all nodes are sorted in descending order of their anomaly scores, and anomalies are determined by selecting a certain threshold ρ.
[0024] S1.5: Divide the processed data into training samples and test samples. This division helps to use a portion of the data to learn normal traffic trajectory network data patterns during the model training phase, while using separate data to evaluate the model's performance during the testing phase, ensuring the model's generalization ability and reliability.
[0025] Specifically, step S2 includes:
[0026] S2.1: Reconstructing Neighborhood Information in Graph Structure Data. In traffic trajectory anomaly detection, the neighborhood reconstruction module uses a graph neural network (GNN) to encode the receptive domain of the vehicle trajectory network, reconstructing the vehicle's neighborhood structure in a reduced-dimensional space. This reconstruction process not only restores the vehicle's own feature attributes (such as position, speed, acceleration, etc.) but also reconstructs the connection patterns between vehicles and their traffic relationships with neighboring vehicles, thus effectively capturing anomalies in the attribute space of traffic trajectory data. This method not only uses the representation of vehicle nodes to reconstruct local neighborhood information but also introduces the structural information of the global traffic network, further enhancing the modeling ability for complex relationships between vehicles and the attribute space through contrastive learning. In this way, abnormal driving patterns of vehicles in the graph, such as speeding, sudden braking, or driving in the wrong direction, can be captured more comprehensively, improving the model's performance in traffic trajectory anomaly detection.
[0027] S2.2: Capturing the similarity and differences in the attribute space. First, the node's representation is updated by iteratively aggregating its neighbor information using a GNN encoder. This aggregation operation captures the structural information of the node's local neighborhood and the relationship features with its direct neighbors. The mathematical expression of this process is as follows:
[0028]
[0029] where f i (l) denotes the feature vector of node i at layer l, UPDATE denotes the operation for updating the node feature, and the Aggregation function is used to aggregate the information of neighboring nodes. N i denotes the set of all neighboring nodes of node i.
[0030] is reconstructed by a multi-layer perceptron (MLP) i (l+1) is decoded step by step to reconstruct the original feature vector f i (0) . Then, the difference between f i (0) and f is calculated using l2-loss to obtain the node reconstruction loss:
[0031]
[0032] The node degree is reconstructed using a MLP with the loss function as follows:
[0033]
[0034] The empirical distribution of the neighborhood is approximated by a multivariate Gaussian distribution with the mean and covariance matrix estimation formula as follows:
[0035]
[0036] Then, from f i (l+1) , the approximate distribution is constructed. Specifically, the mean and covariance matrix of the multivariate Gaussian distribution are generated using f i (l+1) , with the formula as follows:
[0037]
[0038] From the generated Gaussian distribution , k samples are sampled, and then these samples are transformed through a fully connected neural network (FNN) into approximate samples of the neighbor feature representation Finally, the generated neighbor feature samples are used to estimate the new mean and covariance matrix:
[0039]
[0040] Based on the given and The reconstruction loss of neighbor attribute features is measured using the KL divergence between the two distributions:
[0041]
[0042] where p represents the dimension.
[0043] Finally, the total loss in the neighborhood reconstruction module is as follows:
[0044]
[0045] Wherein, step S3 specifically comprises:
[0046] S3.1: Extracting the embedding vector of the subgraph is a crucial step in traffic trajectory anomaly detection, mainly using the method of graph convolution network (GCN) layer. Before that, in order to make the obtained representation more discriminative, it is necessary to mask the features of the target nodes in the subgraph. Their hidden layer feature representation can be represented by the following formula:
[0047]
[0048] where represents the symmetric normalized adjacency matrix, represents the hidden representation of the lth layer, W (l) represents the weight.
[0049] The GCN layer is used to perform convolution operation on the subgraph, aggregate node features and update its representation. After multi-layer GCN stacking, the node features are gradually improved and the structural information of the subgraph is enriched.
[0050] S3.2: The node embedding vector output by the GCN layer is pooled or aggregated to obtain the latent representation of the entire subgraph. This process fuses the structure and feature information of the subgraph into the embedding vector, providing a higher level and more comprehensive subgraph representation for subsequent graph contrastive learning, enabling the model to more accurately capture patterns and abnormal behaviors in traffic trajectory data. Then, the final representation of the subgraph is calculated using the skip connection, which can increase the connectivity of the nodes in the graph. Based on the node-based features X (l) and a projection vector α (l) Sort the nodes and find the indices corresponding to the top k maximum values:
[0051]
[0052] Then, the corresponding subgraph adjacency matrix A is extracted from the original adjacency matrix A
[0053]
[0054] In addition, element-wise matrix multiplication is used to obtain a new feature matrix:
[0055]
[0056] Finally, the original structure of the graph is recovered by the distribute(·) operation and the final representation z of the subgraph is obtained i , as follows:
[0057] z i = distribute(0 n×c , X (l+1) , idx) (13)
[0058] Correspondingly, the target node feature is converted to the same embedding space as the subgraph using an MLP, obtaining the final representation e of the node i , which shares the weight W (l) with the previous GCN:
[0059] e i = σ(X (l) W (l) ) (14)
[0060] The step S4 specifically comprises:
[0061] S4.1: Based on the above operations, the embedding representation of the positive and negative sample pairs is obtained, and it is further necessary to measure the similarities and differences between them. The process of the graph contrast learning network capturing the similarity and difference of the embedding vectors is mainly realized by comparing the similarity of the positive and negative sample pairs. For each pair of positive and negative samples, by calculating the similarity of the embedding vectors, the network can learn that the similarity of the positive sample pair is high, while the similarity of the negative sample pair is low. A bilinear model is used to measure the relationship between them, which is calculated by the following formula:
[0062]
[0063] Among the positive sample pairs, the target node tends to be similar to the subgraph, i.e. s i = 1, and vice versa, among the negative sample pairs, the target node may not be similar to the subgraph, i.e. s i = 0. Therefore, the contrast loss is calculated using the binary cross-entropy loss function:
[0064]
[0065] Meanwhile, comparison between subgraphs is also needed, which is more conducive to finding node-level anomalies. Similarly, the features of the target node are masked, and positive and negative sample pairs are constructed for the target node, and the subgraph representation is obtained using the new GCN layer:
[0066]
[0067] where W ′(l) Different from the node-subgraph parameter matrix.
[0068] Map the node features to the same hidden space through the MLP to obtain the final representation of the node Then a bilinear model is used to evaluate the relationship between nodes Then the node-node contrast loss function can be defined as:
[0069]
[0070] In order to optimize the embedding representation of the subgraph and learn its intrinsic features, a third contrast mode: subgraph-subgraph contrast is defined. The subgraph and the subgraph in another view of the same target node are regarded as a positive sample pair, and the subgraphs generated in the two views of another node and are regarded as a negative sample pair. The following loss function is used to optimize the contrast:
[0071]
[0072] Finally, the loss in the contrast learning module is as follows:
[0073]
[0074] where β∈(0,1) is a parameter for balancing node-level anomaly information, is a parameter for balancing subgraph-level anomaly information.
[0075] The subgraph is convolved through the GCN layer to aggregate node features and update its representation, thereby capturing the relationship between nodes in the traffic trajectory network. Through the multi-layer GCN stack, the node features are gradually enhanced to help identify abnormal patterns.
[0076] Wherein, step S5 specifically comprises:
[0077] S5.1: By minimizing the set objective function, the anomaly score of each node can be calculated. By minimizing the objective function, the anomaly score of each node can be calculated In the neighborhood reconstruction module, the anomaly score is calculated according to the node self-reconstruction error. The reconstruction error is measured by the difference between the reconstructed feature vector and the original feature vector, and the calculation method is as follows:
[0078]
[0079] Correspondingly, since the normal node is usually similar to the positive sample and dissimilar to the negative sample, the abnormal node is very different from both the positive sample and the negative sample. Define Wherein And Respectively represent the similarity of positive and negative pairs. Based on this rule, the anomaly score of the comparison module can be obtained as follows:
[0080]
[0081] In summary, the anomaly score of each node is obtained by combining the two kinds of anomaly scores:
[0082]
[0083] In order to reduce the inherent randomness of single detection, multiple detections are performed on each node to obtain their anomaly scores, and the average value is taken as the final anomaly score. The above formula is further rewritten as:
[0084]
[0085] Wherein, R represents the number of anomaly detection.
[0086] Wherein, step S6 specifically comprises:
[0087] S6.1: In the previous steps, the anomaly score of each node is obtained Next, setting a suitable anomaly score threshold is a key step, which directly determines whether the node is judged as abnormal. The selection of threshold should consider business demand, system performance and risk tolerance, and is usually determined by the performance index (such as ROC-AUC) of verification sample or test sample. Common threshold determination methods include empirical rule, historical data analysis and dynamic adjustment. In the present application, a certain anomaly score is taken as the limit, and if it exceeds the limit, it is abnormal, otherwise it is normal, that is, the threshold Threshold is obtained:
[0088] Threshold=POT(Score Train ,Score Test ,δ) (25)
[0089] In practical operation, the POT (POT) method is used to dynamically adjust the threshold value according to the estimated risk value. By calculating the anomaly score of each vehicle, a ranking list is formed, and vehicles with higher anomaly scores are marked as potential abnormal vehicles, helping traffic management personnel focus on high-risk behaviors and improving the efficiency of identifying and handling abnormal driving patterns. This method combines the graph structure information of the traffic network and deep learning technology to effectively enhance the ability of traffic trajectory anomaly detection, enabling timely detection of potential traffic violations or abnormal driving patterns such as speeding, sudden braking, or reverse driving. By flexibly adjusting the threshold value, the system can adapt to different situations and optimize detection performance, providing an efficient and intelligent solution for urban traffic management and safety.
[0090] S6.2: Form a ranking list by calculating the anomaly score of each interaction, and mark high-scoring abnormal trajectories as potential anomalies. In this way, traffic management departments can focus on high-risk driving behaviors and identify and handle abnormal trajectories such as speeding, sudden braking, or reverse driving in a timely manner, thereby improving the safety and stability of the traffic system. This integration process fully utilizes the graph structure information of the traffic network and deep learning technology to provide a powerful and efficient solution for traffic trajectory anomaly detection.
[0091] The second aspect of the present application relates to a traffic trajectory anomaly detection device based on neighborhood reconstruction and graph contrastive learning, characterized by comprising a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the traffic trajectory anomaly detection method based on neighborhood reconstruction and graph contrastive learning of the present application.
[0092] The present application provides a computer-readable storage medium having a program stored thereon, wherein the program is executed by a processor to implement the traffic trajectory anomaly detection method based on neighborhood reconstruction and graph contrastive learning of the present application.
[0093] The innovation of the present application is: through the combination of graph neural networks and graph contrastive learning technology, the limitations of traditional traffic trajectory anomaly detection methods are broken through, and efficient identification of complex traffic behavior patterns is achieved. Through deep modeling of vehicle nodes and their neighbor nodes, it can accurately capture abnormal behaviors at the vehicle level and vehicle interaction level. At the same time, the present application introduces the ability to identify mixed abnormal behavior patterns, so that the system can not only detect single-type abnormalities, but also handle complex patterns composed of multiple abnormal behaviors.
[0094] The working principle of the present application is (analyze the reasons for the advantages of the invention); the traffic trajectory data is reconstructed by a graph neural network (GNN) to recover the feature vector of the vehicle node and the relationship characteristics with the neighbor nodes. Through multiple GCN layers, the representation of the vehicle node is aggregated and updated, so that each node can learn deeper traffic behavior characteristics. In addition, the graph contrast learning technology is adopted, and through the comparison of positive and negative sample pairs, the model helps to capture node-level and subgraph-level abnormal behaviors. Finally, through multiple detections and the fusion of different abnormal score mechanisms, combined with a dynamically adjusted threshold, the accuracy and stability of traffic trajectory anomaly detection are improved. At the same time, the present application can also identify mixed abnormal behavior patterns, that is, it can detect complex abnormal patterns composed of different types of abnormal behaviors (such as overspeeding, sudden braking, reverse driving, lane deviation, etc.) at the same time, thereby more accurately reflecting the diversified abnormal behaviors in the traffic scene.
[0095] The advantages of the present application are:
[0096] 1. High-precision anomaly detection: combining graph neural networks with graph contrast learning, accurately identifying traffic abnormal driving patterns.
[0097] 2. Robustness: suitable for various traffic scenarios, reducing false positives and false negatives.
[0098] 3. Flexible threshold adjustment: using extreme value theory to dynamically adjust the threshold, optimizing the detection strategy and improving system adaptability.
[0099] 4. Efficient data processing: using graph neural networks and deep learning to process large-scale data, with good scalability. BRIEF DESCRIPTION OF DRAWINGS
[0100] Figure 1 is a structural diagram of the method of the present application;
[0101] Figure 2 is a flowchart of the method of the present application;
[0102] Figure 3 is a traffic trajectory data construction graph;
[0103] Figure 4 is a POT threshold selection diagram for the method of the present application;
[0104] Figure 5 is a schematic diagram of the device of the present application. DETAILED DESCRIPTION
[0105] In order to make the purpose, technical scheme and advantages of the present application clearer, the specific embodiments of the present application will be further described in detail below.
[0106] Example 1
[0107] The embodiment of the application provides a traffic trajectory anomaly detection method based on neighborhood reconstruction and graph contrastive learning, and a system flow as shown in Figure 1 and Figure 2 The method comprises the following steps:
[0108] S1: data cleaning is performed on the basis of original traffic trajectory data, and the steps are as follows:
[0109] S1.1: the original data comes from the Porto data set, the data set is widely used in the traffic trajectory anomaly detection task, and is especially suitable for analyzing urban traffic patterns. The Porto data set contains driving trajectory data of taxis from Porto city, including trajectory records of thousands of taxis and traffic relationships between the taxis. Each trajectory record contains the position (latitude and longitude) of the taxi, a timestamp, a speed, an acceleration and the like. Each taxi in the data is regarded as a node, and the mutual relationship (such as proximity, influence and the like) between the taxis is represented by an edge. The attributes possessed by the data include:
[0110] Table 1
[0111] Number Name Comment 1 Vehicle ID Each taxi has a unique identifier in the dataset 2 Location Each trajectory point contains the current location of the taxi 3 Timestamp Each trajectory point also records the time information 4 Speed The speed of the vehicle 5 Acceleration The acceleration of the vehicle 6 Road type Different types of roads can affect the driving patterns of vehicles …… ……
[0112] S1.2: As can be seen from the table, the Porto data set contains rich traffic trajectory information, involving the position information, speed, acceleration, timestamp and the like of the taxi. In order to ensure the data quality and usability, the data needs to be processed, such as removing noise points, excluding abnormal trajectories, correcting wrong speed or position data and the like. These steps help to ensure the integrity of the data, improve the consistency, and ensure the accuracy. Through the cleaning and preprocessing of the data, a more reliable traffic trajectory anomaly detection model can be constructed, and the abnormal behaviors in the traffic, such as overspeed, reverse driving, sudden braking and the like, can be more accurately analyzed and identified, so that the safety and efficiency of the traffic management are improved, and the normal operation and safety of the traffic system are ensured.
[0113] The following methods are adopted for data cleaning: 1) removing invalid or abnormal records, for example, deleting trajectory points with incomplete position data or beyond the reasonable range, removing noise points caused by positioning system errors or weak signals, and ensuring the authenticity of the trajectory data. 2) filling the missing vehicle feature data such as speed and acceleration, which can be filled by using mean interpolation or features based on similar trajectories, to ensure the integrity and consistency of each trajectory point. Through these cleaning steps, the high quality and accuracy of the Porto data set can be ensured, and a reliable data basis is provided for the traffic trajectory anomaly detection.
[0114] S1.3: Constructing graph structure data. When processing the Porto dataset, the traffic trajectory data is transformed into a graph structure. Each taxi's trajectory is considered as a node in the graph, and the node features include the vehicle's location information (latitude and longitude), speed, timestamp, etc. The edges in the graph represent the relationship between vehicles, usually consisting of trajectories that travel on the same road segment or adjacent intersections within the same time period. By taking the road network (intersections, road segments) as nodes and constructing edges based on the relationship between vehicles, a traffic flow graph structure is formed. In addition, the weight of the edge can be defined by the distance or travel time between vehicles. This graph structure provides the basis data for subsequent anomaly detection and pattern recognition.
[0115] S1.4: For a given undirected graph G = (V, E), where {V1, V2, V3... V N} represents the set of nodes, N represents the number of nodes, and E represents the set of edges. In addition, the node feature matrix X ∈ R N×D is used to represent the node feature information, and the adjacency matrix A ∈ R N×N is used to represent the graph structure information. At the same time, x i ∈ R D is used to represent the features of node v i , and d i is used to represent the degree of each node. For the adjacency matrix A, if A ij = 1, it means that there is an edge between nodes v i and v j , otherwise A ij = 0.
[0116] S1.5: By setting the division ratio of 80% training data and 20% test data, the data distribution is ensured to be uniform. Random sampling is used to allocate samples to the training and test sets, and the training set is used for model learning and optimization, while the test set is used to evaluate the generalization ability of the model. This step helps to accurately evaluate the model effect and provides a basis for parameter optimization.
[0117] S2: Reconstructing graph structure data neighborhood information captures the similarity and difference of attribute space, such as Figure 3 , the specific steps are as follows:
[0118] S2.1: In traffic trajectory anomaly detection, the neighborhood reconstruction module encodes the receiving domain of the node through a graph neural network (GNN) and reconstructs the neighborhood structure of the node in the dimension reduction space. This process not only restores the feature attributes of the node, but also reconstructs the connection mode and attribute relationship between the node and the neighbor nodes, effectively capturing the abnormal information in the trajectory network. The method not only utilizes node representation to reconstruct local neighborhood information, but also further improves the modeling ability of complex relationships between nodes and attribute space by introducing contrastive learning of global structure information. In this way, the abnormal patterns of nodes can be more comprehensively identified, significantly improving the effect of traffic trajectory network anomaly detection.
[0119] S2.2: Capture the similarity and difference of the attribute space. First, the GNN encoder iteratively aggregates the neighbor information of the node to update its own representation. This aggregation operation can capture the structure information of the local neighborhood of the node and the relationship features between the direct neighbors. The mathematical expression of this process is as follows:
[0120]
[0121] where f i (l) represents the feature vector of node i at the l-th layer, UPDATE represents the operation for updating the node feature, and the Aggregation function is used to aggregate the information of the neighbor nodes. N i represents the set of all neighbor nodes of node i.
[0122] f i (l+1) is decoded step by step into to reconstruct the original feature vector f i (0) . Then, the l2-loss is used to calculate the difference between i (0) and f to obtain the node reconstruction loss:
[0123]
[0124] An MLP is used to reconstruct the node degree , and its loss function is as follows:
[0125]
[0126] The empirical distribution P i emp of the neighborhood is approximated by a multivariate Gaussian distribution , and the mean estimation and covariance matrix estimation formula of are as follows:
[0127]
[0128] Then, from f i (l+1) Constructing the approximate distribution Specifically, we utilize f i (l+1) The mean and covariance matrix of the multivariate Gaussian distribution are generated, which can be formulated as follows:
[0129]
[0130] From the generated Gaussian distribution k samples are sampled, and then these samples are transformed into approximate samples of neighbor feature representation by a fully connected neural network (FNN) Finally, the generated neighbor feature samples are used to estimate the new mean and covariance matrix:
[0131]
[0132] Based on the given and The KL divergence between the two distributions is used to measure the reconstruction loss of neighbor attribute features:
[0133]
[0134] where p represents the dimension.
[0135] Finally, the total loss in the neighborhood reconstruction module is as follows:
[0136]
[0137] S3: Subgraph and node sampling to obtain positive and negative sample pairs, and extract the latent representation of subgraph embedding vectors, the specific steps are as follows:
[0138] S3.1: First, initialize the node features, each node is assigned an initial feature vector. Then, through multiple rounds of convolution operations of GCN layers, the node features are gradually updated and aggregated, considering the relationship between the node and its neighbors. This process enables each node to gradually gather information from surrounding nodes, forming a richer representation. It can be represented by the following formula:
[0139]
[0140] where denotes the symmetric normalized adjacency matrix, denotes the hidden representation of the l-th layer, W (l) denotes the weight.
[0141] By extracting the embedding vectors of subgraphs through GCN, the model can more accurately understand the features in the graph structure, providing powerful feature representation for subsequent anomaly detection.
[0142] S3.2: In order to increase the connectivity between nodes in the graph, use skip connection to fuse the underlying spatial features. The new pool readout module mainly includes the following steps. Find the index of the k maximum values:
[0143]
[0144] Then, the corresponding subgraph adjacency matrix is extracted from the original adjacency matrix
[0145]
[0146] In addition, element matrix multiplication is used to obtain a new feature matrix:
[0147]
[0148] Finally, the original structure of the graph is restored by the distribute(·) operation and the final representation z of the subgraph is obtained i , as follows:
[0149] z i = distribute(0 n×c , X (l+1) , idx) (13)
[0150] Correspondingly, the target node features are converted to the same embedding space as the subgraph using MLP, obtaining the final representation e of the node i , and sharing the weight W with the previous GCN (l) :
[0151] e i = σ(X (l) W (l) ) (14)
[0152] S4: The graph contrast learning network captures the similarity and difference of embedding vectors, and the specific steps are as follows:
[0153] S4.1: The embedding representation of the positive and negative sample pairs is obtained. The process of capturing the similarity and difference of embedding vectors by the graph contrast learning network is mainly realized by comparing the similarity of positive and negative sample pairs.
[0154] A bilinear model is used to measure their relationship, which is calculated by the following formula:
[0155]
[0156] Then, the node-subgraph contrast training loss value is calculated using binary cross-entropy (BCE):
[0157]
[0158] Meanwhile, comparison between nodes is also needed, which is more conducive to discovering node-level anomalies. Similarly, a new GCN layer and a pooling layer are used to obtain the GCN embedding of the target node and another node and the final embedding of the target node. A sample pair of positive and negative embeddings representing node-node contrast can also be constructed, and the node-level contrast training loss can be expressed as:
[0159]
[0160] In order to better optimize the embedding representation of subgraphs and the feature recognition ability of nodes, a third contrast mode, i.e., subgraph-subgraph contrast, is defined. As one of the more popular contrast losses, the InfoNCE loss is defined as:
[0161]
[0162] In general, minimizing the InfoNCE loss is equivalent to maximizing the lower bound of mutual information between positive pairs. Finally, in order to speed up the convergence of the model, the loss in the contrast learning training process is aggregated:
[0163]
[0164] where β∈(0,1) is a parameter for balancing node-level anomaly information, is a parameter for balancing subgraph-level anomaly information.
[0165] S5: Define an anomaly score function, and the specific steps are as follows:
[0166] By minimizing the set objective function, the anomaly score of each node can be calculated. By minimizing the objective function, the anomaly score of each node can be calculated In the neighborhood reconstruction module, the anomaly score is calculated according to the node self-reconstruction error, and the reconstruction error is measured by the difference between the reconstructed feature vector and the original feature vector. The calculation method is:
[0167]
[0168] Definition where and represent the similarity of positive pairs and negative pairs, respectively. Based on this rule, the anomaly score of the contrast module can be obtained:
[0169]
[0170] To avoid this situation, multiple detections are performed on each node, and the average of the anomaly scores of each node is taken as the final anomaly score. The above formula is further rewritten as:
[0171]
[0172] where R represents the number of anomaly detections.
[0173] S6: Traffic trajectory data anomaly identification application process, such as Figure 4 , the specific steps are as follows:
[0174] S6.1: Take a certain anomaly score as the boundary, and if it exceeds the boundary, it is abnormal, otherwise it is normal, that is, get Threshold:
[0175] Threshold=POT(Score Train ,Score Test ,δ) (25)
[0176] Where POT is a statistical method based on extreme value theory, which dynamically determines the threshold value through the estimated risk value, first calculates the anomaly score of all points in the training sample and test sample sequence, then sets the risk value δ∈(0,1) size, get Threshold.
[0177] S6.2: By calculating the anomaly score of each interaction, a sorted list is formed, and the high-score anomaly trajectory is marked as a possible anomaly. In this way, the traffic management department can focus on high-risk trajectory behavior, achieve timely identification and processing of abnormal behavior, and improve traffic safety and efficiency. Through the integration of graph structure and deep learning technology, traffic trajectory anomaly detection provides an efficient solution.
[0178] The application case implementation shows that the traffic trajectory anomaly detection method based on neighborhood reconstruction and graph contrast learning is effective. Compared with other design methods, the application combines graph contrast learning with a neighborhood reconstruction module and applies it to traffic trajectory data to perform efficient anomaly detection in combination with three contrast modes. The neighborhood reconstruction module uses a graph neural network (GNN) to encode the receptive field of the vehicle trajectory, reconstructs the neighborhood relationship between vehicles in the dimension reduction space, and effectively captures the abnormal information of the traffic network in the attribute space. In order to enhance the connectivity between trajectories, a GCN layer and a jump connection are used to fuse the bottom features. The model processes the Porto dataset into graph structure data as input and outputs the anomaly score of each vehicle. In addition, the POT method is used to dynamically determine the threshold, and whether the trajectory is abnormal is determined according to whether the anomaly score is greater than the threshold. The experiment uses real traffic trajectory data, and the results fully prove the feasibility and superiority of the model.
[0179] Embodiment 2 is as Figure 5 The embodiment relates to a traffic trajectory anomaly detection device based on neighborhood reconstruction and graph contrast learning, comprising a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the traffic trajectory anomaly detection method based on neighborhood reconstruction and graph contrast learning in embodiment 1.
[0180] Embodiment 3
[0181] The embodiment relates to a computer readable storage medium, which stores a program, and the program is executed by a processor to implement the traffic trajectory anomaly detection method based on neighborhood reconstruction and graph contrast learning in the claim.
[0182] The above is a specific embodiment of the application and the technical principle applied, and if changes are made according to the concept of the application, the function generated still does not exceed the spirit covered by the specification and drawings, and still belongs to the protection range of the application.
Claims
1. A traffic trajectory anomaly detection method based on neighborhood reconstruction and graph comparison learning, comprising the following steps: S1: Select widely used traffic trajectory data, preprocess the raw data, and define the corresponding graph structure data; S2: Reconstructing the neighborhood information of graph structure data captures the similarity and differences in the attribute space; S3: Subgraph and node sampling obtain positive and negative sample pairs, and extract the latent representation of the subgraph embedding vector; S4: Graph contrastive learning networks capture the similarity and differences of embedded vectors; S5: Define the anomaly scoring function; S6: Perform anomaly detection on traffic trajectory data; Step S1 includes the following steps: S1.1: Select a suitable traffic trajectory dataset; S1.2: Clean the raw data, remove invalid or abnormal records, and fill in missing node feature data; S1.3: Construct graph-structured data, abstracting the cleaned Porto traffic trajectory data into graph data; each taxi is represented as a node in the graph, and the characteristics of the node include the vehicle's location information, speed, and acceleration; construct a graph structure that reflects the urban traffic network, and the weight of the edges is defined according to the distance between vehicles, travel time, or traffic flow density, so as to more accurately capture the dynamic features in the traffic network. S1.4: For a given undirected graph G = (V, E), where {V1, V2, V3, ..., V} N Let} represent the set of nodes, N represent the number of nodes, and E represent the set of edges; furthermore, the node feature matrix X∈R is used. N×D Representing node feature information, the adjacency matrix A∈R N ×N Represents graph structure information; simultaneously, x is used i ∈R D Represents node v i Features, using d i Represents the degree of each node; for an adjacency matrix A, if A ij =1, then it means node v i and v j There exists an edge between them, otherwise A ij =0; S1.5: Divide the processed traffic trajectory data into training samples and test samples; 80% are used for training and 20% for testing. Step S2 includes the following steps: S2.1: In reconstructing the neighborhood information of graph structure data, the receiving domain of the node is encoded by the graph neural network (GNN), and the neighborhood structure of the node is reconstructed in the dimensionality reduction space. Not only is local neighborhood information reconstructed using node representation, but also the ability to model complex relationships between nodes and attribute space is further improved by introducing comparative learning of global structural information. S2.2: In order to capture the similarity and difference in the attribute space, the node's own representation is updated by iteratively aggregating the neighbor information of the node through the GNN Encoder. This aggregation operation can capture the structural information of the node's local neighborhood and the relationship features with its direct neighbors. The feature information is then decoded by the GNN Decoder.
2. The traffic trajectory anomaly detection method based on neighborhood reconstruction and graph comparison learning as described in claim 1, characterized in that: Step S3 includes the following steps: S3.1: Extracting the embedding vectors of the subgraph is a crucial step in traffic trajectory anomaly detection, employing a Graph Convolutional Network (GCN) layer. Prior to this, to make the obtained latent representation more discriminative, the attributes of the target nodes in the subgraph need to be masked beforehand. Their hidden layer feature representations can be expressed by the following formula: in Represents a symmetric normalized adjacency matrix. W represents the hidden representation of the l-th layer. (l) Indicates weight; By extracting the embedding vectors of subgraphs using GCN, the model can more accurately understand the features in the graph structure, providing a powerful feature representation for subsequent anomaly detection. S3.2: To increase connectivity between nodes in the graph, skip connections are used to fuse underlying spatial features; the new pool readout module includes the following steps; find the indices of the k maximum values: Then, in the original adjacency matrix Extract the corresponding subgraph adjacency matrix In addition, element-wise matrix multiplication is used to obtain new feature matrices: Finally, the original structure of the graph is restored through the distribute(·) operation, and the final subgraph representation z is obtained. i The formula is as follows: z i =distribute(0 n×c ,X (l+1) ,idx) (13) Accordingly, the target node features are transformed into the same embedding space as the subgraph using MLP, resulting in the final node representation e. i It shares weight W with the previous GCN. (l) : e i = σ(X (l) W (l) ) (14).
3. The traffic trajectory anomaly detection method based on neighborhood reconstruction and graph comparison learning as described in claim 1, characterized in that: Step S4 includes the following steps: S4.1: Based on the above operations, the embedding representations of positive and negative sample pairs are obtained; the process of the graph contrastive learning network capturing the similarity and difference of the embedding vectors is achieved by comparing the similarity of positive and negative sample pairs; The relationship between them is measured using a bilinear model, calculated using the following formula: Then, the node-subgraph comparison training loss is calculated using binary cross-entropy (BCE): Simultaneously, comparisons need to be made between nodes, which is more conducive to detecting node-level anomalies; the training loss for comparisons between nodes can be expressed as: To better optimize the embedding representation of subgraphs and the feature recognition capability of nodes, a third contrast mode is defined: subgraph-subgraph contrast. As one of the more popular contrast losses, the InfoNCE loss is defined as: Generally, minimizing the InfoNCE loss is equivalent to maximizing the lower bound of the mutual information between opposing views; finally, to accelerate model convergence, the losses during contrastive learning training were aggregated. Where β∈(0,1) is a parameter used to balance node-level anomaly information. These are parameters used to balance anomaly information at the subgraph level; By maximizing the similarity of positive sample pairs and minimizing the similarity of negative sample pairs, graph contrastive learning networks optimize model parameters through an aggregated loss function, aiming to make similar embedding vectors closer together and dissimilar embedding vectors more dispersed.
4. The traffic trajectory anomaly detection method based on neighborhood reconstruction and graph comparison learning as described in claim 1, characterized in that: Step S5 includes the following steps: S5: By minimizing the defined objective function, the anomaly score for each node can be calculated; by minimizing the objective function, the anomaly score for each node can be calculated. In the neighborhood reconstruction module, anomaly scores are calculated based on node self-reconstruction errors. The reconstruction error is measured by the degree of difference between the reconstructed feature vector and the original feature vector. The calculation method is as follows: definition in and These represent the similarity scores of positive and negative pairs, respectively; based on this rule, the anomaly score of the comparison module can be obtained: Considering the randomness of a single detection, to avoid this, multiple detections are performed on each node to obtain an anomaly score for each node, and the average of these scores is taken as the final anomaly score; the above formula is further rewritten as: Where R represents the number of anomaly detections.
5. The traffic trajectory anomaly detection method based on neighborhood reconstruction and graph comparison learning as described in claim 1, characterized in that: Step S6 includes the following steps: S6.1: Use a certain abnormal score as a threshold; scores exceeding this threshold are considered abnormal, while scores below it are considered normal. This is how the threshold is determined. Threshold= POT(Score Train ,Score Test ,δ) (25) POT is a statistical method based on extreme value theory. It dynamically determines the threshold by estimating the risk value. First, it calculates the outlier score of all points in the training and test sample sequences, and then sets the risk value δ∈(0,1) to obtain the Threshold. S6.2: By calculating the anomaly score for each interaction, a sorted list is formed, with high-scoring anomaly trajectories... Marked as a possible exception; In this way, traffic management departments can focus on high-risk trajectory behaviors, achieve timely identification and handling of abnormal behaviors, and improve traffic safety and efficiency; by integrating graph structure and deep learning technologies, traffic trajectory anomaly detection provides an efficient solution.
6. A traffic trajectory anomaly detection device based on neighborhood reconstruction and graph comparison learning, characterized in that, The device includes a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the traffic trajectory anomaly detection method based on neighborhood reconstruction and graph comparison learning as described in any one of claims 1-5.
7. A computer-readable storage medium, characterized in that, It stores a program that, when executed by a processor, implements the traffic trajectory anomaly detection method based on neighborhood reconstruction and graph comparison learning as described in any one of claims 1-5.
Citation Information
Patent Citations
Traffic track anomaly detection method and device based on graph contrast learning
CN118196534A
Mobile user track prediction method and system
CN119005457A