Traffic flow prediction method and system based on spatiotemporal graph attention network based on transitive perception
By combining the TAGAT-LSTM model with graph attention and transfer probability matrix, the limitations of existing traffic flow prediction methods in complex road networks and time-varying characteristics are overcome, achieving more accurate traffic flow prediction and dynamically capturing the spatiotemporal dependencies of traffic flow.
Patent Information
- Application Number
- CN202411413696.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-11
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2044-10-11
AI Technical Summary
Existing traffic flow prediction methods have limitations when dealing with complex road network structures and time-varying characteristics. In particular, graph convolutional networks assume that nodes are equally important, while graph attention networks ignore node transitivity and have poor interpretability, and fail to fully consider the spatiotemporal continuity of traffic flow.
A transitive-aware spatiotemporal graph attention network traffic flow prediction method is adopted. The spatial and temporal features are extracted through the TAGAT-LSTM model. Combined with the graph attention model, the transitive probability matrix and the distance decay matrix, the spatial and temporal features are dynamically integrated to capture the spatiotemporal dependency of traffic flow.
It improves the precision and accuracy of traffic flow prediction, enhances the model's ability to model complex traffic patterns, and dynamically captures the time dependence of traffic flow and the time-varying nature of spatial characteristics.
Smart Images

Figure CN119360607B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of traffic flow prediction, and more specifically, to a method and system for traffic flow prediction based on a spatiotemporal graph attention network based on transfer perception. Background Art
[0002] Intelligent transportation systems (ITS) play a vital role in urban road traffic management, and traffic flow forecasting is a key component of ITS. Accurate and efficient traffic flow forecasting can predict future traffic flows based on past traffic flow patterns, thereby improving urban traffic mobility, reducing congestion, and enhancing the efficiency and safety of urban transportation systems.
[0003] With the acceleration of urbanization and the rapid growth of private car ownership, traffic congestion has become increasingly common. Traffic congestion not only reduces urban operational efficiency but also creates a series of environmental problems, such as energy consumption, exhaust pollution, and noise pollution. These issues severely hinder the healthy and harmonious development of cities and have become a common problem in many cities. Therefore, developing effective traffic flow prediction methods is crucial for optimizing traffic management, improving the travel experience, and achieving sustainable urban development.
[0004] Currently, the most widely used traffic flow prediction methods are those based on deep learning. Existing prediction models, especially graph convolutional neural networks (GCNs) and graph attention networks (GATs), perform well in capturing the spatial characteristics of traffic flow. However, these models still have limitations when dealing with complex road network structures and time-varying characteristics. For example, traditional GCNs assume that all nodes are equally important, while GATs introduce an attention mechanism to assign different weights. Although this improves prediction accuracy, its interpretability is poor and it ignores the transitivity of nodes, that is, the ability of nodes to transmit their own traffic characteristics. In addition, most existing models design spatial feature extraction and temporal feature extraction as independent modules, ignoring the time-varying nature of spatial features and failing to fully consider the spatiotemporal continuity of traffic flow.
[0005] In view of this, this application is hereby made. Summary of the Invention
[0006] The purpose of the present invention is to provide a method and system for traffic flow prediction based on a spatiotemporal graph attention network based on transfer perception to solve the problems existing in the above-mentioned background technology.
[0007] The above technical objectives of the present invention are achieved through the following technical solutions:
[0008] In the first aspect, the present application provides a method for traffic flow prediction based on a spatiotemporal graph attention network based on transitive perception, comprising the following specific steps:
[0009] Obtain the actual road network of the area to be predicted, and establish a graph structure set corresponding to the area to be predicted based on the spatial connectivity of the actual road network. The graph structure set represents the road nodes in the area to be predicted and the connectivity between the road nodes.
[0010] Obtain traffic flow data of the area to be predicted within a first preset time length. Based on the graph structure set, use the traffic flow data of the area to be predicted to train the preset TAGAT-LSTM model to obtain a target model that corresponds to and is trained in the TAGAT-LSTM model. The target model is obtained by the following method:
[0011] Traffic flow data is preprocessed using the input module of the TAGAT-LSTM model and then input into the spatial feature extraction module of the TAGAT-LSTM model for processing to obtain a first feature sequence of spatial features of each road node aggregating adjacent nodes within a first preset time length. The preprocessing includes smoothing and normalization.
[0012] The gating network module in the TAGAT-LSTM model is used to process the first feature sequence of each road node to obtain the second feature sequence of each road node aggregating the spatial features of adjacent time steps;
[0013] Processing the second feature sequence using a time feature extraction module in the TAGAT-LSTM model to obtain a time feature of the second feature sequence, and generating a preliminary prediction value within a second preset time length through a fully connected layer in the TAGAT-LSTM model, where the second preset time length corresponds to the first preset time length;
[0014] Denormalize the preliminary prediction values, and calculate the loss function of the TAGAT-LSTM model based on the denormalized preliminary prediction values until the loss function meets a preset training end condition, and determine the TAGAT-LSTM model that meets the training end condition as the target model;
[0015] The historical traffic flow of the area to be predicted within a preset time length is obtained, and the historical traffic flow is input into the target model for processing to obtain the predicted traffic flow of the area to be predicted within the future preset time length.
[0016] The beneficial effects of the present invention are as follows: in this solution, the spatial feature extraction module is used to capture spatial dependencies, the gated network module performs preliminary temporal aggregation on the extracted spatial features, and weightedly fuses the spatial features of adjacent time steps to obtain a richer spatial feature representation, and the temporal feature extraction module is responsible for further capturing temporal dependencies. Through the combination of the three modules, the model can capture richer spatiotemporal dependencies and improve the accuracy of traffic flow prediction.
[0017] In this scheme, the gating network module serves as a transition layer between spatial feature extraction and temporal feature extraction, enabling the model to dynamically fuse spatial features at different time steps and capture the time-varying nature of spatial features, thereby more accurately capturing the temporal dependence of traffic flow and enhancing the model's ability to model complex traffic patterns. Furthermore, through the gating network, the model can better learn the temporal continuity and changing patterns of spatial features of traffic flow, thereby improving the model's feature extraction capability and thus the model's prediction accuracy.
[0018] On the basis of the above technical solution, the present invention can also be improved as follows.
[0019] Furthermore, the above-mentioned spatial feature extraction module includes a graph attention model, a transfer probability matrix and a distance attenuation matrix.
[0020] The beneficial effects of adopting the above further scheme are: using the transfer probability matrix to represent the ability of road nodes to transmit traffic characteristics at the current time step, and calculating the distance decay matrix based on the distance between road nodes to replace the traditional adjacency matrix, enriching the spatial expression ability of the model, thereby improving GAT's extraction of traffic flow spatial characteristics.
[0021] Furthermore, the above traffic flow data includes the flow rate, average speed and occupancy rate of each road node, and the spatial characteristics include congestion coefficient, transmission probability factor, distance attenuation factor and weight coefficient, among which:
[0022] The congestion coefficient is as follows:
[0023]
[0024] Where, represents the congestion coefficient of road node i at the tth time step, v i,max represents the maximum speed of road node i in the entire time series, represents the average speed of road node i at time step t, q i,max represents the maximum flow rate of road node i in the entire time series, represents the flow of road node i at time step t, k i,max represents the maximum occupancy rate of road node i in the entire time series, represents the occupancy rate of road node i at time step t.
[0025] Furthermore, the above transmission probability factor is specifically:
[0026]
[0027] Where p ij represents the transmission probability factor from road node j to road node i, represents the transfer coefficient of road node i, represents the transfer coefficient of road node j, c i represents the congestion coefficient of road node i, c j represents the congestion coefficient of road node j, where congestion coefficient = 1-transmission coefficient.
[0028] Furthermore, the above distance attenuation factor is specifically:
[0029]
[0030] Where, distance ij represents the distance between node i and node j, σ is the standard deviation of the Gaussian kernel function, which is calculated from the statistical information of the data, and d ij It is the distance attenuation factor between node i and node j. The greater the distance, the smaller the attenuation factor, which means the influence between the nodes is weaker.
[0031] Furthermore, the above weight coefficient is specifically:
[0032]
[0033] Where p ij is the transmission probability factor between road nodes i and j, d ij is the distance attenuation factor between road nodes i and j, That is the weight coefficient of the improved road nodes i and j, is the new feature of the lth layer after node i is transformed, is the new feature of the lth layer after node j is transformed, a T represents a trainable attention vector, || represents the concatenation operation of the feature vector, and LeakyReLU represents the activation function.
[0034] Furthermore, the spatial features of the above-mentioned aggregation of adjacent time steps are specifically:
[0035] Among them G t =σ(W g ·X t +b g ), X t =[Ht-1 ,H t ];
[0036] Where H t-1 is the vector of spatial features at time step t-1, H t is the vector of spatial features at time step t, X t is the vector of spatial features after splicing, w g is the weight matrix, b g is the bias vector, σ is the sigmoid function, G t is the gating signal, which is used to adaptively adjust the contribution of different time steps. The new vector after aggregating the spatial features of the previous time step for the t time step.
[0037] Furthermore, the above denormalization process is specifically as follows:
[0038] y=y′·σ+μ;
[0039] Where y′ is the initial prediction value output by the fully connected layer, σ is the standard deviation obtained during normalization, μ is the mean obtained during normalization, and y represents the initial prediction value after denormalization.
[0040] Furthermore, the above loss function is specifically:
[0041]
[0042] Where N is the total number of road nodes, q t+p,i is the actual traffic flow of road node i at time step t+p, is the initial predicted value of node i at time t after denormalization.
[0043] In a second aspect, the present application provides a spatiotemporal graph attention network traffic flow prediction system based on transfer perception, which is applied to any of the spatiotemporal graph attention network traffic flow prediction methods based on transfer perception in the first aspect, including:
[0044] The first module is used to obtain the actual road network of the area to be predicted and establish a graph structure set corresponding to the area to be predicted based on the spatial connectivity of the actual road network. The graph structure set represents the road nodes in the area to be predicted and the connectivity between each road node.
[0045] The second module is used to obtain traffic flow data of the area to be predicted within a first preset time length, and based on the graph structure set, use the traffic flow data of the area to be predicted to train the preset TAGAT-LSTM model to obtain a target model corresponding to the TAGAT-LSTM model and trained. The second module includes:
[0046] The first submodule is used to preprocess the traffic flow data using the input module in the TAGAT-LSTM model, and input the preprocessed traffic flow data into the spatial feature extraction module in the TAGAT-LSTM model for processing to obtain a first feature sequence of spatial features of adjacent nodes aggregated by each road node within a first preset time length. The preprocessing includes smoothing and normalization.
[0047] The second submodule is used to process the first feature sequence of each road node using the gated network module in the TAGAT-LSTM model to obtain a second feature sequence of spatial features of each road node that aggregates adjacent time steps;
[0048] A third submodule is used to process the second feature sequence using the time feature extraction module in the TAGAT-LSTM model to obtain the time features of the second feature sequence, and generate a preliminary prediction value within a second preset time length through the fully connected layer in the TAGAT-LSTM model, where the second preset time length corresponds to the first preset time length;
[0049] The fourth submodule is used to perform denormalization processing on the preliminary prediction value, and calculate the loss function of the TAGAT-LSTM model based on the denormalized preliminary prediction value until the loss function meets the preset training end condition, and determine the TAGAT-LSTM model that meets the training end condition as the target model;
[0050] The third module is used to obtain the historical traffic flow of the area to be predicted within a preset time length, and input the historical traffic flow into the target model for processing to obtain the predicted traffic flow of the area to be predicted within the future preset time length.
[0051] In a third aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any one of the methods in the first aspect when executing the computer program.
[0052] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable a computer to execute any one of the methods in the first aspect.
[0053] Compared with the prior art, the present invention has at least the following beneficial effects:
[0054] In this application, the spatial feature extraction module is used to capture spatial dependencies, the gated network module performs preliminary temporal aggregation on the extracted spatial features, and weightedly fuses the spatial features of adjacent time steps to obtain a richer spatial feature representation. The temporal feature extraction module is responsible for further capturing temporal dependencies. The combination of the three modules enables the model to capture richer spatiotemporal dependencies and improve the accuracy of traffic flow prediction.
[0055] In this application, the gated network module serves as a transition layer between spatial feature extraction and temporal feature extraction, enabling the model to dynamically fuse spatial features at different time steps and capture the time-varying nature of spatial features, thereby more accurately capturing the temporal dependence of traffic flow and enhancing the model's ability to model complex traffic patterns. Furthermore, through the gated network, the model can better learn the temporal continuity and changing patterns of spatial features of traffic flow, thereby improving the model's feature extraction capability and thus improving the model's prediction accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] The drawings described herein are used to provide a further understanding of the embodiments of the present invention, constitute a part of this application, and do not constitute a limitation of the embodiments of the present invention. In the drawings:
[0057] Figure 1 A flowchart of a prediction method according to an embodiment of the present invention;
[0058] Figure 2 This is a basic framework diagram of the TAGAT-LSTM model in an embodiment of the present invention;
[0059] Figure 3 This is a GAT layer model framework diagram in an embodiment of the present invention;
[0060] Figure 4 Schematic diagram of node transmission probability in an embodiment of the present invention;
[0061] Figure 5 Schematic diagram of a TA-GAT module according to an embodiment of the present invention;
[0062] Figure 6 Schematic diagram of a gated network module in an embodiment of the present invention. DETAILED DESCRIPTION
[0063] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions of the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings herein can be arranged and designed in various different configurations.
[0064] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention as claimed, but rather merely represents selected embodiments of the present invention. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without creative effort shall fall within the scope of protection of the present invention.
[0065] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings.
[0066] In the description of the embodiments of the present invention, "a plurality of" means at least two.
[0067] Example 1: This example provides a method for predicting traffic flow based on a spatiotemporal graph attention network based on transfer perception. Figure 1 As shown, the following specific steps are included:
[0068] S1, obtain the actual road network of the area to be predicted, and establish a graph structure set corresponding to the area to be predicted based on the spatial connection relationship of the actual road network. The graph structure set represents the road nodes in the area to be predicted and the connection relationship between each road node.
[0069] Among them, since traffic flow has unique spatiotemporal characteristics, it is not only affected by the historical traffic flow of the road section itself, but also has spatial interactions with its surrounding adjacent sections. Therefore, it is necessary to consider both time and space dimensions when predicting. Specifically, the spatial connection relationship of the actual road network represents the graph structure of the road network as G = (V, E, A), where V = {v1, v2, ..., v N} represents the set of all road nodes in the road network; N is the number of road nodes, E is the set of edges, if two nodes are connected in space, then there is an edge connecting these two nodes in G; A∈R N×N is the adjacency matrix of the graph, and the element a in A is ij Then it means node v i and v j The spatial connection status of , represented by 0 and 1, is as follows:
[0070]
[0071] Furthermore, the temporal features of all nodes in G = (V, E, A) are represented by X∈R N×T×C Indicated by, where T represents the time series length of the node, C represents the number of feature types of the node. In this embodiment, C is taken as {flow rate, average speed, occupancy rate}, then the traffic flow prediction problem can be described by the following formula:
[0072] (X t+1 ,Xt+2 ,…,X t+P )=F{(X t-T+1 ,X t-T+2 ,…,X t ); G}
[0073] Where t is the time step, T is the length of the historical traffic sequence, and P is the length of the predicted traffic sequence. Given the historical traffic sequence (X t-T+1 ,X t-T+2 ,…,X t ) and graph structure G, and predict the traffic status (X t+1 ,X t+2 ,…,X t+P ).
[0074] S2, obtaining traffic flow data of the area to be predicted within a first preset time length, and based on the graph structure set, using the traffic flow data of the area to be predicted to train a preset TAGAT-LSTM model to obtain a target model that corresponds to the TAGAT-LSTM model and has been trained.
[0075] Traffic flow prediction is a spatiotemporal data prediction problem. The difficulty lies in the accurate modeling and feature extraction of the time and space of the traffic network. To this end, a spatiotemporal graph attention network model TAGAT-LSTM based on transfer perception is designed. Its basic framework is as follows Figure 2 As shown in the figure, it mainly consists of five modules: ① Data Input Module (Inputs), ② Spatial Feature Extraction Module (TA-GAT), ③ Gating Network Module (Gating Network), ④ Temporal Feature Extraction Module (LSTM), and ⑤ Training and Output Module (Outputs). The Data Input Module obtains the model input by smoothing and normalizing the raw input data; the Spatial Feature Extraction Module TA-GAT, which consists of a Graph Attention Model (GAT), a transfer coefficient matrix, and a distance decay matrix, is responsible for modeling and extracting the spatial features of the traffic network; the Gating Network Module, composed of several gating networks, is responsible for performing preliminary temporal aggregation on the extracted spatial features; the Temporal Feature Extraction Module, composed of an LSTM network, is responsible for extracting the temporal features of historical traffic sequences; the Training and Output Module maps the obtained spatiotemporal features into prediction results through a fully connected layer, then restores the results to the original scale through denormalization. Finally, the model is trained using a loss function to output the final prediction results.
[0076] Specifically, the target model can be obtained by:
[0077] S21, using the input module in the TAGAT-LSTM model to preprocess the traffic flow data, and input the preprocessed traffic flow data into the spatial feature extraction module in the TAGAT-LSTM model for processing, to obtain a first feature sequence of spatial features of adjacent nodes aggregated for each road node within a first preset time length, the preprocessing including smoothing and normalization.
[0078] Among them, preprocessing includes smoothing and standardization. Since there are many noises in the original traffic data, these noises may come from sensor errors or abnormal events (such as traffic accidents, road construction, etc.), which will seriously affect the training and prediction performance of the prediction model. Therefore, smoothing the original data is an important step in data preprocessing, which helps to reduce short-term fluctuations, reduce the risk of model overfitting, and improve model performance. This paper uses a sliding average filter to smooth the data and reduce noise. For a given time series data x t , the calculation process of the sliding average filter is shown as follows:
[0079] Where W is the size of the sliding window, x t-i is the original data at time ti, is the data after noise removal.
[0080] Optionally, time series models are affected by the statistical properties of the data (such as mean and standard deviation), which reduces the prediction accuracy. Therefore, standardization is also an important part of data preprocessing. Z-score standardization converts the data into a standard normal distribution with a mean of 0 and a standard deviation of 1, eliminating the dimensional differences between different features, which helps to accelerate the convergence of the gradient descent algorithm and improve model performance. For a given input data The calculation of Z-score standardization is as follows:
[0081] Where μ is the input data The mean of , σ is its standard deviation, is the input data of feature f, is the normalized output data.
[0082] Optionally, the above-mentioned spatial feature extraction module includes a graph attention model, a transfer probability matrix and a distance attenuation matrix.
[0083] Among them, due to the complex time-varying spatial characteristics of real-world traffic flows, the spatial relationship and importance between road nodes and their neighboring nodes will change over time. GAT introduces an attention mechanism to assign adaptive weights to each edge and dynamically adjust the relationship between nodes, so that the model can better capture the time-varying spatial relationship in the traffic network. At the same time, the introduction of a multi-head attention mechanism enables the model to jointly learn attention coefficients from multiple representation subspaces to obtain a richer spatial representation. Its structure is as follows: Figure 3 shown.
[0084] Specifically, when extracting spatial features from the input data at each time step, GAT first defines a feature transformation matrix W∈R F×F′ Perform a linear transformation on the input features of each node and map the input features to the new feature space, as shown in the following formula: Where h i is the input feature of node i, W is the learnable feature transformation matrix, is the new feature of the lth layer after transformation.
[0085] Furthermore, the weight between two nodes is calculated through an attention mechanism, as shown in the formula: Where a is a trainable attention vector, || represents the concatenation operation of the feature vector, LeakyReLU is the activation function, and the attention coefficient e is calculated by concatenating the features of node i and node j. ij Node j is a neighbor node of node i. Since node i may have more than one neighbor node, it needs to be normalized as shown in the following formula:
[0086]
[0087] Where, is the set of neighboring nodes of node i, and the attention weight α is obtained by performing softmax normalization on the attention coefficient ij .
[0088] Furthermore, the attention weights are used to perform weighted summation on the features of neighboring nodes to obtain the output features of node i, as shown below:
[0089] Where σ is the activation function, is the neighbor node feature, α ij is the attention weight of node j for node i, and the weighted sum of all neighbor node features is used to obtain the new feature representation of node i.
[0090] In this embodiment, in order to enhance the performance of the model and the ability to capture more feature information and relationships, a multi-head attention mechanism is adopted, such as Figure 2 As shown in , multi-head attention calculation is performed on the input features, and the output features of all attention heads are spliced together to obtain the final output features, as shown in the following formula:
[0091]
[0092] Where K is the number of attention heads, l is the current layer. If the current layer is an intermediate layer, the output features of all attention heads are concatenated using formula (1). In the final output layer, the concatenated features are averaged using formula (2) to generate the final output features.
[0093] Optionally, the traffic flow data includes the flow rate, average speed and occupancy rate of each road node, and the spatial characteristics include the congestion coefficient, transfer probability factor, distance attenuation factor and weight coefficient, where:
[0094] The congestion coefficient is as follows:
[0095]
[0096] Where, represents the congestion coefficient of road node i at the tth time step, v i,max represents the maximum speed of road node i in the entire time series, represents the average speed of road node i at time step t, q i,max represents the maximum flow rate of road node i in the entire time series, represents the flow of road node i at time step t, k i,max represents the maximum occupancy rate of road node i in the entire time series, represents the occupancy rate of road node i at time step t.
[0097] Among them, GAT is used to extract the spatial characteristics of the traffic network. Its principle is to calculate the importance of neighbor nodes to the central node at each time step based on the feature similarity between nodes, so as to achieve the effect of aggregating the spatial characteristics of neighbor nodes. However, in real traffic networks, the spatial interaction between nodes not only depends on the similarity and connection relationship of their traffic characteristics, but also the traffic status of the node at the current time step is also crucial. This is related to the ability of the neighbor node's features to be transmitted to the target node and the target node's ability to receive the neighbor node's features. Therefore, this method takes into account the traffic status of each node at the current time step. In this embodiment, the congestion coefficient is used to describe the current status of the node.
[0098] Optionally, the above transmission probability factor is specifically:
[0099]
[0100] Where pij represents the transmission probability factor from road node j to road node i, represents the transfer coefficient of road node i, represents the transfer coefficient of road node j, c i represents the congestion coefficient of road node i, c j represents the congestion coefficient of road node j, where congestion coefficient = 1-transmission coefficient.
[0101] After obtaining the current congestion coefficient of the node, the node's transfer coefficient is further calculated. The transfer coefficient represents the node's ability to output and receive features. By introducing the node's transfer coefficient matrix, the model can more accurately reflect and extract the real spatial characteristics of the traffic network. Its calculation is shown in the following formula: Where, is the transfer coefficient of node i at time step t, is the congestion coefficient of node i at time step t.
[0102] Specifically, if Figure 4 As shown in the figure, after obtaining the transmission coefficient of a single node, the transmission probability of the neighboring node transmitting its own characteristics to the target node is further calculated. At the same time, taking into account the influence of the node on itself, that is, the self-connectivity of the node, the congestion probability is used to represent the probability that the node maintains its own characteristics unchanged, and then the transmission probability matrix P is constructed. The transmission probability of each position in the transmission probability matrix is the calculation formula of the above transmission probability factor.
[0103] Among them, the transmission probability matrix of road nodes in the traffic network has been obtained above, which represents the probability of nodes transmitting their own features and maintaining the features unchanged. However, in reality, the factors affecting the node transmission ability are very complex, and distance is the most direct and influential factor. As the spatial distance between nodes increases, the mutual influence between nodes will inevitably weaken, and the probability of neighbor nodes transmitting features to the target node will also decrease. Therefore, in this embodiment, the distance factor is introduced when extracting the spatial features of the traffic road network; the distance attenuation factor is used to represent the influence of distance on the spatial features extracted by the model. It is calculated by the Gaussian kernel function. The above distance attenuation factor is specifically:
[0104]
[0105] Where, distance ij represents the distance between node i and node j, σ is the standard deviation of the Gaussian kernel function, which is calculated from the statistical information of the data, and d ij It is the distance attenuation factor between node i and node j. The greater the distance, the smaller the attenuation factor, which means the influence between the nodes is weaker.
[0106] The adjacency matrix of the GAT model only uses 0 and 1 to represent the connectivity of nodes, which is used to help the model identify the set of neighboring nodes of a node. However, it is difficult to reflect the complex spatial structure of the transportation network, which greatly limits its expression ability. Therefore, the adjacency matrix is replaced by the distance decay matrix, and the connectivity of the node is expressed by the distance decay factor. This results in a distance decay matrix with richer spatial features, as shown below:
[0107]
[0108] The diagonal of the matrix is set to 1, indicating the self-connectivity of the nodes.
[0109] Specifically, the transfer probability matrix and the distance attenuation matrix are integrated with the GAT module. The transfer probability factor and the distance attenuation factor are added to the calculation process of the neighbor node weight coefficient to obtain a new neighbor node weight calculation formula. The above weight coefficient is specifically:
[0110]
[0111] Where p ij is the transmission probability factor between road nodes i and j, d ij is the distance attenuation factor between road nodes i and j, That is the weight coefficient of the improved road nodes i and j, is the new feature of the lth layer after node i is transformed, is the new feature of the lth layer after node j is transformed, a T Represents a trainable attention vector, || represents the concatenation operation of the feature vector, and LeakyReLU represents the activation function. Figure 5 The figure shows the fused TA-GAT module, where D is the distance attenuation matrix module and P is the transmission probability matrix module. is the element-wise product of tensors, is the element-wise sum of tensors. The module input is the preprocessed traffic sequence data and adjacency matrix, and the output is a new feature sequence after aggregating the spatial features of neighbor nodes.
[0112] S22, using the gated network module in the TAGAT-LSTM model to process the first feature sequence of each road node, to obtain a second feature sequence of each road node aggregating spatial features of adjacent time steps.
[0113] Among them, the spatial features of the road node are not only affected by its neighbor nodes in the current time step, but also by the previous time step. Therefore, a gating network is inserted after TA-GAT to fuse the spatial features of the previous time step and the current time step, such as Figure 6As shown in the figure, the feature sequence processed by TA-GAT is input into the gating network. The gating network performs a weighted fusion of the spatial features of the previous time step and the spatial features of the current time step to form a new spatial feature representation of the current time step. By introducing the gating network, the model's expressive power is improved, enabling it to better understand the dynamic changes in traffic flow and improve prediction accuracy. At the same time, it provides a preliminary temporal aggregation of the feature sequence of the data, which facilitates the next step of extracting temporal features.
[0114] Optionally, the spatial features of the above-mentioned aggregation of adjacent time steps are specifically:
[0115] Among them G t =σ(W g ·X t +b g ), X t =[H t-1 ,H t ];
[0116] Where H t-1 is the vector of spatial features at time step t-1, H t is the vector of spatial features at time step t, X t is the vector of spatial features after splicing, w g is the weight matrix, b g is the bias vector, σ is the sigmoid function, G t is the gating signal, which is used to adaptively adjust the contribution of different time steps. The new vector after aggregating the spatial features of the previous time step for the t time step.
[0117] S23, using the time feature extraction module in the TAGAT-LSTM model to process the second feature sequence to obtain the time features of the second feature sequence, and generating a preliminary prediction value within a second preset time length through the fully connected layer in the TAGAT-LSTM model, where the second preset time length corresponds to the first preset time length.
[0118] Traffic data has obvious time dependency. RNN is usually used to learn time dependency and time series prediction. However, it has gradient explosion and gradient vanishing problems. LSTM solves this problem by introducing a set of gated units and unit states that control information flow. In this embodiment, LSTM network is selected to extract time features. The node spatial feature sequence processed by TA-GAT and gated network is input into LSTM. Given data x t , whose input feature is represented as H∈R T×N×F′ , where F′ is the feature dimension of TA-GAT output, then the unit output state c tand the hidden layer output h t It can be calculated by the following formula:
[0119] i t =σ(W ii x t +b ii +W hi h t-1 +b hi ), f t =σ(W if x t +b if +W hf h t-1 +b hf );
[0120] g t =tanh(W ig x t +b ig +W hg h t-1 +b hg ), o t =σ(W io x t +b io +W ho h t-1 +b ho );
[0121] c t =f t *c t-1 +i t *g t , h t =o t *tanh(c t );
[0122] In the above formula, i t 、f t 、o t They are input, forget and output gates, g t is the memory cell state, W ii 、W if 、W ig 、W io 、W hi 、W hf 、W hg Is the connection x t , h t-1 The weight matrix to the three gates and input unit, b ii , b if , b ig , b io , b hi , bhf ,hg,b ho is the corresponding bias, σ represents the sigmoid function, tanh represents the hyperbolic tangent function, and * represents element-wise multiplication.
[0123] Specifically, the hidden state of the LSTM is finally input into the fully connected layer, which is responsible for mapping the hidden state to the target output space and generating a preliminary prediction value of the traffic flow.
[0124] S24, performing denormalization processing on the preliminary prediction value, and calculating the loss function of the TAGAT-LSTM model based on the denormalized preliminary prediction value, until the loss function meets the preset training end condition, and determining the TAGAT-LSTM model that meets the training end condition as the target model.
[0125] Optionally, the predicted values obtained by the fully connected layer are normalized values, and denormalization is required to reintegrate the non-stationary elements back into the dataset and restore them to their original scale. The denormalization process is as follows:
[0126] y=y′·σ+μ;
[0127] Where y′ is the initial prediction value output by the fully connected layer, σ is the standard deviation obtained during normalization, μ is the mean obtained during normalization, and y represents the initial prediction value after denormalization.
[0128] Optionally, the TAGAT-LSTM model can be optimized using the mean square error (MSE) as a loss function. The loss function is:
[0129]
[0130] Where N is the total number of road nodes, q t+p,i is the actual traffic flow of road node i at time step t+p, is the initial predicted value of node i at time t after denormalization.
[0131] Among them, the adjustable parameters of the model are continuously optimized by minimizing the loss function, thereby improving the performance of the prediction model. When the loss function value reaches the set threshold, the best set of parameters is selected, and the predicted value calculated under this parameter is used as the output of the traffic flow prediction model.
[0132] S3, obtaining historical traffic flows in the area to be predicted within a preset time length, and inputting the historical traffic flows into the target model for processing to obtain predicted traffic flows in the area to be predicted within a future preset time length.
[0133] Example 2: This embodiment of the present application provides a spatiotemporal graph attention network traffic flow prediction system based on transfer perception, which is applied to any of the spatiotemporal graph attention network traffic flow prediction methods based on transfer perception in Example 1, including:
[0134] The first module is used to obtain the actual road network of the area to be predicted and establish a graph structure set corresponding to the area to be predicted based on the spatial connection relationship of the actual road network. The graph structure set represents the road nodes in the area to be predicted and the connection relationship between each road node.
[0135] The second module is used to obtain traffic flow data of the area to be predicted within a first preset time length, and based on the graph structure set, use the traffic flow data of the area to be predicted to train the preset TAGAT-LSTM model to obtain a target model corresponding to the TAGAT-LSTM model and trained. The second module includes:
[0136] The first submodule is used to preprocess the traffic flow data using the input module in the TAGAT-LSTM model, and input the preprocessed traffic flow data into the spatial feature extraction module in the TAGAT-LSTM model for processing, so as to obtain a first feature sequence of spatial features of each road node aggregating adjacent nodes within a first preset time length. The preprocessing includes smoothing and normalization.
[0137] The second submodule is used to process the first feature sequence of each road node using the gated network module in the TAGAT-LSTM model to obtain a second feature sequence of each road node aggregating spatial features of adjacent time steps.
[0138] The third submodule is used to process the second feature sequence using the time feature extraction module in the TAGAT-LSTM model to obtain the time features of the second feature sequence, and generate a preliminary prediction value within a second preset time length through the fully connected layer in the TAGAT-LSTM model, where the second preset time length corresponds to the first preset time length.
[0139] The fourth submodule is used to perform denormalization on the preliminary prediction values and calculate the loss function of the TAGAT-LSTM model based on the denormalized preliminary prediction values until the loss function meets the preset training end condition, and the TAGAT-LSTM model that meets the training end condition is determined as the target model.
[0140] The third module is used to obtain the historical traffic flow of the area to be predicted within a preset time length, and input the historical traffic flow into the target model for processing to obtain the predicted traffic flow of the area to be predicted within the future preset time length.
[0141] Example 3: An embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any one of the methods in Example 1 when executing the computer program.
[0142] Example 4: The embodiment of the present application provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable a computer to execute any method in Example 1.
[0143] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A traffic flow prediction method based on spatiotemporal graph attention network based on transfer perception, characterized by: The specific steps include: Obtaining the actual road network of the area to be predicted, and establishing a graph structure set corresponding to the area to be predicted based on the spatial connectivity of the actual road network, wherein the graph structure set represents the road nodes in the area to be predicted and the connectivity between the road nodes; Obtain traffic flow data of the area to be predicted within a first preset time length, and based on the graph structure set, train a preset TAGAT-LSTM model using the traffic flow data of the area to be predicted to obtain a target model corresponding to the TAGAT-LSTM model and trained. The target model is obtained by: Traffic flow data is preprocessed using an input module in the TAGAT-LSTM model, and the preprocessed traffic flow data is input into a spatial feature extraction module in the TAGAT-LSTM model for processing to obtain a first feature sequence of spatial features of adjacent nodes aggregated for each road node within a first preset time length, wherein the preprocessing includes smoothing and normalization. The first feature sequence of each road node is processed using the gated network module in the TAGAT-LSTM model to obtain a second feature sequence of each road node aggregating spatial features of adjacent time steps; Processing the second feature sequence using a time feature extraction module in a TAGAT-LSTM model to obtain a time feature of the second feature sequence, and generating a preliminary prediction value within a second preset time length through a fully connected layer in the TAGAT-LSTM model, where the second preset time length corresponds to the first preset time length; Performing a denormalization process on the preliminary predicted values, and calculating a loss function of the TAGAT-LSTM model based on the denormalized preliminary predicted values until the loss function satisfies a preset training end condition, and determining the TAGAT-LSTM model that satisfies the training end condition as a target model; The historical traffic flow of the area to be predicted within a preset time length is obtained, and the historical traffic flow is input into the target model for processing to obtain the predicted traffic flow of the area to be predicted within a future preset time length.
2. The traffic flow prediction method based on spatiotemporal graph attention network based on transfer perception according to claim 1 is characterized in that: The spatial feature extraction module includes a graph attention model, a transfer probability matrix and a distance attenuation matrix.
3. The traffic flow prediction method based on spatiotemporal graph attention network based on transfer perception according to claim 1 is characterized in that: The traffic flow data includes the flow rate, average speed and occupancy rate of each road node, and the spatial characteristics include the congestion coefficient, transfer probability factor, distance attenuation factor and weight coefficient, where: The congestion coefficient is specifically: Where, represents the congestion coefficient of road node i at the tth time step, v i,max represents the maximum speed of road node i in the entire time series, represents the average speed of road node i at time step t, q i,max represents the maximum flow rate of road node i in the entire time series, represents the flow of road node i at time step t, k i,max represents the maximum occupancy rate of road node i in the entire time series, represents the occupancy rate of road node i at time step t.
4. The method for traffic flow prediction based on spatiotemporal graph attention network based on transfer perception according to claim 3 is characterized in that: The transmission probability factor is specifically: Where p ij represents the transmission probability factor from road node j to road node i, l i represents the transfer coefficient of road node i, l j represents the transfer coefficient of road node j, c i represents the congestion coefficient of road node i, c j represents the congestion coefficient of road node j, where congestion coefficient = 1-transmission coefficient.
5. The method for traffic flow prediction based on spatiotemporal graph attention network based on transfer perception according to claim 3 is characterized in that: The distance attenuation factor is specifically: Where, distance ij represents the distance between node i and node j, σ is the standard deviation of the Gaussian kernel function, which is calculated from the statistical information of the data, and d ij It is the distance attenuation factor between node i and node j. The greater the distance, the smaller the attenuation factor, which means the influence between the nodes is weaker.
6. The method for traffic flow prediction based on spatiotemporal graph attention network based on transfer perception according to claim 3 is characterized in that: The weight coefficient is specifically: Where: p ij is the transmission probability factor between road nodes i and j, d ij is the distance attenuation factor between road nodes i and j, That is the weight coefficient of the improved road nodes i and j, is the new feature of the lth layer after node i is transformed, is the new feature of the lth layer after node j is transformed, a T represents a trainable attention vector, || represents the concatenation operation of the feature vector, and LeakyReLU represents the activation function.
7. The method for traffic flow prediction based on spatiotemporal graph attention network based on transfer perception according to claim 1 is characterized in that: The spatial features of the aggregation of adjacent time steps are specifically: among them G t =σ(W g ·X t +b g ),X t =[H t-1 ,H t ]; Where H t-1 is the vector of spatial features at time step t-1, H t is the vector of spatial features at time step t, X t is the vector of spatial features after splicing, w g is the weight matrix, b g is the bias vector, σ is the sigmoid function, G t is the gating signal, which is used to adaptively adjust the contribution of different time steps. The new vector after aggregating the spatial features of the previous time step for the t time step.
8. The method for traffic flow prediction based on spatiotemporal graph attention network based on transfer perception according to claim 1 is characterized in that: The denormalization process is specifically as follows: y=y′·σ+μ; Where y′ is the initial prediction value output by the fully connected layer, σ is the standard deviation obtained during normalization, μ is the mean obtained during normalization, and y represents the initial prediction value after denormalization.
9. The method for traffic flow prediction based on spatiotemporal graph attention network based on transfer perception according to claim 1 is characterized in that: The loss function is specifically: Where N is the total number of road nodes, q t+p,i is the actual traffic flow of road node i at time step t+p, is the initial predicted value of node i at time t after denormalization.
10. A spatiotemporal graph attention network traffic flow prediction system based on transfer perception, applied to the spatiotemporal graph attention network traffic flow prediction method based on transfer perception according to any one of claims 1 to 9, characterized in that: include: The first module is used to obtain the actual road network of the area to be predicted and establish a graph structure set corresponding to the area to be predicted based on the spatial connectivity of the actual road network. The graph structure set represents the road nodes in the area to be predicted and the connectivity between the road nodes; The second module is configured to obtain traffic flow data of the area to be predicted within a first preset time length, and based on the graph structure set, train a preset TAGAT-LSTM model using the traffic flow data of the area to be predicted to obtain a target model corresponding to the TAGAT-LSTM model and trained. The second module includes: The first submodule is used to preprocess the traffic flow data using the input module in the TAGAT-LSTM model, and input the preprocessed traffic flow data into the spatial feature extraction module in the TAGAT-LSTM model for processing to obtain a first feature sequence of spatial features of adjacent nodes aggregated by each road node within a first preset time length, wherein the preprocessing includes smoothing and normalization. The second submodule is configured to process the first feature sequence of each road node using the gated network module in the TAGAT-LSTM model to obtain a second feature sequence of spatial features of each road node that aggregates adjacent time steps; A third submodule is configured to process the second feature sequence using a time feature extraction module in the TAGAT-LSTM model to obtain a time feature of the second feature sequence, and generate a preliminary prediction value within a second preset time length through a fully connected layer in the TAGAT-LSTM model, where the second preset time length corresponds to the first preset time length; A fourth submodule is configured to perform denormalization processing on the preliminary predicted values, and calculate a loss function of the TAGAT-LSTM model based on the denormalized preliminary predicted values until the loss function satisfies a preset training end condition, and determine the TAGAT-LSTM model that satisfies the training end condition as a target model; The third module is used to obtain the historical traffic flow of the area to be predicted within a preset time length, and input the historical traffic flow into the target model for processing to obtain the predicted traffic flow of the area to be predicted within a future preset time length.
Citation Information
Patent Citations
Traffic flow prediction method based on Transform space-time diagram convolutional network
CN114330671A
Traffic flow prediction method based on graph discrete attention network, medium and equipment
CN114582128A