A traffic flow prediction method based on spatiotemporal attention network
Through the spatiotemporal attention network model, combined with time convolution and graph attention mechanism, the problem of insufficient fusion of time and space correlation in traffic flow prediction is solved, and a higher precision traffic flow prediction is achieved.
Patent Information
- Application Number
- CN202211616313.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-15
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2042-12-15
AI Technical Summary
The existing traffic flow prediction methods have shortcomings in fusion time dependence and spatial correlation. Traditional neural networks have problems with gradient vanishing and network degradation, making it difficult to effectively capture long-term temporal correlation and spatial correlation.
The spatiotemporal attention network model is adopted, combining the temporal convolutional network and graph attention mechanism, and the gradient disappearance problem is alleviated through residual connections, and spatial features are learned using node2vec, and time and spatial features are adaptively integrated.
It improves the accuracy of traffic flow prediction, effectively models spatial correlation, alleviates the problems caused by the increase in network depth, and improves the prediction effect.
Smart Images

Figure CN115936069B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of traffic flow prediction, and specifically relates to a traffic flow prediction method based on a spatiotemporal attention network. Background Art
[0002] Traffic flow prediction, a highly sought-after measure for intelligent transportation systems and daily mobility, has attracted numerous researchers. Its accuracy not only aids transportation deployment, improves road efficiency, and alleviates congestion, but also helps autonomous vehicles predict traffic conditions and plan optimal trajectories. However, traffic prediction remains a challenging problem for transportation researchers due to the complex topology of road networks and the random, time-varying dynamics of traffic conditions.
[0003] Traffic flow prediction essentially involves predicting the future state of a road based on its historical state. Numerous traffic flow prediction methods exist, most of which focus on temporal dependencies, typically using neural networks such as recurrent neural networks (RNNs), long short-term memory (LSTMs), and gated recurrent units (GRUs) to capture temporal features. However, changes in traffic state are also influenced by the complex topological structure of traffic networks, making capturing spatial correlation crucial in traffic prediction. In recent years, some methods have addressed both temporal and spatial dependencies, primarily using convolutional neural networks (CNNs) or graph convolutional neural networks (GCNs) to model spatial dependencies. However, convolutional methods are far from optimal in integrating node features and topological structure, and therefore cannot fully model spatial dependencies. Furthermore, traditional recurrent neural networks, such as LSTMs and GRUs, suffer from the vanishing gradient problem and network degradation with increasing network depth, generally failing to capture longer-term temporal dependencies. Summary of the Invention
[0004] To solve the above technical problems, the present invention proposes a traffic flow prediction method based on a spatiotemporal attention network, comprising:
[0005] S1: Collect real-time traffic flow data through sensors on urban traffic roads and pre-process the collected real-time traffic flow data;
[0006] The traffic flow data includes: the average vehicle speed in the lane at each time interval t of each road section, the number of vehicles passing through, and the vehicle density in the lane;
[0007] S2: Input the pre-processed real-time traffic flow data into the spatiotemporal attention network model, which includes a spatial correlation extraction module, a temporal correlation extraction module, and a spatiotemporal attention module;
[0008] S3: Extracting the temporal features of real-time traffic flow data through the temporal correlation extraction module;
[0009] S4: Extracting spatial features of real-time traffic flow data through the spatial correlation extraction module;
[0010] S5: The extracted temporal features and spatial features are concatenated and input into the spatiotemporal attention module, which adaptively fuses the temporal features and spatial features and outputs the spatiotemporal features.
[0011] S6: The spatiotemporal features output by the spatiotemporal attention network are passed through the fully connected layer to generate predicted traffic flow data.
[0012] Beneficial effects of the present invention:
[0013] 1. The present invention alleviates the gradient vanishing problem that may be encountered in processing long time series based on the recurrent neural network model and the network degradation problem encountered when the network depth increases by using a temporal convolutional network with residual connections.
[0014] 2. Compared with the existing graph neural network model based on the convolution operator, the present invention can more effectively model spatial correlation and adaptively learn spatial features through the graph attention mechanism combined with node2vec with a random walk mechanism, thereby improving the accuracy of traffic flow prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is the overall flow chart of the present invention;
[0016] Figure 2 (a) and (b) are schematic diagrams of the causal convolution and causal dilated convolution structures of the present invention;
[0017] Figure 3 This is a schematic diagram of the structure of the time correlation extraction module of the present invention;
[0018] Figure 4 This is a flow chart of the attention coefficient calculation process of the graph attention network of the present invention. DETAILED DESCRIPTION
[0019] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0020] A traffic flow prediction method based on spatiotemporal attention network, such as Figure 1 As shown, the following steps are included:
[0021] S1: Preprocessing the collected raw traffic data;
[0022] S2: Input historical traffic flow data into the spatiotemporal attention network model, which includes a spatial correlation extraction module, a temporal correlation extraction module, and an attention module;
[0023] S3: Extracting temporal features from traffic data through the temporal correlation extraction module;
[0024] S4: Extract spatial features from traffic data through the spatial correlation extraction module;
[0025] S5: Connect the temporal features and spatial features obtained by the temporal correlation extraction module and the spatial correlation extraction module, input them into the attention module, adaptively assign weights to the temporal features and spatial features, and fuse the temporal and spatial features;
[0026] S6: Prediction layer, which generates predicted traffic flow data by passing the spatiotemporal features output by the spatiotemporal attention network through the fully connected layer.
[0027] Specifically, the data preprocessing stage includes:
[0028] Traffic data refers to the traffic flow information and traffic network on each road section collected by sensors on urban traffic roads. Traffic flow information usually refers to the average speed in the lane, the number of passing vehicles, and the vehicle density in the lane at each interval t of each road section.
[0029] The traffic road network topology is used to represent the complex connectivity between traffic roads. The traffic road network topology is represented as an undirected graph G = (V, E, A); each road segment (sensor) is regarded as a node in the graph; V represents the node set, and each node in V is the feature matrix of its corresponding attribute; E represents the edge set between road segments; the connectivity between road segments is represented by the adjacency matrix A∈R N×N Indicates, N represents the number of nodes, the adjacency matrix shown is composed of numbers 0 and 1, A ij =1 means node i and node j are connected, A ij =0 means that node i and node j are not connected;
[0030] The traffic road network topology diagram is specifically expressed as follows (1):
[0031]
[0032] Among them, G represents the undirected graph composed of the topological structure of the traffic road network, V represents the node set, and v i Represents nodes i, v j represents node j, E represents the edge set between nodes, is a self-connection matrix, I is a unit diagonal matrix, A ij Indicates v i and v j Connection status;
[0033] Traffic flow time series, assuming that we have a total of T time steps, then the traffic flow time series of the traffic network is expressed as the following formula (2):
[0034] Y={Y t |t∈T}; (2)
[0035] Where t represents the time step; Y t ={y1,y2,…,y N} represents the traffic flow characteristic matrix of all nodes at time step t, Y t y in i Indicates v i ∈V traffic flow characteristics.
[0036] Specifically, the data input to the spatiotemporal attention network model is The goal of traffic flow prediction is to predict the traffic flow sequence for the next Q time steps based on the traffic flow sequence of the first M time steps and other factors. Therefore, traffic flow prediction can be viewed as learning the mapping function f(·) based on the traffic road network topology G and the traffic flow time series Y, and making predictions based on this. The traffic flow prediction objective function is defined as follows:
[0037]
[0038] (3) Represents the predicted traffic flow of N nodes at time t.
[0039] Specifically, the temporal correlation extraction module uses a temporal convolutional network to extract temporal correlation, with the input being the traffic flow time series Y. The specific steps are as follows:
[0040] The temporal convolutional network mainly consists of dilated causal convolution layers and residual connection layers.
[0041] The convolutional layer is the core of a convolutional neural network, extracting features from the input data. It combines causal convolution with dilated convolution. Causal convolution ensures that the output features at time t are learned only from data at or before time t. Dilated convolution ensures that the output has the same length as the input. By stacking multiple dilated convolutions, the network has a larger receptive field and can capture long-term dependencies with fewer layers. Figure 2 (a) Figure 2 (b) Causal convolution and dilated causal convolution, respectively.
[0042] Dilated causal convolution allows the filter to skip input values of a certain time step to reach an area greater than its length. Given a one-dimensional traffic flow time series, the dilated causal convolution with convolution kernel w outputs the time feature h at time t. t It is expressed as follows (4):
[0043]
[0044] Where d represents the dilation factor and k represents the size of the convolution kernel. The receptive power of the convolution kernel can be expanded by dilating the convolution. The dilation coefficient d of the i-th layer is expressed as follows (5):
[0045] d = 2 i-1 (5)
[0046] Here i ≥ 1. In actual tasks, the minimum number of layers required by the model needs to be determined based on parameters such as the length of the input data l, the size of the convolution kernel k, and the cardinality of the dilation coefficient b; the calculation method is as follows (6):
[0047]
[0048] Taking into account the depth of the network, the problem of gradient disappearance and network degradation caused by the increase of network depth is solved by adding residual structure, which simplifies network training. The residual connection structure is as follows: Figure 3 , output through the residual connection
[0049] Time feature h′ t As shown in formula (7):
[0050] h′ t =ReLU([h t ||Y]W h +b h ) (7)
[0051] Among them, || is the connection operation, and ReLU is the nonlinear activation function. h and b h Represent the weights and biases during training, respectively.
[0052] Specifically, the spatial correlation extraction module takes as input the traffic road network topology diagram and traffic flow time series. include:
[0053] S41: Use the Graph Attention Network (GAT) to extract the complex spatial correlation between nodes in the traffic road network. The specific steps include:
[0054] First, we use the attention coefficient to represent the spatial correlation weight between nodes in the traffic network. Through the graph attention mechanism, we can obtain the attention coefficient of each node to its neighboring nodes. For each time step t, the formula for calculating the attention coefficient of node j to node i is as follows (8):
[0055]
[0056] Among them, y i,t ,y j,t They are node v at time t i ,v j Traffic status; W is a learnable node feature transformation matrix used for feature extraction; e ij,t Indicates time tv j v i The importance of ; a is the learnable weight parameter vector; LeakyReLU is the nonlinear activation function. The softmax normalization function is used to uniformly normalize the attention weights calculated for all neighbors. The calculation formula is as follows (9):
[0057]
[0058] Among them, α ij,t Indicates time tv j v i The normalized attention coefficient of Indicates v i The neighbor node set of attention coefficient is calculated as follows Figure 4 ; v i All first-order neighbors v j The characteristics and corresponding coefficient α ij,t Perform weighted summation and obtain the spatial feature output of each node through the nonlinear layer. The calculation method is as follows (10):
[0059]
[0060] in, Indicates v i The first-order neighborhood spatial characteristics of α ij,t Represents node v at time t j For node v i The normalized attention coefficient of is a learnable weight matrix; σ represents the nonlinear activation function Relu.
[0061] S42: Learning higher-order neighborhood spatial features. The specific steps include:
[0062] GAT is a learning of first-order neighborhood spatial features. To retain the spatial features of higher-order neighborhoods, the node2vec method is used to learn node spatial feature representations with global information. These feature vectors are input into a fully connected neural network to obtain a more global spatial feature embedding so that it can be trained together with the entire model, which is expressed as The learned first-order neighborhood spatial features and spatial features of higher-order neighborhoods Through the connection operation, we get v i The final output spatial features As shown in formula (11):
[0063]
[0064] Specifically, the attention module has the following steps:
[0065] First, the spatial features and time characteristics h t Through the connection operation, the initial spatiotemporal feature TS is obtained t , as shown in formula (8):
[0066] TS t =[h′ t ||S t ] (12)
[0068] TS t Input attention module, adaptively fuse temporal features and spatial features to obtain spatiotemporal features TS′ at time t t , calculated as follows:
[0069] att t =ReLU(TS t W1+b1) (13)
[0070] att′ t =softmax(att t ) (14)
[0072] TS′ t =ReLU(TS′ t att′ t W2+b2) (15)
[0074] where att′ t are the attention weights of spatiotemporal attention, W1, W2 and b1, b2 are the learnable weight matrices and biases during model training.
[0075] Specifically, the specific steps of the prediction layer are as follows:
[0076] The spatiotemporal features of all nodes in the first M moments obtained by the spatiotemporal attention network are TS = [TS′ t |t=1,…,M], the traffic flow prediction results of all nodes in the next Q moments are finally obtained through the fully connected layer fc, as shown in the following formula (15):
[0077]
[0078] in is the predicted traffic flow at time t.
[0079] In order to minimize the error between the actual traffic flow and the predicted traffic flow in the traffic flow prediction during model training, the loss function of the spatiotemporal attention network model is defined as follows (17):
[0080]
[0081] in, is the loss value; the first term is the mean absolute error, Y t is the actual traffic flow value, is the predicted traffic flow value; the second item L reg is the L2 regularization term used to alleviate overfitting; λ is a hyperparameter.
[0082] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A traffic flow prediction method based on spatiotemporal attention network, characterized in that: include: S1: Collect real-time traffic flow data through sensors on urban traffic roads and pre-process the collected real-time traffic flow data; The traffic flow data includes: the average vehicle speed in the lane at each time interval t of each road section, the number of vehicles passing through, and the vehicle density in the lane; S2: Input the preprocessed real-time traffic flow data into the spatiotemporal attention network model, which includes a spatial correlation extraction module, a temporal correlation extraction module, and a spatiotemporal attention module; S3: Extracting the temporal features of real-time traffic flow data through the temporal correlation extraction module; The temporal features of real-time traffic flow data are extracted through the temporal correlation extraction module, including: h′ t =ReLU([h t ||Y]W h +b h ) Among them, h′ t Represents the time feature, h t represents the output time feature of the dilated causal convolution at time t, Y represents the traffic flow time series, and W h and b h Represent the weight and bias during training respectively; S4: Extracting spatial features of real-time traffic flow data through the spatial correlation extraction module; The spatial correlation extraction module is used to extract the spatial features of real-time traffic flow data, including: The spatial correlation extraction module includes: a graph attention network layer, a nonlinear layer, a node2vec layer, and a fully connected neural network layer; S41: Use the graph attention network layer to learn the complex first-order neighborhood spatial correlation between nodes in the traffic road network. According to the complex first-order neighborhood spatial correlation between nodes, the graph attention mechanism is used to obtain the attention coefficient of each node for its first-order neighboring nodes. The attention weights calculated for all first-order neighboring nodes are uniformly normalized using the softmax function. The features of all first-order neighboring nodes j of node i and the corresponding attention weight coefficients are weighted summed, and the first-order neighborhood spatial features of each node are generated through a nonlinear layer. S42: learning the spatial feature representation of nodes with global information in the traffic road network through the node2vec layer, inputting the learned feature vector into the fully connected neural network layer to obtain spatial features with global information, and concatenating the learned first-order neighborhood spatial features and the spatial features with global information to obtain the output spatial features of the nodes; S5: The extracted temporal features and spatial features are concatenated and input into the spatiotemporal attention module, which adaptively fuses the temporal features and spatial features and outputs the spatiotemporal features. S6: The spatiotemporal features output by the spatiotemporal attention network are passed through the fully connected layer to generate predicted traffic flow data.
2. The traffic flow prediction method based on spatiotemporal attention network according to claim 1 is characterized in that: Preprocess the collected real-time traffic flow data, including: The collected traffic flow data is used to construct a traffic road network topology diagram according to the connection properties of the urban road network. The traffic flow data is standardized using the maximization method based on the channel road network topology diagram to generate a traffic flow time series.
3. The traffic flow prediction method based on spatiotemporal attention network according to claim 1 is characterized in that: Get the attention coefficient of each node for its first-order neighboring nodes, including: e ij,i =LeakyReLU(a T [You i,t ||You j,t ]) Among them, e ij,t Represents node v j For node v i The attention coefficient, y i,t ,y j,t Represents the node v at time t i ,v j traffic state, W represents the learnable node feature transformation matrix, a represents the learnable weight parameter vector, and LeakyReLU() represents the Leaky ReLU activation function.
4. The traffic flow prediction method based on spatiotemporal attention network according to claim 1 is characterized in that: Use the softmax function to uniformly normalize the attention weights calculated for all first-order neighbor nodes, including: Among them, α ij,t Represents node v at time t j For node v i The normalized attention coefficient of Indicates v i The set of neighbor nodes.
5. The traffic flow prediction method based on spatiotemporal attention network according to claim 1 is characterized in that: The features of all first-order neighboring nodes j of node i and the corresponding attention weight coefficients are weighted summed, and the first-order neighborhood spatial features of each node are generated through a nonlinear layer, including: in, Represents node v i The first-order neighborhood spatial characteristics of α ij,t Represents node v at time t j For node v i The normalized attention coefficient of , W represents the learnable node feature transformation matrix, Represents node v j The first-order neighborhood spatial features of , σ represents the nonlinear activation function, and t represents the time.
6. The traffic flow prediction method based on spatiotemporal attention network according to claim 1 is characterized in that: The spatiotemporal attention module adaptively integrates temporal features and spatial features and outputs spatiotemporal features, including: TS′ t =ReLU(TS t to' t W2+b2) Among them, TS′ t Represents spatiotemporal features, TS t Represents the initial spatiotemporal features, TS t =[h′ t ||S t ], S t Represents spatial features, Represents node v i The first-order neighborhood spatial features, t represents the time, h′ t Represents the time feature, att′ t Represents the attention weight of spatiotemporal attention, W1, W2 and b1, b2 represent the first and second learnable weight matrices and the first and second biases during model training, respectively, and ReLU() represents the activation function.
7. The traffic flow prediction method based on spatiotemporal attention network according to claim 1 is characterized in that: The spatiotemporal features output by the spatiotemporal attention network are passed through a fully connected layer to generate predicted traffic flow data, including: in, is the traffic flow at the predicted time t, fc() represents the fully connected layer, TS′ t Represents spatiotemporal characteristics.