A method for predicting urban road traffic flow
By constructing an encoder and decoder, and utilizing a multi-head gated self-attention layer and a gated recursive graph unit layer to extract the spatiotemporal characteristics of urban road traffic flow data, the problem of poor prediction performance in existing technologies is solved, and fast and accurate traffic flow prediction is achieved, improving the efficiency and safety of traffic management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAQIAO UNIVERSITY
- Filing Date
- 2024-01-29
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies struggle to fully extract the spatiotemporal characteristics of urban road traffic flow data when predicting urban road traffic flow, resulting in poor prediction performance. This is especially true in complex non-Euclidean spatial structures, where traditional models are unable to effectively extract spatial features.
An encoder and decoder structure is adopted, including a multi-head gated self-attention layer and a gated recursive graph unit layer. By constructing a feature matrix of the road traffic network, spatiotemporal correlations are extracted. Multi-graph convolutional layers and multi-head graph attention layers are used in combination with the gated recursive structure for feature extraction and prediction.
It enables rapid and accurate urban road traffic flow prediction, improving prediction accuracy and practicality, and allowing for better traffic flow planning, reducing congestion and accidents.
Smart Images

Figure CN117953684B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of intelligent transportation technology, and particularly relates to a city road traffic flow prediction method. BACKGROUND
[0002] With the acceleration of urbanization and the popularity of transportation tools, the increase of road traffic flow has become an important problem faced by modern cities. If the traffic management department cannot plan and control traffic flow in time, traffic congestion, traffic accidents and other problems will occur, causing great inconvenience to the travel and life of urban residents.
[0003] In order to solve the above problems, road traffic flow prediction technology emerges as the times require. Predicting traffic flow can help the traffic management department to better plan traffic flow, reduce the occurrence of traffic congestion and traffic accidents. In addition, predicting traffic flow can also help public transportation operators to better plan bus routes, vehicle scheduling, etc., and improve the efficiency and accuracy of public transportation.
[0004] With the continuous development and popularization of data collection technology, data analysis technology, machine learning technology and other related technologies, road traffic flow prediction technology is also constantly progressing. The accuracy and practicality of the prediction model are gradually improving. Therefore, road traffic flow prediction technology has become an important means of urban traffic management, and has important significance for improving the efficiency and safety of urban traffic.
[0005] Road traffic flow is to take road as the research object, adopts fixed coil detection, video detection or floating car GPS sampling and so on to count the traffic flow of road in a certain time, usually adopts the number of vehicles passing per unit time and the average speed of vehicles on the road to measure. Due to the complexity of road traffic network in real scene, so the road traffic flow data is irregular time series data of traffic network graph space relation in form. Some early research works are based on linear regression method to model a specific single road, which has the shortcoming of being difficult to generalize to other roads. Some research works after that began to use nonlinear models to mine the spatiotemporal information in traffic data, such as wavelet analysis, support vector machine, etc., but still have the problems of insufficient feature mining and poor prediction effect. In recent years, with the improvement of computing power, deep neural network model is gradually applied to road traffic flow prediction problem, some early research works are mostly based on convolutional neural network to extract the spatial features of traffic data, based on recurrent neural network to extract the time features of traffic data, but these methods ignore an important problem, that is, in the real world, the traffic network structure is usually irregular, and each road segment is connected as a node to form a graph structure, and this non-euclidean space data uses two-dimensional convolution, which is a model specially designed for euclidean space feature extraction, obviously the spatial feature extraction is insufficient. In some research works in recent years, the road traffic flow data is gradually modeled into graph structure data through the road traffic network structure, but still cannot achieve good prediction effect. SUMMARY
[0006] The purpose of the present application is to provide a city road traffic flow prediction method, which can realize fast and accurate prediction of city road traffic flow by fully mining the spatiotemporal characteristics of road traffic flow data.
[0007] The present application is realized by the following technical scheme:
[0008] A city road traffic flow prediction method, comprising the following steps:
[0009] Step S1, constructing an encoder and a decoder, the encoder comprising sequentially connected layer encoder layers, the encoder layer comprising sequentially connected multi-head gated self-attention layers and gated recurrent graph unit layers, the gated recurrent graph unit layer being composed of a plurality of sequentially connected gated recurrent graph units, the gated recurrent graph unit comprising sequentially connected multi-graph graph convolution layers, multi-head graph attention layers and gated recurrent structures, and the decoder comprising sequentially connected layer decoder layers, the decoder layer comprising sequentially connected multi-head gated self-attention layers with masking, multi-head gated self-attention layers and gated recurrent graph unit layers;
[0010] Step S2, constructing a feature matrix for representing city road traffic flow in a time interval t according to a road traffic network , according to the feature matrix The original input of the encoder is obtained as The original input of the decoder is obtained as The dimension of the original input of the encoder and the original input of the decoder is raised, and then additional information embedding is performed, to obtain the encoder input and the decoder input , represents a real number set with a size of , N represents the total number of nodes in the road traffic network, , , all represent time steps, , and f represents the raised dimension.
[0011] Step S3, the encoder input passes through the multi-head gated self-attention layer of the encoder layer to extract the feature matrix , according to the feature matrix extracts the spatio-temporal correlation through the gated recurrent graph unit layer, so that the encoder layer is calculated layer by layer through layer to obtain the encoder output and , wherein, is the output containing spatio-temporal information, is the hidden state containing spatial information.
[0012] Step S4, for the first layer of the decoder layer, the decoder input is input into the masked multi-head gated self-attention layer of the decoder layer to capture the time sequence information in the decoder input, and the output of the masked multi-head gated self-attention layer is input into the multi-head gated self-attention layer of the decoder layer together with the encoder output to obtain the correlation between the two, and the output of the multi-head gated self-attention layer is input into the gated recurrent graph unit layer of the decoder layer together with the of the encoder output, so that the prediction result is obtained after the encoder layer is calculated layer by layer through layer.
[0013] Further, in the step S2, the feature matrix is constructed, specifically:
[0014] The latitude and longitude center point of each road segment in the road network is taken as a node, and all nodes are connected to form an undirected graph G=(V, E), wherein, V={v1, v2, …, v N} represents the set of all nodes, E={e1, e2, …e N} represents the set of all connection edges, N is the number of nodes in the road network, and the connection edge refers to the connection between two nodes;
[0015] For each road segment, the average driving speed or the total number of vehicles passing through each road segment in a time interval t is counted by sampling at a certain time interval t, and the characteristic matrix of the road traffic flow in the road network in the time interval t is represented as .
[0016] Further, the encoder and the decoder each further include a first linear layer and an information embedding layer, the dimensions of the original input of the encoder and the original input of the decoder are mapped to high dimensions through the corresponding first linear layers, and additional information embedding is performed through the information embedding layer, the additional information including global time information, local time information and influence factor information of each time step.
[0017] Further, in the step S3, the characteristic matrix in the time dimension is extracted according to the formula . , , , , , , , , , , , , , , , , , , , , ,
[0018] Further, in the step S3, the Euclidean distance graph adjacency matrix A E , the driving distance graph adjacency matrix A D and the traffic signal distance graph adjacency matrix A T are constructed in the multi-graph graph convolution layer, , , , the distanceE function is a Euclidean distance calculation function, and v i represents the i-th node, 1≤i≤N, represents the node v ix-coordinate of node v denotes node v i y-coordinate of node v denotes the shortest driving distance from node v i to node v j , denotes the minimum number of traffic lights among all driving routes from node v i to node v j , when the number of traffic lights is 0, it is assigned a value greater than zero to avoid the case of denominator being 0.
[0019] Further, in the step S3, the output of the multi-graph convolution layer is wherein, , , , , , , and , is the unit matrix, is the parameter matrix, is the sigmoid activation function, is the element of matrix , is the element of matrix .
[0020] Further, in the step S3, the output of the multi-head graph attention layer is wherein, denotes the attention mechanism, denotes the in the time interval t, is the weight parameter of the attention mechanism, || represents the concatenation operation, , are the feature vectors of node , the feature vectors of the adjacent nodes of node , is the parameter matrix with size , , C denotes the number of attention mechanisms, c=1,2,…,C, denotes the weight coefficient of the cth attention mechanism, is the parameter matrix of the cth attention mechanism, is the sigmoid activation function, .
[0021] Further, in the step S3, the output of the multi-head graph attention layer is obtained after the gating recurrent structure , and the result is obtained after the linear layer and , wherein , , , , , , , and , , and are parameter matrices.
[0022] Further, in the step S4, the encoding layer further comprises a second linear layer, and the output of the gating recurrent graph unit layer of the decoder layer is obtained after the second linear layer to obtain a prediction result , , is the prediction result in the time interval t.
[0023] The present application has the following beneficial effects:
[0024] 1. The encoder and the decoder of the present application are respectively composed of a multi-layer encoder layer and a multi-layer decoder layer, the encoder layer comprises a multi-head gated self-attention layer and a gating recurrent graph unit layer connected in sequence, the decoder layer comprises a multi-head gated self-attention layer with masking, a multi-head gated self-attention layer and a gating recurrent graph unit layer connected in sequence, and the gating recurrent graph unit layer is composed of a plurality of gating recurrent graph units connected in sequence, the gating recurrent graph unit comprises a multi-graph graph convolution layer, a multi-head graph attention layer and a gating recurrent structure connected in sequence, in the encoder part, the multi-head gated self-attention layer of the encoder layer is used to extract the feature matrix of the encoder layer input in the time dimension, and then the spatio-temporal correlation is extracted through the gating recurrent graph unit layer according to the feature matrix, in the decoder part, the time sequence information of the decoder input is captured through the multi-head gated self-attention layer with masking, then the correlation between the output of the multi-head gated self-attention layer with masking and the output of the encoder is obtained through the multi-head gated self-attention layer, and the result is input into the gating recurrent graph unit layer together with the hidden state output of the encoder containing spatial information, and then the prediction result is obtained, so that the spatio-temporal characteristics in the road traffic flow data are fully mined, and the city road traffic flow is quickly and accurately predicted. BRIEF DESCRIPTION OF DRAWINGS
[0025] The present application will be further described in detail below with reference to the accompanying drawings.
[0026] Figure 1 is a flowchart of the present application.
[0027] Figure 2 This is a schematic diagram of the multi-head gated self-attention layer of the present invention.
[0028] Figure 3 This is a schematic diagram of the gated recursive graph unit layer of the present invention. Detailed Implementation
[0029] like Figures 1 to 3 As shown, the urban road traffic flow prediction method includes the following steps:
[0030] Step S1: Construct the encoder and decoder. The encoder includes a first linear layer, an information embedding layer, and sequentially connected layers. The encoder layer comprises a multi-head gated self-attention layer and a gated recursive graph unit layer connected in sequence. The gated recursive graph unit layer consists of multiple gated recursive graph units (GRGUs) connected in sequence. Each GRGU includes a multi-graph convolutional layer, a multi-head graph attention layer, and a gated recursive structure connected in sequence. The decoder comprises a multi-head gated recursive graph unit layer connected in sequence. The decoder layer includes a first linear layer, an information embedding layer, a masked multi-head gated self-attention layer, a multi-head gated self-attention layer, a gated recursive graph unit layer, and a second linear layer connected in sequence. The specific structures of the first linear layer, information embedding layer, masked multi-head gated self-attention layer, multi-head gated self-attention layer, and gated recursive graph unit layer of the decoder are the same as the corresponding structures of the encoder. , All are integers;
[0031] Step S2: Construct a feature matrix based on the road traffic network to represent urban road traffic flow within time interval t. Based on this feature matrix The encoder's original input is obtained as The decoder's original input is The encoder input is obtained by increasing the dimensionality of the original inputs to the encoder and decoder and then embedding additional information. and decoder input , Indicates size is The set of real numbers, Indicates size is The set of real numbers, Indicates size is The set of real numbers, Indicates size is The set of real numbers, Indicates size is The set of real numbers, where N represents the total number of nodes in the road traffic network. , , each represents a time step, f represents the dimension after lifting;
[0032] Specifically, for the encoder, the original input is mapped to a high latitude f after the first linear layer, and additional information embedding is performed through the information embedding layer, and the additional information includes global time information (such as dimension information of hours, days, weeks, months, and holidays) at each time step, local time information (such as relative distance information of each time step), and influencing factor information (such as temperature and weather information). The decoder also performs the same operation.
[0033] The specific process of constructing the feature matrix is as follows: taking the latitude and longitude center point of each road segment in the road network as a node, all nodes are connected to form an undirected graph G=(V, E), wherein V={v1, v2, …, v N} represents the set of all nodes, E={e1, e2, …e N} represents the set of all connecting edges, N is the number of nodes in the road network, and the connecting edge refers to the connecting line of two nodes;
[0034] The road traffic flow can be measured by the number of vehicles passing through or the average speed of the vehicles traveling in a period of time. The average driving speed of a road segment reflects the traffic condition of the road segment. For each road segment, sampling is performed at a certain time interval t, and the average driving speed or the total number of vehicles passing through each road segment in the time interval t can be counted. Then, the feature matrix of the road traffic flow in the road network in the time interval t is represented as .
[0035] In this embodiment, the road network is limited to the area surrounded by Xiahelu-Hubinzhonglu-Huguanglu-Jialu in Xiamen Island, and there are 133 road segments. Then, the total number of nodes N in the road traffic network is 133. The average speed of each node is counted at a time interval of t=15 minutes. The average speed in the time interval is used to represent the traffic flow condition of the road segment. The traffic flow data set of the road network shown in Table 1 can be obtained, and the data dimension size is 133*2976*1. The future 1-hour data is predicted based on the historical 1-hour data. The values of T h and Tp are both equal to 4, and T b is set to 2.
[0036] Table 1
[0037] Key information Values Time range From 31 May 2019 to 30 June 2019 Time interval 15 minutes Number of road segment nodes 133 Number of time intervals 2976 Feature dimension 1
[0038] Step S3, the encoder input extracts the feature matrix in the time dimension through the multi-head gated self-attention layer of the encoder layer According to the feature matrix Spatiotemporal correlations are extracted through gated recursive graph cell layers, thus... The encoder output is obtained by calculating layer by layer. and ,in, For outputs containing spatiotemporal information, This is a hidden state that contains spatial information about the current time step;
[0039] Specifically:
[0040] A Euclidean distance graph adjacency matrix A is constructed in the multi-graph convolutional layer. E Adjacency Matrix A of Driving Distance Map D Adjacency Matrix A of Traffic Light Distance Map T ,in, , , The `distanceE` function is the Euclidean distance calculation function. i Let i represent the i-th node, where 1 ≤ i ≤ N. Represents node v i x-coordinate, Represents node v i y-coordinate, Indicates from node v i to node v j The shortest driving distance, Indicates from node v i to node v j The minimum number of traffic lights across all routes, where the number of traffic lights is 0. Assign a value of 0.9 to avoid the case where the denominator is 0.
[0041] For the first encoder layer:
[0042] According to the formula Extract encoder input Feature matrix in the time dimension ,in, , , This indicates the number of heads in the multi-head gating self-attention layer. This represents the output of the k-th head of the multi-head gated self-attention layer. , , , , , , , , , , are parameter matrices in the calculation of multi-head gated self-attention layer, which are prior art; , , are query, key, value of multi-head gated self-attention algorithm respectively, which can be obtained according to the encoder input , is the time step of the encoder input;
[0043] The output of the multi-graph convolution layer is , , , , , , , , , , , is an identity matrix, is a parameter matrix in the calculation of GCN, which is prior art, is a sigmoid activation function, is an element of matrix , is an element of matrix ;
[0044] The output of the multi-head graph attention layer is , represents an attention mechanism, represents the number of time intervals t, , is a weight parameter of the attention mechanism, || represents a splicing operation, , are the feature vector of node , the feature vector of the neighbor node of node , is a parameter matrix with a size of , is a set value, satisfying , C represents the number of attention mechanisms, c=1, 2, …, C, represents the weight coefficient of the cth attention mechanism, is the parameter matrix of the cth attention mechanism, is a sigmoid activation function, ;
[0045] The output of the multi-head graph attention layer is obtained after the gating recursive structure , the result after linear layer is the output of the first layer encoder , , , , , , , and , , and are the parameter matrix in the corresponding formula, which is the prior art, is the reset gate, is the update gate.
[0046] The output of the first layer encoder layer is taken as the input of the second layer encoder layer, and the above calculation is performed again until the output of the layer encoder is obtained and , which is also the output of the encoder.
[0047] Step S4, for the first layer decoder layer, the decoder input The masked multi-head gated self-attention layer is input into the decoder layer to capture the temporal information in the decoder input, and a masking mechanism is used to place each temporal position to pay attention to the future temporal information, the output (query) of the masked multi-head gated self-attention layer is input into the multi-head gated self-attention layer of the decoder layer together with the encoder output (key value) to obtain the correlation between the query and the key value, and the output of the multi-head gated self-attention layer is input into the gated recurrent graph unit layer of the decoder layer together with the encoder output , so that the output of the gated recurrent graph unit layer of the layer decoder layer is obtained after layer-by-layer calculation of the layer encoder layer , which is output After the second linear layer, the prediction result is obtained
[0048] The above only describes the preferred embodiments of the present application, and cannot limit the scope of the present application, that is, equivalent changes and modifications made according to the patent application scope and content of the present application should still be within the scope of the present application.
Claims
1. A method for predicting urban road traffic flow, characterized in that: Includes the following steps: Step S1: Construct the encoder and decoder. The encoder consists of sequentially connected... The encoder layer comprises a multi-head gated self-attention layer and a gated recursive graph unit layer connected in sequence. The gated recursive graph unit layer consists of multiple gated recursive graph units connected in sequence, each including a multi-graph convolutional layer, a multi-head graph attention layer, and a gated recursive structure connected in sequence. The decoder comprises a multi-head gated recursive graph unit layer connected in sequence. The decoder layer consists of a masked multi-head gated self-attention layer, a multi-head gated self-attention layer, and a gated recursive graph unit layer connected in sequence. Step S2: Construct a feature matrix based on the road traffic network to represent urban road traffic flow within time interval t. Based on this feature matrix The encoder's original input is obtained as The decoder's original input is The encoder input is obtained by increasing the dimensionality of the original inputs to the encoder and decoder and then embedding additional information. and decoder input , Indicates size is The set of real numbers, where N represents the total number of nodes in the road traffic network. , , Both represent the time step. f represents the boosted dimension; Step S3, Encoder Input The feature matrix in the time dimension is extracted by the multi-head gated self-attention layer after passing through the encoder layer. According to the feature matrix Spatiotemporal correlations are extracted through gated recursive graph cell layers, thus... The encoder output is obtained by calculating layer by layer. and ,in, For outputs containing spatiotemporal information, This is a hidden state containing spatial information; Step S4: For the first decoder layer, the decoder input... The input to this masked multi-head gated self-attention layer is to capture timing information in the decoder input. The output of this masked multi-head gated self-attention layer is compared with the encoder output. A multi-head gated self-attention layer is used as the common input to the decoder layer to obtain the correlation between the two. The output of this multi-head gated self-attention layer is compared with the encoder output. The gated recursive graph unit layer of the common input decoder layer, thus through The prediction result is obtained by calculating layer by layer by the layer encoder; In step S2, the feature matrix is constructed. Specifically: Taking the latitude and longitude center point of each road segment in the road network as a node, connecting all nodes forms an undirected graph G=(V, E), where V={v1,v2,…,v...} N Let E = {e1, e2, ..., e} represent the set of all nodes. N } represents the set of all connecting edges, where N is the number of nodes in the road network, and a connecting edge refers to the line connecting two nodes; For each road segment, sampling is performed at certain time intervals t. The average driving speed or the total number of vehicles passing through each road segment within time interval t can be statistically obtained. Therefore, the characteristic matrix of road traffic flow in the road network within time interval t is represented as follows: ; Both the encoder and the decoder further include a first linear layer and an information embedding layer. The dimensions of the original input of the encoder and the original input of the decoder are respectively mapped to higher dimensions through the corresponding first linear layer, and additional information is embedded through the information embedding layer. The additional information includes global time information, local time information and influencing factor information for each time step. In step S3, according to the formula Extracting the feature matrix in the time dimension ,in, , , This indicates the number of heads in the multi-head gating self-attention layer. This represents the output of the k-th head of the multi-head gated self-attention layer. , , , , , , , , , , Both are parameter matrices; , , According to encoder input get, The time step input to the encoder; In step S3, a Euclidean distance graph adjacency matrix A is constructed in the multi-graph convolutional layer. E Adjacency Matrix A of Driving Distance Map D Adjacency Matrix A of Traffic Light Distance Map T ,in, , , distance E The function is the Euclidean distance calculation function, v i Let i represent the i-th node, where 1 ≤ i ≤ N. Represents node v i x-coordinate, Represents node v i y-coordinate, Indicates from node v i to node v j The shortest driving distance, Indicates from node v i to node v j The minimum number of traffic lights across all routes, where the number of traffic lights is 0. Assign a value greater than zero to avoid cases where the denominator is 0.
2. The urban road traffic flow prediction method according to claim 1, characterized in that: In step S3, the output of the multi-graph convolutional layer is ,in, , , , , Take respectively , and , It is the identity matrix. For parameter matrices, It is the sigmoid activation function. For matrix elements, For matrix Element.
3. The urban road traffic flow prediction method according to claim 2, characterized in that: In step S3, the output of the multi-head graph attention layer is: ,in, This represents the attention mechanism. Indicates the time interval t , Here are the weight parameters for the attention mechanism, and || represents the concatenation operation. , They are nodes Feature vectors, nodes neighboring nodes eigenvectors, For size The parameter matrix, C represents the number of attention mechanisms, c = 1, 2, ..., C. This represents the weight coefficient of the c-th attention mechanism. Let c be the parameter matrix of the attention mechanism. It is the sigmoid activation function. .
4. The urban road traffic flow prediction method according to claim 3, characterized in that: In step S3, the output of the multi-head graph attention layer is obtained after passing through a gated recursive structure. The result is obtained after passing through a linear layer. and ,in, , , W xr、 W xz、 W xh、 W hr、 W hz and b r b z and All are parameter matrices.
5. A method for predicting urban road traffic flow according to claim 1, 2, or 3, characterized in that: In step S4, the coding layer further includes a second linear layer, the first... Output of the gated recursive graph unit layer of the layer decoder layer The prediction results are obtained after the second linear layer. , This represents the prediction results within the time interval t.
Citation Information
Patent Citations
Traffic demand prediction method and system, electronic equipment and computer storage medium
CN115938112A
Traffic flow prediction method based on U-shaped multi-scale space-time diagram convolutional network
CN116682271A