A Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method and system
Through the adaptive spatio-temporal graph neural network based on Transformer, combined with the multi-head attention mechanism and the adaptive adjacency matrix, the problem of difficulty in capturing the spatio-temporal correlation of traffic data with existing technology is solved, and efficient prediction of traffic flow is achieved.
Patent Information
- Application Number
- CN202210085688.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-25
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2042-01-25
AI Technical Summary
Existing traffic flow prediction methods are difficult to simultaneously capture hidden spatial relationships and dynamic spatiotemporal correlations, resulting in poor prediction results.
The adaptive spatio-temporal graph neural network based on Transformer is used to extract the temporal correlation, spatio-temporal correlation and hidden spatial correlation of nodes by obtaining historical traffic flow data and road network structure information, and utilizes the multi-head attention mechanism and adaptive adjacency. The matrix performs feature fusion to capture the complex spatiotemporal characteristics of traffic data.
Effectively capturing the dynamic spatial correlation and spatio-temporal correlation of traffic data improves the accuracy and stability of traffic flow prediction, especially the prediction effect for longer periods under complex traffic conditions is significant.
Smart Images

Figure CN114492992B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of intelligent transportation, and specifically relates to a Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method and system. Background Art
[0002] At present, there are many papers studying traffic flow prediction methods. The paper T-GCN: A Temporal Graph Convolutional Network for Traffic Prediction applies graph convolution to traffic flow prediction, using graph convolutional networks and gated recurrent units (GRU) to capture temporal dependencies and spatial dependencies respectively. The paper Attention Based Spatial-Temporal Graph Convolutional Networks for Traffic Flow Forecasting introduces the attention mechanism into the traffic flow prediction model, using the spatiotemporal attention mechanism to capture the dynamic spatiotemporal correlation of traffic data, and using two separate components to capture temporal correlation and spatial correlation respectively. The paper Spatial-Temporal Synchronous Graph Convolutional Networks: A New Framework for Spatial-Temporal Network Data Forecasting proposes a local spatiotemporal subgraph that can effectively capture complex local spatiotemporal correlations. The paper Spatial-Temporal Fusion Graph Neural Networks for Traffic Flow Forecasting proposes a data-driven "temporal graph" generation method that can capture correlations that are not reflected in the spatial graph. The paper Spatial-Temporal Transformer Networks for Traffic Flow Forecasting introduces Transformer into the traffic flow prediction model and uses Transformer to capture dynamic spatial correlation and spatiotemporal correlation. So far, few papers can capture both hidden spatial relationships and dynamic spatiotemporal correlations.
[0003] Traffic flow data has complex spatiotemporal correlations. The hidden spatial dependence, temporal correlation, and temporal multi-modal nature of the data are all challenges faced by existing traffic flow predictions. Summary of the invention
[0004] In order to effectively capture the dynamic and hidden spatial correlation and spatiotemporal correlation in traffic data, the present invention provides a Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method and system, the method comprising the following steps:
[0005] Obtain historical data, including traffic flow in the previous hour, traffic flow one day ago, and traffic flow one week ago, and use the traffic flow feature matrix obtained by splicing the historical data and the adjacency matrix of nodes in the road network as input data;
[0006] According to the connectivity of the road network and the traffic flow characteristic matrix, the time correlation of the nodes themselves and the time-space correlation between different nodes are extracted to obtain the first traffic flow characteristic matrix, and according to the hidden spatial correlation in the road network structure, the second traffic flow characteristic matrix is obtained;
[0007] The first traffic flow feature matrix and the second traffic flow feature matrix are fused to obtain the final traffic flow feature, and the feature is input into the prediction model for prediction to obtain the prediction result.
[0008] Furthermore, the acquisition of input data includes: splicing the traffic flow of the day, the traffic flow one day ago, and the traffic flow one week ago together, and then using a convolutional neural network to project the spliced data into a high-order space as input data. The spliced data of the traffic flow of the day, the traffic flow one day ago, and the traffic flow one week ago are expressed as:
[0009] X = concat(X r ,X d ,X w );
[0010] Among them, X is the data of the traffic flow of the day, the traffic flow of the day before, and the traffic flow of the week before, X∈R N×M Represents the characteristics of N nodes and M time slices; X r ∈R N×M′ Represents the traffic flow data of N nodes and M′ time slices a few hours ago; X d ∈R N×M′ represents the periodic data of traffic flow at N nodes and M′ time slices one day ago; X w ∈R N×M′ Represents the periodic data of traffic flow at N nodes and M′ time slices one week ago.
[0011] Furthermore, obtaining the first traffic flow characteristic matrix includes:
[0012] Considering the distance and connectivity between nodes in the road network, the location information is injected into the features of the input data;
[0013] The Transformer network with time position coding of traffic flow and spatial position coding between nodes is used to obtain the characteristics of long-term dependency and dynamic spatiotemporal correlation between traffic flow and nodes.
[0014] After the long-term dependency between traffic flow and nodes and the dynamic spatiotemporal correlation features are processed in parallel, the multi-head attention mechanism is used to obtain the dynamic spatiotemporal correlation of traffic flow;
[0015] The softmax function is used to normalize the features of the spatiotemporal correlation of the traffic flow dynamics, and the normalized features of each node are concatenated according to the spatial axis to form the first traffic flow feature matrix.
[0016] Furthermore, embedding the location information into the features of the input data includes:
[0017]
[0018] G = (V, E, A);
[0019] in, Embedding matrix representing spatial information; A∈R N×N is the adjacency matrix of the road network structure graph G constructed based on the Euclidean distance between sensors, σ 2 is the standard deviation of the Euclidean distance between all two nodes in the road network structure graph G; V represents a set of N nodes, where the nodes are detectors deployed at road checkpoints; E is the set of edges between nodes, and N is the number of nodes.
[0020] Furthermore, the features of the input data embedded with location information are input into the Transformer network for convolution to obtain the features of the long-term dependency and dynamic spatiotemporal correlation between traffic flow and nodes, which can be expressed as:
[0021] X′=Conv(concat(X,D M ,D S ));
[0022] Where X′∈R C×N×M It represents the characteristics of long-term dependency and dynamic spatiotemporal correlation between traffic flow and nodes; Conv() represents convolution operation; concat() represents concatenation operation; X represents input data; D M ∈R N×M×M Represents the characteristics of the input data with embedded temporal information; D S ∈R M×N×N Represents the characteristics of the input data with embedded location information; C is the number of channels, N is the number of nodes, and M is the number of historical time slices of the input node.
[0023] Furthermore, the process of using the multi-head attention mechanism to obtain the spatiotemporal correlation of traffic flow dynamics includes:
[0024] The features of the input data are projected into three high-dimensional latent subspaces through a feedforward neural network;
[0025] The three potential subspaces of the projection are query subspace key subspace and value subspace V∈R M×C , the dynamic dependencies between nodes are calculated through three subspaces, which are expressed as:
[0026]
[0027]
[0028]
[0029] in, W V ∈R C×C are the weight matrices of Q, K, and V respectively, It represents the characteristics of the long-term dependency and dynamic spatiotemporal correlation between the traffic flow and nodes after parallel processing; M is the number of historical time slices of the input node, C is the number of channels, d k is the dimension of matrix K.
[0030] Furthermore, the softmax function is used to normalize the features of the spatiotemporal correlation of traffic flow dynamics, including:
[0031]
[0032] in, It means that the softmax function is used to normalize the features and then the value of the value subspace V is updated to obtain the output.
[0033] Furthermore, the second traffic flow feature matrix is composed of the hidden spatial correlations of nodes in all time slices in the road network structure. The hidden spatial correlation of nodes in a single time slice in the road network structure is expressed as:
[0034]
[0035] in, Represents the hidden spatial correlation in the road network structure; A adp is the adaptive adjacency matrix, A adp =sigmoid(E1E2), E1∈R N×b , E2∈R b×Nis a randomly initialized learnable parameter; k is the order of the Chebyshev polynomial, k = 1, 2, 3, 4...K; W k ∈R C×C is the k-th order weight matrix of the model formula, θ k is a learnable parameter; is the Chebyshev polynomial about the Laplace matrix, N is the number of nodes, C is the number of channels, and b is a positive integer much smaller than N; It is the feature input after time parallel processing.
[0036] Furthermore, fusing the first traffic flow feature matrix with the second traffic flow feature matrix includes:
[0037] The first traffic flow feature matrix and the second traffic flow feature matrix are spliced together and initially fused using a weight matrix, expressed as:
[0038] Y F =Y Gt W F ;
[0039] The preliminary fusion result is input into the softmax activation function to obtain the gate, which is expressed as:
[0040] RT = softmax(Y F );
[0041] The initial fusion result Y F Dot multiplication with the gated RT to output the final fused feature information Y, expressed as:
[0042] Y=Y F *RT;
[0043] Among them, Y Gt is a matrix formed by concatenating the first traffic flow feature matrix and the second traffic flow feature matrix; Y∈R N×M×C represents the final fused feature information, RT is the gate, Y F is the preliminary fusion result, * represents dot product, N is the number of nodes, M is the number of historical time slices of the input nodes, and C is the number of channels.
[0044] The present invention also proposes a Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction system, which includes a feature representation module, a Transformer module, a GCN module, and a Gate module, wherein:
[0045] A feature representation module is used to obtain the adjacency matrix and traffic flow feature matrix that represent the spatial characteristics of the road network based on historical data;
[0046] Transformer module, which is used to capture dynamic spatial correlation, spatiotemporal correlation and temporal correlation based on the traffic flow feature matrix, adjacency matrix and one-hot encoding matrix;
[0047] GCN module, which is used to capture explicit and implicit spatial correlations based on the traffic flow feature matrix, adjacency matrix, and adaptive adjacency matrix;
[0048] The Gate module is used to fuse the traffic flow features extracted by the Transformer module and the GCN module, and then input the fused traffic flow features into the convolution layer to obtain the prediction results.
[0049] The present invention effectively captures the dynamic and hidden spatial correlation and spatiotemporal correlation in traffic data, and solves the challenges faced by in-depth research on traffic flow prediction, such as the complex spatiotemporal correlation of traffic flow data, the hidden spatial dependence of data, the temporal correlation, and the multi-modal nature of time. The model has a good prediction effect on long-term traffic flow under complex traffic conditions. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 This is an overall flow chart of a Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method of the present invention;
[0051] Figure 2 It is a performance comparison diagram of the real value and the predicted value of the present invention;
[0052] Figure 3 This is a comparison chart of the MAE performance of the present invention. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in 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. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0054] The present invention proposes a Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method, comprising the following steps:
[0055] Obtain historical data, including traffic flow in the previous hour, traffic flow a day ago, and traffic flow a week ago, and use the traffic flow feature matrix obtained by splicing historical data and the adjacency matrix of nodes in the road network as input data; if two nodes in the road network are connected, the value of the element of the adjacency matrix is the Euclidean distance between the two nodes in the road network, and if the two nodes are not connected, the value of the element of the adjacency matrix is 0. According to the connectivity of the road network and the traffic flow feature matrix, extract the time correlation of the node itself and the time-space correlation between different nodes to obtain the first traffic flow feature matrix, and according to the hidden spatial correlation in the road network structure, obtain the second traffic flow feature matrix;
[0056] The first traffic flow feature matrix and the second traffic flow feature matrix are fused to obtain the final traffic flow feature, and the feature is input into the prediction model for prediction to obtain the prediction result.
[0057] In this embodiment, a Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method is characterized by comprising the following steps:
[0058] S1: Feature representation. Vectorize the historical traffic data of the road network structure and nodes to obtain the adjacency matrix and traffic flow feature matrix that can characterize the spatial characteristics of the road network;
[0059] S2: Feature extraction. By analyzing the connectivity of the road network and the node feature matrix, the temporal correlation of the node itself and the spatiotemporal correlation between different nodes are extracted; an adaptive GCN module is constructed to extract the hidden spatial correlation in the road network structure.
[0060] S3: Feature fusion. The traffic flow features extracted by the Transformer layer are integrated with the traffic flow features extracted by the adaptive GCN module to improve the prediction accuracy.
[0061] S4: Performance and simulation results analysis.
[0062] Further, the feature representation in step S1 can be specifically as follows:
[0063] First, concatenate the recent traffic flow, the traffic flow one day ago, and the traffic flow one week ago to obtain X = concat (X r ,X d ,X w ), X∈R N×M represents the features of N nodes at M moments, X r ∈R N×M′ Indicates the recent data of the node; X d ∈R N×M′ , X w ∈R N×M′They represent the periodic data of traffic flow one day ago and one week ago respectively. Then, they are fused and projected into the high-order space through the convolutional neural network to obtain:
[0064] X1=Conv(X) (1)
[0065] where X1∈R C×N×M is the input of the first layer of the model.
[0066] The model layer is defined as:
[0067] Y j =F(X j ) (2)
[0068] Where X j ∈R C×N×M is the input of the jth layer of the model, M is the number of historical time slices of the input node, N is the number of nodes, C is the number of channels, and Y j ∈R C×N×M is the output of the jth layer of the model layer, F is the traffic flow prediction model, X j+1 =Y j +X j , X j+1 is the input of the j+1th layer. The model layer consists of three parts: Transformer module, GCN module and gated fusion module.
[0069] Further, step S2 feature extraction can be specifically as follows:
[0070] The future traffic flow of a node is determined by the historical traffic flow of the node, the historical traffic flow of its adjacent nodes, and the time step of historical observations. There are complex dependencies between nodes, and the accuracy of traffic flow prediction depends on whether these dependencies can be accurately captured. Based on the temporal variation law of traffic flow data and the spatiotemporal dynamic dependencies, a Transformer-adaptive GCN dynamic spatiotemporal capture model is proposed. First, time and space information are integrated into traffic flow characteristics, so that the model can dynamically capture the complex spatiotemporal correlations between nodes in the traffic network; secondly, an adaptive GCN model is proposed to capture the hidden spatial correlations of the road network, thereby improving the prediction accuracy.
[0071] S201: Time information and space information are added to the model so that the input features contain the time and space information of the traffic flow data, thereby achieving the purpose of accurately capturing the complex dependencies between traffic flow nodes.
[0072] The Transformer layer:
[0073] Y j TL =Trans(Xj ,D S ,D M ) (3)
[0074] Where Y j TL ∈R C×N×M is the output of the jth Transformer layer, D S , D M Encodes both temporal and spatial information.
[0075] are the embedding matrices of time and space information respectively, M is the number of historical time slices of the input node, and N is the number of nodes. Initialized as a one-hot encoding of the time step, inject the time step into each node, The adjacency matrix initialized by the Gaussian kernel of the road network structure graph G takes into account the distance and connectivity between nodes and injects location information into the input features, where:
[0076]
[0077] G=(V,E,A) (5)
[0078] In formula (4), A∈R N×N is the adjacency matrix of the road network structure graph G constructed based on the Euclidean distance between sensors, σ 2 is the standard deviation of the Euclidean distance between all two nodes in the road network structure graph G. The road network structure graph G is defined in formula (5), where V represents a set of N nodes, in this paper, nodes represent detectors deployed at road checkpoints, and E is the set of edges between nodes, representing the physical connectivity between nodes.
[0079] In traffic flow prediction, the Transformer network is introduced, the temporal position encoding of traffic flow and the spatial position encoding between nodes are added, and the multi-head attention mechanism is used to capture the long-term dependency and dynamic spatiotemporal correlation between traffic flow and nodes.
[0080] First, the features embedded with the spatiotemporal information of traffic flow data are input into the Transformer network, which is defined as follows:
[0081] X′=Conv(concat(X,D M ,D S )) (6)
[0082] X′∈R C×N×M , where X is the model layer input after omitting the subscript j, D M ∈R N×M×M and D S ∈RM×N×N is the time embedding matrix and the spatial embedding matrix Tiling along the spatial axis and the space-time axis respectively. C×N×M After node parallel processing, we get Among them, C is the number of channels, N is the number of nodes, and M is the number of historical time slices of the input node.
[0083] The multi-head self-attention mechanism enables the model to focus on the information of different representation subspaces at different positions, thereby capturing the spatiotemporal correlation of traffic flow dynamics. Through the feedforward neural network, it is possible to learn the mapping of input features to three high-dimensional latent subspaces. The three latent subspaces of the projection are query subspace key subspace and value subspace V∈R M×C .in:
[0084]
[0085]
[0086]
[0087] In the formula W V ∈R C×C are the weight matrices of Q, K, and V respectively, The matrix is obtained by parallel processing of X′ along the node dimension, M is the number of historical time slices of the input node, C is the number of channels, and d k is the dimension of matrix K.
[0088] The dot product of Q and K is used to obtain the dynamic dependencies between nodes, while reducing the storage and computation costs. This ensures that the gradient is stable during back propagation. After using the softmax function to normalize the features, the value of the value subspace V is updated to obtain the output of the Transformer submodule.
[0089]
[0090] Among them, Q, K, and V correspond to the query subspace, key subspace, and value subspace respectively. k is the dimension of matrix K, M is the number of historical time slices of the input node, and C is the number of channels.
[0091] Y TL ∈R C×N×MTo collect the output of N nodes, first parallelize the input of the Transformer layer into N inputs Input it into the Transformer submodule, and then output N submodules Concatenate them according to the spatial axis to get the output Y of the Transformer layer TL .
[0092] S202: In order to solve the problem that the traditional graph convolutional neural network model is based on graph theory and is difficult to capture the hidden spatial relationships in the traffic network, a graph convolutional neural network (adaptive GCN) model based on an adaptive adjacency matrix is proposed. This model can learn the hidden spatial correlations in the road network.
[0093] Among them, the GCN layer:
[0094] Y j GL =Graph(X j ,A,A adp ) (11)
[0095] Where Y j GL ∈R C×N×M is the output of the jth GCN layer, A adp ∈R N×N is the constructed road network adaptive adjacency matrix, C is the number of channels, N is the number of nodes, and M is the number of historical time slices of the input nodes.
[0096] The adaptive adjacency matrix A is established adp As shown below:
[0097] A adp =sigmoid(E1E2) (12)
[0098] Where E1∈R N×b , E2∈R b×N is a randomly initialized learnable parameter, and N is the number of nodes. In general, b is much smaller than N. By initializing the multiplication of two node embedding dictionaries to obtain an adaptive adjacency matrix, the learnable parameters of the model can be reduced. The adaptive adjacency matrix can autonomously discover invisible graph structures from the data without any prior knowledge guidance, and accurately capture the hidden spatial dependencies in the data.
[0099] The adaptive adjacency matrix captures the hidden spatial correlation of the road network. At the same time, it is also necessary to obtain the explicit spatial relationship of the road network. The traditional graph convolutional neural network based on Chebyshev polynomial approximation can capture the local explicit spatial correlation. The Chebyshev polynomial is recursively defined as:
[0100]
[0101] Chebyshev polynomials are a sequence of polynomials defined recursively. This article uses the first kind of Chebyshev polynomials, where T0(x) and T1(x) are the 0th and 1st order, and T k (x) is the kth order. An adaptive GCN model is constructed by combining the adaptive adjacency matrix and Chebyshev polynomial approximation. The output of this model is the feature output of a single time slice.
[0102]
[0103] Where k is the order of the Chebyshev polynomial, A adp is the adaptive adjacency matrix, A adp =sigmoid(E1E2), E1∈R N×b , E2∈R b×N is a randomly initialized learnable parameter. In general, b is much smaller than N. is the feature input after time parallel processing, W k ∈R C×C is the k-th order weight matrix of the model formula, θ k is a learnable parameter, is the Chebyshev polynomial about the Laplace matrix, N is the number of nodes, and C is the number of channels. is the scaled Laplacian matrix, where λ max is the largest eigenvalue of L, L is the symmetric normalized Laplace matrix, I n is the n-th order identity matrix. D is the degree matrix of the road network structure graph G, where A∈R N ×N It is the adjacency matrix of the road network structure graph G constructed according to the Euclidean distance between sensors, and N is the number of nodes.
[0104] Y GL ∈R N×M×C The output of M time slices is collected, where M is the number of historical time slices of the input node, N is the number of nodes, and C is the number of channels. The input of the GCN layer is parallelized according to the time axis into M GCN sub-module inputs, and then the output of each sub-module is spliced together according to the time axis to obtain the output Y of the GCN layer GL .
[0105] Further, step S3 feature extraction can be specifically as follows:
[0106] In order to improve the prediction accuracy of the model, a gated fusion mechanism Gate is proposed to fuse the extracted features Y of the Transformer layer. TL And the adaptive GCN layer extracts feature Y GL .
[0107] The gated fusion layer:
[0108]
[0109] Where Y j is the output of the jth gated fusion layer, Y j TL ∈R C×N×M is the output of the j-th Transformer layer, Y GL is the output of the GCN module, M is the number of historical time slices of the input node, N is the number of nodes, and C is the number of channels.
[0110] The input Y of this module Gt ∈R N×M×2C Y is composed of the traffic flow feature information captured by the Transformer dynamic spatiotemporal capture model layer and the adaptive GCN model layer. Gt =concat(Y GL ,Y TL ). Input Y Gt It is just the output Y of the two model layers. GL and Y TL Simple splicing does not achieve true integration.
[0111] First, the weight matrix is used to achieve preliminary fusion and output Y F ∈R N×M×C :
[0112] Y F =Y Gt W F (16)
[0113] Among them, W F ∈R N×2C×C is the weight matrix, Y GL is the output of the GCN module, M is the number of historical time slices of the input node, N is the number of nodes, and C is the number of channels.
[0114] Then, the preliminary fusion result is input into the softmax activation function to obtain the gated RT∈R N×M×C :
[0115] RT = softmax(Y F ) (17)
[0116] Finally, the preliminary fusion result YF Do a dot multiplication with the gated RT to output the final fused feature information Y:
[0117] Y=Y F *RT (18)
[0118] Among them, Y∈R N×M×C , RT is gate control, Y F is the preliminary fusion result, '*' represents dot product, that is, multiplication of corresponding positions, N is the number of nodes, M is the number of historical time slices of the input node, and C is the number of channels.
[0119] The content of the proposed traffic flow prediction algorithm (TAGCN) is shown below.
[0120]
[0121]
[0122] Further, the experimental analysis of step S4 can be specifically as follows:
[0123] We conducted comparative experiments with more advanced models in recent years, and the experimental results are as follows: Figure 2 This is a performance comparison chart of the true value and the predicted value. Figure 2 The comparison results of the proposed traffic prediction algorithm (TAGCN) and the STSGCN algorithm with the actual traffic flow are given. Figure 2 It can be seen that the prediction results of the proposed TAGCN algorithm are closer to the actual value of traffic flow. Figure 3 This is a MAE performance comparison chart, which compares the MAE performance of this TAGCN model with the latest STFGNN and STSGCN models. It can be seen from the figure that the MAE (mean absolute error) of this model is relatively small and stable.
[0124] The present invention aims at the problems that still exist in the application of graph neural network to traffic flow prediction, such as how to effectively capture the dynamic and hidden nature of spatial dependency of traffic network nodes, the complex spatiotemporal correlation of traffic data, and the multi-mode nature of traffic data in time. This paper proposes an adaptive spatiotemporal graph neural network and multi-mode spatiotemporal fusion method based on Transformer. First, considering the hidden spatial correlation in traffic flow data, the adaptive adjacency matrix model is improved to capture the hidden spatial dependency. Then, while introducing the Transformer model to capture temporal dependency, spatial information is added to achieve the purpose of dynamically capturing spatial correlation and spatiotemporal correlation. Finally, the model was experimentally evaluated on 4 real data sets. The evaluation results show that the model framework model can achieve good results under complex traffic conditions such as different traffic characteristics and number of roads.
[0125] Although 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 the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method, characterized in that: The following steps are involved: Obtain historical data, including the traffic flow in the previous hour, the traffic flow a day ago, and the traffic flow a week ago. The traffic flow feature matrix obtained by splicing the historical data and the adjacency matrix of the nodes in the road network are used as input data. The data spliced together from the traffic flow of the day, the traffic flow a day ago, and the traffic flow a week ago are expressed as: X=concat(X r ,X d ,X w ); Among them, X is the data of the traffic flow of the day, the traffic flow of the day before, and the traffic flow of the week before, X∈R N ×M Represents the characteristics of N nodes and M time slices; X r ∈R N×M′ Represents the traffic flow data of N nodes and M′ time slices a few hours ago; X d ∈R N×M′ represents the periodic data of traffic flow at N nodes and M′ time slices one day ago; X w ∈R N×M′ Represents the periodic data of M′ time slices of N nodes in the traffic flow one week ago; According to the connectivity of the road network, the adjacency matrix and the traffic flow characteristic matrix, the time correlation of the nodes themselves and the time-space correlation between different nodes are extracted to obtain the first traffic flow characteristic matrix, and according to the hidden spatial correlation in the road network structure, the second traffic flow characteristic matrix is obtained; The acquisition of the first traffic flow characteristic matrix includes: Considering the distance and connectivity between nodes in the road network, the location information is injected into the features of the input data, namely: G = (V, E, A); in, Embedding matrix representing spatial information; A∈R N×N is the adjacency matrix of the road network structure graph G constructed based on the Euclidean distance between sensors, σ 2 is the standard deviation of the Euclidean distance between all two nodes in the road network structure graph G; V represents a set of N nodes, where the nodes are detectors deployed at road checkpoints; E is the set of edges between nodes, and N is the number of nodes; The Transformer network with time position coding of traffic flow and spatial position coding between nodes is used to obtain the characteristics of long-term dependency and dynamic spatiotemporal correlation between traffic flow and nodes, namely: X′=Conv(concat(X,D M ,D S )); Where X′∈R C×N×M It represents the characteristics of long-term dependency and dynamic spatiotemporal correlation between traffic flow and nodes; Conv() represents convolution operation; concat() represents concatenation operation; X represents input data; D M ∈R N×M×M Represents the characteristics of the input data with embedded temporal information; D S ∈R M×N×N Represents the characteristics of the input data with embedded location information; C is the number of channels, N is the number of nodes, and M is the number of historical time slices of the input node; After the long-term dependency between traffic flow and nodes and the dynamic spatiotemporal correlation features are processed in parallel, the multi-head attention mechanism is used to obtain the dynamic spatiotemporal correlation of traffic flow, namely: The features of the input data are projected into three high-dimensional latent subspaces through a feedforward neural network; The three potential subspaces of the projection are query subspace key subspace and value subspace V∈R M×C , the dynamic dependencies between nodes are calculated through three subspaces, which are expressed as: in, W V ∈R C×C are the weight matrices of Q, K, and V respectively, It represents the characteristics of the long-term dependency and dynamic spatiotemporal correlation between the traffic flow and nodes after parallel processing; M is the number of historical time slices of the input node, C is the number of channels, d k is the dimension of matrix K; The softmax function is used to normalize the features of the spatiotemporal correlation of traffic flow dynamics, and the normalized features of each node are concatenated according to the spatial axis to form the first traffic flow feature matrix, namely: in, It means that the softmax function is used to normalize the features and then the value of the value subspace V is updated to obtain the output; The first traffic flow feature matrix and the second traffic flow feature matrix are fused to obtain the final traffic flow feature, and the feature is input into the prediction model for prediction to obtain the prediction result.
2. According to claim 1, a Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method is characterized in that: The second traffic flow feature matrix is composed of the hidden spatial correlation of nodes in all time slices in the road network structure. The hidden spatial correlation of nodes in a single time slice in the road network structure is expressed as: in, Represents the hidden spatial correlation in the road network structure; A adp is the adaptive adjacency matrix, A adp =sigmoid(E1E2), E1∈R N×b , E2∈R b×N is a randomly initialized learnable parameter; k is the order of the Chebyshev polynomial, k = 1, 2, 3, 4...K; W k ∈R C×C is the k-th order weight matrix of the model formula, θ k is a learnable parameter; T k (L~) is the Chebyshev polynomial about the Laplace matrix, N is the number of nodes, C is the number of channels, and b is a positive integer much smaller than N; It is the feature input after time parallel processing.
3. According to claim 1, a Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method is characterized in that: The fusion of the first traffic flow characteristic matrix and the second traffic flow characteristic matrix includes: The first traffic flow feature matrix and the second traffic flow feature matrix are spliced together and initially fused using a weight matrix, expressed as: Y F =Y Gt W F ; The preliminary fusion result is input into the softmax activation function to obtain the gate, which is expressed as: RT=softmax(Y F ); The initial fusion result Y F Dot multiplication with the gated RT to output the final fused feature information Y, expressed as: Y=Y F *RT; Among them, Y Gt is a matrix formed by concatenating the first traffic flow feature matrix and the second traffic flow feature matrix; Y∈R N×M×C represents the final fused feature information, RT is the gate, Y F is the preliminary fusion result, * represents dot product, N is the number of nodes, M is the number of historical time slices of the input nodes, and C is the number of channels; W F is the weight matrix.
4. A Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction system, characterized in that: The system is used to implement the Transformer-based adaptive spatiotemporal graph neural network traffic flow prediction method described in claim 1, and the system includes a feature representation module, a Transformer module, a GCN module, and a Gate module, wherein: A feature representation module is used to obtain the adjacency matrix and traffic flow feature matrix that represent the spatial characteristics of the road network based on historical data; Transformer module, which is used to capture dynamic spatial correlation, spatiotemporal correlation and temporal correlation based on the traffic flow feature matrix, adjacency matrix and one-hot encoding matrix; GCN module, which is used to capture explicit and implicit spatial correlations based on the traffic flow feature matrix, adjacency matrix, and adaptive adjacency matrix; The Gate module is used to fuse the traffic flow features extracted by the Transformer module and the GCN module, and then input the fused traffic flow features into the convolution layer to obtain the prediction results; The data of the traffic flow of the day, the traffic flow of the day before, and the traffic flow of the week before are expressed as follows: X=concat(X r ,X d ,X w ); Among them, X is the data of the traffic flow of the day, the traffic flow of the day before, and the traffic flow of the week before, X∈R N ×M Represents the characteristics of N nodes and M time slices; X r ∈R N×M′ Represents the traffic flow data of N nodes and M′ time slices a few hours ago; X d ∈R N×M′ represents the periodic data of traffic flow at N nodes and M′ time slices one day ago; X w ∈R N×M′ Represents the periodic data of M′ time slices of N nodes in the traffic flow one week ago; The acquisition of the first traffic flow characteristic matrix includes: Considering the distance and connectivity between nodes in the road network, the location information is injected into the features of the input data, namely: G = (V, E, A); in, Embedding matrix representing spatial information; A∈R N×N is the adjacency matrix of the road network structure graph G constructed based on the Euclidean distance between sensors, σ 2 is the standard deviation of the Euclidean distance between all two nodes in the road network structure graph G; V represents a set of N nodes, where the nodes are detectors deployed at road checkpoints; E is the set of edges between nodes, and N is the number of nodes; The Transformer network with time position coding of traffic flow and spatial position coding between nodes is used to obtain the characteristics of long-term dependency and dynamic spatiotemporal correlation between traffic flow and nodes, namely: X′=Conv(concat(X,D M ,D S )); Where X′∈R C×N×M It represents the characteristics of long-term dependency and dynamic spatiotemporal correlation between traffic flow and nodes; Conv() represents convolution operation; concat() represents concatenation operation; X represents input data; D M ∈R N×M×M Represents the characteristics of the input data with embedded temporal information; D S ∈R M×N×N Represents the characteristics of the input data with embedded location information; C is the number of channels, N is the number of nodes, and M is the number of historical time slices of the input node; After the long-term dependency between traffic flow and nodes and the dynamic spatiotemporal correlation features are processed in parallel, the multi-head attention mechanism is used to obtain the spatiotemporal correlation of traffic flow dynamics, namely: The features of the input data are projected into three high-dimensional latent subspaces through a feedforward neural network; The three potential subspaces of the projection are query subspace key subspace and value subspace V∈R M×C , the dynamic dependencies between nodes are calculated through three subspaces, which are expressed as: in, W V ∈R C×C are the weight matrices of Q, K, and V respectively, It represents the characteristics of the long-term dependency and dynamic spatiotemporal correlation between the traffic flow and nodes after parallel processing; M is the number of historical time slices of the input node, C is the number of channels, d k is the dimension of matrix K; The softmax function is used to normalize the features of the spatiotemporal correlation of traffic flow dynamics, and the normalized features of each node are concatenated according to the spatial axis to form the first traffic flow feature matrix, namely: in, It means that the softmax function is used to normalize the features and then the value of the value subspace V is updated to obtain the output.
