Graph attention based traffic accident risk prediction method and system
Patent Information
- Application Number
- CN202611245013.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-17
- Publication Date
- 2026-10-13
AI Technical Summary
[0008]本发明的目的是针对现有交通事故风险预测模型无法有效捕捉多视图异质空间依赖、长时序建模计算复杂度过高且缺乏预测可靠性评估,进而导致面临稀疏事故数据与复杂环境影响时预测精度不足及决策支持能力弱的问题,提供一种基于图注意力的交通事故风险预测方法及系统,能够提升交通事故风险预测的精度、计算效率与预测可靠性
[0041]根据上述技术方案,本发明中的基于GATv3的空间特征提取器通过条件化的多头图注意力机制,自适应地学习异质邻接节点的差异化权重,突破了传统图卷积网络无法区分不同语义邻域关系的局限,显著提升了多视图空间特征的判别能力与泛化性。时间特征提取器通过双向门控循环单元捕获短期动态,并结合因果稀疏注意力在保持时序因果性的同时高效筛选长历史窗口中的关键影响时刻,既降低了计算复杂度,又增强了模型的可解释性。贝叶斯预测头通过蒙特卡洛进行多次随机前向传播,输出风险预测值及其预测结果的方差,为高风险决策场景提供了量化的置信依据,弥补了现有模型仅输出点估计而缺乏可靠性评估的不足。可见,本发明通过空间、时序、不确定性评估三个维度的协同创新,实现了交通事故风险预测在精度、效率和可靠性上的全面提升。
Smart Images

