A traffic accident prediction method based on graph attention network

By constructing a traffic accident prediction method based on graph attention network, the problem of difficulty in capturing the spatiotemporal characteristics of traffic accident data in existing technologies is solved, accurate prediction of traffic accidents is achieved, and the accuracy and robustness of the prediction are improved.

CN118053095BActive Publication Date: 2025-09-26SOUTH CHINA UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410049604.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-12
Publication Date
2025-09-26
Estimated Expiration
2044-01-12

AI Technical Summary

Technical Problem

Existing traffic accident prediction methods are difficult to effectively capture the spatiotemporal characteristics of traffic accident data, especially since traffic accident data accounts for a small proportion in the dataset, leading to the zero-inflation problem. In addition, traditional methods cannot fully consider the non-Euclidean spatial structure of urban road networks.

Method used

A graph attention network-based method is used to construct risk similarity graphs, road similarity graphs, and POI similarity graphs. Spatial features are extracted through the GAT network, and temporal dependencies are captured using the multi-head self-attention TCN network. Traffic accident prediction is performed in combination with the exogenous variable feature extraction network.

Benefits of technology

It achieves accurate prediction of traffic accidents, can better focus on traffic accident data, capture spatial information and temporal dependencies, and improve the accuracy and robustness of predictions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118053095B_ABST
    Figure CN118053095B_ABST
Patent Text Reader

Abstract

The present invention discloses a traffic accident prediction method based on a graph attention network, comprising the following steps: dividing a prediction area into a number of equal-sized sub-areas; obtaining traffic characteristics of the prediction area in a historical time period; constructing a risk similarity graph, a road similarity graph, and a POI similarity graph for the prediction area; inputting traffic characteristics and the risk similarity graph, the road similarity graph, and the POI similarity graph, and using a spatial feature extraction network to extract grid features of neighboring nodes and road features of road network nodes; for the output spatial extracted features, using a temporal feature extraction network to further extract the temporal features of each node; for the output spatiotemporal extracted features, using an exogenous variable feature extraction network to further extract the date features of each node; obtaining a traffic accident risk prediction output by passing the obtained features through a fully connected layer; defining a loss function, training the proposed model, and obtaining a traffic accident prediction result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to spatiotemporal traffic prediction technology, and in particular to a traffic accident prediction method based on a graph attention network. Background Art

[0002] With economic growth and technological advancements, commuting has become a part of daily life. However, as travel demand continues to increase and the number of vehicles continues to grow, traffic accidents are becoming increasingly frequent. Therefore, traffic accident prediction is crucial for assisting drivers with their decisions, assisting relevant departments in regulating overall traffic flow, avoiding traffic accidents, and improving road operation efficiency. Network-level traffic accident prediction uses the entire urban road area as the prediction region, comprehensively considering all factors influencing traffic accidents. Because road network traffic areas exhibit spatial and temporal correlations, traffic accident prediction requires comprehensive consideration of the spatial and temporal impacts on each area of ​​the road network when an accident occurs.

[0003] Traffic accident prediction methods consider the multiple impacts of traffic accidents across time and space. Spatially, traffic characteristics exhibit interdependence and similarity. Interdependence means that when a traffic accident occurs in a certain area, the areas above and below it will inevitably be affected. Similarity means that areas with the same road characteristics will have similar traffic characteristics. Temporally, traffic characteristics exhibit proximity, periodicity, and trend. Proximity means that the traffic state at the next moment is a continuation of the traffic state at the previous moment. Periodicity means that traffic data will exhibit the same cyclical patterns due to the periodicity of human activities. Trend refers to the overall trend of traffic data over time.

[0004] Because the factors influencing traffic accidents are complex and the underlying spatiotemporal relationships are difficult to detect, the current main approach is to use deep learning networks to mine this latent information for traffic accident prediction. Traditional convolutional neural networks can only process Euclidean space, while actual urban traffic networks exhibit irregular shapes in non-Euclidean space. Consequently, graph-based neural networks have been proposed for research and application, and various graph convolutional networks and their variants have been proposed for learning tasks with different graph structures.

[0005] Currently, research on traffic accident prediction based on graph neural networks is gradually developing. The existing literature (Learning Spatial-Temporal Correlations from Geographical and Semantic Aspects for Traffic Accident Risk Forecasting) constructs the traffic network as a graph structure, using CNN and GRU networks to model local regional spatiotemporal correlations, and GCN and GRU networks to model global regional spatiotemporal correlations, ultimately fusing the output to produce traffic accident prediction results. While this literature fully considers the impact of spatial and temporal correlations, it pays insufficient attention to traffic accident data. Since traffic accidents account for a relatively small proportion of the entire dataset, this data must be prioritized to avoid the zero-inflation problem. Summary of the Invention

[0006] The present invention aims to overcome the shortcomings and defects of existing methods and proposes a traffic accident prediction method based on a graph attention network. This method predicts the entire road network area by treating it as a graph structure. The GAT network is used to capture the influence of road similarity between nodes in different sub-regions. The neighbor node feature aggregation function is used to calculate attention weights and update node features, thereby expanding the model's ability to capture spatial information correlations. The Muli-Head Self-Attention TCN network is used to extract long-term contextual information association features, focusing on traffic accident data in the data and capturing temporal dependencies in sequence data. The present invention comprehensively focuses on the spatiotemporal characteristics of the traffic area, while using the attention mechanism to focus on accident data that is a minority case in the traffic data, thereby obtaining accurate prediction results.

[0007] The present invention is achieved through at least one of the following technical solutions.

[0008] A traffic accident prediction method based on a graph attention network comprises the following steps:

[0009] Divide the prediction area into several sub-areas of equal size;

[0010] Obtain the traffic characteristics of the forecast area in the historical time period;

