Traffic accident prediction method based on VAE-attention and GCN

Through the method based on VAE-attention and GCN, traffic accident data are segmented and balanced data are generated, which solves the problem of uneven distribution of traffic accident data, and improves the accuracy and social safety of traffic accident prediction.

CN120123876APending Publication Date: 2025-06-10XIAN UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510229289.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-28
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

The uneven distribution of traffic accident data leads to a decrease in the accuracy of traffic accident prediction.

Method used

The traffic accident prediction method based on VAE-attention and GCN is adopted to segment the data through sliding windows, combine VAE and self-attention mechanism to generate equalized accident data, and use the GCN network to construct graph data and accident prediction model.

Benefits of technology

It improves the quality of sample generation and the accuracy of accident prediction, reduces the incidence of traffic accidents, and improves the safety of the public.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120123876A_ABST
    Figure CN120123876A_ABST
Patent Text Reader

Abstract

The invention discloses a traffic accident prediction method based on VAE-attention and GCN, and the method specifically comprises the following steps: 1, segmenting traffic accident data through a sliding window, and obtaining small window accident data; step 2, establishing a VAE-attention sample generation model in combination with VAE and a self-attention mechanism method, generating small window accident data, and taking a smooth L1 loss function as a reconstruction error of the VAE-attention sample generation model to obtain high-quality balanced accident data; and step 3, combining the high-quality balanced accident data obtained in the step 2, constructing graph data and an accident prediction model through a GCN network, and realizing traffic accident prediction. The intelligent level of road traffic can be improved, and a basis is provided for decision making of a road management system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of traffic accident safety analysis and prediction, and specifically relates to a traffic accident prediction method based on VAE-attention and GCN. Background Technique

[0002] Traffic accidents are an important issue affecting social safety, which can directly threaten human life safety and economic issues. By accurately predicting traffic accidents, the traffic management level can be greatly improved. However, since the frequency of vehicle accidents is much lower than the normal situation, the monitored accident data is unevenly distributed, which in turn reduces the accuracy of accident prediction. Therefore, in order to establish an accurate accident prediction model and further improve road traffic efficiency, it is first necessary to perform an operation to balance the distribution of the monitored traffic accident data. The variational autoencoder (VAE) method can explicitly describe the distribution generation process of rare-class variables through the data probability distribution, and has high interpretability. The self-attention mechanism can consider the positions of each sequence in the input data, and thus capture the global information of the sample. The graph convolutional network (GCN) can capture the global information in the sample and establish a deep topological structure between sample features. Therefore, the present invention proposes an accident prediction method based on VAE-attention and GCN to further improve the intelligent level of road traffic and accelerate the process of intelligent travel. Summary of the Invention

[0003] The purpose of the present invention is to provide a traffic accident prediction method based on VAE-attention and GCN, which helps to improve the intelligent level of road traffic and provides a basis for the decision-making of the road management system.

[0004] The technical solution adopted by the present invention is a traffic accident prediction method based on VAE-attention and GCN, which is specifically implemented according to the following steps:

[0005] Step 1: Use a sliding window to segment the traffic accident data to obtain small-window accident data;

[0006] Step 2: Combine the VAE and the self-attention mechanism method to establish a VAE-attention sample generation model, generate the small-window accident data, and combine the smooth L1 loss function as the reconstruction error of the VAE-attention model to obtain high-quality balanced accident data;

[0007] Step 3: Combine the high-quality balanced accident data obtained in Step 2, construct graph data and an accident prediction model through the GCN network, and realize traffic accident prediction.

[0008] The features of the present invention also lie in that,

[0009] Step 1 is specifically implemented according to the following steps:

[0010] Assume that the size of the original accident data monitored is D' = {X M*N , Y M}, M is the accident sample size, N is the number of features. First, the original accident data D’ is divided into P subsets through a sliding window, and the size of each subset is L*N, where L is the sliding window size and the step size is k, indicating the number of bits the window moves. Therefore, P small-window accident data D i,i=1,...,p = {X L*N , Y L} are obtained through the sliding window. The P small-window accident data D i,i=1,...,p = {X L*N , Y L} are simply called subsets, X L*N is a feature, and Y L is the accident severity.

[0011] Step 2 is specifically implemented according to the following steps:

[0012] Step 2.1: Establish a VAE-attention sample generation model;

[0013] After obtaining the output value of the self-attention mechanism in Step 2.1, record the entire self-attention mechanism output sequence as H L*N . Through the encoder (i.e., a multi-layer neural network) in the VAE model, train the output sequence H L*N to obtain the mean μ(H L*N ) and variance Σ(H L*N ) of the output sequence. Then, sample the sample ε in the standard normal distribution N(0, I) to obtain the latent variable Z. Use the sampled sample and the decoder (i.e., a multi-layer neural network) to obtain P generated subsets X' L*N,i=1,...,P , and optimize the quality of the P generated subsets through the loss function.

[0014] Step 2.1 is specifically as follows:

[0015] After obtaining P subsets D i through Step 1, input the sample features X i,i=1,...,p in the P subsets D L*N , Y L} into the Encoder of the VAE model. The sample features X L*N follow the probability distribution p(X). Through the multi-layer neural network, perform a mapping transformation on the sample features X L*N to obtain the subset output L*N Then, the self-attention mechanism is used to construct data dependency relationships and calculate the subset output. The result of the self-attention mechanism is calculated, and the calculation process is as shown in Equation (1):

