Traffic trajectory anomaly detection method and device based on graph contrastive learning
Patent Information
- Application Number
- CN202410406837.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-07
- Publication Date
- 2026-08-28
- Estimated Expiration
- 2044-04-07
AI Technical Summary
[0003]随着城市交通系统的复杂化和交通数据的急剧增长,传统的交通异常检测方法面临着越来越大的挑战:1)通常依赖于手工制定的规则和阈值,这使得其难以适应交通系统动态变化和多样性的异常模式
[0068]本发明的优点是:采用了基于图对比学习的网络模型,有效克服了传统交通异常检测方法的诸多限制,实现了精准的交通异常检测。本发明不依赖于手工制定的规则和阈值,能够更好地适应交通系统的动态变化和多样性的异常模式;同时,能够处理高维度和异构性的交通数据,捕捉车辆之间复杂的关联关系和交通的内在结构;此外,还具备对时序数据和动态变化的处理能力,能够实时地适应交通流量的变化和新兴的异常模式,大大提高了交通异常检测的准确性和实时性,为城市管理和智慧城市的发展带来了显著的改进,提高了城市运行效率,增强了公民安全和生活质量。
Smart Images

Figure CN118196534B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method and apparatus for identifying abnormal behavior in traffic trajectories, belonging to the field of artificial intelligence technology. Background Technology
[0002] Against the backdrop of the booming development and digital transformation of the current transportation system, traffic trajectory anomaly detection remains a core tool for traffic management and maintaining social safety, and has made significant progress in its level of intelligence. This progress has led to a larger and more complex traffic trajectory network, but it has also brought about more concealed and sophisticated traffic violations, accidents, and other illegal activities. Imagine if traffic management departments fail to detect and prevent traffic violations in a timely manner; this would directly lead to an increase in traffic accidents, threaten road safety, and may even result in legal liability. With the continuous increase in urban traffic flow, the importance of traffic trajectory anomaly detection is becoming increasingly prominent. Furthermore, emphasizing potential traffic accident hazards has become crucial. The lack of a robust anomaly detection system may allow drivers to introduce dangers into normal traffic flows through complex driving behaviors, thereby evading detection. This not only threatens the safety of the transportation system but may also, to some extent, undermine the stability of the entire transportation network. Therefore, building a robust and intelligent traffic trajectory anomaly detection mechanism is essential. This will not only help improve the safety and management efficiency of the transportation system but also ensure the travel safety of urban residents, reduce the tragedies caused by traffic accidents, and create a safer and more stable transportation environment for society.
[0003] With the increasing complexity of urban transportation systems and the rapid growth of traffic data, traditional traffic anomaly detection methods face growing challenges: 1) They typically rely on manually defined rules and thresholds, making them ill-suited to the dynamic changes and diverse anomaly patterns within the transportation system. This rigid rule system struggles to address new violations and traffic patterns, resulting in high false negative rates and vulnerability to attacks. 2) They have limited processing capabilities for high-dimensional and heterogeneous traffic data, failing to effectively capture the complex relationships between vehicles and the inherent structure of traffic. This makes traditional methods inadequate for identifying abnormal traffic or accident behaviors involving multiple nodes. 3) They lack the ability to process time-series data and dynamic changes, failing to adapt to real-time changes in traffic flow and emerging anomaly patterns, thus becoming slow and insensitive.
[0004] Overall, traditional traffic anomaly detection methods exhibit certain limitations in dealing with complex and ever-changing urban traffic systems, urgently requiring more adaptive and intelligent methods to improve the accuracy and real-time performance of anomaly detection. New traffic anomaly detection methods should be able to flexibly adapt to changes in different scenarios, using intelligent algorithms to process high-dimensional, heterogeneous data to more comprehensively and accurately identify abnormal traffic behaviors involving multiple nodes, thereby better maintaining the safety and smooth flow of urban traffic.
[0005] Thanks to the development of deep learning methods based on graph-structured data, especially the expansion of graph neural network (GNN) technology, new ideas and efficiency have been provided for anomaly detection. GNNs can effectively capture the complex relationships between nodes (such as vehicles or intersections) in traffic systems, thus providing a more comprehensive analysis and understanding of the entire traffic trajectory network. Their powerful feature learning capabilities enable the system to automatically learn and adapt to constantly evolving anomaly patterns, making them more flexible and intelligent compared to traditional methods. GNNs can learn complex interactions between nodes, better understanding the temporal and spatiotemporal relationships in traffic systems. Secondly, GNNs can learn and capture anomaly patterns in traffic trajectories. By analyzing the embedded representations of nodes and edges, unusual traffic behaviors, such as abnormal speeds and illogical paths, can be identified, helping to promptly discover potential problems. Therefore, the development of graph neural networks has provided a powerful tool for traffic trajectory anomaly detection, driving innovation and progress in anomaly detection technology in the transportation field. These innovations will help improve the safety and smoothness of urban traffic, reduce traffic accidents, and provide a safer and more efficient travel environment for urban residents.
[0006] Against this backdrop, this study focuses on the transportation field and proposes a traffic trajectory anomaly detection method based on graph contrastive learning. First, traffic trajectories are abstracted as a graph structure, where nodes represent vehicles or intersections, and edges represent the spatiotemporal relationships between them. By introducing graph contrastive learning, features of normal traffic trajectory graphs are captured, enabling efficient detection of anomalous trajectories that do not conform to normal patterns. The key lies in using graph embedding technology to map the graph structure to a low-dimensional space. By comparing graph embedding vectors to measure the similarity between graphs, the existence of anomalous trajectories is determined. The innovation of this method lies in integrating the structural information of the graph, providing a more flexible and intelligent means to capture complex anomaly patterns. Summary of the Invention
[0007] The present invention aims to overcome the above-mentioned shortcomings of the prior art and provides a method and apparatus for detecting traffic trajectory anomalies based on graph comparison learning.
[0008] This invention employs a graph-based contrastive learning network model to achieve accurate detection of abnormal trajectories in the transportation sector. By utilizing deep learning technology to analyze real-time and historical data in urban transportation networks, it identifies unusual traffic patterns and behaviors, such as traffic congestion, accidents, and illegal driving. This information is crucial for city managers, as it allows for rapid response to traffic anomalies, optimization of traffic flow, improvement of road safety, and provides strong data support for public transportation planning. Furthermore, anomaly detection in traffic trajectories helps reduce environmental impact by optimizing traffic flow to reduce carbon emissions, providing an effective means for smart cities to improve urban operational efficiency and enhance citizen safety and quality of life.
[0009] This invention first abstracts traffic trajectories into a graph structure, where nodes represent vehicles or intersections, and edges represent the spatiotemporal relationships between them. Second, positive and negative sample pairs are generated through subgraph sampling so that the model can learn patterns of normal and abnormal trajectories. Next, the subgraph data is input into a Graph Convolutional Network (GCN) layer to obtain hidden layer information and latent representations of the subgraphs, and features of nodes and edges are extracted progressively. Then, three comparison methods of graph contrastive learning (node-to-node comparison, subgraph-to-subgraph comparison, and node-to-subgraph comparison) are used to learn the differences between normal and abnormal nodes in the graph structure. Finally, the abnormal information learned from each comparison mode is integrated to identify traffic trajectory anomalies.
[0010] The present invention achieves the above objectives through the following technical solutions:
[0011] The first aspect of this invention relates to a traffic trajectory anomaly identification method based on graph contrast learning, comprising the following implementation steps:
[0012] S1: Define the graph structure corresponding to the traffic trajectory;
[0013] S2: Subgraph and node sampling to obtain positive and negative sample pairs;
[0014] S3: Extract the latent representation of the subgraph embedding vector;
[0015] S4: Graph contrastive learning networks capture the similarity and differences of embedded vectors;
[0016] S5: Define the anomaly scoring function;
[0017] S6: Apply a scoring function to detect traffic trajectory anomalies.
[0018] S1 specifically includes the following steps:
[0019] S1.1: The invention is further described using a large-scale natural vehicle trajectory example from a German highway (HighD). This trajectory includes six different locations near Cologne, Germany, with locations varying depending on the number of lanes and speed limits. The recorded data includes both cars and trucks. It encompasses 11.5 hours of measurements from the six locations and 110,000 vehicles, with a total measured vehicle mileage of 45,000 km, and also includes 5,600 complete lane change records.
[0020] S1.2: HighD abstraction of traffic trajectory data into a graph. Each vehicle is represented as a node in the graph, and edges represent relationships between them, such as proximity and mutual influence, constructing a graph structure reflecting the urban traffic network. During this process, additional attribute information, such as vehicle type, speed, and acceleration, can be added to nodes and edges to enrich the graph's representational capabilities. Specifically, this traffic trajectory data includes vehicle driving information on highways, including location, speed, and acceleration. Within this graph structure, nodes can be further classified, for example, vehicles can be categorized into normal driving, speeding, and emergency braking. Such classification helps identify abnormal traffic behaviors, such as traffic violations and accidents. Overall, by constructing a graph structure for traffic trajectories, a better understanding of the dynamic characteristics of urban traffic can be achieved, thus providing more insights and support for traffic management and safety.
[0021] S1.3: Defining the graph and anomaly detection problem. For a given undirected graph... Let T represent the set of nodes, T represent the number of nodes in the graph, and E represent the set of edges. Additionally, use... and Representing node features and graph structure respectively, where Represents node n t Features The adjacency matrix is a square matrix. Representation. For an adjacency matrix A, if A ij =1, then it represents node n i and n j There exists an edge between them, otherwise A ij =0. The goal of this invention is to detect all abnormal nodes in a given graph that contain abnormal nodes. The solution to this problem is as follows: The model with adjacency matrix A learns an anomaly scoring function. To measure The degree of anomaly of each node in S(n). t The larger the value of n, the better. t 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 ρ.
[0022] S2 specifically includes the following steps:
[0023] S2.1: Subgraph Sampling to Obtain Positive and Negative Sample Pairs. The EdgeModification (EM) method plays a crucial role in the subgraph sampling process for traffic trajectory anomaly detection. First, a center node is selected, typically representing a specific vehicle. Next, sampling is performed from the set of neighboring nodes of the center node to obtain the neighbor node set. Then, through edge addition or removal operations, with probability P... add Add an edge with probability P remove Remove one edge. This process probabilistically generates positive and negative sample subgraph pairs. The positive sample subgraph retains some correspondences from the original graph, while the negative sample subgraph introduces anomalies or interference by adjusting edge connections. Through this process, the Edge Modification method generates a series of positive and negative sample subgraph pairs with different connection structures, providing diverse and rich training data for subsequent graph comparison learning, and helping to improve the model's ability to learn normal and abnormal patterns in trajectory data.
[0024] S2.2: Node Sampling for Positive and Negative Sample Pairs. Since this paper focuses on node-level anomalies in the graph, it is necessary to sample the target nodes. The main method used is to randomly extract the target node and its edges from a view of the subgraph sample. To effectively distinguish between abnormal and normal nodes, random walks and restarts (RWR) are used for sampling. Starting with a node, a series of node sequences, i.e., random walk paths, are generated by performing random walks and periodically restarting the walk process. Positive and negative sample node pairs can be obtained through these paths. Positive samples correspond to nodes with similar random walk paths, while negative samples correspond to nodes with different paths. By adjusting the number of random walk steps and the restart frequency, the RWR method can balance the capture of local structure and the consideration of global information during the generation of sample pairs, providing rich training data for subsequent graph comparison learning and enhancing the model's ability to learn and identify abnormal patterns in traffic trajectory data.
[0025] S3 specifically includes the following steps:
[0026] S3.1: Extracting embedding vectors from subgraphs using Graph Convolutional Network (GCN) layers. Extracting subgraph embedding vectors using GCN layers is a crucial step in traffic trajectory anomaly detection. To make the obtained latent representations more discriminative, the attributes of target nodes in the subgraphs are masked beforehand. Their hidden layer feature representations can be expressed by the following formula:
[0027]
[0028]
[0029]
[0030] in, Let I be the adjacency matrix of a subgraph with self-loops. T It is the identity matrix. Represents a symmetric normalized adjacency matrix. express The degree matrix, W (l-1) Let represent the learnable weight matrix of the l-th layer. σ is the nonlinear parameter ReLU (PReLU). Graph convolution operations are performed on the subgraph through GCN layers to aggregate and update the feature information of each node. This process utilizes the adjacency matrix and node features of the subgraph, achieving information transfer and feature extraction of the subgraph structure through weight sharing. Subsequently, by stacking multiple GCN layers, higher-order node representations are gradually obtained, enriching the structural and feature information of the subgraph.
[0031] S3.2: Pooling or aggregation operations are performed on the node embedding vectors to obtain the latent representation of the entire subgraph. This process integrates the structural and feature information of the subgraph into the embedding vectors, providing a higher-level and more comprehensive subgraph representation for subsequent graph comparison learning, enabling the model to more accurately capture patterns and anomalous behaviors in traffic trajectory data. Generally, the final representation of the subgraph can be calculated using the ReadOut(·) function. A common method is to implement ReadOut(·) using average pooling, i.e., using the average of all node representations as the final graph representation. However, this method often ignores a lot of key information, such as the graph structure. To increase the connectivity between nodes in the graph, skip connections are used to fuse underlying spatial features. The new pooling readout module mainly includes the following steps: Sort the nodes with the largest projected scalar values on v and find the indices of the k largest values:
[0032] y = X (l) v (l) / ||v (l) ||
[0033] idx = rank(y,k)
[0034] Where v represents a learnable projection vector. Then, for Perform row and fetch operations:
[0035]
[0036] Furthermore, using a vector of size C, with all components equal to 1, and employing element-matrix multiplication, a new adjacency matrix is obtained. and characteristic matrix
[0037]
[0038] Finally, the original structure of the graph is restored, and the final representation of the subgraph is obtained through the distribute(·) operation. This operation distributes the row vectors in X to 0 according to their corresponding indices in idx. N×C In the characteristic matrix:
[0039] z = distribute(0 T×C ,X (l+1) ,idx)
[0040] Since the target nodes in the subgraph are pre-masked, their features are mapped into the subgraph embedding space using the weight matrix of the GCN to obtain the final representation e of the target nodes. t :
[0041]
[0042] S4 specifically includes the following steps:
[0043] S4.1: Quantization of embedding representations of positive and negative sample pairs (z t ,e t )and The similarity is calculated. The process by which graph contrastive learning networks capture the similarity and differences in embedding vectors is primarily achieved by comparing the similarity of positive and negative sample pairs. For each pair of positive and negative samples, by calculating the similarity of their embedding vectors, the network can learn that positive sample pairs have higher similarity, while negative sample pairs have lower similarity. Further measurement of their similarities and differences is needed, calculated using the following formula:
[0044]
[0045]
[0046] Then, the node-subgraph comparison training loss is calculated using binary cross-entropy (BCE):
[0047]
[0048] Simultaneously, comparisons between nodes are necessary to facilitate the detection of trajectory anomalies. Similarly, a new GCN layer and pooling layers are used to obtain the GCN embeddings of the target node and another node, as well as the final embedding of the target node. Furthermore, sample pairs representing positive and negative embeddings for node-to-node comparisons can be constructed, and the correlation (u) between these two sample pairs can be obtained. t and The comparison training loss between nodes can then be expressed as:
[0049]
[0050] S4.2: Define the subgraph-subgraph comparison mode. Specifically, compare the subgraph z... i And its perturbation subgraph is considered to be positively relative to g t The augmented view of other subgraphs with the same training batch is treated as a negative pair. z i and other subgraphs z in the same training batch j As the first negative pair and z j As the second negative pair An augmented view. As one of the more popular contrast losses, InfoNCE loss is defined as:
[0051]
[0052] 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 from the contrastive learning training process were aggregated:
[0053]
[0054] Here, β∈(0,1) is a parameter used to balance node-level anomaly information, and γ∈(0,1) is a parameter used to balance subgraph-level anomaly information. By maximizing the similarity of positive sample pairs and minimizing the similarity of negative sample pairs, the graph contrastive learning network optimizes the model parameters through an aggregated loss function, aiming to make similar embedding vectors closer together and dissimilar embedding vectors more dispersed. This process enables the model to better distinguish the embedding vectors of normal and anomalous trajectories during learning, thereby improving the accuracy and robustness of anomaly detection.
[0055] S5 specifically includes the following steps:
[0056] S5.1: Calculate the anomaly score for each node by minimizing the defined objective function. In contrastive learning networks, taking the comparison between a node and its subgraph as an example, a normal node is similar to the subgraph of its positive sample pair, but dissimilar to the subgraph of its negative sample pair. Anomaly nodes behave differently, significantly different from positive and negative samples. Based on this rule, the anomaly score calculation formula can be obtained as follows:
[0057]
[0058] Considering the randomness inherent in a single detection, to avoid this, each node is detected multiple times to obtain an anomaly score for each node, and the average of these scores is taken as the final anomaly score. The above formula can be further rewritten as:
[0059]
[0060] Where R represents the number of anomaly detections.
[0061] S6 specifically includes the following steps:
[0062] S6.1: Applying the scoring function Anomaly detection is performed on traffic trajectories. Setting an anomaly score threshold is a crucial decision-making step, directly impacting the determination of normal and abnormal trajectories. The selection of this threshold should comprehensively consider business needs, system performance requirements, and risk tolerance. Typically, depending on the specific application scenario, a suitable threshold can be selected by evaluating performance metrics (such as ROC curves and AUC). Rules of thumb, historical data analysis, error analysis, and dynamic adjustment are all effective methods for determining the threshold, aiming to balance accuracy, recall, and false positive rate to achieve accurate identification of abnormal trajectories and optimize system performance. This process provides the anomaly detection system with flexibility and adjustability, enabling it to effectively cope with the complexity of traffic trajectory data in different scenarios. In this invention, a certain anomaly score is used as a boundary; exceeding this boundary indicates an anomaly, while falling below it indicates normality, i.e., obtaining the threshold:
[0063] Threshold=POT(Score_Train,Score_Test,δ)
[0064] POT is a statistical method based on extreme value theory. It dynamically determines the threshold by estimating the risk value and setting the size of the risk value δ∈{0,1} to obtain the Threshold.
[0065] S6.2: By calculating the anomaly score for each traffic trajectory data point, a sorted list is generated, with high-scoring anomaly trajectories being the most likely to be anomalies. These are marked as potential anomalies. This allows traffic management departments or analysts to focus on high-risk vehicle behaviors, enabling timely identification and handling of abnormal behavior, thus improving the safety and stability of the traffic system. This integrated process fully leverages graph structure information and deep learning technology, providing a powerful and efficient solution for traffic trajectory anomaly identification.
[0066] A second aspect of the present invention relates to a traffic trajectory anomaly detection device based on 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 a traffic trajectory anomaly detection method based on graph contrast learning of the present invention.
[0067] A third aspect of the invention relates to a computer-readable storage medium having a program stored thereon that, when executed by a processor, implements a traffic trajectory anomaly detection method based on graph contrast learning according to the present invention.
[0068] The advantages of this invention are: it employs a network model based on graph contrastive learning, effectively overcoming many limitations of traditional traffic anomaly detection methods and achieving accurate traffic anomaly detection. This invention does not rely on manually defined rules and thresholds, enabling it to better adapt to the dynamic changes and diverse anomaly patterns of the traffic system; simultaneously, it can handle high-dimensional and heterogeneous traffic data, capturing complex relationships between vehicles and the inherent structure of traffic; furthermore, it possesses the ability to process time-series data and dynamic changes, adapting in real-time to changes in traffic flow and emerging anomaly patterns, greatly improving the accuracy and real-time performance of traffic anomaly detection. This brings significant improvements to urban management and the development of smart cities, enhancing urban operational efficiency and improving citizen safety and quality of life. Attached Figure Description
[0069] Figure 1 This is a structural diagram of the method of the present invention;
[0070] Figure 2 This is a projection diagram of the GCN layer of the present invention;
[0071] Figure 3 This is a diagram of the graph contrast learning network structure of the present invention;
[0072] Figure 4 This is a diagram showing the selection of the POT threshold in this invention;
[0073] Figure 5 This is a flowchart of the method of the present invention. Detailed Implementation
[0074] To make the objectives, technical solutions, and advantages of the present invention clearer, the specific embodiments of the present invention will be described in further detail below.
[0075] Example 1
[0076] This invention provides a traffic anomaly trajectory detection method based on graph comparison learning. The system flow is as follows: Figure 1 As shown, the method includes:
[0077] S1: Define the graph structure of the traffic trajectory, the steps are as follows:
[0078] S1.1: The invention is further described using HighD, a large-scale natural vehicle trajectory example from a German highway. It includes six different locations near Cologne, Germany, with locations varying depending on the number of lanes and speed limits. The recorded trajectories include both cars and trucks. The traffic trajectory encompasses 11.5 hours of measurements from the six locations and 110,000 vehicles, with a total measured vehicle mileage of 45,000 km, and also includes 5,600 complete lane change records. In this traffic trajectory data, each vehicle can be considered a node, and the relationships between vehicles are represented by edges. This trajectory data records information such as vehicle position, speed, and acceleration, providing rich features for anomaly detection tasks. Nodes can be labeled as legitimate (normal driving, compliant lane changes, etc.) or illegitimate (violations, accidents, etc.) entities. The goal of using this traffic trajectory for anomaly detection is to classify the nodes in the graph to identify abnormal vehicle behavior, contributing to the research and development of traffic trajectory anomaly detection algorithms.
[0079] S1.2: Traffic trajectories are abstracted into a graph structure using HighD. Each vehicle is represented as a node in the graph, and the relationships between vehicles are represented by the edges. Nodes can include information such as vehicle position, speed, and acceleration, while edges represent the spatiotemporal positional relationships between vehicles. Through this abstraction, complex traffic trajectories are transformed into a graph structure, making it possible to perform anomaly detection using methods such as graph neural networks. This graph structure not only better captures the correlations between trajectories but also provides a strong foundation for subsequent graph comparison learning, enabling the model to more comprehensively understand and identify abnormal trajectory behaviors.
[0080] S1.3: Defines the graph structure, nodes, and edges of the HighD trajectory. Undirected graph. Let T represent the set of nodes, T represent the number of nodes in the graph, and E represent the set of edges. Additionally, use... and These represent the node features and the graph structure, respectively. Represents node n t Features The adjacency matrix is a square matrix. Representation. For an adjacency matrix A, if A ij =1, then it represents node n i and n j There exists an edge between them, otherwise A ij =0.
[0081] S2: Obtain positive and negative sample pairs by sampling subgraphs and nodes. The specific steps are as follows:
[0082] S2.1: Subgraph sampling is performed on the graph structure of the HighD trajectory using the Edge Modification (EM) method. First, vehicles with potentially anomalous characteristics are selected as center nodes, and edges are modified starting from these nodes to generate a subgraph slightly different from the original graph. This modification process aims to simulate potential anomalous behavior, ensuring that the generated subgraph contains contextual information about possible anomalous trajectories. Next, some nodes are randomly selected from the modified subgraph as negative samples. These nodes are not directly related to the center node and are used to construct negative sample pairs. Simultaneously, the center node and its direct neighbors are used as positive sample pairs. Thus, the positive and negative sample pairs obtained through the EM method constitute the positive trajectory samples for training the graph contrastive learning model, enabling the model to learn the contextual relationships of anomalous trajectories and improve its sensitivity to anomalous behavior. This subgraph sampling process is crucial for capturing the contextual information of anomalous trajectories, providing targeted samples for subsequent model training.
[0083] S2.2: The Random Walks and Restart (RWR) method is used to sample nodes in the graph structure of the HighD trajectory. Vehicle nodes with potentially anomalous features are selected as seed nodes. The RWR method performs random walks in the graph to simulate the propagation process of vehicles in the graph network. The concept of restarting allows the walk to return to the seed node with a certain probability at each step, thus enhancing the seed node's influence. During the walk, some nodes are selected from each step as negative samples; these nodes have no direct association with the seed node and are used to construct negative sample pairs. Simultaneously, the seed node and its direct neighbors are used as positive sample pairs. In this way, the positive and negative sample pairs obtained from node sampling constitute the trajectory samples for comparative learning of the training graph, enabling the model to better capture the relationships between nodes.
[0084] S3: Extract the latent representation of the subgraph embedding vectors. The specific steps are as follows:
[0085] S3.1: Extracting the embedding vector of the subgraph using GCN. First, the node features are initialized, with each node assigned an initial feature vector. Then, through multiple rounds of convolutional operations in the GCN layer, the node features are progressively updated and aggregated, taking into account the relationships between nodes and their neighbors. This process allows each node to gradually gather information from surrounding nodes, forming a richer representation. For the subgraph, GCN transmits information among all nodes in the subgraph, ultimately generating a hidden layer embedding vector that represents the overall features of the subgraph. This embedding vector reflects the relationships between nodes in the subgraph, helping to capture the contextual information of abnormal trajectories. It can be expressed by the following formula:
[0086]
[0087]
[0088]
[0089] in, Let I be the adjacency matrix of a subgraph with self-loops. T It is the identity matrix. Represents a symmetric normalized adjacency matrix. express The degree matrix, W (l-1) Let represent the learnable weight matrix of the l-th layer. σ is the nonlinearity of the ReLU (PReLU) parameter. By extracting the embedding vectors of the subgraph through GCN, the model can more accurately understand the features in the graph structure, providing a powerful feature representation for subsequent anomaly detection.
[0090] S3.2: Embedding vector X of nodes (l) Pooling or aggregation operations are performed to obtain the latent representation of the entire subgraph. To increase connectivity between nodes in the graph, skip connections are used to fuse underlying spatial features. The new pooling readout module mainly includes the following steps: 1) Sort the nodes with the largest projected scalar values on v and find the indices of the k largest values:
[0091] y = X (l) v (l) / ‖v (l) ||
[0092] idx = rank(y,k)
[0093] Where v represents a learnable projection vector. 2) For Perform row and fetch operations:
[0094]
[0095] 3) Use a vector of size C, with all components equal to 1, and obtain a new adjacency matrix using element-wise matrix multiplication. and characteristic matrix
[0096]
[0097] 4) Restore the original structure of the graph and obtain the final representation of the subgraph through the distribute(·) operation. This operation distributes the row vectors in X to 0 according to their corresponding indices in idx. N×C In the characteristic matrix:
[0098] z = distribute(0 T×C ,X (l+1) ,idx)
[0099] Since the target nodes in the subgraph are pre-masked, their features are mapped into the subgraph embedding space using the weight matrix of the GCN, resulting in the final representation e of the target nodes. t :
[0100]
[0101] S4: The graph contrastive learning network captures the similarity and differences of the embedded vectors. The specific steps are as follows:
[0102] S4.1: Measure positive sample pairs (z t ,e t ) and negative sample pairs The similarity and differences between them. The process of graph contrastive learning networks capturing the similarity and differences of embedded vectors is mainly achieved by comparing the similarity between positive and negative sample pairs. The following formula measures their similarities and differences:
[0103]
[0104]
[0105] Then, the node-subgraph comparison training loss is calculated using binary cross-entropy (BCE):
[0106]
[0107] Simultaneously, comparisons between nodes are necessary to facilitate the detection of node-level anomalies. Similarly, a new GCN layer and pooling layer are used to obtain the GCN embeddings of the target node and another node, as well as the final embedding of the target node. Furthermore, sample pairs representing positive and negative embeddings for node-to-node comparisons can be constructed, and the correlation (u) between these two sample pairs can be obtained. t and The comparison training loss between nodes can then be expressed as:
[0108]
[0109] S4.2: Defines the subgraph-subgraph comparison mode. Specifically, it compares subgraph z... i And its perturbation subgraph is considered to be positively relative to g t The augmented view of other subgraphs with the same training batch is treated as a negative pair. z i and other subgraphs z in the same training batch j As the first negative pair and z j As the second negative pair An augmented view. As one of the more popular contrast losses, InfoNCE loss is defined as:
[0110]
[0111] 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 from the contrastive learning training process were aggregated:
[0112]
[0113] Where β∈(0,1) is a parameter used to balance node-level anomaly information, and γ∈(0,1) is a parameter used to balance subgraph-level anomaly information.
[0114] S5: Define the anomaly scoring function, the specific steps are as follows:
[0115] S5.1: Calculate the anomaly score for each node by minimizing the defined objective function. In contrastive learning networks, taking the comparison between a node and its subgraph as an example, a normal node is similar to the subgraph of its positive sample pair, but dissimilar to the subgraph of its negative sample pair. Anomaly nodes behave differently, significantly different from positive and negative samples. Based on this rule, the anomaly score calculation formula can be obtained as follows:
[0116]
[0117] Considering the randomness inherent in a single detection, to avoid this, each node is detected multiple times to obtain an anomaly score for each node, and the average of these scores is taken as the final anomaly score. The above formula can be further rewritten as:
[0118]
[0119] Where R represents the number of anomaly detections.
[0120] S6: Apply a scoring function to detect anomalies in traffic trajectories. The specific steps are as follows:
[0121] 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.
[0122] Threshold=POT(Score_Train,Score_Test,δ)
[0123] POT is a statistical method based on extreme value theory. It dynamically determines the threshold by estimating the risk value and setting the size of the risk value δ∈{0,1} to obtain the Threshold.
[0124] S6.2: By calculating the anomaly score of each trajectory segment, a sorted list is formed, with high-scoring trajectories being the most prominent. These are flagged as potential anomalies. This allows traffic regulators or analysts to focus on high-risk vehicle driving behaviors, enabling timely identification and handling of abnormal behavior, thus improving the safety and stability of the traffic system. This integrated process fully leverages graph structure information and deep learning techniques, providing a powerful and efficient solution for traffic trajectory anomaly identification.
[0125] Implementation examples demonstrate that the traffic anomaly trajectory detection method based on graph contrastive learning proposed in this invention is effective. Compared to other design methods, this invention employs graph contrastive learning on traffic anomaly trajectories and integrates three contrast modes for effective anomaly detection. To increase the connectivity between nodes in the graph, a GCN layer and skip connections are used to fuse underlying spatial features. The detection method processes the traffic trajectory into a graph structure as input and outputs anomaly scores for each node. Furthermore, the POT method is used to dynamically determine the threshold value, and the trajectory information at that moment is judged to be abnormal based on whether the anomaly score is greater than the threshold.
[0126] Example 2
[0127] This embodiment relates to a traffic trajectory anomaly detection device based on graph comparison learning, including a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, they are used to implement a traffic trajectory anomaly detection method based on graph comparison learning according to Embodiment 1.
[0128] Example 3
[0129] This embodiment relates to a computer-readable storage medium storing a program that, when executed by a processor, implements a traffic trajectory anomaly detection method based on graph comparison learning as described in Embodiment 1.
[0130] The above description describes specific embodiments of the present invention and the technical principles employed. Any changes made in accordance with the concept of the present invention that do not exceed the spirit of the specification and drawings should still fall within the protection scope of the present invention.
Claims
1. A traffic trajectory anomaly detection method based on graph contrastive learning, comprising the following steps: S1: Define the graph structure corresponding to the traffic trajectory; S2: Subgraph and node sampling to obtain positive and negative sample pairs; S3: 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: Apply a scoring function to detect traffic trajectory anomalies; Step S1 includes the following steps: S1.1: Select HighD, a large dataset of natural vehicle trajectory instances on German highways, which includes both legal and illegal entities; S1.2: Abstract the traffic trajectory HighD into a graph structure; each vehicle is represented as a node in the graph, and the relationship between them is represented by edges, thus constructing a graph structure that reflects the urban traffic network; S1.3: Define the graph structure, nodes, and edges of the HighD trajectory; for a given undirected graph , Represents a set of nodes. This represents the number of nodes in the graph. Represents an edge set; and These represent the node features and the graph structure, respectively. Represents a node Features The adjacency matrix is a square matrix. Representation; for the adjacency matrix ,if , then it represents a node and There exists an edge between them, otherwise ; Step S4 includes the following steps: S4.1: Measuring positive sample pairs and negative sample pairs Similarities and differences between them; Calculated using the following formula: (10) (11) Then, the node-subgraph comparison training loss is calculated using binary cross-entropy (BCE): (12) 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: (13) S4.2: Define subgraph-subgraph comparison mode; compare subgraphs And its perturbation subgraph is considered as positive opposite The augmented view of other subgraphs with the same training batch is treated as a negative pair. ;Will and other subgraphs in the same training batch As the first negative pair and will As the second negative pair Augmented view; InfoNCE loss is defined as: (14) Finally, to accelerate the model's convergence speed, the loss during the contrastive learning training process was aggregated: (15) in, These are parameters used to balance node-level anomaly information. These are parameters used to balance subgraph-level anomaly information; by maximizing the similarity of positive sample pairs and minimizing the similarity of negative sample pairs, the graph contrastive learning network optimizes the model parameters through the aggregated loss function, making similar embedding vectors closer and dissimilar embedding vectors more dispersed. Step S5 includes the following steps: S5.1: Calculate the anomaly score for each node by minimizing the defined objective function. The formula for calculating the anomaly score is as follows: (17) in, This represents the number of anomaly detections.
2. The traffic trajectory anomaly detection method based on graph contrast learning as described in claim 1, characterized in that... It lies in: Step S2 includes the following steps: S2.1: Use Edge Modification (EM) to sample the graph structure of HighD trajectories; select the center node, sample from the neighboring nodes, and form positive and negative sample subgraph pairs by adjusting the edge connections according to probability; generate diverse traffic trajectories through the EM method to improve the model's learning of normal and abnormal patterns; S2.2: Random Walks and Restart (RWR) method is used to sample nodes in the graph structure of HighD trajectories. To focus on node-level anomalies in the graph, a node sampling method is adopted. Node sequences are generated by random walks and restarts to distinguish positive and negative sample pairs. The RWR method has advantages in balancing local structure and global information, providing diverse traffic trajectories for graph comparison learning and enhancing the model's ability to learn abnormal traffic trajectories.
3. The traffic trajectory anomaly detection method based on graph contrast learning as described in claim 1, characterized in that: Step S3 includes the following steps: S3.1: Extract the embedding vector of the subgraph using GCN; to make the obtained latent representation more discriminative, mask the attributes of the target nodes in the subgraph beforehand; the embedding vector can be obtained using the following formula: (8) (2) (3) in, Let be the adjacency matrix of a subgraph with self-loops. It is the identity matrix. Represents a symmetric normalized adjacency matrix. express The degree matrix, Indicates the first The learnable weight matrix of a layer; The parameter ReLU is nonlinear; higher-order node representations are gradually obtained through the stacking of multiple GCNs. This enriches the structural and feature information of the subgraph; S3.2: Embedding vectors of nodes Pooling or aggregation operations are performed to obtain the latent representation of the entire subgraph; this is achieved through the ReadOut() function. To increase the connectivity between nodes in the graph, skip connections are used to fuse underlying spatial features. Therefore, the new pooling readout module includes: 1) To Sort the nodes with the largest upward projection scalar values and find... The index of the maximum value: (4) (5) in This represents a learnable projection vector; 2) To Execution and extraction operations: (6) 3) Use size A vector whose components are all 1 is given, and a new adjacency matrix is obtained by element-matrix multiplication. and characteristic matrix : (7) 4) Restore the original structure of the graph, through... The operation yields the final representation of the subgraph. and will The row vectors in the data are distributed according to the corresponding indices in idx. In the characteristic matrix: (8) Since the target nodes in the subgraph are pre-masked, their features are mapped into the subgraph embedding space using the weight matrix of the GCN to obtain the final representation of the target nodes. : (9)。 4. The traffic trajectory anomaly detection method based on graph contrast learning as described in claim 1, characterized in that: Step S6 includes the following steps: S6.1: Applying the scoring function Anomaly detection is performed on traffic trajectories; anomaly score thresholds are set to obtain thresholds. Threshold : (18) POT (Potential Analysis and Threatening) is a statistical method based on extreme value theory. It dynamically determines a threshold by estimating the risk value, first calculating the anomaly score of all trajectories, and then setting the risk value. The size is obtained Threshold ; S6.2: By calculating the anomaly score for each traffic trajectory, a sorted list is formed, with high-scoring anomaly trajectories being... It is marked as a possible exception.
5. A traffic trajectory anomaly detection device based on 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 graph contrast learning as described in any one of claims 1-4.
6. A computer-readable storage medium, characterized in that, It stores a program that, when executed by a processor, implements a traffic trajectory anomaly detection method based on graph contrast learning as described in any one of claims 1-4.