[0011] Construct risk similarity graph, road similarity graph and POI similarity graph of the prediction area;

[0012] Input traffic characteristics and risk similarity graph, road similarity graph and POI similarity graph, use spatial feature extraction network to extract neighboring node grid features and road network node road features to obtain spatial extraction features;

[0013] For the output spatial extraction features, the temporal feature extraction network is used to further extract the temporal features of each node to obtain spatiotemporal extraction features;

[0014] For the output spatiotemporal extraction features, an exogenous variable feature extraction network is used to further extract the date features of each node;

[0015] The obtained features are passed through the fully connected layer to obtain the traffic accident risk prediction output, which is the traffic accident risk value of each node at the next moment;

[0016] Define the loss function, train the proposed model, and obtain the traffic accident prediction results.

[0017] Furthermore, the prediction area is divided into a number of equal-sized sub-areas based on longitude and latitude, and is divided into I×J sub-areas, each of which has the same size.

[0018] Furthermore, obtaining the traffic characteristics of the prediction area in the historical time period includes the following steps:

[0019] Collect relevant data on accident information, road information, and weather information in the forecast area over a historical period;

[0020] Data preprocessing is performed to obtain traffic accident risk characteristics, date characteristics, POI characteristics, weather characteristics, road characteristics, and traffic flow characteristics for historical time periods.

[0021] Furthermore, data preprocessing is performed to obtain traffic accident risk characteristics for a historical period, including the following steps:

[0022] All traffic accidents are divided into three risk levels according to the severity of the accident, with 1, 2, and 3 as the risk values ​​of traffic accidents. The traffic accident risk value of 1 represents a minor traffic accident, the traffic accident risk value of 2 represents a moderate traffic accident, and the traffic accident risk value of 3 represents a serious traffic accident.

[0023] The sum of the risk values ​​of traffic accidents that occurred in each sub-region during the historical time period is calculated as the historical traffic accident risk characteristic of the node.

[0024] Furthermore, the construction of the risk similarity graph, the road similarity graph, and the POI similarity graph of the predicted area includes the following steps:

[0025] Construct risk similarity graph G R =(V, E R , A R ): Each sub-region is regarded as a node V of the graph. The risk similarity between nodes is compared. The node with the most similar characteristics to the node is selected as its first-order neighbor. The first-order neighbor nodes are connected to obtain the edge E of the graph.R , A R As the adjacency matrix of the graph, it is expressed as:

[0026]

[0027] Construct road similarity graph G D =(V, E D , A D ): Each sub-region is regarded as a node V of the graph, and the road similarity between nodes is calculated. The L nodes with the highest similarity are selected as first-order neighbors, and the first-order neighbor nodes are connected to obtain the edge E of the graph. D , A D As the adjacency matrix of the graph, it is expressed as:

[0028]

[0029] Where i and j represent nodes i and j in the matrix, e i,j represents the edge between nodes, sim(i, j) represents the road similarity value between the two;

[0030] Construct POI similarity graph G P =(V, E P , A P ): Each sub-region is regarded as a node V of the graph. The POI similarity between two nodes is calculated by JS divergence. The top L nodes with the highest similarity are selected as first-order neighbors. The first-order neighbor nodes are connected to obtain the edge E of the graph. P , A P As the adjacency matrix of a graph, its representation is the same as that of the road similarity graph.

[0031] Furthermore, the spatial feature extraction network extracts the neighboring node grid features and the road network node road features to obtain spatial extraction features, including the following steps:

[0032] The CNN network is used to obtain the spatial correlation features of the neighboring nodes.

[0033] The GAT network is used to process the risk similarity graph, road similarity graph and POI similarity graph to obtain three road network node-road spatial correlation sub-features between nodes respectively;

[0034] The three output road network node road spatial correlation sub-features are added together to obtain the road network node road features;

[0035] Dimensional transformation of road features of road network nodes is performed through mapping matrix;

[0036] The grid features of neighboring nodes and the road features of road network nodes are fused through the gated fusion unit.

[0037] Furthermore, the CNN network includes a convolutional subnetwork, which includes two convolutional layers and a ReLU activation layer. The convolutional subnetwork is expressed as follows:

[0038]

[0039] Where * represents the convolution operation, and is the learnable parameter of the kth convolutional layer, ReLU is used as the activation function of the convolution function, represents the convolution output of the kth layer at time t,

[0040] The GAT network includes a LeakyReLU activation function layer, a softmax normalization layer, and a concat connection layer, and includes the following steps:

[0041] The initial feature dimension h of node i is shared by the weight matrix W i Perform feature transformation, expressed as:

[0042] z i =Wh i

[0043] Calculate the correlation between nodes i and j and obtain the attention score, which is expressed as:

[0044] s ij =LeakeyReLU(a T (z i ||z j ))

[0045] Where a represents the attention vector, which is used to convert the vector obtained by concatenating the feature representations of nodes i and j into a scalar value, (·) T represents vector transposition, || represents vector concatenation, and the normalization of the correlation between all nodes is used to obtain the attention coefficient, which is expressed as:

[0046]

[0047] Where N i represents all first-order neighbors of node i and node i itself, s ik For nodes i and N i The attention score between nodes in the range, exp(·) is an exponential function, which is expressed by the feature weights of adjacent nodes and the update of the central node, and the output information aggregation vector is obtained, which is expressed as:

[0048]

[0049] Where σ is a nonlinear activation function, z j Ni The transformed expression of node features within the range.

[0050] Furthermore, the time feature extraction network further extracts the time feature of each node, including the following steps:

[0051] A multi-head self-attention mechanism is used to focus on inputs from different representation subspaces;

[0052] The TCN network is used to obtain the time correlation characteristics of each child node.