[0016]

[0017] Among them, Q, K, and V are the query value, key value, and V value of the attention mechanism respectively, and W Q , W K are the weight parameters of the attention mechanism respectively. The weight parameter values W Q , W K can be obtained by training the network using a fully connected layer.

[0018] Then, the attention mechanism weight value a is calculated through the dot product and the softmax function, and the calculation process is as shown in Equation (2):

[0019]

[0020] Among them, d is the dimension of the query value Q or the key value K.

[0021] The self-attention mechanism output value h is obtained by calculating the dot product of the attention weight value and the V value i,j , and the specific calculation process is as shown in Equation (3):

[0022]

[0023] Among them, i is the position of the self-attention mechanism output value, j is the feature dimension, j = 1,..., N, a is the attention mechanism weight value, and k is the position of the subset output .

[0024] So far, the VAE-attention sample generation model is established.

[0025] The calculation process of the loss function in Step 2.2 is as follows:

[0026] In Step 2.2.1, the smooth L1 function is used as the reconstruction error of the VAE-attention model. Therefore, the calculation process of the loss function of the VAE-attention model is as shown in Equation (4):

[0027]

[0028] Among them, the KL divergence loss is used to calculate the similarity between the posterior distribution of the sample generated by the self-attention mechanism and the standard normal distribution;

[0029] In Step 2.2.2, by minimizing Enable the latent variable Z to have better distribution characteristics, L 1 is the reconstruction error between the generated sample and the original sample The calculation process is shown in formula (5):

[0030]

[0031] Among them, the generated subset X' L*N,i=1,...,P is denoted as X', and the subset input X L*N is denoted as X.

[0032] In step 3, the GCN network consists of an input layer, a hidden layer, and an output layer. The hidden layer is the core of the GCN network. The hidden layer is composed of graph convolutional layers. Each graph convolutional layer is obtained by performing a convolutional operation on the adjacency matrix A and the feature matrix H to update the node feature representation.

[0033] In step 3, use the balanced accident data obtained in step 2, that is, P generated subsets X' L*N,i=1,...,P , construct graph data based on the Euclidean distance between nodes, and use the GCN network to predict traffic accidents.

[0034] Step 3 is specifically as follows:

[0035] The sample size input to the GCN network is D U ={X U*N ,Y U}, where U = M + C, M is the original sample size, C is the generated sample size, N is the sample feature, and Y U is the data node, and the feature of each node is X U*N . The relationship between nodes forms an adjacency matrix A of U * U. Calculate the Euclidean distance l between any two nodes X i and X j . When the distance is less than the threshold, it is considered that there is an edge between the two nodes. Store the edge index in the edge list, and then convert the edge list into a tensor;

[0036] Input the sample X U*N into the input layer of the GCN network, then pass through the GCN graph convolutional hidden layer, and then output the accident severity results corresponding to different samples X U*N . The calculation formula of the feature matrix H in the hidden layer of the GCN network is as in (6), that is, the propagation process of the input node features in the GCN network:

[0037]

[0038] Among them, W is the weight parameter in each layer of the model, is the sum of the adjacency matrix A and the identity matrix I, that is, calculate the edge connection for each node itself, is the degree matrix of, that is, the number of edges connected to the nodes. L represents the number of layers in the network structure. When l = 0, it represents the current input layer. f(·) is a non-linear function, that is, the activation function in the neuron;

[0039] By stacking two convolutional layers for the transfer of multi-order neighborhood information, the spatial features of the input samples are extracted. The process of two-layer graph convolution calculation is as shown in formula (7):

[0040]

[0041] O is the traffic accident prediction result output by the GCN network. The severity of the traffic accident is predicted in the form of probability to determine which type of accident this sample is.

[0042] The beneficial effect of the present invention is that based on the traffic accident prediction method of VAE-attention and GCN, the traffic accident data is segmented by using a sliding window to obtain small-window accident data. Then, a VAE-attention sample generation model is established by combining VAE and the self-attention mechanism to generate the samples in the small-window accident data, and the smooth L1 loss function is combined as the reconstruction error of the VAE-attention model to obtain balanced accident data. Finally, a graph data and accident prediction model is constructed through the GCN network to realize traffic accident prediction. It improves the quality of sample generation and the accuracy of accident prediction, further reduces the incidence of traffic accidents, and improves the safety of the general public. Description of the Drawings

[0043] Figure 1 is the overall flowchart of the accident prediction method of the present invention based on VAE-attention and GCN;

[0044] Figure 2 is the sample generation result of the accident prediction method of the present invention based on VAE-attention and GCN;

[0045] Figure 3 is the construction result of the accident graph data of the accident prediction method of the present invention based on VAE-attention and GCN;

[0046] Figure 4(a) is the accident prediction result of the accident prediction method of the present invention based on VAE-attention and GCN;

[0047] Figure 4(b) is the analysis result of the accident confusion matrix of the accident prediction method of the present invention based on VAE-attention and GCN. Detailed Embodiments

[0048] The present invention will be described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0049] The traffic accident prediction method of the present invention based on VAE-attention and GCN has a flowchart as Figure 1 shown, and is specifically implemented according to the following steps:

[0050] Step 1: Use a sliding window to segment the traffic accident data to obtain small-window accident data;

[0051] Step 1 is specifically implemented according to the following steps:

[0052] Suppose the size of the monitored original accident data is D' = {X M*N , Y M}, M is the accident sample size, N is the number of features. If the length of the original accident data is too large, it will affect the learning efficiency of the sample distribution. First, the present invention divides the original accident data D’ into P subsets through a sliding window, and the size of each subset is L*N, where L is the sliding window size and the step size is k, indicating the number of bits the window moves. Therefore, P small-window accident data D i,i=1,...,p = {X L*N , Y L} are obtained. The P small-window accident data D i,i=1,...,p = {X L*N , Y L} are simply called subsets, X L*N is the feature, and Y L is the accident severity.

[0053] Step 2: Combine the VAE and self-attention mechanism methods to establish a VAE-attention sample generation model, generate the small-window accident data, and combine the smooth L1 loss function as the reconstruction error of the VAE-attention model to obtain high-quality balanced accident data;

[0054] Step 2 is specifically implemented according to the following steps:

[0055] Step 2.1: Establish a VAE-attention sample generation model;

[0056] Step 2.1 is specifically as follows:

[0057] After obtaining P subsets D i through Step 1, the sample features X i,i=1,...,p in the P subsets D L*N , Y L} are input into the Encoder of the VAE model. The sample features X L*N follow the probability distribution p(X). Through a multi-layer neural network, the sample features X L*N ​L*N Perform a mapping transformation to obtain a subset output Then, use the self-attention mechanism to construct data dependency relationships and calculate the subset output The result of the self-attention mechanism, and the calculation process is as shown in Equation (1):

[0058]

[0059] where Q, K, and V are the query value, key value, and V value of the attention mechanism respectively, and W Q , W K are the weight parameters of the attention mechanism respectively, and the weight parameter values W Q , W K can be obtained by training the network using a fully connected layer;

[0060] Then, calculate the attention mechanism weight value a through the dot product and the softmax function, and the calculation process is as shown in Equation (2):

[0061]

[0062] where d is the dimension of the query value Q or the key value K;

[0063] Obtain the self-attention mechanism output value h by calculating the dot product of the attention weight value and the V value i,j , and the specific calculation process is as shown in Equation (3):

[0064]

[0065] where i is the position of the self-attention mechanism output value, j is the feature dimension, j = 1,..., N, a is the attention mechanism weight value, and k is the position of the subset output ;

[0066] So far, the VAE-attention sample generation model is established

[0067] Step 2.2. After obtaining the self-attention mechanism output value through Step 2.1, denote the entire self-attention mechanism output sequence as H L*N (abbreviation: output sequence), and train the output sequence H through the encoder (which is a multi-layer neural network) in the VAE model L*N to obtain the mean μ(H L*N ) and variance Σ(H L*N ) of the output sequence, then sample the sample ε in the standard normal distribution N(0, I) to obtain the latent variable Z, and use the sampled sample and the decoder (which is a multi-layer neural network) to obtain P generated subsets X' L*N,i=1,...,P , and optimize the quality of the P generated subsets through the loss function

[0068] The calculation process of the loss function in Step 2.2 is as follows:

[0069] Step 2.2.1: Since the loss function of the VAE model consists of two parts, the first part is the KL divergence loss The second part is the reconstruction error loss Generally speaking, the reconstruction error is calculated by the root mean square error. This calculation method is too simple and too broad, without pertinence. In order to improve the quality of the generated samples, the present invention uses the smooth L1 function as the reconstruction error of the VAE-attention model. Therefore, the calculation process of the loss function of the VAE-attention model is shown in Formula (4):

[0070]

[0071] Among them, the KL divergence loss is Calculate the similarity between the posterior distribution of the sample generated by the self-attention mechanism and the standard normal distribution;

[0072] Step 2.2.2: By minimizing Make the latent variable Z have better distribution characteristics, where L 1 Is the reconstruction error between the generated sample and the original sample The calculation process is shown in Formula (5):

[0073]

[0074] Among them, the generated subset X' L*N,i=1,...,P Is denoted as X', and the subset input X L*N Is denoted as X.

[0075] L 1 Is the smooth L 1 Loss function, which increases the robustness of the model and solves the defect that the sample generation cannot approximate the integer characteristics. On the other hand, since the L1 loss function is calculated in a piecewise form when calculating the error, it reduces the sensitivity of the loss function calculation process to outliers and is not prone to problems such as gradient explosion or disappearance.

[0076] Therefore, the balanced accident data is obtained through Step 2.

[0077] Step 3: Combine the high-quality balanced accident data obtained in Step 2, construct graph data and an accident prediction model through the GCN network, and realize traffic accident prediction.

[0078] The GCN network in Step 3 consists of an input layer, a hidden layer, and an output layer. The hidden layer is the core of the GCN network. The hidden layer consists of graph convolutional layers. Each graph convolutional layer is obtained by performing a convolutional operation on the adjacency matrix A and the feature matrix H to update the node feature representation.

[0079] In step 3, the equalized accident data obtained in step 2, that is, P generated subsets X' L*N,i=1,...,P is used to construct graph data based on the Euclidean distance between nodes, and a GCN network is used to predict traffic accidents.