Figure CN122906877A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and intelligent transportation technology, specifically to a method and system for predicting traffic accident risks based on graph attention. Background Technology
[0002] In recent years, with the gradual development of the automotive industry, the global road traffic safety situation has become increasingly severe. A World Health Organization report indicates that approximately 1.35 million people die globally each year from road traffic accidents, and traffic injuries have become one of the leading causes of death among people aged 5-29. This reflects the long-term and enormous burden that road traffic accidents impose on public health and social development. Against this backdrop, how to achieve accurate and timely prediction of urban traffic accident risks has become a research hotspot in the field of intelligent transportation systems. Effective traffic accident risk prediction can not only assist traffic management departments in the refined allocation of police resources, road segment management, and emergency response, but also provide navigation and travel suggestion systems with safe-priority route recommendations, thereby helping to reduce accident rates and casualties in practice.
[0003] Traffic accidents are influenced by a combination of heterogeneous information from multiple sources, including driving behavior, road network structure, weather, time of day, and population distribution, exhibiting high spatiotemporal sparsity and heterogeneity. This makes accurate and timely prediction of high-risk areas and time periods a challenging task. In recent years, with the rapid development of deep learning technology, especially the successful application of graph neural networks (GNNs) and attention mechanisms in spatiotemporal modeling, accident risk prediction methods based on multi-source data fusion and spatiotemporal modeling have received widespread attention.
[0004] In recent years, several studies have proposed minute-level urban accident prediction frameworks to improve prediction granularity and support decision-making (e.g., RiskOracle). Meanwhile, to enable the prediction results to be used for risk-sensitive decision-making, quantifying the uncertainty of model predictions has proven to be a lightweight and practical method, facilitating the selection of safety strategies and threshold setting in practical deployments by incorporating confidence levels. Based on these practical needs and methodological advancements, research on accident risk prediction that can both enhance spatiotemporal representation capabilities and output reliability assessments has significant theoretical value and substantial social application implications.
[0005] However, despite significant progress in accident risk prediction, existing research still faces the following core challenges in real-world city-level, multi-source heterogeneous data environments: First, the construction and fusion of multi-view information is a major problem in the field of traffic accident prediction. Specifically, how to construct semantically consistent views from multi-source data such as POIs, population, road network structure, dangerous driving statistics, traffic flow, and weather, and how to measure the similarity between views and suppress the negative impact of noisy views on the final prediction, still lack systematic methods and engineering practices. At the same time, existing graph convolution-based spatial modeling methods struggle to adaptively distinguish heterogeneous neighborhood relationships under different semantic views, resulting in insufficient representation ability for functionally similar but geographically non-adjacent areas, thus limiting the discriminative power and generalization of spatial features.
[0006] Secondly, the time series modeling module faces the dual constraints of computational efficiency and causal consistency over long historical windows. Traditional Transformer has high computational overhead, while simple recurrent networks are difficult to capture long-term critical dependencies, affecting the real-time performance and interpretability of predictions.
[0007] Furthermore, most models only output point estimates and lack a quantitative assessment of the reliability of the prediction results, making it difficult to support confidence-based resource allocation and early warning strategies in high-risk decision-making scenarios. Summary of the Invention
[0008] The purpose of this invention is to address the problems of existing traffic accident risk prediction models, such as their inability to effectively capture heterogeneous spatial dependencies in multiple views, excessive computational complexity in long-term modeling, and lack of prediction reliability assessment, which lead to insufficient prediction accuracy and weak decision support capabilities when faced with sparse accident data and complex environmental influences. This invention provides a traffic accident risk prediction method and system based on graph attention, which can improve the accuracy, computational efficiency, and prediction reliability of traffic accident risk prediction.
[0009] To achieve the above objectives, this invention provides a traffic accident risk prediction method based on graph attention, the method comprising: S1: Obtain historical traffic data, construct a multi-view graph structure containing static and dynamic views, and obtain a multi-view set; where each view corresponds to an adjacency matrix, which is used to describe the correlation between nodes of different administrative divisions; S2: The multi-view graph structure constructed in S1, along with date and weather data from historical traffic data, are input into a spatial feature extractor based on GATv3. GATv3 dynamically calculates and adaptively weights and aggregates attention coefficients through a conditional query-key attention mechanism to distinguish heterogeneous neighborhood relationships. For each view, GATv3 generates spatial embeddings of each view through multi-head attention and multi-level stacking, and then adaptively weights and fuses them using an inter-view attention mechanism to obtain unified multi-view spatial features. ; S3: The multi-view space features obtained in S2 The input temporal feature extractor comprises a bidirectional gated recurrent unit layer and a causal sparse attention layer connected in sequence; the bidirectional gated recurrent unit layer first processes the multi-view spatial features. The temporal dimension is bidirectionally encoded to capture short-term temporal dynamics and local context, generating an initial temporal representation. This initial temporal representation is then input into a causal sparse attention layer, which, while maintaining causal constraints, uses a sparse mask to filter key temporal dependencies from the long history, generating multi-granularity temporal features. ; S4: The multi-view space features obtained in S2 Multi-granularity temporal features obtained with S3 The input spatiotemporal feature fusion processor is used to fuse the features and obtain a spatiotemporal joint representation. Fusion includes integrating multi-view spatial features. Multi-granularity temporal features By splicing along the feature dimension and engaging in bidirectional information interaction through a cross-attention mechanism, deep fusion of spatial and temporal domain information can be achieved. S5: The spatiotemporal joint representation obtained in S4 The input is a Monte Carlo-based Bayesian prediction head. During model inference, the Monte Carlo layer remains on, and multiple random forward propagations are performed on the same input, with a different proportion of neurons being randomly discarded each time, resulting in multiple predictions. The average of these multiple predictions is used as the predicted traffic accident risk value. It calculates the variance of multiple prediction results; outputs the predicted value of traffic accident risk and the variance of the prediction results, which can be used to assist risk-sensitive decision-making.
[0010] Preferably, in S1, Historical traffic data includes static environmental characteristics and dynamic environmental characteristics Among them, static environmental characteristics To maintain stable regional inherent properties within the prediction timescale, dynamic environmental characteristics The traffic operation status and environmental conditions change over time; Static views include spatial adjacency views built based on spatial adjacency relationships between regions. Functional similarity view constructed based on the functional distribution similarity of points of interest between regions A road network similarity view constructed based on the structural similarity of road networks between regions. and demographic similarity views built based on the similarity of demographic distributions between regions ; The dynamic view includes a time-varying traffic pattern view built based on real-time traffic flow, average vehicle speed, and statistics on dangerous driving behaviors of drivers. .
[0011] Preferably, constructing the multi-view diagram structure in S1 includes: For spatial adjacency views An adjacency matrix is constructed based on the geographical boundary adjacency relationships between administrative divisions, and its elements are defined as follows:
[0012] in, Indicates the first i Each administrative region Indicates the first j Each administrative region, subscript i and j Indicates the index of the administrative region node; For functionally similar views Based on the distribution of interest point categories in each region, cosine similarity is used to calculate the functional similarity between regions, and a threshold is set to control the sparsity of the adjacency matrix, whose elements are defined as:
[0013] in, Indicates the area Interest point category frequency vector Indicates the area Interest point category frequency vector For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a range of values: ; For road network similarity view Using the same thresholding method as functionally similar views, an adjacency matrix is constructed based on feature vectors such as road grade, number of lanes, and speed limit for each region. Its elements are defined as follows:
[0014] in, Indicates the area Road network feature vectors such as road grade, number of lanes, and speed limit; Indicates the area Road network feature vectors such as road grade, number of lanes, and speed limit; For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a value range of . ; For demographic similarity views Using the same thresholding method as the functionally similar view, an adjacency matrix is constructed based on feature vectors such as population age distribution, gender ratio, and population density of each region. Its elements are defined as follows:
[0015] in, Indicates the area demographic feature vector, Indicates the area demographic feature vector, For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a value range of . ; For time-varying traffic pattern views At each time step Within this framework, the similarity between regions is dynamically calculated based on statistical characteristics of traffic flow, average speed, and dangerous driving behavior. A time-varying adjacency matrix is constructed, with its elements defined as follows:
[0016] in, Indicates the area The statistical feature vectors of traffic flow, average speed, and dangerous driving behavior at time step t. Indicates the area The statistical feature vectors of traffic flow, average speed, and dangerous driving behavior at time step t. For cosine similarity function, the threshold is... Similarly, let's set it as the mean of the similarity matrix at the current time step, with a value range of... ; At this point, the adjacency matrix of the five views is obtained. This is used for subsequent spatial feature extraction.
[0017] Preferably, the spatial feature extractor based on GATv3 in S2, whose single-layer GATv3, based on the conditional attention mechanism, captures multiple types of spatial dependencies through multi-head attention joint processing, is as follows:
[0018] in, Indicates the first Layer nodes eigenvectors, For the first The updated feature vector after layer; The number of heads receiving multi-head attention; Indicates a splicing operation; It is a non-linear activation function; For nodes The set of adjacent nodes; For the first The learnable weight matrix corresponding to each attention head; For the first Nodes in each attention head With adjacent nodes Attention coefficient between them; Attention coefficient The query vector is calculated using a conditional form, meaning it depends on the features of the target node. The key vector depends on the features of neighboring nodes. The calculation process is as follows:
[0019]
[0020] in, For the first The learnable attention parameter vector within the head; LeakyReLU is a linear unit activation function with leakage correction; and The first The learnable projection matrix used to generate queries and keys in the head; The unnormalized attention score is obtained after softmax normalization. ; For each view The adjacency matrix of the corresponding view As input to the graph structure, the node feature matrix As feature input, after being stacked through multiple layers of GATv3, the output is the spatial embedding representation of the view at time step t. The outputs of multiple views are then concatenated and attention fused to obtain the final multi-view spatial features. .
[0021] Preferably, in S3, The calculation process for the bidirectional gated cyclic cell layer is as follows:
[0022]
[0023] in, For time steps The input feature vector; For the forward GRU at time step The hidden state; For backward GRU at time step The hidden state; Indicates a splicing operation; For bidirectional GRU at time steps The output is an initial temporal representation that incorporates both forward and backward contextual information; The calculation process of the causal sparse attention layer is as follows:
[0024] in, For querying the matrix, The key matrix, The three are value matrices, and all are represented by the initial time series. Obtained by linear projection; This represents element-wise multiplication; Dimensions for queries and keys; The causal sparse mask matrix is defined as follows:
[0025] in, and These represent the time indexes for the query position and the key position, respectively. This ensures causal constraints, preventing future information from affecting the present. To limit the size of the sliding window, each query can only focus on queries within its historical sequence that are no more than a certain distance away. Time step; An optional set of sparse pattern indices is used to additionally select non-continuous key historical time steps; this is achieved through a causal sparse mask matrix. The computational complexity of the causal sparse attention layer is reduced from Reduce to ; The output of the causal sparse attention layer is processed through residual connections and layer normalization to obtain the final multi-granularity temporal features. .
[0026] Preferably, S4 specifically includes: With multi-view space features As a query, with multi-granularity time features As keys and values, temporal dynamics are injected into the spatial representation through cross-attention:
[0027]
[0028] in, This represents the number of nodes in the region. The number of time steps; , These are the dimensions of spatial features and temporal features, respectively; The projection matrix is learnable; This is the scaling factor; A spatiotemporal joint representation of spatial features enhanced by temporal information; Meanwhile, with multi-granularity time features As a query, with multi-view spatial features Spatial structure information is injected into the temporal representation as keys and values through cross-attention:
[0029]
[0030] in, This is a spatiotemporal joint representation of temporal features enhanced by spatial information. Finally, the two bidirectionally enhanced representations are fused to obtain the final spatiotemporal joint representation. :
[0031] in, LayerNorm This is a layer normalization operation.
[0032] Preferably, the calculation process of the Monte Carlo-based Bayesian prediction head in the model inference stage in S5 is as follows: Maintain the drop probability of the Monte Carlo layer Consistent with the training phase, a joint spatiotemporal representation of the same input is developed. conduct Each forward propagation involves randomly discarding a different proportion of neurons, resulting in... Each predicted output ; Traffic accident risk prediction value The calculation formula is:
[0033] in, For the first The predicted value obtained from the second forward propagation Number of Monte Carlo samples; Variance of prediction results The calculation formula is:
[0034] in, This indicates the model's cognitive uncertainty; the larger the value, the lower the model's confidence in the current prediction result. Ultimately, the Bayesian prediction head simultaneously outputs risk prediction values. variance of the predicted results It is used to assist in threshold judgment and resource scheduling in risk-sensitive decision-making scenarios.
[0035] Preferably, the method employs an end-to-end optimization approach during the training phase, using Huber loss as its loss function, defined as:
[0036] in, This represents the actual risk value for traffic accidents. The risk value predicted by the model. This is an adjustable hyperparameter used to control the switching threshold between squared error and absolute error; The overall objective of the loss function is to minimize the sum of the Huber losses for all training samples:
[0037] in, This represents the number of nodes in the region. To predict the number of time steps, and The first The region in the first The actual risk value and the predicted risk value at each future time step; During training, the Adam optimizer is used for parameter updates, and the initial learning rate is set to... The exponential decay rate is set to , Simultaneously, an early stopping method is employed, where the loss function value on the validation set is continuous. When the weights no longer decrease after a certain number of rounds, training is terminated and the optimal model weights are restored.
[0038] On the other hand, the present invention provides a system for risk prediction using the above-mentioned graph attention-based traffic accident risk prediction method, the system comprising: The multi-view generation module is used to acquire historical traffic data, construct static views based on static environmental features in the historical traffic data, and construct dynamic views based on dynamic environmental features to obtain a multi-view graph structure. Each view corresponds to an adjacency matrix that describes the correlation between nodes in the region. The spatial feature extraction module integrates the GATv3 network and uses date and weather data from the multi-view graph structure and historical traffic data as input. It dynamically calculates and adaptively weights and aggregates attention coefficients through a conditional query-key attention mechanism to distinguish heterogeneous neighborhood relationships, and generates spatial embeddings of each view through multi-head attention and multi-layer stacking. The spatial feature fusion module receives the spatial embeddings of each view output by the spatial feature extraction module, adaptively learns the importance weights of each view through the inter-view attention mechanism, and performs weighted fusion of the spatial embeddings of each view to obtain unified multi-view spatial features. The temporal feature extraction module integrates a bidirectional gated recurrent unit layer and a causal sparse attention layer connected in sequence. It is used to receive multi-view spatial features. First, the bidirectional gated recurrent unit layer performs bidirectional encoding to capture short-term temporal dynamics and local context to generate an initial temporal representation. Then, the causal sparse attention layer filters key temporal dependencies from the long history through sparse masking while maintaining causal constraints to generate multi-granular temporal features. The spatiotemporal feature fusion module is used to splice multi-view spatial features and multi-granular temporal features along the feature dimension, and to achieve bidirectional information interaction through a cross-attention mechanism, thereby realizing deep fusion of the spatial and temporal domains and obtaining a spatiotemporal joint representation. The Bayesian prediction module internally implements the Monte Carlo method, which keeps the Monte Carlo layer on during model inference. It performs multiple random forward propagations on the same input, randomly discarding a different proportion of neurons each time to obtain multiple prediction results. The mean of the multiple prediction results is used as the traffic accident risk prediction value, and the variance of the multiple prediction results is used as the prediction uncertainty measure. The module outputs the traffic accident risk prediction value and its variance.
[0039] Preferably, the final prediction result output by the system is expressed as:
[0040] in, For the system output vector, This is the predicted risk value. The variance of the predicted results, This indicates that the two will be provided to the decision-making body as a joint output.
[0041] According to the above technical solution, the spatial feature extractor based on GATv3 in this invention adaptively learns the differentiated weights of heterogeneous adjacent nodes through a conditional multi-head graph attention mechanism, overcoming the limitation of traditional graph convolutional networks in distinguishing different semantic neighborhood relationships, and significantly improving the discriminative ability and generalization of multi-view spatial features. The temporal feature extractor captures short-term dynamics through bidirectional gated recurrent units and combines causal sparse attention to efficiently filter key influencing moments in long historical windows while maintaining temporal causality, thus reducing computational complexity and enhancing model interpretability. The Bayesian prediction head performs multiple random forward propagations through Monte Carlo, outputting risk prediction values and the variance of the prediction results, providing quantitative confidence evidence for high-risk decision-making scenarios, and making up for the shortcomings of existing models that only output point estimates and lack reliability assessment. It can be seen that this invention achieves a comprehensive improvement in the accuracy, efficiency, and reliability of traffic accident risk prediction through synergistic innovation in three dimensions: spatial, temporal, and uncertainty assessment.
[0042] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description section. Attached Figure Description
[0043] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings: Figure 1 This is an overall architecture diagram of the traffic accident risk prediction system based on graph attention provided by the present invention; Figure 2 This is a schematic diagram of the internal composition and workflow of the time feature extractor in the graph attention-based traffic accident risk prediction system provided by the present invention. Figure 3 This is a schematic diagram of the internal composition and workflow of the Bayesian prediction head in the graph attention-based traffic accident risk prediction system provided by the present invention. Figure 4 This is a schematic diagram illustrating the prediction performance of the present invention and baseline on a real traffic accident dataset; Figure 5 This is a schematic diagram illustrating the prediction performance of the present invention and baseline on another real traffic accident dataset. Detailed Implementation
[0044] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.
[0045] It should be noted that the acquisition, transmission, storage, use, and processing of data in the technical solution of this application all comply with relevant laws and regulations. In the embodiments of this application, certain existing industry solutions such as software, components, and models may be mentioned. These should be considered exemplary, intended only to illustrate the feasibility of implementing the technical solution of this application, and do not imply that the applicant has already used or necessarily used such solutions.
[0046] This invention provides a traffic accident risk prediction method based on graph attention, the method comprising: S1: Obtain historical traffic data, which includes static environmental characteristics. (Refers to the inherent properties of a region that remain stable within the prediction timescale) and dynamic environmental characteristics (Refers to the changing traffic operation status and environmental conditions over time); Based on static and dynamic environmental characteristics, a multi-view graph structure is constructed, including static and dynamic views; the static view includes a spatial adjacency view constructed based on the spatial adjacency relationship between regions. Functional similarity view constructed based on the functional distribution similarity of points of interest between regions A road network similarity view constructed based on the structural similarity of road networks between regions. A demographic similarity view constructed based on the similarity of demographic distribution among regions. The dynamic view includes a time-varying traffic pattern view built based on real-time traffic flow, average vehicle speed, and statistical data on dangerous driving behaviors of drivers. Finally, a multi-view set is obtained. Each view corresponds to an adjacency matrix, which is used to describe the correlation between nodes of different administrative divisions; S2: The multi-view graph structure constructed in step S1, along with date and weather data from historical traffic data, is input into a GATv3-based spatial feature extractor. Date and weather data serve as node features in the spatial feature extraction process. GATv3 is a third-generation improved version of Graph Attention Network (GAN). It introduces a conditional query-key attention mechanism to dynamically calculate and adaptively weighted aggregate attention coefficients, overcoming the limitation of traditional graph convolutional networks that use fixed weights to aggregate adjacency information and cannot effectively distinguish heterogeneous neighborhood relationships. For each view, GATv3 adaptively calculates the attention weights between each central node and its neighboring nodes through a conditional query-key attention mechanism. The calculation of these attention weights depends on the feature vectors of the central node and its neighboring nodes. Multiple types of spatial dependencies are jointly captured through a multi-head attention mechanism, and after stacking and nonlinear transformations of multiple GATv3 layers, spatial embedding representations of each view are generated. These spatial embedding representations are then input into a spatial feature fusion unit. The spatial feature fusion unit adaptively learns the importance weights of each view through an inter-view attention mechanism, and performs weighted fusion of the spatial embeddings of each view to obtain unified multi-view spatial features. ; S3: Apply the multi-view spatial features obtained in step S2 The input is fed into a temporal feature extractor; the temporal feature extractor consists of a bidirectional gated recurrent unit layer and a causal sparse attention layer connected in sequence; firstly, the bidirectional gated recurrent unit layer is used to extract multi-view spatial features. The time dimension is bidirectionally encoded in both forward and backward directions to capture short-term temporal dynamics and local contextual information in the sequence, generating an initial temporal representation. This initial temporal representation is then input into a causal sparse attention layer. While maintaining causal constraints (i.e., information from future time steps cannot affect predictions at the current time step), the causal sparse attention layer uses a sparse attention masking strategy to restrict each query position to only focusing on key-value pairs in its historical sequence that satisfy a preset sparse pattern. This allows for the filtering of temporal dependencies that have a critical impact on future traffic accident risks from a long historical window, generating multi-granularity temporal features. ; S4: Apply the multi-view spatial features obtained in step S2 Compared with the multi-granularity temporal features obtained in step S3 The input spatiotemporal feature fusion processor is used to fuse the features and obtain a spatiotemporal joint representation. Fusion includes integrating multi-view spatial features. Multi-granularity temporal features By splicing along the feature dimension and engaging in bidirectional information interaction through a cross-attention mechanism, deep fusion of spatial and temporal domain information can be achieved. S5: The spatiotemporal joint representation obtained in step S4 The input is fed into a Monte Carlo-based Bayesian prediction head. During the model inference phase, the Monte Carlo layer remains active, and multiple random forward propagations are performed on the same input sample. A different proportion of neurons are randomly discarded during each forward propagation, resulting in multiple different predictions. The mean of these predictions is calculated as the final traffic accident risk prediction value. It calculates the variance of multiple prediction results; outputs the predicted value of traffic accident risk and the variance of the prediction results, which can be used to assist risk-sensitive decision-making.
[0047] Specifically, in this embodiment, the preferred method for constructing the multi-view diagram structure in step S1 includes: First, a spatial adjacency view is constructed based on the geographical boundaries and adjacency relationships of administrative divisions: Assume there is a total A number of regional nodes, if the region With the region If they share geographical boundaries, then the adjacency matrix... The corresponding element is set to 1, otherwise it is set to 0.
[0048] in, Indicates the first i Each administrative region Indicates the first j Each administrative region, subscript i and j Indicates the index of the administrative region node; This view reflects the propagation characteristics of traffic accident risk between geographically adjacent areas.
[0049] Secondly, construct functionally similar views: Collect the frequency vector of each point of interest (POI) category for each region. (41 categories in total), cosine similarity is used to calculate the functional similarity between regions:
[0050] To control the sparsity of the adjacency matrix, a threshold is set. This is the mean similarity across all regions. Only when the similarity is not less than... Establishing edges at time:
[0051] in, Indicates the area Interest point category frequency vector Indicates the area Interest point category frequency vector For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a range of values: ; This view enables the model to aggregate risk information from functionally similar but geographically non-adjacent areas.
[0052] Next, construct a road network similarity view: Based on feature vectors such as road grade, number of lanes, and speed limit of each region Using the same thresholding method as for functionally similar views, the adjacency matrix is obtained. Used to capture risk associations between areas with similar road structures:
[0053] in, Indicates the area Road network feature vectors such as road grade, number of lanes, and speed limit; Indicates the area Road network feature vectors such as road grade, number of lanes, and speed limit; For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a value range of . .
[0054] Then, construct a demographic similarity view. : Using the same thresholding method as for functionally similar views, an adjacency matrix is constructed based on feature vectors such as population age distribution, gender ratio, and population density for each region:
[0055] in, Indicates the area demographic feature vector, Indicates the area demographic feature vector, For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a value range of . .
[0056] Finally, construct a time-varying traffic pattern view: At each time step (Hourly) The statistical features of traffic flow, average speed, and nine types of dangerous driving behaviors are concatenated into a dynamic feature vector. Similarly, cosine similarity is used to calculate the dynamic similarity between regions, and a threshold is set... (Dynamically calculated over time steps) to obtain the time-varying adjacency matrix:
[0057] in, Indicates the area The statistical feature vectors of traffic flow, average speed, and dangerous driving behavior at time step t. Indicates the area The statistical feature vectors of traffic flow, average speed, and dangerous driving behavior at time step t. For cosine similarity function, the threshold is... Similarly, let's set it as the mean of the similarity matrix at the current time step, with a value range of... ; This view can reflect the spatiotemporal dynamics of traffic conditions and dangerous driving behaviors, enabling the model to adaptively adjust spatial dependencies at different times.
[0058] At this point, the adjacency matrix of the five views is obtained. Together, they form a multi-view graph structure, which is then input into the subsequent spatial feature extractor.
[0059] For each view The adjacency matrix of this view and the corresponding node feature matrix The input is fed into a multi-layer GATv3 network. Taking a single-layer GATv3 network as an example, the node feature update process is as follows:
[0060] in, Indicates the first Layer nodes eigenvectors, For the first The updated feature vector after layer; The number of heads receiving multi-head attention; Indicates a splicing operation; It is a non-linear activation function; For nodes The set of adjacent nodes; For the first The learnable weight matrix corresponding to each attention head; For the first Nodes in each attention head With adjacent nodes Attention coefficient between them; Attention coefficient The query vector is calculated using a conditional form, meaning it depends on the features of the target node. The key vector depends on the features of neighboring nodes. Unlike traditional GCNs that use fixed adjacency weights, GATv3 dynamically adjusts them based on node characteristics. First, it calculates the unnormalized attention score:
[0061] in, and The first The query projection matrix and key projection matrix are for each head; LeakyReLU is a linear unit activation function with leakage correction; This is a learnable attention parameter vector. It is achieved by using target node features. Generate query vectors Adjacent node characteristics Generate key vectors This enables conditional modeling of the relationships between node pairs.
[0062] Then, normalization is performed on the adjacency set using the softmax function:
[0063] Set the number of GATv3 layers Attention count Output dimension per head The activation function used is ELU, and a batch normalization layer is added after every two layers to stabilize training. For each of the five views, the above GATv3 operation is performed independently, outputting the spatial embeddings of each view. Finally, these embeddings are concatenated along the feature dimension and then dimensionality-reduced through a learnable fully connected layer to obtain the final multi-view space features. This is for use by subsequent fusion modules.
[0064] The specific implementation process of the time feature extractor in step S3 is as follows: Figure 2 As shown, it mainly consists of a bidirectional gated recurrent unit layer and a causal sparse attention layer connected sequentially. Specifically: First, the historical traffic data (including dynamic environmental characteristics, dangerous driving statistics, etc.) obtained in step S1 is input into the bidirectional GRU layer. Let the historical time window length be... The input feature vector at each time step is 1 hour. The forward GRU processes the sequence in ascending chronological order, while the backward GRU processes the sequence in descending chronological order, yielding the forward hidden states respectively. and backward hidden state :
[0065] Then, the hidden states in both directions are concatenated along the feature dimension to obtain an initial temporal representation that incorporates forward and backward contextual information:
[0066] The number of GRU hidden units is set to The bidirectional structure enables the model to capture both past and future short-term dependencies (using the complete sequence during training and only the historical part during prediction).
[0067] Next, the initial time-series representation sequence Linear projection as query matrix Key matrix Sum matrix ,in The calculation of causal sparse attention is as follows:
[0068] in, The causal sparse mask matrix is defined as follows:
[0069] in, and These represent the time indexes for the query position and the key position, respectively. Conditions This ensures causal constraints, meaning that the current time step cannot utilize future information; The sliding window size limits each query to only focus on the most recent ones in its history. One time step; As an optional sparse pattern index set, this embodiment additionally includes the same time period of the previous day (i.e. (if present), to capture key effects of daily periodicity. This represents element-wise multiplication. Using this mask, the computational complexity of attention is reduced from... Downgraded to This significantly improves the efficiency of long sequence processing.
[0070] The output of the causal sparse attention layer is processed through residual connections and layer normalization to obtain the final multi-granularity temporal features. This feature preserves short-term dynamics (through Bi-GRU), highlights key historical moments that have a causal impact on future accident risks (through causal sparse attention), and also has good computational efficiency.
[0071] In this embodiment, S4 preferably includes receiving the multi-view spatial features output in step S2. and the multi-granularity temporal features output in step S3 Achieving deep integration of spatial and temporal domains through a bidirectional cross-attention mechanism: First, based on multi-view space features As a query, with multi-granularity time features As keys and values, temporal dynamics are injected into the spatial representation through cross-attention:
[0072]
[0073] in, This represents the number of nodes in the region. The number of time steps; , These are the dimensions of spatial features and temporal features, respectively; The projection matrix is learnable; This is the scaling factor; A spatiotemporal joint representation of spatial features enhanced by temporal information; Secondly, using multi-granularity time features As a query, with multi-view spatial features Spatial structure information is injected into the temporal representation as keys and values through cross-attention:
[0074]
[0075] in, This is a spatiotemporal joint representation of temporal features enhanced by spatial information. Finally, the two bidirectionally enhanced representations are fused to obtain the final spatiotemporal joint representation. :
[0076] in, LayerNorm This is a layer normalization operation. Cross-attention uses single-head attention (expandable to multi-head), and the projection matrix output dimension remains at 128. Through this bidirectional interaction mechanism, spatial features can perceive the temporal dynamic correlations between regions (such as risk propagation during morning and evening rush hours), while temporal features can perceive the static structural constraints of different regions (such as the impact of road network topology on traffic flow), thus achieving true spatiotemporal collaborative representation and providing richer input for subsequent Bayesian prediction.
[0077] like Figure 3 As shown, in this embodiment, the specific implementation process of the Monte Carlo-based Bayesian prediction head in preferred step S5 is divided into a training phase and an inference (inference) phase: During the training phase, the spatiotemporal joint representation output in step S4 will be... The input is fed into a Bayesian fully connected layer. Unlike traditional fully connected layers that use fixed weights, Bayesian fully connected layers treat the weights and biases as random variables following a Gaussian distribution. During each forward propagation, specific weights and biases are obtained through reparameterization techniques:
[0078]
[0079] Then, the predicted output is calculated, and the KL divergence is simultaneously calculated and added as a regularization term to the total loss to constrain the posterior distribution to approximate the prior distribution. In this embodiment, there are two Bayesian fully connected layers, each with an output dimension of... The activation function is ReLU, and the dropout probability is... During training, the Dropout layer is enabled normally for regularization.
[0080] During the inference phase, when the model infers (predicts), the Dropout layer remains on (unlike the traditional approach of disabling Dropout during prediction), and the same input is spatiotemporally jointly represented. conduct Each forward propagation involves randomly discarding a different proportion of neurons, which is equivalent to sampling from an approximate posterior distribution. Different model parameter configurations yield Each predicted output In this embodiment, we take... .
[0081] Final traffic accident risk prediction value Take this The mean of the outputs:
[0082] in, For the first The predicted value obtained from the second forward propagation Number of Monte Carlo samples; Variance of prediction results The calculation formula is:
[0083] in, This indicates the model's cognitive uncertainty; the larger the value, the lower the model's confidence in the current prediction result. Ultimately, the Bayesian prediction head simultaneously outputs risk prediction values. variance of the predicted results , with joint vector This information is provided to decision-makers in a specific format. In practical applications, traffic management departments can then... Set an early warning threshold: when If the risk exceeds a preset threshold, it indicates that the model's risk prediction for that area is unreliable, and manual review or a more conservative resource allocation strategy should be triggered. This mechanism significantly enhances the model's practical value in high-risk decision-making scenarios.
[0084] Furthermore, the method provided in this invention employs an end-to-end training approach. Due to the sparsity and zero-inflation characteristics of traffic accident risk data, directly using the mean squared error (MSE) will cause the model to tend to predict zero values, while using the mean absolute error (MAE) is insufficient in penalizing larger errors. Therefore, this embodiment uses the Huber loss function as the optimization objective, which combines the advantages of MSE and MAE and has better robustness to outliers. The Huber loss is defined as:
[0085] in, This represents the actual risk value for traffic accidents. The risk value predicted by the model. This is an adjustable hyperparameter used to control the switching threshold between squared error and absolute error; The overall objective of the loss function is to minimize the sum of the Huber losses for all training samples:
[0086] in, This represents the number of nodes in the region. To predict the number of time steps, and The first The region in the first The actual risk value and the predicted risk value for each future time step.
[0087] Furthermore, when the Bayesian fully connected layer in the Bayesian prediction head is enabled, the total loss also needs to be increased by the KL divergence regularization term. The posterior distribution of the constraint weights approximates the standard normal prior, i.e.:
[0088] Wherein, the KL divergence coefficient is taken as .
[0089] During training, the Adam optimizer is used for parameter updates, and the initial learning rate is set to... The exponential decay rate is set to , Simultaneously, an early stopping method is employed, where the loss function value on the validation set is continuous. When the weights no longer decrease after a certain number of epochs, training is terminated and the optimal model weights are restored. The batch size is set to 64, and the maximum number of training epochs is 100. Using this training strategy, the model can learn stably on sparse accident data and achieve excellent predictive performance.
[0090] Furthermore, this invention also provides a traffic accident risk prediction system based on graph attention, the overall architecture of which is as follows: Figure 1 As shown, the system is used to perform steps S1 to S5 in the above method embodiments. The system includes: The multi-view generation module is used to acquire historical traffic data, construct static views based on static environmental features in the historical traffic data, and construct dynamic views based on dynamic environmental features to obtain a multi-view graph structure. Each view corresponds to an adjacency matrix that describes the correlation between nodes in the region. The spatial feature extraction module integrates the GATv3 network and uses date and weather data from the multi-view graph structure and historical traffic data as input. It dynamically calculates and adaptively weights and aggregates attention coefficients through a conditional query-key attention mechanism to distinguish heterogeneous neighborhood relationships, and generates spatial embeddings of each view through multi-head attention and multi-layer stacking. The spatial feature fusion module receives the spatial embeddings of each view output by the spatial feature extraction module, adaptively learns the importance weights of each view through the inter-view attention mechanism, and performs weighted fusion of the spatial embeddings of each view to obtain unified multi-view spatial features. The temporal feature extraction module integrates a bidirectional gated recurrent unit layer and a causal sparse attention layer connected in sequence. It is used to receive multi-view spatial features. First, the bidirectional gated recurrent unit layer performs bidirectional encoding to capture short-term temporal dynamics and local context to generate an initial temporal representation. Then, the causal sparse attention layer filters key temporal dependencies from the long history through sparse masking while maintaining causal constraints to generate multi-granular temporal features. The spatiotemporal feature fusion module is used to splice multi-view spatial features and multi-granular temporal features along the feature dimension, and to achieve bidirectional information interaction through a cross-attention mechanism, thereby realizing deep fusion of the spatial and temporal domains and obtaining a spatiotemporal joint representation. The Bayesian prediction module internally implements the Monte Carlo method, which keeps the Monte Carlo layer on during model inference. It performs multiple random forward propagations on the same input, randomly discarding a different proportion of neurons each time to obtain multiple prediction results. The mean of the multiple prediction results is used as the traffic accident risk prediction value, and the variance of the multiple prediction results is used as the prediction uncertainty measure. The module outputs the traffic accident risk prediction value and its variance.
[0091] In one specific implementation, the system can be deployed on a traffic management center server or cloud computing platform to access traffic flow data, dangerous driving statistics and environmental data in real time, output the traffic accident risk level and confidence level of various urban areas in the future, and assist in police dispatch and safety early warning.
[0092] To verify the effectiveness of the method of the present invention, Figure 4 , Figure 5 The image shows a comparative experiment conducted on two real traffic accident datasets from a city in a certain country in September 2016 and September 2018. The datasets are aggregated at hourly intervals, covering 25 administrative regions, and include static environmental features (POI, road network, population), dynamic environmental features (traffic flow, speed, weather), and statistics on nine types of dangerous driving behaviors. The datasets are divided into training, validation, and test sets in an 8:1:1 ratio. Data from the past 12 hours is used to predict traffic accident risk scores for the next 6 hours. Evaluation metrics include Mean Absolute Error (MAE), Mean Squared Error (MSE), Mean Absolute Percentage Error (MAPE), high-risk area recall (Acc@K), and time to inference per sample (Time(test)).
[0093] The method of this invention was compared with various baseline models, including Hetero-ConvLSTM, TA-STAN, RiskOracle, RiskSeq, DF-TAR, MG-TAR, MV-RSTTAG, and STCAGNN-RNKDE. Figure 4 and Figure 5As can be seen, the method of this invention (labeled Ours in the figure) outperforms all baseline models in all four evaluation metrics: MAE, MSE, MAPE, and Acc@K. On the 2016 dataset, the MSE of the method of this invention is 2.5622, a reduction of 0.24% compared to the best baseline MV-RSTTAG (MSE=2.5683), and the Acc@K reaches 0.3376, better than MG-TAR's 0.3264. On the 2018 dataset, the MSE of the method of this invention is 2.4523, a reduction of 0.48% compared to MV-RSTTAG (MSE=2.4642), and the Acc@K is 0.2962, close to the optimal value. Regarding inference time, the method of this invention takes approximately 1.195 seconds per step per sample, better than MG-TAR's 5.956 seconds per step, verifying the efficiency improvement brought by causal sparse attention in the temporal module.
[0094] Furthermore, ablation experiments can be conducted to further verify the effectiveness of each core module. Specifically, the multi-view generator, spatial feature extractor, spatial feature fusionist, temporal feature extractor, spatiotemporal feature fusionist, and Bayesian prediction head are removed and compared. The results show that the complete model outperforms all variants. Removing any module leads to an increase in prediction error and a decrease in recall. Removing the causal sparse attention module significantly increases inference time, validating the necessity and synergistic gain of the module design in this invention.
[0095] The above experiments fully demonstrate the superiority of the method of the present invention in the task of traffic accident risk prediction. It has reached an advanced level in terms of accuracy, efficiency and reliability, and is suitable for city-level real-time risk warning and traffic management decision support.
[0096] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0097] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0098] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0099] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0100] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0101] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0102] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0103] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0104] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A traffic accident risk prediction method based on graph attention, characterized in that, The method includes: S1: Obtain historical traffic data, construct a multi-view graph structure containing static and dynamic views, and obtain a multi-view set; where each view corresponds to an adjacency matrix, which is used to describe the correlation between nodes of different administrative divisions; S2: The multi-view graph structure constructed in S1, along with date and weather data from historical traffic data, are input into a spatial feature extractor based on GATv3. GATv3 dynamically calculates and adaptively weights and aggregates attention coefficients through a conditional query-key attention mechanism to distinguish heterogeneous neighborhood relationships. For each view, GATv3 generates spatial embeddings of each view through multi-head attention and multi-level stacking, and then adaptively weights and fuses them using an inter-view attention mechanism to obtain unified multi-view spatial features. ; S3: The multi-view space features obtained in S2 The input temporal feature extractor comprises a bidirectional gated recurrent unit layer and a causal sparse attention layer connected in sequence; the bidirectional gated recurrent unit layer first processes the multi-view spatial features. The temporal dimension is bidirectionally encoded to capture short-term temporal dynamics and local context, generating an initial temporal representation. This initial temporal representation is then input into a causal sparse attention layer, which, while maintaining causal constraints, uses a sparse mask to filter key temporal dependencies from the long history, generating multi-granularity temporal features. ; S4: The multi-view space features obtained in S2 Multi-granularity temporal features obtained with S3 The input spatiotemporal feature fusion processor is used to fuse the features and obtain a spatiotemporal joint representation. The fusion includes combining multi-view spatial features. Multi-granularity temporal features By splicing along the feature dimension and engaging in bidirectional information interaction through a cross-attention mechanism, deep fusion of spatial and temporal domain information can be achieved. S5: The spatiotemporal joint representation obtained in S4 The input is a Monte Carlo-based Bayesian prediction head. During model inference, the Monte Carlo layer remains on, and multiple random forward propagations are performed on the same input, with a different proportion of neurons being randomly discarded each time, resulting in multiple predictions. The average of these multiple predictions is used as the predicted traffic accident risk value. It calculates the variance of multiple prediction results; outputs the predicted value of traffic accident risk and the variance of the prediction results, which can be used to assist risk-sensitive decision-making.
2. The traffic accident risk prediction method based on graph attention according to claim 1, characterized in that, In S1, Historical traffic data includes static environmental characteristics and dynamic environmental characteristics Among them, static environmental characteristics To maintain stable regional inherent properties within the prediction timescale, dynamic environmental characteristics The traffic operation status and environmental conditions change over time; Static views include spatial adjacency views built based on spatial adjacency relationships between regions. Functional similarity view constructed based on the functional distribution similarity of points of interest between regions A road network similarity view constructed based on the structural similarity of road networks between regions. and demographic similarity views built based on the similarity of demographic distributions between regions ; The dynamic view includes a time-varying traffic pattern view built based on real-time traffic flow, average vehicle speed, and statistics on dangerous driving behaviors of drivers. .
3. The traffic accident risk prediction method based on graph attention according to claim 2, characterized in that, The construction of the multi-view graph structure in S1 includes: For spatial adjacency views An adjacency matrix is constructed based on the geographical boundary adjacency relationships between administrative divisions, and its elements are defined as follows: in, Indicates the first i Each administrative region Indicates the first j Each administrative region, subscript i and j Indicates the index of the administrative region node; For functionally similar views Based on the distribution of interest point categories in each region, cosine similarity is used to calculate the functional similarity between regions, and a threshold is set to control the sparsity of the adjacency matrix, whose elements are defined as: in, Indicates the region Interest point category frequency vector Indicates the region Interest point category frequency vector For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a range of values: ; For road network similarity view Using the same thresholding method as functionally similar views, an adjacency matrix is constructed based on the road grade, number of lanes, and speed limit feature vectors of each region. Its elements are defined as follows: in, Indicates the region The road network feature vectors, including road grade, number of lanes, and speed limit. Indicates the region The road network feature vectors, including road grade, number of lanes, and speed limit. For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a value range of . ; For demographic similarity views Using the same thresholding method as the functionally similar view, an adjacency matrix is constructed based on the feature vectors of population age distribution, gender ratio, and population density of each region. Its elements are defined as follows: in, Indicates the region Demographic feature vector, Indicates the region Demographic feature vector, For cosine similarity function, the threshold is... Let be the mean of the elements of each similarity matrix, with a value range of . ; For time-varying traffic pattern views At each time step Within this framework, the similarity between regions is dynamically calculated based on statistical characteristics of traffic flow, average speed, and dangerous driving behavior. A time-varying adjacency matrix is constructed, with its elements defined as follows: in, Indicates the region The statistical feature vectors of traffic flow, average speed, and dangerous driving behavior at time step t. Indicates the region The statistical feature vectors of traffic flow, average speed, and dangerous driving behavior at time step t. For cosine similarity function, the threshold is... Similarly, let's set it as the mean of the similarity matrix at the current time step, with a value range of... ; At this point, the adjacency matrix of the five views is obtained. This is used for subsequent spatial feature extraction.
4. The traffic accident risk prediction method based on graph attention according to claim 1, characterized in that, The spatial feature extractor based on GATv3 described in S2, with its single-layer GATv3 layer, captures various types of spatial dependencies through multi-head attention in addition to the conditional attention mechanism. The computation process is as follows: in, Indicates the first Layer nodes eigenvectors, For the first The updated feature vector after the layer; The number of heads receiving multi-head attention; Indicates a splicing operation; It is a non-linear activation function; For nodes The set of adjacent nodes; For the first The learnable weight matrix corresponding to each attention head; For the first Nodes in each attention head With adjacent nodes Attention coefficient between them; The attention coefficient The query vector is calculated using a conditional form, meaning it depends on the features of the target node. The key vector depends on the features of neighboring nodes. The calculation process is as follows: in, For the first The learnable attention parameter vector within the head; LeakyReLU is a linear unit activation function with leakage correction; and The first The learnable projection matrix used to generate queries and keys in the head; The unnormalized attention score is obtained after softmax normalization. ; For each view The adjacency matrix of the corresponding view As input to the graph structure, the node feature matrix As feature input, after being stacked through multiple layers of GATv3, the output is the spatial embedding representation of the view at time step t. The outputs of multiple views are then concatenated and attention fused to obtain the final multi-view spatial features. .
5. The traffic accident risk prediction method based on graph attention according to claim 1, characterized in that, In S3, The calculation process for the bidirectional gated loop unit layer is as follows: in, For time step The input feature vector; For the forward GRU at time step The hidden state; For backward GRU at time step The hidden state; Indicates a splicing operation; For bidirectional GRU at time step The output is an initial temporal representation that incorporates both forward and backward contextual information; The calculation process for the causal sparse attention layer is as follows: in, For querying the matrix, The key matrix, The three are value matrices, and all three are represented by the initial time series. Obtained by linear projection; This represents element-wise multiplication; Dimensions for queries and keys; The causal sparse mask matrix is defined as follows: in, and These represent the time indexes for the query position and the key position, respectively. This ensures causal constraints, preventing future information from affecting the present. To limit the size of the sliding window, each query can only focus on queries within its historical sequence that are no more than a certain distance away. Time step; An optional set of sparse pattern indices is used to additionally select non-continuous key historical time steps; this is achieved through a causal sparse mask matrix. The computational complexity of the causal sparse attention layer is reduced from Reduce to ; The output of the causal sparse attention layer is then processed through residual connections and layer normalization to obtain the final multi-granularity temporal features. .
6. The traffic accident risk prediction method based on graph attention according to claim 1, characterized in that, S4 specifically includes: Based on the multi-view space features As a query, the multi-granularity time features As keys and values, temporal dynamics are injected into the spatial representation through cross-attention: in, This represents the number of nodes in the region. The number of time steps; , These are the dimensions of spatial features and temporal features, respectively; The projection matrix is learnable; This is the scaling factor; A spatiotemporal joint representation of spatial features enhanced by temporal information; Meanwhile, using the aforementioned multi-granularity time features As a query, based on the multi-view spatial features Spatial structure information is injected into the temporal representation as keys and values through cross-attention: in, This is a spatiotemporal joint representation of temporal features enhanced by spatial information. Finally, the two bidirectionally enhanced representations are fused to obtain the final spatiotemporal joint representation. : in, LayerNorm This is a layer normalization operation.
7. The traffic accident risk prediction method based on graph attention according to claim 1, characterized in that, The calculation process of the Monte Carlo-based Bayesian prediction head in the model inference stage, as described in S5, is as follows: Maintain the drop probability of the Monte Carlo layer Consistent with the training phase, a joint spatiotemporal representation of the same input is developed. conduct Each forward propagation involves randomly discarding a different proportion of neurons, resulting in... Each predicted output ; The predicted value of traffic accident risk The calculation formula is: in, For the first The predicted value obtained from the second forward propagation Number of Monte Carlo samples; The variance of the prediction results The calculation formula is: in, This indicates the model's cognitive uncertainty; the larger the value, the lower the model's confidence in the current prediction result. Finally, the Bayesian prediction head simultaneously outputs the predicted risk value. variance of the prediction result It is used to assist in threshold judgment and resource scheduling in risk-sensitive decision-making scenarios.
8. The traffic accident risk prediction method based on graph attention according to claim 1, characterized in that, The method employs an end-to-end optimization approach during the training phase, and its loss function uses Huber loss, defined as: in, This represents the actual risk value for traffic accidents. The risk value predicted by the model. This is an adjustable hyperparameter used to control the switching threshold between squared error and absolute error; The overall objective of the loss function is to minimize the sum of the Huber losses for all training samples: in, This represents the number of nodes in the region. To predict the number of time steps, and The first The region in the first The actual risk value and the predicted risk value at each future time step; During training, the Adam optimizer is used for parameter updates, and the initial learning rate is set to... The exponential decay rate is set to , Simultaneously, an early stopping method is employed, where the loss function value on the validation set is continuous. When the weights no longer decrease after a certain number of rounds, training is terminated and the optimal model weights are restored.
9. A system for risk prediction using the graph attention-based traffic accident risk prediction method as described in any one of claims 1-8, characterized in that, The system includes: The multi-view generation module is used to acquire historical traffic data, construct a static view based on the static environmental features in the historical traffic data, and construct a dynamic view based on the dynamic environmental features to obtain a multi-view graph structure. Each view corresponds to an adjacency matrix that describes the correlation between regional nodes. The spatial feature extraction module integrates a GATv3 network. It takes the date data and weather data in the multi-view graph structure and historical traffic data as input, dynamically calculates and adaptively weights and aggregates attention coefficients through a conditional query-key attention mechanism to distinguish heterogeneous neighborhood relationships, and generates spatial embeddings of each view through multi-head attention and multi-layer stacking. The spatial feature fusion module is used to receive the spatial embeddings of each view output by the spatial feature extraction module, adaptively learn the importance weights of each view through the inter-view attention mechanism, and perform weighted fusion of the spatial embeddings of each view to obtain unified multi-view spatial features. The temporal feature extraction module integrates a bidirectional gated recurrent unit layer and a causal sparse attention layer connected in sequence. It is used to receive the multi-view spatial features. First, the bidirectional gated recurrent unit layer performs bidirectional encoding to capture short-term temporal dynamics and local context to generate an initial temporal representation. Then, the causal sparse attention layer filters key temporal dependencies from the long history through sparse masking while maintaining causal constraints to generate multi-granular temporal features. The spatiotemporal feature fusion module is used to splice the multi-view spatial features and the multi-granularity temporal features in the feature dimension, and to perform bidirectional information interaction through a cross-attention mechanism to achieve deep fusion of the spatial domain and the temporal domain, and obtain a spatiotemporal joint representation. The Bayesian prediction module internally implements the Monte Carlo method, which keeps the Monte Carlo layer on during model inference, performs multiple random forward propagations on the same input, and randomly discards a different proportion of neurons each time to obtain multiple prediction results. The mean of the multiple prediction results is used as the traffic accident risk prediction value, and the variance of the multiple prediction results is used as the prediction uncertainty measure. The traffic accident risk prediction value and its variance are then output.
10. The traffic accident risk prediction system based on graph attention according to claim 9, characterized in that, The final prediction result output by the system is expressed as follows: in, For the system output vector, This is the predicted risk value. The variance of the predicted results, This indicates that the two will be provided to the decision-making body as a joint output.