[0053] Furthermore, the multi-head self-attention mechanism focuses on inputs from different representation subspaces, including the following steps:

[0054] Construct query matrix W Q , keyword matrix W K and the value matrix W V ;

[0055] Map the input feature vector X to the query vector Q, keyword vector K and value vector V, expressed as:

[0056] Q=XW Q

[0057] K=XW K

[0058] V=XW V

[0059] The similarity between the query vector and the keyword vector is calculated using scaled dot product attention and divided by the number of feature channels d k Perform feature scaling to obtain the attention score vector, expressed as:

[0060]

[0061] The context vector information of each node is obtained by weighted summing of the attention score vector and the value vector, which is expressed as:

[0062] Attention(Q, K, V) = AV

[0063] Apply the above steps to multiple attention heads, process them in parallel to obtain multiple sets of context vectors, and concatenate them together to map the final output representation as:

[0064] MultiHead(Q,K,V)=Concat(head1,...head i ..., head n )W O

[0065] Where, headi =Attention(Q i , K i , V i ), represents the attention weight and context vector of the ith attention head, there are n attention heads in total, Concat represents the concatenation operation, W O It is a linear transformation weight matrix used to map the concatenated context vector to the final output representation;

[0066] The TCN network consists of two layers of TCN modules and one layer of residual connection, wherein the TCN module includes:

[0067] Dilated causal convolutional layers capture temporal dependencies of input sequences;

[0068] The Weight Norm layer normalizes the weight values;

[0069] ReLU is used as the activation function in the module to achieve delinearization;

[0070] The Dropout layer randomly discards parts from the network to reduce the number of parameters and computational complexity of the model;

[0071] After expanding the TCN network through multi-layer stacking, the output representation of the node after time feature extraction is obtained.

[0072] Furthermore, the exogenous variable feature extraction network calculates the attention score of the date feature to obtain features related to the date.

[0073] Furthermore, the loss function uses FocalLoss to calculate the classification loss, which is expressed as:

[0074]

[0075] Where p represents the probability that the model predicts correctly, a is the weight factor, a∈[0,1], when it is a positive sample, the weight factor is a, when it is a negative sample, the weight factor is 1-a, and γ is the modulation factor.

[0076] The present invention has the following advantages and effects compared to the prior art:

[0077] 1. The present invention discloses a traffic accident prediction method based on a graph attention network, which constructs a risk similarity graph, a road similarity graph, and a POI similarity graph for the prediction area. GAT is used to extract features based on the spatial correlation characteristics of road network nodes. The attention mechanism is used to calculate the relationship between first-order neighbor nodes, and the features of the neighbors are aggregated on the central vertex, so that the features can be better integrated into the model.

[0078] 2. The present invention discloses a traffic accident prediction method based on a graph attention network. A time series extraction network based on Muli-Head Self-Attention TCN is designed. The multi-head self-attention mechanism can better capture the dependency between upper and lower time series, and the multi-layer TCN stacking can extract multi-resolution time information. BRIEF DESCRIPTION OF THE DRAWINGS

[0079] Figure 1 This is a structural diagram of a traffic accident prediction system based on a graph attention network in an embodiment of the present invention;

[0080] Figure 2 This is a diagram of a spatial feature extraction network structure in an embodiment of the present invention;

[0081] Figure 3 This is a diagram of the GAT network structure in an embodiment of the present invention;

[0082] Figure 4 This is a diagram of a network structure for extracting time features in an embodiment of the present invention;

[0083] Figure 5 This is a diagram of the multi-head self-attention network structure in an embodiment of the present invention;

[0084] Figure 6 This is a flowchart of an embodiment of a traffic accident prediction method based on a graph attention network. DETAILED DESCRIPTION

[0085] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.

[0086] Figure 1 This is a structural diagram of a traffic accident prediction system based on a graph attention network in an embodiment of the present invention, including a multi-component spatiotemporal feature extraction model. The model includes a spatial feature extraction network, a temporal feature extraction network, an exogenous variable feature extraction network, and an FC layer. The spatial feature extraction network extracts the spatial correlation features of adjacent node grids and the spatial correlation features of road network nodes. The temporal feature extraction network extracts the long-term sequential relationships between different nodes. The exogenous variable feature extraction network extracts the date features of the node at the next moment. The FC layer processes the features to obtain the traffic accident risk value of each node at the next moment.

[0087] This embodiment uses the entire urban road network area as the traffic accident prediction range, fully considers the spatial and temporal correlation between accidents, and focuses on traffic accident data that belongs to a small number of data to achieve traffic accident prediction. Specifically, the following steps are included:

[0088] S1. Divide the prediction area into I×J sub-areas based on longitude and latitude, with each area of ​​equal size. Using the entire urban road network as the prediction range is too coarse-grained, resulting in only uniform prediction results that are unsuitable for real-world scenarios. Therefore, the prediction area is divided into several sub-areas of equal size. Traffic prediction is achieved by predicting these sub-areas. Furthermore, the interactions between sub-areas can be used to comprehensively understand the traffic characteristics of each area.

[0089] S2. Obtain traffic characteristics of the predicted area in the historical time period. For the I×J divided sub-areas, fill the sub-areas without roads with zero data as traffic characteristics, and process the data of the sub-areas with roads to obtain traffic characteristics. The acquisition of traffic characteristics includes the following steps:

[0090] Collect relevant data such as accident information, road information, weather information, etc. in the historical period of the forecast area;

[0091] Data preprocessing is performed to obtain traffic accident risk characteristics, date characteristics, POI characteristics, weather characteristics, road characteristics, and traffic flow characteristics for historical time periods.