[0080] Step 3 is specifically as follows:

[0081] The sample size input to the GCN network is D U ={X U*N ,Y U}, where U = M + C, M is the original sample size, C is the generated sample size, N is the sample feature, and Y U is the data node, and the feature of each node is X U*N . The relationship between nodes forms an adjacency matrix A of U*U. Calculate the Euclidean distance l between any two nodes X i and X j . When the distance is less than the threshold ε (l < ε), it is considered that there is an edge between the two nodes. Store the edge index in the edge list, and then convert the edge list into a tensor;

[0082] Input the sample X U*N into the input layer of the GCN network, then pass through the GCN graph convolution hidden layer, and then output the accident severity results corresponding to different samples X U*N . The calculation formula of the feature matrix H in the hidden layer of the GCN network is as shown in (6), that is, the propagation process of the input node features in the GCN network:

[0083]

[0084] Among them, W is the weight parameter in each layer of the model, is the sum of the adjacency matrix A and the identity matrix I, that is, calculate the edge connection for each node itself, is 's degree matrix, that is, the number of edges connected to the node. L represents the number of layers in the network structure. When l = 0, it means the current is the input layer, and f(·) is a non-linear function, that is, the activation function in the neuron;

[0085] By stacking two convolutional layers for the transfer of multi-order neighborhood information, extract the spatial features of the input samples. The process of two-layer graph convolution calculation is as shown in formula (7):

[0086]

[0087] O is the traffic accident prediction result output by the GCN network. Predict the severity of traffic accidents in the form of probability to determine which type of accident this sample is.

[0088] In the face of traffic accident prediction problems, since the frequency of major or severe accidents is much lower than that of minor accidents, the collected traffic accident data is unevenly distributed, further reducing the accuracy of traffic accident data prediction. Therefore, in order to improve the accuracy of the traffic accident prediction model, new traffic accident samples are generated to balance the sample distribution, thereby improving the sample quality. The present invention uses the VAE method for sample generation. During the process of expanding the samples, in order to improve the quality of sample generation, the self-attention mechanism is combined to enhance the learning efficiency of sample distribution, and the smooth L 1 loss function is used as the model reconstruction error, making the newly generated samples more in line with the characteristics of the original samples. Finally, a GCN network is used to establish an accident prediction model to enhance the internal topological structure of the samples. The present invention helps to improve the quantity and quality of accident samples, uses the self-attention mechanism and the smooth L 1 loss function to enhance the sample generation effect, ensure the accident prediction efficiency, and further improve the traffic operation safety level.

[0089] Example 1

[0090] The traffic accident prediction method based on VAE-attention and GCN of the present invention has a flowchart as Figure 1 shown, and is specifically implemented according to the following steps:

[0091] Step 1: Use a sliding window to segment the traffic accident data to obtain small-window accident data;

[0092] Step 2: Combine the VAE and self-attention mechanism methods to establish a VAE-attention sample generation model, generate the small-window accident data, and combine the smooth L1 loss function as the VAE-attention model reconstruction error to obtain high-quality balanced accident data;

[0093] Step 3: Combine the high-quality balanced accident data obtained in Step 2, construct graph data and an accident prediction model through a GCN network, and realize traffic accident prediction.

[0094] Example 2

[0095] The traffic accident prediction method based on VAE-attention and GCN of the present invention has a flowchart as Figure 1 shown, and is specifically implemented according to the following steps:

[0096] Step 1: Use a sliding window to segment the traffic accident data to obtain small-window accident data;

[0097] Step 1 is specifically implemented according to the following steps:

[0098] Assume that the size of the monitored original accident data is D' = {XM*N , Y M}, where M is the accident sample size, N is the number of features. The excessive length of the original accident data will affect the learning efficiency of the sample distribution. First, the present invention divides the original accident data D' into P subsets through a sliding window, and the size of each subset is L * N, where L is the size of the sliding window and the step size is k, representing the number of bits the window moves. Therefore, P small-window accident data D i,i=1,...,p = {X L*N , Y L} are obtained through the sliding window. The P small-window accident data D i,i=1,...,p = {X L*N , Y L} are abbreviated as subsets. X L*N is a feature, and Y L is the accident severity.

[0099] Step 2: Combine the VAE and self-attention mechanism methods to establish a VAE-attention sample generation model, generate the small-window accident data, and combine the smooth L1 loss function as the reconstruction error of the VAE-attention model to obtain high-quality balanced accident data;

[0100] Step 3: Combine the high-quality balanced accident data obtained in Step 2, construct graph data and an accident prediction model through the GCN network, and realize traffic accident prediction.

[0101] Example 3

[0102] The traffic accident prediction method based on VAE-attention and GCN of the present invention has a flowchart as Figure 1 shown, and is specifically implemented according to the following steps:

[0103] Step 1: Use a sliding window to divide the traffic accident data to obtain small-window accident data;

[0104] Step 1 is specifically implemented according to the following steps:

