Traffic flow prediction method based on deep learning
Through deep learning methods, combined with graph neural network, recurrent neural network and convolutional neural network, an end-to-end traffic flow prediction model is built, which solves the problem of traditional methods' dependence assumptions and complexity, and achieves higher traffic flow prediction accuracy and stability sex.
Patent Information
- Application Number
- CN202210152521.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-18
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2042-02-18
AI Technical Summary
Traditional traffic flow prediction methods are based on assumptions and cannot effectively meet the needs of complex traffic data, resulting in poor prediction results, and common machine learning methods are complex and difficult to implement.
Using deep learning-based methods, combined with graph neural networks, recurrent neural networks and convolutional neural networks to construct an end-to-end traffic flow prediction model. Spatial correlation information is extracted through graph neural networks, recurrent neural networks extract time correlation information, and convolutional neural networks The neural network performs decoding to realize multi-step prediction of traffic flow.
It improves the accuracy and stability of traffic flow prediction, simplifies the implementation process, avoids complex manual feature design and extraction, and achieves higher reliability and accuracy.
Smart Images

Figure CN114444813B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a traffic flow prediction method based on deep learning. Background Art
[0002] With the development of economy and technology and the improvement of people's living standards, traffic flow prediction has become one of the research focuses. High-precision traffic flow prediction can enable traffic management agencies to better control traffic and reduce congestion; it also enables travelers to foresee traffic conditions on the road and plan appropriate routes accordingly; moreover, accurate traffic flow prediction can also provide navigation systems with short-term traffic flow prediction results in the future, thereby providing decision-making basis for navigation system route planning and other issues.
[0003] At present, many sensors, cameras and other information collection devices are deployed in major cities and highways. These devices have accumulated a large amount of traffic time series data and geographic location information, providing a solid data foundation for traffic forecasting. This has led to an increasing number of researchers conducting traffic flow forecasting research.
[0004] Traditional traffic flow prediction methods are generally based on statistical methods. Such methods are usually based on some assumptions, such as independence assumptions, but actual traffic data is often complex and does not meet these assumptions. Therefore, in practical applications, the actual prediction effect of these traffic flow prediction models is average. With the popularity of machine learning, common and powerful machine learning methods such as KNN and SVM have been applied in the field of traffic flow prediction. Such methods can model more complex data and achieve quite good performance. However, the disadvantages are also obvious. Such methods are generally very complex. Summary of the invention
[0005] The purpose of the present invention is to provide a traffic flow prediction method based on deep learning that has high reliability, good accuracy and is relatively simple to implement.
[0006] The traffic flow prediction method based on deep learning provided by the present invention comprises the following steps:
[0007] S1. Obtain a traffic status data set and process it to obtain a training data set;
[0008] S2. Build an end-to-end traffic flow prediction primitive model based on graph neural network, recurrent neural network and convolutional neural network;
[0009] S3. Using the training data set obtained in step S1, the original traffic flow prediction model constructed in step S2 is trained to obtain a traffic flow prediction model;
[0010] S4. Use the traffic flow prediction model obtained in step S3 to predict traffic flow under actual conditions.
[0011] The step S1 of obtaining a traffic status data set and processing it to obtain a training data set specifically includes the following steps:
[0012] A. Sensors are set up in the set area of the target city. The sensors detect traffic volume at set intervals to obtain an initial traffic matrix of size T×N. The first dimension T of the initial traffic matrix represents the number of time slices, and the second dimension N represents the number of sensors.
[0013] B. Standardize the initial traffic matrix obtained in step A to obtain a standardized traffic matrix;
[0014] C. The standardized traffic matrix obtained in step B is sampled and stacked according to the set window size to obtain T'×t 1 A tensor of size ×N; where t 1 is the set window size; T' is the number of time steps after sampling and stacking, and T' = Tt 1 +1;
[0015] D. Divide the data set obtained in step C into a training set, a validation set, and a test set to obtain the final training data set.
[0016] The data set obtained in step C is divided into a training set, a validation set and a test set. Specifically, 70% of the data in the data set obtained in step C is divided into a training set, 10% of the data is divided into a validation set, and 20% of the data is divided into a test set.
[0017] The end-to-end traffic flow prediction original model is constructed based on the graph neural network, the recurrent neural network and the convolutional neural network as described in step S2, and specifically includes the following steps:
[0018] The original model of traffic flow prediction includes an encoder and a decoder;
[0019] The encoder uses a graph neural network to extract spatial correlation information from the traffic status dynamic graph, and then uses the GRU in the recurrent neural network to extract temporal correlation information from the traffic status dynamic graph; the encoder extracts spatial correlation information and temporal correlation information from the traffic status dynamic graph in both spatial and temporal dimensions, and outputs the hidden intermediate states of the nodes;
[0020] The decoder uses a convolutional neural network to decode the hidden intermediate states of the nodes output by the encoder; the output of the decoder is the final traffic flow prediction result.
[0021] The method of using a graph neural network to extract spatial correlation information from a traffic status dynamic graph specifically includes the following steps:
[0022] The graph neural network includes a first fully connected layer, two layers of graph convolutional layers connected in series, a second fully connected layer and a softmax activation function; the first fully connected layer, the two layers of graph convolutional layers connected in series, the second fully connected layer and the softmax activation function are connected in series in sequence; the first fully connected layer and the second fully connected layer are used to map the input data to an initial representation with a lower dimension when the feature dimension of the input data is greater than a set value, so as to facilitate forward propagation; the two layers of graph convolutional layers connected in series are used to extract features of spatial correlation;
[0023] The following formula is used to calculate the graph convolution in the graph neural network:
[0024]
[0025] Where H (l+1) is the output of the lth layer; σ() is the ReLU activation function; α l is the first weight set; is the parameter after regularizing the adjacency matrix of the graph in the graph neural network, and is a diagonal matrix, each diagonal element i represents the degree of the i-th node of the graph with self-loops, is the adjacency matrix of the graph with self-loops; H (0) is the initial input of the graph neural network; β l is the second weight set; n is the identity matrix; E is the shared trainable node embedding matrix; W (l) is the weight pool of the lth layer; b (l) is the skew pool of the lth layer;
[0026] Random dropout is performed before the first fully connected layer, each graph convolutional layer, and the second fully connected layer to complete the regularization process and prevent the model from overfitting.
[0027] The use of GRU in the recurrent neural network to extract time correlation information in the traffic state dynamic graph specifically includes the following steps:
[0028] The following formula of GRU in the recurrent neural network is used for processing:
[0029] z t ,r t =σ 1 (GCN gate ([x t ,h t-1 ]))
[0030] c t=tanh(GCN update ([x t ,z t *h t-1 ]))
[0031] h t =r t *h t-1 +(1-r t )*c t
[0032] Where z t Update the door state for the current moment; r t Reset the door state for the current moment; σ 1 () is the sigmoid activation function; GCN gate () is the graph neural network used for the reset gate; GCN update () is the graph neural network used for the update gate; x t is the current input feature; h t is the current output hidden layer state; c t is the candidate state; tanh() is the tanh activation function; [] is the matrix connection operation.
[0033] The decoder adopts a convolutional neural network, which specifically includes the following steps:
[0034] A two-dimensional convolutional neural network is used as a decoder; the convolutional neural network decodes the node hidden intermediate state output by the encoder; the convolution kernel size of the two-dimensional convolutional neural network is 1*H enc , H enc is the hidden state dimension of GRU in the encoder;
[0035] The decoder output size is t 2 *N two-dimensional matrix, t 2 is the prediction duration, N is the number of sensors; the value of the corresponding element in the matrix is the final predicted traffic flow value.
[0036] Step S3 uses the training data set obtained in step S1 to train the original traffic flow prediction model constructed in step S2, thereby obtaining a traffic flow prediction model, which specifically includes the following steps:
[0037] During the training process, the L1 loss function is used for loss calculation;
[0038] During training, the original traffic flow prediction model is first trained using the training set, and then the trained model is regularized using the validation set until the trained model converges;
[0039] Finally, the converged model is tested using the test set to obtain the predicted value of the model, and the prediction results are evaluated using the mean absolute error (MAE) and root mean square error (RSME).
[0040] The traffic flow prediction method based on deep learning provided by the present invention extracts features from both spatial and temporal dimensions for multi-step prediction. Compared with traditional methods, it eliminates the complex manual feature design and extraction process. Therefore, the method of the present invention has higher stability and reliability, better accuracy, and is relatively simple to implement. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 The figure is a schematic diagram of the method flow of the present invention.
[0042] Figure 2 It is a schematic diagram of the structure of the prediction model of the method of the present invention.
[0043] Figure 3 Schematic diagram of the structure of the graph neural network of the method of the present invention.
[0044] Figure 4 It is a result schematic diagram of the traffic speed characteristic matrix of an embodiment of the method of the present invention.
[0045] Figure 5 The figure is a result diagram of the adjacency matrix of an embodiment of the method of the present invention.
[0046] Figure 6 Schematic diagram of evaluation results of the predicted value of an embodiment of the method of the present invention. DETAILED DESCRIPTION
[0047] like Figure 1 The method flow chart of the method of the present invention is shown as follows: The traffic flow prediction method based on deep learning provided by the present invention comprises the following steps:
[0048] S1. Obtain a traffic status data set and process it to obtain a training data set; specifically, the steps include:
[0049] A. Sensors are set up in the set area of the target city. The sensors detect traffic volume at set intervals to obtain an initial traffic matrix of size T×N. The first dimension T of the initial traffic matrix represents the number of time slices, and the second dimension N represents the number of sensors (also the number of nodes).
[0050] B. Standardize the initial traffic matrix obtained in step A to obtain a standardized traffic matrix;
[0051] C. The standardized traffic matrix obtained in step B is sampled and stacked according to the set window size to obtain T'×t 1A tensor of size ×N; where t 1 is the set window size; T' is the number of time steps after sampling and stacking, and T' = Tt 1 +1;
[0052] D. Divide the data set obtained in step C into a training set, a validation set and a test set, thereby obtaining the final training data set; specifically, in the data set obtained in step C, 70% of the data is divided into a training set, 10% of the data is divided into a validation set, and 20% of the data is divided into a test set;
[0053] S2. Based on graph neural network, recurrent neural network and convolutional neural network, an end-to-end traffic flow prediction primitive model is constructed; specifically, the following steps are included:
[0054] The original model of traffic flow prediction includes an encoder and a decoder; the model structure is as follows Figure 2 As shown;
[0055] The encoder uses a graph neural network to extract spatial correlation information from the traffic status dynamic graph, and then uses the GRU in the recurrent neural network to extract temporal correlation information from the traffic status dynamic graph; the encoder extracts spatial correlation information and temporal correlation information from the traffic status dynamic graph in both spatial and temporal dimensions, and outputs the hidden intermediate states of the nodes;
[0056] The decoder uses a convolutional neural network to decode the hidden intermediate states of the nodes output by the encoder; the output of the decoder is the final traffic flow prediction result;
[0057] In the specific implementation, the graph neural network is used to extract the spatial correlation information in the traffic status dynamic graph, which includes the following steps:
[0058] Graph neural network (improved graph neural network, the structure is as follows Figure 3 The first fully connected layer, the two-layer graph convolution layer connected in series, the second fully connected layer and the softmax activation function are connected in series in sequence; the first fully connected layer and the second fully connected layer are used to map the input data to an initial representation with a lower dimension when the feature dimension of the input data is greater than a set value, so as to facilitate forward propagation; the two-layer graph convolution layer connected in series is used to extract features of spatial correlation;
[0059] The following formula is used to calculate the graph convolution in the graph neural network:
[0060]
[0061] Where H (l+1) is the output of the lth layer; σ() is the ReLU activation function; αl is the first weight set; is the parameter after regularizing the adjacency matrix of the graph in the graph neural network, and
[0062] is a diagonal matrix, each diagonal element i represents the degree of the i-th node of the graph with self-loops, is the adjacency matrix of the graph with self-loops; H (0) is the initial input of the graph neural network; β l is the second weight set; n is the identity matrix; E is the shared trainable node embedding matrix; W (l) is the weight pool of the lth layer; b (l) is the skew pool of the lth layer;
[0063] In the above process, referring to the classic ResNet, residual connections are used to alleviate the over-smoothing problem when the graph neural network is deepened: each layer is connected to H (0) Connections make it possible for the model to process the initial input even if the number of layers increases, while achieving the effect of regularization;
[0064] When each layer is multiplied by the weight matrix, an identity matrix I is added n ,Experiments show that this method of "increasing self-attention" is helpful for regularizing the model, alleviating the over-smoothing problem, and improving performance;
[0065] Traditionally, for dynamic traffic flow graphs, a shared weight matrix is used to extract the features of the graph in each time slice; this method has certain problems, because graphs of different time slices, although temporally correlated, also have many differences, and these differences will be ignored if shared weights are used. Therefore, a shared trainable node embedding matrix and a weight pool are used: the node embedding matrix E contains the basic features of each node, and the weight pool W can be regarded as a collection of multiple weight matrices, and the model adaptively selects the best weight matrix to participate in the calculation; although more calculations are involved (depending on the dimension of the node embedding), the performance is improved in return;
[0066] Random dropout is performed before the first fully connected layer, each graph convolutional layer, and the second fully connected layer to complete the regularization process and prevent the model from overfitting.
[0067] The GRU in the recurrent neural network is used to extract the time correlation information in the traffic state dynamic graph, which specifically includes the following steps:
[0068] Compared with the classic GRU model, the present invention replaces the feature calculation part from the classic matrix multiplication to the above-mentioned improved graph neural network; the following formula of GRU in the recurrent neural network is used for processing:
[0069] z t ,r t =σ 1 (GCN gate ([x t ,h t-1 ]))
[0070] c t =tanh(GCN update ([x t ,z t *h t-1 ]))
[0071] h t =r t *h t-1 +(1-r t )*c t
[0072] Where z t Update the door state for the current moment; r t Reset the door state for the current moment; σ 1 () is the sigmoid activation function; GCN gate () is the graph neural network used for the reset gate; GCN update () is the graph neural network used for the update gate; x t is the current input feature; h t is the current output hidden layer state; c t is the candidate state; tanh() is the tanh activation function; [] is the matrix connection operation;
[0073] The decoder uses a convolutional neural network, which includes the following steps:
[0074] A two-dimensional convolutional neural network is used as a decoder; the convolutional neural network decodes the node hidden intermediate state output by the encoder; the convolution kernel size of the two-dimensional convolutional neural network is 1*H enc , H enc is the hidden state dimension of the GRU in the encoder (i.e., the number of gated recurrent units of the GRU);
[0075] The decoder output size is t 2 *N two-dimensional matrix, t 2 is the prediction duration, N is the number of sensors; the value of the corresponding element in the matrix is the final predicted traffic flow value;
[0076] S3. Using the training data set obtained in step S1, the original traffic flow prediction model constructed in step S2 is trained to obtain a traffic flow prediction model; specifically, the steps include:
[0077] During the training process, the L1 loss function is used for loss calculation;
[0078] During training, the original traffic flow prediction model is first trained using the training set, and then the trained model is regularized using the validation set until the trained model converges;
[0079] Finally, the converged model is tested using the test set to obtain the predicted value of the model, and the prediction results are evaluated using the mean absolute error (MAE) and root mean square error (RSME).
[0080] S4. Use the traffic flow prediction model obtained in step S3 to predict traffic flow under actual conditions.
[0081] The method of the present invention is further described below in conjunction with an embodiment:
[0082] The data set used in this example is the Shenzhen taxi speed data set collected in January 2015. 156 sensors were deployed on the main roads in Luohu District, Shenzhen. The data collection interval was 15 minutes, and a total of 28 days of data were collected. The model was built into a 2976*156 traffic speed feature matrix (such as Figure 4 ) and a 156*156 adjacency matrix (as shown Figure 5 shown).
[0083] The specific steps of the method of the present invention are as follows:
[0084] Data processing: First, the traffic speed feature matrix needs to be standardized using standard normalization (STD). Then, according to the preset time window size of 64 and the prediction step size of 4, that is, the traffic speed of the next hour is predicted based on the traffic speed of the past 16 hours, the data set is processed into an input tensor of 2775*64*156 and label data of 2775*4*156.
[0085] Data division: According to the preset training set: validation set: test set ratio of 7:1:2, the data obtained in the previous step is randomly divided into a training set of 2017*64*156, a validation set of 230*64*156, a test set of 528*64*156 and corresponding label data;
[0086] Calculate the Laplace matrix: Use the classic GCN method to regularize the adjacency matrix of the graph to obtain the Laplace matrix of the graph;
[0087] Training model: According to the preset batch size of 64, the training set will be input into the model batch by batch to help the model train. The designed encoder will get the feature embedding, and then input into the designed decoder to get the prediction result, calculate all losses, and perform back propagation to update each weight parameter.
[0088] Graph neural network: The improved graph convolutional neural network in the method of the present invention will adaptively match the appropriate weight matrix from the weight pool for each time slice of the graph (i.e., 64 static graphs), better extract the spatial correlation from the graph, and obtain the hidden features of each node;
[0089] Recurrent neural network: The recurrent neural network in the method of the present invention adopts a gated recurrent unit GRU with 64 units. The neural network weight calculations of the reset gate and the update gate are replaced by two different improved graph neural networks proposed by the method of the present invention. The hidden features extracted from 64 temporally continuous static graphs by the graph neural network are used as input to extract the temporal correlation on the dynamic graph, and obtain the feature embedding output by the encoder;
[0090] Convolutional neural network: The method of the present invention uses a classic 2D convolutional neural network to decode the feature embedding output by the encoder and output the prediction result. The convolution kernel size used is 1*64, and the final output prediction result is a tensor of 2775*4*156;
[0091] Loss calculation: L1 loss is used to calculate the loss of predicted data and label data. The framework automatically performs back propagation calculations and updates various parameters.
[0092] Verification model: After each epoch, the model will be verified with the validation set data. No back propagation is performed, only the loss value is counted. The loss value of the validation set is used to determine whether it is the best model and whether to stop training early.
[0093] Test model: After completing the above training process and the model converges, the model is actually used. Here, the test set data is used to make predictions, calculate and count the predicted values, and the results are as follows: Figure 6 As shown, it can be seen that the mean absolute error (MAE) and root mean square error (RSME) of the model prediction of the method of the present invention have reached a very good level.
Claims
1. A traffic flow prediction method based on deep learning, comprising the following steps: S1. Obtain a traffic status data set and process it to obtain a training data set; specifically, the steps include: A. Set up sensors in the set area of the target city; the sensors detect traffic volume at set intervals to obtain an initial flow matrix of size T×N; The first dimension T of the initial traffic matrix represents the number of time slices, and the second dimension N represents the number of sensors; B. Standardize the initial traffic matrix obtained in step A to obtain a standardized traffic matrix; C. The standardized traffic matrix obtained in step B is sampled and stacked according to the set window size to obtain a tensor of size T'×t1×N; where t1 is the set window size; T' is the number of time steps after sampling and stacking, and T'=T-t1+1; D. Divide the data set obtained in step C into a training set, a validation set, and a test set to obtain the final training data set; S2. Based on graph neural network, recurrent neural network and convolutional neural network, an end-to-end traffic flow prediction primitive model is constructed; specifically, the following steps are included: The original model of traffic flow prediction includes an encoder and a decoder; The encoder uses a graph neural network to extract spatial correlation information from the traffic status dynamic graph, and then uses the GRU in the recurrent neural network to extract temporal correlation information from the traffic status dynamic graph; the encoder extracts spatial correlation information and temporal correlation information from the traffic status dynamic graph in both spatial and temporal dimensions, and outputs the hidden intermediate states of the nodes; The decoder uses a convolutional neural network to decode the hidden intermediate states of the nodes output by the encoder; the output of the decoder is the final traffic flow prediction result; The method of using a graph neural network to extract spatial correlation information from a traffic status dynamic graph specifically includes the following steps: The graph neural network includes a first fully connected layer, two layers of graph convolutional layers connected in series, a second fully connected layer and a softmax activation function; the first fully connected layer, the two layers of graph convolutional layers connected in series, the second fully connected layer and the softmax activation function are connected in series in sequence; the first fully connected layer and the second fully connected layer are used to map the input data to an initial representation with a lower dimension when the feature dimension of the input data is greater than a set value, so as to facilitate forward propagation; the two layers of graph convolutional layers connected in series are used to extract features of spatial correlation; The following formula is used to calculate the graph convolution in the graph neural network: Where H (l+1) is the output of the lth layer; σ() is the ReLU activation function; α l is the first weight set; is the parameter after regularizing the adjacency matrix of the graph in the graph neural network, and is a diagonal matrix, each diagonal element i represents the degree of the i-th node of the graph with self-loops, is the adjacency matrix of the graph with self-loops; H (0) is the initial input of the graph neural network; β l is the second weight set; n is the identity matrix; E is the shared trainable node embedding matrix; W (l) is the weight pool of the lth layer; b (l) is the skew pool of the lth layer; Random dropout is performed before the first fully connected layer, each graph convolutional layer, and the second fully connected layer to complete the regularization process and prevent the model from overfitting. The use of GRU in the recurrent neural network to extract time correlation information in the traffic state dynamic graph specifically includes the following steps: The following formula is used to process the GRU in the recurrent neural network: z t ,r t =σ1(GCN gate ([x t ,h t-1 ])) c t =tanh(GCN update ([x t ,z t *h t-1 ])) h t =r t *h t-1 +(1-r t )*c t Where z t Update the door state for the current moment; r t Reset the gate state at the current moment; σ1() is the sigmoid activation function; GCN gate () is the graph neural network used for the reset gate; GCN update () is the graph neural network used for the update gate; x t is the current input feature; h t is the current output hidden layer state; c t is the candidate state; tanh() is the tanh activation function; [] is the matrix connection operation; The decoder adopts a convolutional neural network, which specifically includes the following steps: A two-dimensional convolutional neural network is used as a decoder; the convolutional neural network decodes the node hidden intermediate state output by the encoder; the convolution kernel size of the two-dimensional convolutional neural network is 1*H enc , H enc is the hidden state dimension of GRU in the encoder; The decoder outputs a two-dimensional matrix of size t2*N, where t2 is the predicted duration and N is the number of sensors. The value of the corresponding element in the matrix is the final predicted traffic flow value. S3. Using the training data set obtained in step S1, the original traffic flow prediction model constructed in step S2 is trained to obtain a traffic flow prediction model; S4. Use the traffic flow prediction model obtained in step S3 to predict traffic flow under actual conditions.
2. The traffic flow prediction method based on deep learning according to claim 1 is characterized in that The data set obtained in step C is divided into a training set, a validation set and a test set. Specifically, 70% of the data in the data set obtained in step C is divided into a training set, 10% of the data is divided into a validation set, and 20% of the data is divided into a test set.
3. The traffic flow prediction method based on deep learning according to claim 1 is characterized in that Step S3 uses the training data set obtained in step S1 to train the original traffic flow prediction model constructed in step S2, thereby obtaining a traffic flow prediction model, which specifically includes the following steps: During the training process, the L1 loss function is used for loss calculation; During training, the original traffic flow prediction model is first trained using the training set, and then the trained model is regularized using the validation set until the trained model converges; Finally, the converged model is tested using the test set to obtain the model's predicted value, and the prediction results are evaluated using the mean absolute error and root mean square error.
Citation Information
Patent Citations
Network flow prediction method based on lightweight space-time deep learning model
CN110851782A
Expressway traffic flow prediction method
CN111710154A
Traffic prediction method based on adaptive spatial self-attention map convolution
CN112801404A
Graph neutral networks with attention
US20210081717A1
Methods, computing devices, and storage media for predicting traffic matrix
US20210133569A1