[0092] As one of the embodiments, the traffic accident risk feature first divides all traffic accidents into three risk levels according to the severity of the accident, with 1, 2, and 3 as the risk values ​​of traffic accidents, where a traffic accident risk value of 1 represents a minor traffic accident, a traffic accident risk value of 2 represents a moderate traffic accident, and a traffic accident risk value of 3 represents a serious traffic accident. Secondly, the sum of the risk values ​​of traffic accidents occurring in each sub-area during the historical time period is calculated as the historical traffic accident risk feature of the node; the date feature describes the date of the next predicted moment, specifically including which day of the week, which hour of the day, and whether it is a holiday; the POI feature describes whether the node contains special areas such as residential areas, schools, entertainment areas, commercial areas, cultural facilities, social services, and transportation facilities; the weather feature describes information such as temperature and weather conditions; the road feature describes information such as the latitude and longitude, length and width, and type of the road contained in the node; the traffic flow feature describes information such as the traffic flow and average driving speed at the historical moments of the node;

[0093] S3. In order to obtain the spatial similarity between regions with the same road semantic features, a risk similarity map, a road similarity map, and a POI similarity map are constructed for the predicted region. Risk similarity is due to the fact that when two regions show a high degree of similarity in the frequency, time, and severity of traffic accidents at a historical moment, it is believed that the two regions will also present similar traffic accident risks in the future. Road similarity refers to the fact that two regions have similar characteristics in road features, such as similar road conditions and the same road structures such as intersections. It is believed that such regions with the same static features will have similar traffic accident risks. POI similarity refers to the overlap of special areas contained in two regions. For example, the traffic accident situation between regions containing residential areas and schools will be relatively similar. Therefore, constructing similarity maps of the above three road semantic features to obtain the spatial correlation between regions can comprehensively consider the factors affecting traffic accidents.

[0094] In order to construct the risk similarity graph G R =(V, E R , A R ), taking each sub-region as a node V of the graph, for each node i, the sum of the risk values ​​of traffic accidents that occurred at its historical moment is calculated as the traffic accident risk feature vector The difference in accident risk between all nodes is calculated. For each node, the node with the smallest difference is considered to have the most similar historical traffic accident risk characteristics. The node with the smallest difference is taken as the first-order neighbor of the node. The first-order neighbor nodes are connected to obtain the edge E of the graph. R , A R As the adjacency matrix of the graph, it is expressed as:

[0095]

[0096] In order to construct the road similarity graph G D =(V, E D , A D ), each sub-region is regarded as a node V of the graph, and for each node i, the number of roads, length and width of the roads in the region are regarded as the road feature vector The JS divergence is used to calculate the road similarity between nodes. The calculation method is:

[0097] sim(i, j)=1-JS(R i , R j )

[0098]

[0099] Where R i , R jrepresents the road characteristics of region i, j, q is the dimension of the feature vector, R i (l) represents R i The lth feature of the graph is that the similarity between each two regions is between [0, 1]. Select the two nodes with the highest similarity as first-order neighbors, and connect the first-order neighbor nodes to obtain the edge E of the graph. D , A D As the adjacency matrix of the graph, it is expressed as:

[0100]

[0101] In order to construct the POI similarity graph G P =(V,E P ,A P ), take each sub-region as the node V of the graph, for each node i, add the number of POI feature categories existing in the node region to form the POI matrix of the region. Each row in the matrix represents a region, and each column represents the number of POI feature categories of different categories contained in the region of this row. Then divide the value of each row by the sum of all values ​​in the row to obtain the normalized POI feature matrix. Each row in the matrix represents a region, and each column represents the importance of different categories in the region of this row. The sum of all values ​​in each row in the matrix is ​​1. Calculate the POI similarity between nodes using JS divergence, and select the two nodes with the highest similarity as first-order neighbors. Connect the first-order neighbor nodes to obtain the edge E of the graph. P , A P As the adjacency matrix of a graph, its representation is the same as that of the road similarity graph.

[0102] S4. Use Figure 2 The spatial feature extraction network shown extracts the grid features of neighboring nodes and the road features of road network nodes.

[0103] Because traffic features are spatially interdependent and similar, i.e., adjacent nodes in a grid structure will be affected by their geographical proximity, and road network nodes with similar road semantic information will have similar traffic trends, it is necessary to comprehensively consider these two aspects of spatial features to obtain a more comprehensive spatial feature extraction. The spatial feature extraction network proposed in this embodiment uses a CNN network to obtain the spatial correlation features of the grids of adjacent nodes and a GAT network to obtain the spatial correlation features of the roads of the road network nodes.

[0104] The input of the CNN network is the traffic characteristics X of the historical time period tThe network consists of a convolutional subnetwork consisting of two convolutional layers and a ReLU activation layer. The convolutional layer uses a 3×3 convolution operation with a kernel of 3×3 to calculate the convolution result at each position on the input feature data to obtain the feature representation of the input data. The ReLU activation function linearly weights and nonlinearly changes the output of the convolutional layer, enabling the network to extract nonlinear features and increase the ability to extract complex features. By stacking the two convolutional subnetworks, higher-level and larger receptive field features are obtained as spatial correlation features between adjacent regions. The convolutional subnetwork expression formula is:

[0105]

[0106] Where * represents the convolution operation, and is the learnable parameter of the kth convolutional layer, ReLU is used as the activation function of the convolution function, represents the convolution output of the kth layer at time t,

[0107] The input of the GAT network is a time-series graph signal matrix, including the risk similarity graph, road similarity graph, POI similarity graph and the corresponding adjacency matrix. Figure 3 The GAT network structure diagram in an embodiment of the present invention includes a LeakyReLU activation function layer, a softmax normalization layer, and a concat connection layer. The network processes the three types of semantic space correlation separately. The principles and steps for each type of semantic space correlation are the same, including the following steps:

[0108] The feature vector set of the node is used as input, where each node has F features, that is, the node size is F×1, and there are N nodes in total, that is, the size of the input feature vector set is F×N. For all nodes, the initial feature dimension h of the node is the same shared weight matrix W. i Perform feature transformation, expressed as:

[0109] z i =Wh i

[0110] In order to learn the dependency between global features, the Self-Attention mechanism is implemented for each node to calculate the correlation between the node and its adjacent nodes one by one, and obtain the attention score, which is expressed as:

[0111] s ij =LeakeyReLU(a T (z i ||z j ))

[0112] Where a represents the attention vector, which is used to convert the vector obtained by concatenating the feature representations of nodes i and j into a scalar value, (·) T Represents vector transposition, || represents vector concatenation, and the changed features are concatenated. The LeakeyReLU function is used as the activation function of the network output layer, giving all negative values ​​a slope of 0.2. This introduces a certain degree of negative response, enhances the model's ability to handle negative values, and enables the model to more effectively learn the attention weights between nodes. The attention coefficient is obtained by normalizing the correlation between all nodes, expressed as:

[0113]

[0114] Where N i represents all first-order neighbors of node i and node i itself, s ik For nodes i and N i The attention scores between nodes in the range, exp(·) is an exponential function. Through the softmax function, the attention scores are mapped to a probability distribution with a sum of 1, that is, all attention coefficients add up to 1, so that nodes with higher correlation have a greater probability, and nodes with lower correlation have a smaller probability, so that nodes with high similarity can be given a higher aggregation.

[0115] Finally, the feature weights of the adjacent nodes and the updated representation of the central node are used to obtain the output information aggregation vector through the concat layer, which is expressed as:

[0116]

[0117] Where σ is a nonlinear activation function, h′ i The new node feature dimension of the output. For N node features, a new node feature vector set is formed as the output of the GAT network.

[0118] The GAT network assigns different weights to each node and its neighbors, and can simultaneously handle neighborhoods of varying sizes, enabling the model to accurately capture the correlation of spatial information and effectively extract vertex features. The total road spatial correlation is calculated by summing the three output sub-features of road network node spatial correlation. This comprehensively considers the impact of roads with similar risk profiles, similar static characteristics, and the impact between roads sharing specific areas, resulting in more accurate traffic accident predictions.

[0119] Since the dimensions of the feature output of the CNN network are different from those of the GAT network, direct feature fusion is not possible. Therefore, the dimension of the road features of the road network nodes is transformed through the mapping matrix, which is expressed as:

[0120] X G =MF

[0121] Where M is the graph-grid mapping matrix, which is a custom static matrix that represents the correspondence between grid areas and graph nodes. F is the graph signal matrix, which is the road feature matrix of the road network nodes obtained by processing and summing the GAT network. The mapping matrix and the graph signal matrix are multiplied to convert the graph signal matrix into the same data dimension as the grid data. At the same time, the areas without roads are filled with 0 to indicate that there are no spatial features in the area.

[0122] In order to obtain the final spatial features, it is necessary to fuse the neighboring node grid features and the road network node road features. In this embodiment, the two types of spatial features are fused using a gated fusion method, which is expressed as:

[0123] X=gX L +(1-g)X G

[0124] Where g is the gate unit value, which ranges between 0 and 1. L is the neighboring node grid feature, X G It is the road feature of the road network node obtained after the mapping dimension conversion. Gated fusion adjusts the value of the gating unit g so that the model pays different attention to the two types of spatial features. That is, when the gating unit value is closer to 1, the model will pay more attention to the grid features of the adjacent nodes. When the gating unit value is closer to 0, the model will pay more attention to the road features of the road network nodes. In this way, the model can adaptively adjust the weights of the overall features and pay more attention to features with better effects. The road features of the road network nodes focus on the correlation of the nodes in the graph data, contain more shallow information, and can better reflect the spatial correlation in the traffic data. Therefore, as one of the preferred embodiments, the gating unit value is taken as 0.25, so that the model pays more attention to the road features of the road network nodes, thereby improving the expression ability and performance of the model.

[0125] S5. For the output spatial extraction features, a temporal feature extraction network is used to further extract the temporal features of each node, thereby obtaining the temporal features of each node at the historical time step.

[0126] The structure of the temporal feature extraction network is as follows Figure 4 As shown, it includes multi-head self-attention and TCN network. The multi-head self-attention mechanism focuses on inputs from different representation subspaces. The TCN network consists of two layers of TCN submodules and residual connections to obtain the temporal correlation features of each child node. As a preferred embodiment, the specific process of implementing temporal feature extraction is as follows:

[0127] The structure of the multi-head self-attention network is as follows Figure 5As shown, in order to obtain the output with attention features, we first construct the query matrix W Q , keyword matrix W K and the value matrix W V , the dimension of each matrix is ​​64, and the input feature vector X is mapped into query vector, keyword vector and value vector by the linear layer with the query matrix, keyword matrix and value matrix, which can be expressed as:

[0128] Q=XW Q

[0129] K=XW K

[0130] V=XW V

[0131] Q, K, and V are divided according to the number of heads, and each head is provided with a different query vector, keyword vector, and value vector, so that each head can independently learn and focus on different features and calculate the attention weight.

[0132] Perform a dot product operation on the query vector and the keyword vector to obtain the similarity between different heads and divide it by the number of feature channels d k Perform feature scaling to make the gradient more stable, and then normalize the scores through the softmax operation to obtain the attention score vector that represents the correlation between targets. It can be expressed as:

[0133]

[0134] The weighted sum of the attention score vector and the value vector is used to obtain the output vector of the attention head at each position, which is expressed as:

[0135] Attention(Q, K, V) = AV

[0136] Apply the above steps to multiple attention heads, process them in parallel to obtain the context vector of each attention head, and concatenate them together to integrate the focus points and features learned by different heads to obtain more comprehensive and in-depth information association. The final output is expressed as follows through the linear layer and the dropout layer:

[0137] MultiHead(Q,K,V)=Concat(head1,...head i ..., head n )W O

[0138] Where, head i =Attention(Q i , K i , V i), represents the attention weight and context vector of the ith attention head, there are n attention heads in total, Concat represents the concatenation operation, W O It is a linear transformation weight matrix used to map the concatenated context vector to the final output representation.

[0139] To simultaneously account for both local and long-range temporal dependencies, the output of the multi-head self-attention network is fed into a two-layer stacked TCN network. The TCN network consists of two layers of TCN modules and one layer of residual connections. The TCN module includes a dilated causal convolution layer, a WeightNorm layer, a ReLU layer, and a Dropout layer. The dilated causal convolution layer captures the temporal dependencies of the input sequence. The WeightNorm layer normalizes the weights. The ReLU layer serves as the activation function in the module. The Dropout layer randomly drops parts of the network, reducing the number of model parameters and computational complexity.

[0140] After the multi-layer stacked expanded TCN network, the channel feature output of node i in layer p at time t is expressed as:

[0141]

[0142] Where k is the index of the current dilated convolution kernel, K τ is the number of dilated convolution kernels in the p-layer channel, M is the number of channels of the input data, and w k,m,p Is the convolution kernel element, which represents the weight of the k-th dilated convolution kernel in the p-layer channel, obtained through network learning, x i,t-d(k-1),m represents the feature value of the input channel of node i in layer m at time td(k-1), where d is the dilation rate. The dilated causal convolution layer extracts features from different time windows using multiple parallel convolution kernels. By increasing the dilation factor and spacing of the convolution kernels, the receptive field of the convolution layer is expanded. Zero padding is used during the convolution process to maintain the length of the time series. Residual connections enable cross-layer information transfer, preserving original feature information while avoiding potential vanishing or exploding gradient issues.

[0143] Applying the same TCN network to all nodes in the graph, we can get the output represented as:

[0144]

[0145] Where, Represents the shared weight matrix of the TCN network, enabling different nodes to share parameters, X A is the input data, and is the output result obtained after being processed by the multi-head self-attention network.

[0146] The superposition of multiple layers of dilated TCN can not only expand the receptive field on the time axis, but also obtain multi-resolution output. In order to further expand the receptive field, the dilation rate increases at an exponential rate, that is, d l =2 l-1 The output of the network at layer l is Expressed as:

[0147]

[0148] Where, represents the l-th layer of expanded TCN kernel, σ(·) is a nonlinear function, and L is the number of layers of the multi-layer expanded TCN. The output X containing the time information feature is obtained through the time feature extraction network processing st .

[0149] S6. Extract the spatiotemporal features X from the output st , combined with the date feature Z of the next moment T+1 , the attention score is calculated by the exogenous variable feature extraction network based on the influence of different date and time on the node, and the feature expression of the date for time feature processing is obtained, which is expressed as:

[0150]

[0151] Where, W′ Z , b′ a It is a learnable parameter. a′ is the attention score vector, which represents the importance distribution of different historical time intervals to the target time interval. It is obtained through softmax normalization. Different scores represent the importance of the date feature at the same moment. The larger the value, the greater the impact and the more important it is to the prediction result. After extracting the features of all date features at the past T historical moments, the weighted results are obtained to obtain the impact on the next moment, which is expressed as

[0152] S7. The obtained features are passed through the fully connected layer to obtain the traffic accident risk prediction output, which is the traffic accident risk value of each node at the next moment. A corresponding threshold is set based on the accident risk value when past traffic accidents occurred. When the predicted traffic accident risk exceeds the threshold, it is determined that a traffic accident will occur at the next moment.

[0153] S8. Define the loss function and use the public NYC OpenData dataset to train the proposed model to obtain traffic accident prediction results.

[0154] The traffic accident prediction model proposed in this invention ultimately achieves prediction output by classifying the probability of traffic accidents, which is expressed as several categories: no traffic accident will occur, a minor traffic accident will occur (traffic risk value is 1), a moderate traffic accident will occur (traffic risk value is 2), and a severe traffic accident will occur (traffic risk value is 3). Therefore, the loss function uses FocalLoss to calculate the classification loss, which is expressed as:

[0155]

[0156] Where p represents the probability of the model's correct prediction, a is a weight factor, a∈[0,1]. When the sample is positive, the weight factor is a, and when the sample is negative, the weight factor is 1-a. γ is a modulation factor. In a preferred embodiment, a is set to 2 and γ is set to 1.

[0157] The proposed method was experimentally validated on the NYC OpenDate dataset, which contains multi-source traffic data for the New York City area between January 1, 2013, and December 31, 2013. The dataset includes traffic accident data, traffic flow data, point of interest (POI) data, weather data, and road data for the area within this timeframe. The traffic accident data includes the time, location, and number of casualties; the traffic flow data includes traffic speeds and volume at different latitude and longitude zones; the POI data includes the categories and number of specific areas; the weather data includes temperature and weather conditions; and the road data includes the latitude and longitude, length, and type of roads.

[0158] The experiment divides the data set in a ratio of 6:2:2 as training set, validation set and test set respectively. The data of the past 7 days are used as historical moment input. Each day is divided into 24 time periods, and the prediction output is the traffic accident prediction for the next time period.

[0159] For performance evaluation, we used root mean square error (RMSE), F1 score, and AUC. The model outputs the traffic accident risk value for each node at the next moment as a regression value, so we used RMSE to evaluate its prediction performance. For the results of determining whether a traffic accident will occur based on the risk value, we treated it as a binary classification problem, and used F1 score to evaluate the prediction performance for this classification problem. Since traffic accidents are a small percentage of the data in the dataset, there is a data imbalance problem, so AUC is used to more fairly evaluate the classification prediction performance.