[0105] Assume that the size of the monitored original accident data is D' = {X M*N , Y M}. M is the accident sample size, N is the number of features. The excessive length of the original accident data will affect the learning efficiency of the sample distribution. First, the present invention divides the original accident data D' into P subsets through a sliding window, and the size of each subset is L * N, where L is the size of the sliding window and the step size is k, representing the number of bits the window moves. Therefore, P small-window accident data D i,i=1,...,p = {X L*N , Y L} are obtained through the sliding window. The P small-window accident data D i,i=1,...,p = {XL*N , Y L} is abbreviated as subset, X L*N is a feature, Y L is the severity of the accident.

[0106] Step 2: Combine the VAE and self-attention mechanism methods to establish a VAE-attention sample generation model, generate small-window accident data, and combine the smooth L1 loss function as the reconstruction error of the VAE-attention model to obtain high-quality balanced accident data;

[0107] Step 2 is specifically implemented according to the following steps:

[0108] Step 2.1: Establish a VAE-attention sample generation model;

[0109] Step 2.1 is specifically as follows:

[0110] After obtaining P subsets D i through Step 1, the P subsets D i,i=1,...,p ={X L*N , Y L} The sample features X L*N in are input into the Encoder of the VAE model. The sample features X L*N follow the probability distribution p(X). Through a multi-layer neural network, the sample features X L*N are mapped and transformed to obtain a subset output Then, use the self-attention mechanism to construct data dependency relationships and calculate the self-attention mechanism result of the subset output . The calculation process is as shown in formula (1):

[0111]

[0112] Among them, Q, K, and V are the query value, key value, and V value of the attention mechanism respectively, and W Q , W K are the weight parameters of the attention mechanism respectively. The weight parameter values W Q , W K can be obtained by training the network using a fully connected layer;

[0113] Then, calculate the attention mechanism weight value a through the dot product and softmax function. The calculation process is as shown in formula (2):

[0114]

[0115] Among them, d is the dimension of the query value Q or the key value K;

[0116] The self-attention mechanism output value h is obtained by calculating the dot product of the attention weight value and the V value i,j , and the specific calculation process is as shown in formula (3):

[0117]

[0118] where i is the position of the self-attention mechanism output value, j is the feature dimension, j = 1,..., N, a is the attention mechanism weight value, and k is the position of the subset output ;

[0119] So far, the VAE-attention sample generation model is established

[0120] Step 2.2: After obtaining the self-attention mechanism output value through Step 2.1, record the entire self-attention mechanism output sequence as H L*N (abbreviation: output sequence), and train the output sequence H through the encoder (i.e., multi-layer neural network) in the VAE model L*N to obtain the mean μ(H L*N ) and variance Σ(H L*N ), then sample the sample ε in the standard normal distribution N(0, I) to obtain the latent variable Z, and use the sampled sample and the decoder (i.e., multi-layer neural network) to obtain P generated subsets X' L*N,i=1,...,P , and optimize the quality of the P generated subsets through the loss function

[0121] Step 3: Combine the high-quality balanced accident data obtained in Step 2, construct the graph data and accident prediction model through the GCN network, and realize traffic accident prediction

[0122] Example 4

[0123] The traffic accident prediction method based on VAE-attention and GCN of the present invention has a flowchart as Figure 1 shown, and is specifically implemented according to the following steps

[0124] Step 1: Use a sliding window to segment the traffic accident data to obtain small-window accident data

[0125] Step 1 is specifically implemented according to the following steps

[0126] Assume that the size of the monitored original accident data is D' = {X M*N , Y M}, where M is the number of accident samples and N is the number of features. The excessively large length of the original accident data will affect the learning efficiency of the sample distribution. First, the present invention divides the original accident data D’ into P subsets through a sliding window. The size of each subset is L*N, where L is the size of the sliding window and the step size is k, indicating the number of bits the window moves. Therefore, P small-window accident data D are obtained through the sliding window. i,i=1,...,p ={X L*N ,Y L}, and the P small-window accident data D i,i=1,...,p ={X L*N ,Y L} are abbreviated as subsets. X L*N is a feature, and Y L is the accident severity.

[0127] Step 2: Combine the VAE and self-attention mechanism methods to establish a VAE-attention sample generation model, generate the small-window accident data, and combine the smooth L1 loss function as the reconstruction error of the VAE-attention model to obtain high-quality balanced accident data;

[0128] Step 2 is specifically implemented according to the following steps:

[0129] Step 2.1: Establish a VAE-attention sample generation model;

[0130] Step 2.1 is specifically as follows:

[0131] After obtaining the P subsets D i through Step 1, the sample features X i,i=1,...,p ={X L*N ,Y L} in the P subsets D L*N are input into the Encoder of the VAE model. The sample features X L*N follow the probability distribution p(X). The sample features X L*N are mapped and transformed through a multi-layer neural network to obtain the subset output. Then, the self-attention mechanism is used to construct the data dependency relationship, and the self-attention mechanism result of the subset output is calculated. The calculation process is as shown in formula (1):

[0132]

[0133] Among them, Q, K, and V are the query value, key value, and V value of the attention mechanism respectively. W Q , W K are the weight parameters of the attention mechanism respectively. The weight parameter values W Q , W K can be obtained through network training using the fully connected layer.

[0134] Then, the attention mechanism weight value a is calculated through the dot product and the softmax function, and the calculation process is shown in Equation (2):

[0135]

[0136] where d is the dimension of the query value Q or the key value K;

[0137] The self-attention mechanism output value h is obtained by calculating the dot product of the attention weight value and the V value i,j , and the specific calculation process is as shown in Equation (3):

[0138]

[0139] where i is the position of the self-attention mechanism output value, j is the feature dimension, j = 1,..., N, a is the attention mechanism weight value, and k is the position of the subset output ;

[0140] So far, the VAE-attention sample generation model is established.

[0141] Step 2.2: After obtaining the self-attention mechanism output value through Step 2.1, record the entire self-attention mechanism output sequence as H L*N (abbreviation: output sequence), and train the output sequence H through the encoder (i.e., the multi-layer neural network) in the VAE model L*N , to obtain the mean μ(H L*N ) and variance Σ(H L*N ), then sample the sample ε in the standard normal distribution N(0, I) to obtain the latent variable Z, and use the sampled sample and the decoder (i.e., the multi-layer neural network) to obtain P generated subsets X' L*N,i=1,...,P , and optimize the quality of the P generated subsets through the loss function.

[0142] The calculation process of the loss function in Step 2.2 is as follows:

[0143] Step 2.2.1: Since the loss function of the VAE model consists of two parts, the first part is the KL divergence loss The second part is the reconstruction error loss Generally speaking, the reconstruction error is calculated by the root mean square error. This calculation method is too simple and too broad, without pertinence. In order to improve the quality of the generated samples, the present invention uses the smooth L1 function as the reconstruction error of the VAE-attention model. Therefore, the calculation process of the loss function of the VAE-attention model is shown in Equation (4):

[0144]

[0145] Among them, the KL divergence loss is Calculate the similarity between the posterior distribution of the samples generated by the self-attention mechanism and the standard normal distribution;

[0146] Step 2.2.2, by minimizing Make the latent variable Z have better distribution characteristics, where L 1 is the reconstruction error between the generated samples and the original samples The calculation process is shown in formula (5):

[0147]

[0148] Among them, the generated subset X' L*N,i=1,...,P is denoted as X', and the subset input X L*N is denoted as X.

[0149] L 1 is the smooth L 1 loss function, which increases the robustness of the model and solves the defect that the sample generation cannot approximate the integer characteristics. On the other hand, since the L1 loss function is calculated in a piecewise form when calculating the error, it reduces the sensitivity of the loss function calculation process to outliers and is not prone to problems such as gradient explosion or disappearance.

[0150] Therefore, the balanced accident data is obtained through Step 2.

[0151] Step 3, combine the high-quality balanced accident data obtained in Step 2, construct graph data and an accident prediction model through the GCN network, and realize traffic accident prediction.

[0152] Example 5

[0153] The traffic accident prediction method based on VAE-attention and GCN of the present invention has a flowchart as Figure 1 shown, and is specifically implemented according to the following steps:

[0154] Step 1, use a sliding window to segment the traffic accident data to obtain small-window accident data;

[0155] Step 1 is specifically implemented according to the following steps:

[0156] Assume that the size of the monitored original accident data is D' = {X M*N , Y M, where M is the number of accident samples and N is the number of features. Excessively long original accident data will affect the learning efficiency of sample distribution. First, the present invention divides the original accident data D’ into P subsets through a sliding window, and the size of each subset is L*N, where L is the size of the sliding window and the step size is k, representing the number of bits the window moves. Therefore, P small-window accident data D are obtained through the sliding window. i,i=1,...,p ={X L*N ,Y L}, and the P small-window accident data D i,i=1,...,p ={X L*N ,Y L} are abbreviated as subsets, X L*N is a feature, and Y L is the accident severity.

[0157] Step 2: Combine the VAE and self-attention mechanism methods to establish a VAE-attention sample generation model, generate the small-window accident data, and combine the smooth L1 loss function as the reconstruction error of the VAE-attention model to obtain high-quality balanced accident data;

[0158] Step 2 is specifically implemented according to the following steps:

[0159] Step 2.1: Establish a VAE-attention sample generation model;

[0160] Step 2.1 is specifically as follows:

[0161] After obtaining P subsets D i through Step 1, the sample features X i,i=1,...,p ={X L*N ,Y L} in the P subsets D L*N are input into the Encoder of the VAE model. The sample features X L*N follow the probability distribution p(X), and the sample features X L*N are mapped and transformed through a multi-layer neural network to obtain the subset output Then, the self-attention mechanism is used to construct the data dependence relationship, and the self-attention mechanism result of the subset output is calculated. The calculation process is as shown in formula (1):

[0162]

[0163] where Q, K, and V are the query value, key value, and V value of the attention mechanism respectively, and W Q , W K are the weight parameters of the attention mechanism respectively. The weight parameter values W Q , W K can be obtained through network training using the fully connected layer;

[0164] Then, the attention mechanism weight value a is calculated through the dot product and the softmax function, and the calculation process is shown in Equation (2):

[0165]

[0166] where d is the dimension of the query value Q or the key value K;

[0167] The self-attention mechanism output value h is obtained by calculating the dot product of the attention weight value and the V value i,j , and the specific calculation process is as shown in Equation (3):

[0168]

[0169] where i is the position of the self-attention mechanism output value, j is the feature dimension, j = 1,..., N, a is the attention mechanism weight value, and k is the position of the subset output ;