[0160] The RMSE evaluation index is used to determine the deviation between the model prediction results and the actual data, which is expressed as:

[0161]

[0162] Where Yt represents the actual accident risk for all regions at time step t, and Y`t represents the predicted accident risk for all regions at time step t. The lower the RMSE, the more accurate the model is in predicting accident risk.

[0163] The F1 Score evaluation index uses a unified single-value evaluation index, taking into account the two commonly used evaluation indicators of classification models, precision and recall, and can comprehensively evaluate the classification performance of the model. It is expressed as:

[0164]

[0165] Where Precision is the accuracy rate, which indicates the proportion of predicted accident areas that actually experience traffic accidents. Recall is the recall rate, which indicates the proportion of actual accident areas that are predicted to be accident areas. A higher F1 Score indicates a better model prediction.

[0166] The AUC evaluation metric is the area under the ROC curve. The ROC curve is plotted with the proportion of positive samples correctly classified as positive on the vertical axis and the proportion of negative samples incorrectly classified as positive on the horizontal axis. The AUC evaluation metric is independent of the threshold selection and comprehensively considers the model's performance at various thresholds, fully considering the model's classification ability and being unaffected by the sample distribution. It can be expressed as:

[0167]

[0168] Where, This method ranks the probabilities of samples predicted to result in traffic accidents. M is the number of positive samples predicted to result in traffic accidents, N is the number of negative samples predicted to result in no traffic accidents, and M*N is a pair of positive and negative samples. The AUC value ranges between 0 and 1. The closer the AUC value is to 1, the better the model's prediction performance.

[0169] The experimental results of this embodiment on the NYC OpenData dataset are shown in Table 1 below. RMSE * 、F1Score * and AUC *It represents the performance of the model in the accident-high-frequency time period, that is, the prediction results in the time period from 7 to 9 in the morning and from 4 to 7 in the afternoon. The experimental results show that compared with the traditional statistical method HA and the traditional machine learning method XGBoost, the deep learning method has a significant improvement in various indicators. This is because deep learning can capture the deep correlation between data at a deeper level. Compared with the SDCAE method based on GRU or CNN alone, the network that considers the comprehensive spatiotemporal features can obtain better prediction results. This is because the occurrence of traffic accidents has complex spatiotemporal correlations. Compared with the spatiotemporal traffic accident prediction networks ConvLSTM and ST-RiskNet in previous studies, the network proposed in the present invention has better prediction results. This is because the attention mechanism is used to pay more attention to the impact of traffic accident data.

[0170] Table 1 Comparison results of traffic accident prediction network performance

[0171] Benchmark Method RMSE F1 Score AUC RMSE* F1 Score* AUC* HA 10.3243 48.84 0.7540 9.4994 33.88 0.8277 XGBoost 11.0165 46.28 0.7804 10.1730 50.45 0.8417 GRU 8.3375 56.17 0.7676 7.3546 61.52 0.7697 SDCAE 7.9774 61.62 0.7852 7.2806 62.45 0.8130 ConvLSTM 7.9505 61.99 0.7450 7.2554 65.21 0.8410 ST-RiskNet 7.8113 64.71 0.7809 7.0400 66.62 0.8469 Ours 7.6154 66.33 0.8054 6.7761 68.29 0.8432

[0172] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be considered as equivalent replacement methods and are included in the scope of protection of the present invention.

Claims

1. A traffic accident prediction method based on graph attention network, characterized in that: The method comprises the following steps: Divide the prediction area into several sub-areas of equal size; Obtain the traffic characteristics of the forecast area in the historical time period; Construct risk similarity graph, road similarity graph and POI similarity graph of the prediction area; Input traffic characteristics and risk similarity graph, road similarity graph and POI similarity graph, use spatial feature extraction network to extract neighboring node grid features and road network node road features to obtain spatial extraction features; The spatial feature extraction network extracts the grid features of neighboring nodes and the road features of road network nodes to obtain spatial extraction features, including the following steps: The CNN network is used to obtain the spatial correlation features of the neighboring nodes. The GAT network is used to process the risk similarity graph, road similarity graph and POI similarity graph to obtain three road network node-road spatial correlation sub-features between nodes respectively; The three output road network node road spatial correlation sub-features are added together to obtain the road network node road features; Dimensional transformation of road features of road network nodes is performed through mapping matrix; The gated fusion unit is used to fuse the grid features of neighboring nodes and the road features of road network nodes; For the output spatial extraction features, the temporal feature extraction network is used to further extract the temporal features of each node to obtain spatiotemporal extraction features; The time feature extraction network further extracts the time features of each node, including the following steps: A multi-head self-attention mechanism is used to focus on inputs from different representation subspaces; Use TCN network to obtain the time correlation characteristics of each child node; For the output spatiotemporal extracted features, combined with the date features of the next moment, an exogenous variable feature extraction network is used to further extract the date features of each node. This includes calculating the attention score through the exogenous variable feature extraction network. Different scores represent the importance of the date features at the same moment. All date features of the past T historical moments are extracted and weighted to obtain the impact on the next moment. The obtained features are passed through the fully connected layer to obtain the traffic accident risk prediction output, which is the traffic accident risk value of each node at the next moment; Define the loss function, train the proposed model, and obtain the traffic accident prediction results.

2. The traffic accident prediction method based on graph attention network according to claim 1 is characterized in that: The prediction area is divided into a number of sub-areas of equal size, specifically, divided into I×J sub-areas based on longitude and latitude, and each area has the same size.

3. The traffic accident prediction method based on graph attention network according to claim 1 is characterized in that: The method of obtaining the traffic characteristics of the prediction area in the historical time period includes the following steps: Collect relevant data on accident information, road information, and weather information in the forecast area over a historical period; Data preprocessing is performed to obtain traffic accident risk characteristics, date characteristics, POI characteristics, weather characteristics, road characteristics, and traffic flow characteristics for historical time periods.

4. The traffic accident prediction method based on graph attention network according to claim 3 is characterized in that: Data preprocessing to obtain traffic accident risk characteristics for a historical period includes the following steps: All traffic accidents are divided into three risk levels according to the severity of the accident, with 1, 2, and 3 as the risk values ​​of traffic accidents. The traffic accident risk value of 1 represents a minor traffic accident, the traffic accident risk value of 2 represents a moderate traffic accident, and the traffic accident risk value of 3 represents a serious traffic accident. The sum of the risk values ​​of traffic accidents that occurred in each sub-region during the historical time period is calculated as the historical traffic accident risk feature of the node.

5. The traffic accident prediction method based on graph attention network according to claim 1 is characterized in that: The step of constructing a risk similarity map, a road similarity map, and a POI similarity map of the predicted area includes the following steps: Construct risk similarity graph G R =(V,E R ,A R ): Each sub-region is regarded as a node V of the graph. The risk similarity between nodes is compared. The node with the most similar characteristics to the node is selected as its first-order neighbor. The first-order neighbor nodes are connected to obtain the edge E of the graph. R , a R As the adjacency matrix of the graph, it is expressed as: Construct road similarity graph G D =(V,E D ,A D ): Each sub-region is regarded as a node V of the graph, and the road similarity between nodes is calculated. The L nodes with the highest similarity are selected as first-order neighbors, and the first-order neighbor nodes are connected to obtain the edge E of the graph. D , A D As the adjacency matrix of the graph, it is expressed as: Where i and j represent nodes i and j in the matrix, e i,j represents the edge between nodes, and sim(i,j) represents the road similarity value between the two; Construct POI similarity graph G P =(V,E P ,A P ): Each sub-region is regarded as a node V of the graph. The POI similarity between two nodes is calculated by JS divergence. The top L nodes with the highest similarity are selected as first-order neighbors. The first-order neighbor nodes are connected to obtain the edge E of the graph. P , A P As the adjacency matrix of a graph, its representation is the same as that of the road similarity graph.

6. The traffic accident prediction method based on graph attention network according to claim 1 is characterized in that: The CNN network includes a convolutional subnetwork, which includes two convolutional layers and a ReLU activation layer. The convolutional subnetwork expression formula is: Where * represents the convolution operation, and is the learnable parameter of the kth convolutional layer, ReLU is used as the activation function of the convolution function, represents the convolution output of the kth layer at time t, X t is the traffic characteristics of the historical time period; The GAT network includes a LeakyReLU activation function layer, a softmax normalization layer, and a concat connection layer, and includes the following steps: The initial feature dimension h of node i is shared by the weight matrix W i Perform feature transformation, expressed as: z i =Wh i Calculate the correlation between nodes i and j and obtain the attention score, which is expressed as: with ij =LeakeyReLU(a T (from i ||from j )) Where a represents the attention vector, which is used to convert the vector obtained by concatenating the feature representations of nodes i and j into a scalar value, (·) T represents vector transposition, || represents vector concatenation, and the normalization of the correlation between all nodes is used to obtain the attention coefficient, which is expressed as: Where N i represents all first-order neighbors of node i and node i itself, s ik For nodes i and N i The attention score between nodes in the range, exp(·) is an exponential function, which is expressed by the feature weights of adjacent nodes and the update of the central node, and the output information aggregation vector is obtained, which is expressed as: Where σ is a nonlinear activation function, z j N i The transformed expression of node features within the range.

7. The traffic accident prediction method based on graph attention network according to claim 1 is characterized in that: The multi-head self-attention mechanism focuses on inputs from different representation subspaces and includes the following steps: S1. Construct query matrix W Q , keyword matrix W K and the value matrix W V ; S2. Map the input feature vector X into the query vector Q, keyword vector K and value vector V, expressed as: Q=XW Q K=XW K V=XW V S3, use scaled dot product attention to calculate the similarity between the query vector and the keyword vector, and divide it by the number of feature channels d k Perform feature scaling to obtain the attention score vector, expressed as: S4. The weighted sum of the attention score vector and the value vector is used to obtain the context vector information of each node, which is expressed as: Attention(Q,K,V)=AV Apply the above steps to multiple attention heads, process them in parallel to obtain multiple sets of context vectors, and concatenate them together to map the final output representation as: MultiHead(Q,K,V)=Concat(head1,…head i …,head n )W O Where, head i =Attention(Q i ,K i ,V i ) represents the attention weight and context vector of the ith attention head. There are n attention heads in total. Concat represents the concatenation operation. W O It is a linear transformation weight matrix used to map the concatenated context vector to the final output representation; The TCN network consists of two layers of TCN modules and one layer of residual connection, wherein the TCN module includes: Dilated causal convolutional layers capture temporal dependencies of input sequences; The Weight Norm layer normalizes the weight values; ReLU is used as the activation function in the module to achieve delinearization; The Dropout layer randomly discards parts from the network to reduce the number of parameters and computational complexity of the model; After expanding the TCN network through multi-layer stacking, the output representation of the node after time feature extraction is obtained.

8. The traffic accident prediction method based on graph attention network according to claim 1 is characterized in that: The loss function uses FocalLoss to calculate the classification loss, which is expressed as: Where p represents the probability that the model predicts correctly, a is the weight factor, a∈[0,1].

Citation Information

Patent Citations

  • High-speed traffic flow prediction method based on multi-modal fusion and graph attention mechanism

    CN111540199A

  • Urban traffic accident risk prediction method based on road network

    CN113283665A