[0170] So far, the VAE-attention sample generation model is established.

[0171] Step 2.2: After obtaining the self-attention mechanism output value through Step 2.1, record the entire self-attention mechanism output sequence as H L*N (abbreviation: output sequence), and train the output sequence H through the encoder (i.e., a multi-layer neural network) in the VAE model L*N to obtain the mean μ(H L*N ) and variance Σ(H L*N ), then sample a sample in the standard normal distribution N(0, I) ε to obtain the latent variable Z, and use the sampled sample and the decoder, that is, a multi-layer neural network, to obtain P generated subsets X' L*N,i=1,...,P , and optimize the quality of the P generated subsets through the loss function.

[0172] The calculation process of the loss function in Step 2.2 is as follows:

[0173] Step 2.2.1: Since the loss function of the VAE model consists of two parts, the first part is the KL divergence loss The second part is the reconstruction error loss Generally speaking, the reconstruction error is calculated by the root mean square error. This calculation method is too simple and too broad, without pertinence. In order to improve the quality of the generated samples, the present invention uses the smooth L1 function as the reconstruction error of the VAE-attention model. Therefore, the calculation process of the loss function of the VAE-attention model is shown in Equation (4):

[0174]

[0175] Among them, the KL divergence loss is Calculate the similarity between the posterior distribution of the samples generated by the self-attention mechanism and the standard normal distribution;

[0176] Step 2.2.2, by minimizing Make the latent variable Z have better distribution characteristics, where L 1 is the reconstruction error between the generated samples and the original samples The calculation process is shown in formula (5):

[0177]

[0178] Among them, the generated subset X' L*N,i=1,...,P is denoted as X', and the subset input X L*N is denoted as X.

[0179] L 1 is the smoothed L 1 loss function, which increases the robustness of the model and solves the defect that the sample generation cannot approximate the integer characteristics. On the other hand, since the L1 loss function is calculated in a piecewise form when calculating the error, it reduces the sensitivity of the loss function calculation process to outliers and is not prone to problems such as gradient explosion or disappearance.

[0180] Therefore, the balanced accident data is obtained through Step 2.

[0181] Step 3: Combine the balanced accident data obtained in Step 2, construct graph data and an accident prediction model through the GCN network, and realize traffic accident prediction.

[0182] The GCN network in Step 3 consists of an input layer, a hidden layer, and an output layer. The hidden layer is the core of the GCN network. The hidden layer consists of graph convolutional layers. Each graph convolutional layer is obtained by performing a convolutional operation on the adjacency matrix A and the feature matrix H to update the node feature representation.

[0183] In Step 3, use the balanced accident data obtained in Step 2, that is, P generated subsets X' L*N,i=1,...,P , construct graph data based on the Euclidean distance between nodes, and use the GCN network to predict traffic accidents.

[0184] Example 6

[0185] To verify the feasibility of the present invention, the present invention will be further described in combination with embodiments and the accompanying drawings of the specification. Through the accident data that actually occurred in CHILI Town, Chicago, the data characteristics are 9, the sample size is 1,112 accident data, and the accident categories are 4 types, namely minor accidents L1 (775 cases), relatively large accidents L2 (232 cases), serious accidents L3 (98 cases), and major accidents L4 (7 cases), and the proportion of the major accident data set is only 0.6%, and the data distribution is extremely unbalanced. Therefore, using the process of generating samples in the present invention, the sample generation results are obtained, as Figure 2 shown. The abscissa is the accident category, and the ordinate is the accident sample size. The light color represents that the accident data is generated and processed by the method proposed in the present invention. Obviously, the accident data distribution result shows equilibrium. Then, the GCN network is used to construct the graph data of the accident data, and the graph data performance result is as Figure 3 shown, where different colors represent different accident categories. Finally, the accident categories are classified and predicted to determine what the accident categories corresponding to different characteristics are. The results are shown in Figure 4. Figure 4(a) is the prediction result, the abscissa is the number of samples, and the ordinate is the accident category. The true accident category and the predicted category of different samples almost coincide. Figure 4(b) is the confusion matrix analysis result. The larger the value on the diagonal, the better the prediction effect. From the above results, it can be seen that the present invention can accurately predict what the accident types corresponding to different characteristics are, providing an analysis basis for the road management system.

Claims

1. Traffic accident prediction method based on VAE-attention and GCN, characterized by: Follow the steps below to implement it: Step 1: Use a sliding window to segment the traffic accident data to obtain small window accident data; Step 2: Combine VAE and self-attention mechanism to establish a VAE-attention sample generation model, generate small window accident data, and use the smooth L1 loss function as the VAE-attention model reconstruction error to obtain high-quality balanced accident data. Step 3: Combine step 2 to obtain high-quality balanced accident data, build graph data and accident prediction model through GCN network, and realize traffic accident prediction.

2. The traffic accident prediction method based on VAE-attention and GCN according to claim 1 is characterized in that: The step 1 is specifically implemented according to the following steps: Assume that the size of the original accident data monitored is D'={X M*N ,Y M }, M is the accident sample size, N is the number of features, firstly, the original accident data D' is divided into P subsets by sliding window, each subset size is L*N, where L is the sliding window size, the step size is k, which indicates the number of bits of window movement, therefore, P small window accident data D are obtained by sliding window. i,i=1,...,p ={X L*N ,Y L }, P small window accident data D i,i=1,...,p ={X L*N ,Y L } is referred to as a subset, X L*N Characterized by Y L The severity of the accident.

3. The traffic accident prediction method based on VAE-attention and GCN according to claim 2 is characterized in that: The step 2 is specifically implemented according to the following steps: Step 2.1, establish a VAE-attention sample generation model; Step 2.2: After obtaining the output value of the self-attention mechanism through step 2.1, the entire self-attention mechanism output sequence is recorded as H L*N , through the encoder (that is, multi-layer neural network) in the VAE model to train the output sequence H L*N , and obtain the mean μ(H L*N ) and variance Σ(H L*N ), then sample ε from the standard normal distribution N(0,I) to get the latent variable Z, and use the sampled samples and the decoder, that is, the multi-layer neural network, to get P generated subsets X' L*N,i=1,...,P , the quality of P generated subsets is optimized through the loss function.

4. The traffic accident prediction method based on VAE-attention and GCN according to claim 3 is characterized in that: The step 2.1 is as follows: Through step 1, we get P subsets D i Then, P subsets D i,i=1,...,p ={X L*N ,Y L } sample feature X L*N Input to the Encoder of the VAE model, sample feature X L*N Obeying the probability distribution p(X), the sample features X are analyzed through a multi-layer neural network L*N Perform mapping transformation to obtain subset output Then the self-attention mechanism is used to construct data dependencies and calculate the subset output The result of the self-attention mechanism is as follows: Among them, Q, K, and V are the query value, key value, and V value of the attention mechanism respectively, and W Q , W K They are the attention mechanism weight parameters and the weight parameter value W Q , W K It can be obtained by training the network using the fully connected layer; Then, the attention mechanism weight value a is calculated by dot product and softmax function. The calculation process is shown in formula (2): Where d is the dimension of the query value Q or key value K; The output value h of the self-attention mechanism is obtained by calculating the dot product of the attention weight value and the V value i,j , the specific calculation process is as follows: Where i is the position of the self-attention mechanism output value, j is the feature dimension, j = 1, ..., N, a is the attention mechanism weight value, and k is the subset output location; At this point, the VAE-attention sample generation model is established.

5. The traffic accident prediction method based on VAE-attention and GCN according to claim 4 is characterized in that: The loss function calculation process in step 2.2 is as follows: Step 2.2.1: Use the smooth L1 function as the reconstruction error of the VAE-attention model. Therefore, the calculation process of the loss function of the VAE-attention model is as shown in formula (4): Among them, the KL divergence loss is Calculate the similarity between the posterior distribution of the samples generated by the self-attention mechanism and the standard normal distribution; Step 2.2.2, by minimizing This makes the latent variable Z have better distribution characteristics. L1 is the reconstruction error between the generated sample and the original sample. The calculation process is shown in formula (5): Among them, the generated subset X' L*N,i=1,...,P Recorded as X', the subset input X L*N Denoted as X.

6. The traffic accident prediction method based on VAE-attention and GCN according to claim 5 is characterized in that: In step 3, the GCN network consists of an input layer, a hidden layer, and an output layer, and the hidden layer is the core of the GCN network. The hidden layer consists of graph convolutional layers. Each graph convolutional layer is obtained by convolution operation of the adjacency matrix A and the feature matrix H, so as to update the node feature representation.

7. The traffic accident prediction method based on VAE-attention and GCN according to claim 6 is characterized in that: In step 3, the balanced accident data is obtained by using step 2, that is, P generated subsets X' L*N,i=1,...,P , graph data is constructed based on the Euclidean distance between nodes, and traffic accidents are predicted using the GCN network.

8. The traffic accident prediction method based on VAE-attention and GCN according to claim 7 is characterized in that: The step 3 is as follows: The sample size input to the GCN network is D U ={X U*N ,Y U }, where U = M + C, M is the original sample size, C is the generated sample size, N is the sample feature, and Y U is a data node, and the feature of each node is X U*N , the relationship between nodes forms the U*U adjacency matrix A, and calculates the adjacency matrix of any two nodes X i With X j The Euclidean distance l between the two nodes. When the distance is less than the threshold, it is considered that there is an edge between the two nodes, and the edge index is stored in the edge list, which is then converted into a tensor. The sample X U*N Input to the input layer of the GCN network, then pass through the GCN graph convolution hidden layer, and then output different samples X U*N The corresponding accident severity result, the calculation formula of the feature matrix H in the hidden layer of the GCN network is as follows (6), which is the propagation process of the input node features in the GCN network: Among them, W is the weight parameter in each layer of the model, It is the sum of the adjacency matrix A and the identity matrix I, that is, calculating the edge connection for each node itself, for The degree matrix is ​​the number of edges connecting nodes. L represents the number of layers in the network structure. When l = 0, it means that the current layer is the input layer. f(·) is a nonlinear function, which is the activation function in the neuron. By stacking two layers of convolutional layers to transfer multi-order neighborhood information, the spatial features of the input samples are extracted. The process of two-layer graph convolution calculation is as shown in formula (7): O is the traffic accident prediction result output by the GCN network. The severity of the traffic accident is predicted in a probabilistic form to determine what type of accident the sample is.