Traffic speed prediction method and device based on spatiotemporal attention graph convolutional network
By constructing a temporal and spatial attention network based on the spatiotemporal attention graph convolution network, combined with the graph convolution network, the problem of low traffic speed prediction accuracy in the existing technology is solved, and more accurate traffic speed prediction is achieved.
Patent Information
- Application Number
- CN202110980592.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-25
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-08-25
AI Technical Summary
Existing traffic speed prediction methods are difficult to effectively mine the spatiotemporal correlation in traffic conditions, resulting in low prediction accuracy and inability to accurately predict complex urban traffic conditions.
A method based on spatiotemporal attention graph convolutional network is used to train the model to predict traffic speed by constructing a temporal attention network and a spatial attention network, integrating the spatiotemporal correlation matrix, and combining it with the graph convolutional network.
It improves the accuracy of traffic speed prediction, captures the correlation of the traffic network in time and space, and improves the prediction effect.
Smart Images

Figure CN113705880B
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of intelligent transportation and deep learning, and more specifically, to a traffic speed prediction method and related devices based on a spatiotemporal attention graph convolutional network. Background Art
[0002] As per capita income continues to rise, urban traffic is becoming increasingly congested, and traffic forecasting has become an increasingly important research topic. Accurate and timely traffic forecasting not only provides an effective management tool for traffic management departments but also allows for reasonable planning for travelers. Traffic forecasting is of great significance to urban planning, traffic management, traffic governance, and property safety. However, due to the temporal and spatial complexity of traffic conditions, spatiotemporal forecasting has always been a challenging task.
[0003] Early traffic speed prediction methods were primarily based on statistical or simple machine learning approaches. Representative examples include the Autoregressive Integrated Moving Average (ARIMA), Vector Autoregression (VAR), K-Nearest Neighbor (KNN), and Support Vector Regression (SVR). While these methods can predict traffic speed, the increasing spatial complexity of traffic networks and the increasing temporal correlations have led to lower prediction accuracy. Traditional traffic speed prediction struggles to exploit temporal and spatial correlations, significantly limiting its performance in spatiotemporal mining.
[0004] Therefore, how to design a speed prediction method that comprehensively considers the temporal and spatial correlation under traffic conditions is a technical problem that needs to be solved urgently by those skilled in the art. Summary of the Invention
[0005] In view of the above problems, the purpose of the present invention is to provide a traffic speed prediction method and related devices based on spatiotemporal attention graph convolutional network, so that the prediction of traffic speed is more accurate.
[0006] A first aspect of the present invention provides a traffic speed prediction method based on a spatiotemporal attention graph convolutional network, comprising the following steps:
[0007] Sampling the existing velocity data set to obtain a component data matrix of the relevant time series;
[0008] Constructing a temporal attention network;
[0009] Inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix;
[0010] Build a spatial attention network;
[0011] Inputting the temporal correlation matrix into the spatial attention network and fusing them to obtain a spatiotemporal correlation matrix;
[0012] Input the road network topology matrix into the graph convolutional network and combine it with the spatiotemporal correlation matrix to perform model training;
[0013] Speed prediction is performed using the trained model.
[0014] In this solution, inputting the component data matrix into the temporal attention network to obtain the temporal correlation matrix specifically includes:
[0015] Input the component data matrix into the temporal attention network to obtain the temporal attention matrix T:
[0016]
[0017] Among them, K e 、L1、L2、L3、V e is a learnable parameter, σ represents the sigmoid activation function, is the component data matrix, C r-1 Indicates the number of channels of the input data of the rth layer, T r-1 Indicates the length of the time dimension of the input data of the rth layer;
[0018] The temporal attention matrix T is normalized to capture the correlation strength between nodes according to the temporal attention matrix:
[0019]
[0020] T i,j Reflects the temporal correlation strength between time i and j, and multiplies the component data matrix to obtain the temporal correlation matrix
[0021]
[0022] In this solution, the step of inputting the temporal correlation matrix into the spatial attention network and fusing the temporal correlation matrix to obtain the spatiotemporal correlation matrix specifically includes:
[0023] The temporal correlation matrix is input into the spatial attention network to obtain the spatiotemporal attention matrix S:
[0024]
[0025] Among them, K s 、H1、H2、H3、V s are learnable parameters;
[0026] The temporal correlation matrix S′ is calculated based on the spatiotemporal attention matrix S:
[0027]
[0028] In this solution, the road network topology matrix is input into the graph convolutional network and combined with the spatiotemporal correlation matrix to perform model training to obtain the predicted speed. Specifically, the following steps are performed:
[0029] Input the road network topology matrix into the Laplace matrix L:
[0030]
[0031] Among them, A represents the input road network topology matrix, D is the degree matrix, specifically a diagonal matrix, and the diagonal elements are A ij Represents the element in row i and column j;
[0032] The graph convolutional network is specifically a graph convolutional network in the form of Chebyshev polynomials, which can be expressed as:
[0033]
[0034] Among them, *G represents the convolution operation of a graph, is the scaled normalized Laplacian matrix, λ max is the largest eigenvalue of L, θ′ k (k=0,1,…K) is the coefficient of the kth term of the Chebyshev polynomial, which is a learnable parameter;
[0035] The definition of the K-order Chebyshev polynomial is as follows:
[0036] T k (x) = 2xT k-1 (x)-T k-2 (x);
[0037] Combining the input road network topology matrix with the spatiotemporal correlation matrix, the final graph convolution formula is obtained:
[0038]
[0039] After model training is performed on the graph convolution formula, speed prediction is performed using the trained model.
[0040] In this solution, sampling the existing velocity data set to obtain a component data matrix of the relevant time series specifically includes:
[0041] The existing velocity data set is sampled in three dimensions to obtain the hour component data matrix, day component data matrix and week component data matrix of the relevant time series respectively;
[0042] The road network topology matrix is input into the graph convolutional network and combined with the spatiotemporal correlation matrix to perform model training as follows:
[0043] The road network topology matrix is input into the graph convolutional network and combined with the three-dimensional spatiotemporal association matrices respectively. The three-dimensional component data matrices are used to perform model training respectively and perform fusion output.
[0044] In this solution, before performing speed prediction using the trained model, the following steps are also included:
[0045] Constructed loss function
[0046] Among them, Y t represents the actual traffic speed, Indicates the prediction speed, L reg To avoid overfitting parameters, ω is a hyperparameter used to reduce the prediction error.
[0047] A second aspect of the present invention further provides a traffic speed prediction system based on a spatiotemporal attention graph convolutional network, comprising a memory and a processor, wherein the memory includes a traffic speed prediction method program based on a spatiotemporal attention graph convolutional network, and when the traffic speed prediction method program based on a spatiotemporal attention graph convolutional network is executed by the processor, the following steps are implemented:
[0048] Sampling the existing velocity data set to obtain a component data matrix of the relevant time series;
[0049] Constructing a temporal attention network;
[0050] Inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix;
[0051] Build a spatial attention network;
[0052] Inputting the temporal correlation matrix into the spatial attention network and fusing them to obtain a spatiotemporal correlation matrix;
[0053] Input the road network topology matrix into the graph convolutional network and combine it with the spatiotemporal correlation matrix to perform model training;
[0054] Speed prediction is performed using the trained model.
[0055] In this solution, sampling the existing velocity data set to obtain a component data matrix of the relevant time series specifically includes:
[0056] The existing velocity data set is sampled in three dimensions to obtain the hour component data matrix, day component data matrix and week component data matrix of the relevant time series respectively;
[0057] The road network topology matrix is input into the graph convolutional network and combined with the spatiotemporal correlation matrix to perform model training as follows:
[0058] The road network topology matrix is input into the graph convolutional network and combined with the three-dimensional spatiotemporal association matrices respectively. The three-dimensional component data matrices are used to perform model training respectively and perform fusion output.
[0059] In this solution, before using the trained model to predict speed, the following steps are also included:
[0060] The loss function constructed
[0061] Among them, Y t represents the actual traffic speed, Indicates the prediction speed, L reg To avoid overfitting parameters, ω is a hyperparameter used to reduce the prediction error.
[0062] A third aspect of the present invention provides a computer-readable storage medium, which includes a machine-readable program for a traffic speed prediction method based on a spatiotemporal attention graph convolutional network. When the program is executed by a processor, the method implements the steps of a traffic speed prediction method based on a spatiotemporal attention graph convolutional network as described in any one of the above items.
[0063] The present invention discloses a traffic speed prediction method and related device based on a spatiotemporal attention graph convolutional network. The method comprises: sampling an existing speed dataset to obtain a component data matrix of the time series; constructing a temporal attention network; inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix; constructing a spatial attention network; inputting the temporal correlation matrix into the spatial attention network to fuse the matrix to obtain a spatiotemporal correlation matrix; inputting a road network topology matrix into the graph convolutional network and combining it with the spatiotemporal correlation matrix for model training; and performing speed prediction using the trained model. By fusing the temporal attention network with the spatial attention network to form a spatiotemporal attention network, the temporal and spatial correlations of the traffic network are extracted. At the same time, the graph convolutional network is combined with information from adjacent nodes to continuously fuse information to predict traffic speed, thereby improving the accuracy of traffic speed prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1The flowchart of the traffic speed prediction method based on spatiotemporal attention graph convolutional network of the present application is shown;
[0065] Figure 2 A block diagram of a traffic speed prediction system based on a spatiotemporal attention graph convolutional network is shown in the present invention. DETAILED DESCRIPTION
[0066] In order to more clearly understand the above-mentioned objects, features and advantages of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that, in the absence of conflict, the embodiments of the present application and the features therein can be combined with each other.
[0067] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the scope of protection of the present invention is not limited to the specific embodiments disclosed below.
[0068] Figure 1 A flow chart of a traffic speed prediction method based on a spatiotemporal attention graph convolutional network is shown in the present application.
[0069] like Figure 1 As shown, the present application discloses a traffic speed prediction method based on spatiotemporal attention graph convolutional network, comprising the following steps:
[0070] S102, sampling the existing velocity data set to obtain a component data matrix of the relevant time series;
[0071] S104, constructing a temporal attention network;
[0072] S106, inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix;
[0073] S108, building a spatial attention network;
[0074] S110, inputting the temporal correlation matrix into the spatial attention network to fuse them to obtain a spatiotemporal correlation matrix;
[0075] S112, inputting the road network topology matrix into the graph convolutional network and combining it with the spatiotemporal correlation matrix to perform model training;
[0076] S114, performing speed prediction using the trained model.
[0077] It should be noted that, first, data sampling is performed based on the acquired data to obtain relevant time series data, and speed features are extracted from the sampled data. A temporal attention network is constructed and the sampled data is input into the constructed temporal attention network to extract the temporal correlation between speeds. Then, a spatial attention network is constructed and the processed results are used as input into the constructed spatial attention network to fuse and extract spatiotemporal correlations.
[0078] It should be noted that, next, a spatiotemporal attention graph convolutional model is constructed based on the road network matrix. This model is trained using the spatiotemporal correlation data obtained through GCN training and combined with the road network topology map. Finally, speed prediction is performed based on the trained model.
[0079] The present invention provides a traffic speed prediction method based on a spatiotemporal attention graph convolutional network. By fusing the temporal attention network with the spatial attention network to form a spatiotemporal attention network, the temporal and spatial correlation of the traffic network is extracted. At the same time, the traffic speed is predicted by continuously fusing the information of adjacent nodes in combination with the graph convolutional network (GCN). The accuracy of traffic speed prediction is improved by capturing the spatiotemporal correlation between traffic networks.
[0080] According to an embodiment of the present invention, sampling the existing velocity data set to obtain a component data matrix of the relevant time series specifically includes:
[0081] The existing velocity data set is sampled in three dimensions to obtain the hour component data matrix, day component data matrix and week component data matrix of the relevant time series respectively;
[0082] The road network topology matrix is input into the graph convolutional network and combined with the spatiotemporal correlation matrix to perform model training as follows:
[0083] The road network topology matrix is input into the graph convolutional network and combined with the three-dimensional spatiotemporal association matrices respectively. The three-dimensional component data matrices are used to perform model training respectively and perform fusion output.
[0084] It should be noted that according to the rules of data set collection, data of three time dimensions are collected on the data set: data of three different time dimensions are collected separately, specifically Y h 、Y d and Y w , where Y h Represents the time component data matrix of the most recent time, Y d Represents the recent day component data matrix, Y wRepresents the most recent weekly component data matrix. These three time components share the same network structure. Based on the regularity of sampling data every 5 minutes, three sampling batches with different time dimensions can be divided. The sampled data is processed to extract speed features, and training and test sets are constructed based on these speed features. In this embodiment of the present invention, the traffic speed can be predicted for the next hour, so the time window is set to 12, and the last 12 time steps are extracted as test samples.
[0085] According to an embodiment of the present invention, inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix specifically includes:
[0086] Input the component data matrix into the temporal attention network to obtain the temporal attention matrix T:
[0087]
[0088] Among them, K e 、L1、L2、L3、V e is a learnable parameter, σ represents the sigmoid activation function, is the component data matrix, C r-1 Indicates the number of channels of the input data of the rth layer, T r-1 Indicates the length of the time dimension of the input data of the rth layer;
[0089] The temporal attention matrix T is normalized to capture the correlation strength between nodes according to the temporal attention matrix:
[0090]
[0091] T i,j Reflects the temporal correlation strength between time i and j, and multiplies the component data matrix to obtain the temporal correlation matrix
[0092]
[0093] It should be noted that in the temporal dimension, there is a correlation between traffic conditions in different time periods, and the correlation also varies under different circumstances. Similarly, the temporal attention mechanism is used to adaptively capture the temporal correlation between data.
[0094] Construct a time attention network. The main method is as follows: input the node velocity matrix of the sampled time series into the constructed time attention network, and obtain
[0095]
[0096] According to the input of the current layer, the time attention matrix T is dynamically calculated, where K e 、L1、L2、L3、V e is a learnable parameter. σ represents the sigmoid activation function, which is defined as follows:
[0097]
[0098] Represents the temporal association module of the rth layer. C r-1 Indicates the number of channels of the input data of the rth layer, T r-1 Indicates the length of the time dimension of the input data of the rth layer.
[0099] The T matrix is normalized and then calculated based on the temporal attention matrix to capture the strength of the association between nodes:
[0100]
[0101] T i,j Dynamically reflect the temporal correlation strength between time i and j, and multiply the original sampling matrix to obtain the complete temporal correlation matrix:
[0102]
[0103] According to an embodiment of the present invention, inputting the temporal correlation matrix into the spatial attention network to fuse the temporal and spatial correlation matrix specifically includes:
[0104] The temporal correlation matrix is input into the spatial attention network to obtain the spatiotemporal attention matrix S:
[0105]
[0106] Among them, K s 、H1、H2、H3、V s are learnable parameters;
[0107] The temporal correlation matrix S′ is calculated based on the spatiotemporal attention matrix S:
[0108]
[0109] It should be noted that in the spatial dimension, traffic conditions at different locations affect each other. This embodiment of the present invention uses a spatial attention mechanism to adaptively capture the dynamic interactions between nodes in the spatial dimension, fusing the matrix with temporal attention with the spatial attention network to generate a spatiotemporal attention matrix.
[0110] The output of the temporal attention network (temporal correlation matrix) is input into the spatial attention network for further fusion to obtain the spatiotemporal attention matrix S:
[0111]
[0112] According to the input of the temporal attention matrix, the spatiotemporal attention S is dynamically calculated, where K s 、H1、H2、H3、V s are learnable parameters.
[0113] The strength of the association between nodes is captured according to the calculated spatiotemporal attention matrix:
[0114]
[0115] S′ dynamically reflects the spatiotemporal correlation strength between time i and j;
[0116] The attention coefficients of the nodes are dynamically adjusted based on the obtained spatiotemporal correlation matrix S′ and the input road network adjacency matrix. This spatiotemporal correlation allows for a better understanding of the temporal and spatial correlation of road network speeds, providing a broader perspective on speed prediction.
[0117] According to an embodiment of the present invention, inputting the road network topology matrix into the graph convolutional network and combining it with the spatiotemporal correlation matrix to perform model training to obtain the predicted speed specifically includes:
[0118] Input the road network topology matrix into the Laplace matrix L:
[0119]
[0120] Among them, A represents the input road network topology matrix, D is the degree matrix, specifically a diagonal matrix, and the diagonal elements are A ij Represents the element in row i and column j;
[0121] The graph convolutional network is specifically a graph convolutional network in the form of Chebyshev polynomials, which can be expressed as:
[0122]
[0123] Among them, *G represents the convolution operation of a graph, is the scaled normalized Laplacian matrix, λ max is the largest eigenvalue of L, θ′ k (k=0,1,…K) is the coefficient of the kth term of the Chebyshev polynomial, which is a learnable parameter;
[0124] The definition of the K-order Chebyshev polynomial is as follows:
[0125] T k (x) = 2xT k-1 (x)-Tk-2 (x);
[0126] Combining the input road network topology matrix with the spatiotemporal correlation matrix, the final graph convolution formula is obtained:
[0127]
[0128] After model training is performed on the graph convolution formula, speed prediction is performed using the trained model.
[0129] It should be noted that traffic speed prediction based on graph convolutional networks is to predict future traffic conditions based on historical traffic data, and to construct a spatiotemporal attention graph convolutional network (STA-GCN) model through the spatiotemporal correlation matrix and the road network topology matrix.
[0130] In order to capture the relevance of the road network, the present invention uses graph convolution of Chebyshev polynomials to aggregate the information of neighboring nodes. According to the road network, the Laplace matrix is used:
[0131]
[0132] A represents the input road network topology matrix, D is the degree matrix, which is a diagonal matrix with diagonal elements. A ij Represents the element in row i and column j.
[0133] The graph convolutional network in Chebyshev polynomial form is expressed as: Where *G represents a graph convolution operation. Since the convolution operation of the graph signal is equal to the Fourier transform of the product graph of these signals that have been converted into the spectral domain, the above formula can be understood as Fourier transforming g Θ and x are converted to the spectral domain respectively, and then they are transformed and multiplied and Fourier inverse transformed to obtain the final result of the convolution operation. However, it is very difficult to directly perform eigenvalue decomposition on the Laplace matrix, especially for road networks. Therefore, the present invention uses Chebyshev polynomials to approximate but effectively solve this problem. is the scaled normalized Laplacian matrix, λ max is the largest eigenvalue of L, θ′ k (k=0,1,…K) is the coefficient of the kth term of the Chebyshev polynomial. It is a learnable parameter that is updated iteratively during model training by optimizing the loss function. The definition of the K-order Chebyshev polynomial is as follows:
[0134] T k (x) = 2xT k-1 (x)-T k-2 (x);
[0135] Solving this formula using the approximate expansion of Chebyshev polynomials corresponds to extracting information about each surrounding node.
[0136] Combining the input road network adjacency matrix with the obtained spatiotemporal correlation matrix, we get the final graph convolution formula:
[0137]
[0138] The spatiotemporal correlation of the road network is extracted through the spatiotemporal attention mechanism, and the road network matrix is combined for modeling to train networks in three different time dimensions.
[0139] After learning the same network in three different time dimensions, the fusion output is:
[0140]
[0141] For the three time dimensions, the predicted nodes have different dependencies on each dimension, so the influence weights of the three components of each node are different and should be learned from historical data. Where ⊙ is the Hada-Darma product. W h 、W d and W w is a learning parameter that reflects the influence of the three-dimensional time component on the prediction target. The prediction speed is obtained based on the final fusion output.
[0142] According to an embodiment of the present invention, before performing speed prediction using the trained model, the method further includes:
[0143] Constructed loss function
[0144] Among them, Y t represents the actual traffic speed, Indicates the prediction speed, L reg To avoid overfitting parameters, ω is a hyperparameter used to reduce the prediction error.
[0145] It should be noted that based on the comparison between the predicted speed and the actual speed of the spatiotemporal attention graph convolution model, a new loss function calculation method is proposed, which is continuously updated at each iteration to speed up the model training speed. This method can make the networks in three different time dimensions converge simultaneously.
[0146] The constructed loss function is defined as follows:
[0147] The constructed loss function is
[0148] where Y t represents the actual traffic speed, represents the prediction speed, Used to minimize the error between actual traffic speed and prediction.reg It helps to avoid the overfitting problem, while ω is a hyperparameter that minimizes the error between the actual traffic speed and the predicted traffic speed.
[0149] The spatiotemporal attention mechanism can learn the implicit spatiotemporal correlations between nodes based on the features of each node in the input data. Since the attention scores between nodes are dynamically calculated based on the input, it can also capture changes in the topological structure of the road network. In addition, since the spatial self-attention aggregates the information of all nodes, it can also capture the spatial correlation of the road network from a global perspective.
[0150] Figure 2 A block diagram of a traffic speed prediction system based on a spatiotemporal attention graph convolutional network is shown in the present invention.
[0151] like Figure 2 As shown, the present invention discloses a traffic speed prediction system 2 based on a spatiotemporal attention graph convolutional network, comprising a memory 21 and a processor 22. The memory 21 includes a traffic speed prediction method program based on a spatiotemporal attention graph convolutional network. When the traffic speed prediction method program based on a spatiotemporal attention graph convolutional network is executed by the processor 22, the following steps are implemented:
[0152] Sampling the existing velocity data set to obtain a component data matrix of the relevant time series;
[0153] Constructing a temporal attention network;
[0154] Inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix;
[0155] Build a spatial attention network;
[0156] Inputting the temporal correlation matrix into the spatial attention network and fusing them to obtain a spatiotemporal correlation matrix;
[0157] Input the road network topology matrix into the graph convolutional network and combine it with the spatiotemporal correlation matrix to perform model training;
[0158] Speed prediction is performed using the trained model.
[0159] It should be noted that, first, data sampling is performed based on the acquired data to obtain relevant time series data, and speed features are extracted from the sampled data. A temporal attention network is constructed and the sampled data is input into the constructed temporal attention network to extract the temporal correlation between speeds. Then, a spatial attention network is constructed and the processed results are used as input into the constructed spatial attention network to fuse and extract spatiotemporal correlations.
[0160] It should be noted that, next, a spatiotemporal attention graph convolutional model is constructed based on the road network matrix. This model is trained using the spatiotemporal correlation data obtained through GCN training and combined with the road network topology map. Finally, speed prediction is performed based on the trained model.
[0161] The present invention provides a traffic speed prediction method based on a spatiotemporal attention graph convolutional network. By fusing the temporal attention network with the spatial attention network to form a spatiotemporal attention network, the temporal and spatial correlation of the traffic network is extracted. At the same time, the traffic speed is predicted by continuously fusing the information of adjacent nodes in combination with the graph convolutional network (GCN). The accuracy of traffic speed prediction is improved by capturing the spatiotemporal correlation between traffic networks.
[0162] According to an embodiment of the present invention, sampling the existing velocity data set to obtain a component data matrix of the relevant time series specifically includes:
[0163] The existing velocity data set is sampled in three dimensions to obtain the hour component data matrix, day component data matrix and week component data matrix of the relevant time series respectively;
[0164] The road network topology matrix is input into the graph convolutional network and combined with the spatiotemporal correlation matrix to perform model training as follows:
[0165] The road network topology matrix is input into the graph convolutional network and combined with the three-dimensional spatiotemporal association matrices respectively. The three-dimensional component data matrices are used to perform model training respectively and perform fusion output.
[0166] It should be noted that according to the rules of data set collection, data of three time dimensions are collected on the data set: data of three different time dimensions are collected separately, specifically Y h 、Y d and Y w , where Y h Represents the time component data matrix of the most recent time, Y d Represents the recent day component data matrix, Y w Represents the most recent weekly component data matrix. These three time components share the same network structure. Based on the regularity of sampling data every 5 minutes, three sampling batches with different time dimensions can be divided. The sampled data is processed to extract speed features, and training and test sets are constructed based on these speed features. In this embodiment of the present invention, the traffic speed can be predicted for the next hour, so the time window is set to 12, and the last 12 time steps are extracted as test samples.
[0167] According to an embodiment of the present invention, inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix specifically includes:
[0168] Input the component data matrix into the temporal attention network to obtain the temporal attention matrix T:
[0169]
[0170] Among them, K e 、L1、L2、L3、V e is a learnable parameter, σ represents the sigmoid activation function, is the component data matrix, C r-1 Indicates the number of channels of the input data of the rth layer, T r-1 Indicates the length of the time dimension of the input data of the rth layer;
[0171] The temporal attention matrix T is normalized to capture the correlation strength between nodes according to the temporal attention matrix:
[0172]
[0173] T i,j Reflects the temporal correlation strength between time i and j, and multiplies the component data matrix to obtain the temporal correlation matrix
[0174]
[0175] It should be noted that in the temporal dimension, there is a correlation between traffic conditions in different time periods, and the correlation also varies under different circumstances. Similarly, the temporal attention mechanism is used to adaptively capture the temporal correlation between data.
[0176] Construct a time attention network. The main method is as follows: input the node velocity matrix of the sampled time series into the constructed time attention network, and obtain
[0177]
[0178] According to the input of the current layer, the time attention matrix T is dynamically calculated, where K e 、L1、L2、L3、V e is a learnable parameter. σ represents the sigmoid activation function, which is defined as follows:
[0179]
[0180] Represents the temporal association module of the rth layer. Cr-1 Indicates the number of channels of the input data of the rth layer, T r-1 Indicates the length of the time dimension of the input data of the rth layer.
[0181] The T matrix is normalized and then calculated based on the temporal attention matrix to capture the strength of the association between nodes:
[0182]
[0183] T i,j Dynamically reflect the temporal correlation strength between time i and j, and multiply the original sampling matrix to obtain the complete temporal correlation matrix:
[0184]
[0185] According to an embodiment of the present invention, inputting the temporal correlation matrix into the spatial attention network to fuse the temporal and spatial correlation matrix specifically includes:
[0186] The temporal correlation matrix is input into the spatial attention network to obtain the spatiotemporal attention matrix S:
[0187]
[0188] Among them, K s 、H1、H2、H3、V s are learnable parameters;
[0189] The temporal correlation matrix S′ is calculated based on the spatiotemporal attention matrix S:
[0190]
[0191] It should be noted that in the spatial dimension, traffic conditions at different locations affect each other. This embodiment of the present invention uses a spatial attention mechanism to adaptively capture the dynamic interactions between nodes in the spatial dimension, fusing the matrix with temporal attention with the spatial attention network to generate a spatiotemporal attention matrix.
[0192] The output of the temporal attention network (temporal correlation matrix) is input into the spatial attention network for further fusion to obtain the spatiotemporal attention matrix S:
[0193]
[0194] According to the input of the temporal attention matrix, the spatiotemporal attention S is dynamically calculated, where K s 、H1、H2、H3、V s are learnable parameters.
[0195] The strength of the association between nodes is captured according to the calculated spatiotemporal attention matrix:
[0196]
[0197] S′ dynamically reflects the spatiotemporal correlation strength between time i and j;
[0198] The attention coefficients of the nodes are dynamically adjusted based on the obtained spatiotemporal correlation matrix S′ and the input road network adjacency matrix. This spatiotemporal correlation allows for a better understanding of the temporal and spatial correlation of road network speeds, providing a broader perspective on speed prediction.
[0199] According to an embodiment of the present invention, inputting the road network topology matrix into the graph convolutional network and combining it with the spatiotemporal correlation matrix to perform model training to obtain the predicted speed specifically includes:
[0200] Input the road network topology matrix into the Laplace matrix L:
[0201]
[0202] Among them, A represents the input road network topology matrix, D is the degree matrix, specifically a diagonal matrix, and the diagonal elements are A ij Represents the element in row i and column j;
[0203] The graph convolutional network is specifically a graph convolutional network in the form of Chebyshev polynomials, which can be expressed as:
[0204]
[0205] Among them, *G represents the convolution operation of a graph, is the scaled normalized Laplacian matrix, λ max is the largest eigenvalue of L, θ′ k (k=0,1,…K) is the coefficient of the kth term of the Chebyshev polynomial, which is a learnable parameter;
[0206] The definition of the K-order Chebyshev polynomial is as follows:
[0207] T k (x) = 2xT k-1 (x)-T k-2 (x);
[0208] Combining the input road network topology matrix with the spatiotemporal correlation matrix, the final graph convolution formula is obtained:
[0209]
[0210] After model training is performed on the graph convolution formula, speed prediction is performed using the trained model.
[0211] It should be noted that traffic speed prediction based on graph convolutional networks is to predict future traffic conditions based on historical traffic data, and to construct the STA-GCN model through the spatiotemporal correlation matrix and the road network topology matrix.
[0212] In order to capture the relevance of the road network, the present invention uses graph convolution of Chebyshev polynomials to aggregate the information of neighboring nodes. According to the road network, the Laplace matrix is used:
[0213]
[0214] A represents the input road network topology matrix, D is the degree matrix, which is a diagonal matrix with diagonal elements. A ij Represents the element in row i and column j.
[0215] The graph convolutional network in Chebyshev polynomial form is expressed as: Where *G represents a graph convolution operation. Since the convolution operation of the graph signal is equal to the Fourier transform of the product graph of these signals that have been converted into the spectral domain, the above formula can be understood as Fourier transforming g Θ and x are converted to the spectral domain respectively, and then they are transformed and multiplied and Fourier inverse transformed to obtain the final result of the convolution operation. However, it is very difficult to directly perform eigenvalue decomposition on the Laplace matrix, especially for road networks. Therefore, the present invention uses Chebyshev polynomials to approximate but effectively solve this problem. is the scaled normalized Laplacian matrix, λ max is the largest eigenvalue of L, θ′ k (k=0,1,…K) is the coefficient of the kth term of the Chebyshev polynomial. It is a learnable parameter that is updated iteratively during model training by optimizing the loss function. The definition of the K-order Chebyshev polynomial is as follows:
[0216] T k (x) = 2xT k-1 (x)-T k-2 (x);
[0217] Solving this formula using the approximate expansion of Chebyshev polynomials corresponds to extracting information about each surrounding node.
[0218] Combining the input road network adjacency matrix with the obtained spatiotemporal correlation matrix, we get the final graph convolution formula:
[0219]
[0220] The spatiotemporal correlation of the road network is extracted through the spatiotemporal attention mechanism, and the road network matrix is combined for modeling to train networks in three different time dimensions.
[0221] After learning the same network in three different time dimensions, the fusion output is:
[0222]
[0223] For the three time dimensions, the predicted nodes have different dependencies on each dimension, so the influence weights of the three components of each node are different and should be learned from historical data. Where ⊙ is the Hada-Darma product. W h 、W d and W w is a learning parameter that reflects the influence of the three-dimensional time component on the prediction target. The prediction speed is obtained based on the final fusion output.
[0224] According to an embodiment of the present invention, before performing speed prediction using the trained model, the method further includes:
[0225] Constructed loss function
[0226] Among them, Y t represents the actual traffic speed, Indicates the prediction speed, L reg To avoid overfitting parameters, ω is a hyperparameter used to reduce the prediction error.
[0227] It should be noted that based on the comparison between the predicted speed and the actual speed of the spatiotemporal attention graph convolution model, a new loss function calculation method is proposed, which is continuously updated at each iteration to speed up the model training speed. This method can make the networks in three different time dimensions converge simultaneously.
[0228] The constructed loss function is defined as follows:
[0229] The constructed loss function is
[0230] where Y t represents the actual traffic speed, represents the prediction speed, Used to minimize the error between actual traffic speed and prediction. reg It helps to avoid the overfitting problem, while ω is a hyperparameter that minimizes the error between the actual traffic speed and the predicted traffic speed.
[0231] The spatiotemporal attention mechanism can learn the implicit spatiotemporal correlations between nodes based on the features of each node in the input data. Since the attention scores between nodes are dynamically calculated based on the input, it can also capture changes in the topological structure of the road network. In addition, since the spatial self-attention aggregates the information of all nodes, it can also capture the spatial correlation of the road network from a global perspective.
[0232] A third aspect of the present invention provides a computer-readable storage medium, which includes a machine-readable program for a traffic speed prediction method based on a spatiotemporal attention graph convolutional network. When the program is executed by a processor, the method implements the steps of a traffic speed prediction method based on a spatiotemporal attention graph convolutional network as described in any one of the above items.
[0233] The present invention discloses a traffic speed prediction method and related device based on a spatiotemporal attention graph convolutional network. The method comprises: sampling an existing speed dataset to obtain a component data matrix of the time series; constructing a temporal attention network; inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix; constructing a spatial attention network; inputting the temporal correlation matrix into the spatial attention network to fuse the matrix to obtain a spatiotemporal correlation matrix; inputting a road network topology matrix into the graph convolutional network and combining it with the spatiotemporal correlation matrix for model training; and performing speed prediction using the trained model. By fusing the temporal attention network with the spatial attention network to form a spatiotemporal attention network, the temporal and spatial correlations of the traffic network are extracted. Simultaneously, a graph convolutional network (GCN) is used to continuously fuse information from adjacent nodes to predict traffic speed. By capturing the spatiotemporal correlations between traffic networks, the accuracy of traffic speed prediction is improved.
[0234] The following is an application example of a traffic speed prediction method based on spatiotemporal attention graph convolutional network provided by the present invention:
[0235] 1. Data Preprocessing
[0236] The present invention conducts experiments on the PEMSD4 and PEMSD8 datasets. The PEMSD4 dataset contains traffic data (including flow rate, speed, and lane occupancy) collected from 307 loop detectors in the San Francisco Bay Area from January 1, 2018, to February 28, 2018. The PEMSD8 dataset contains traffic data (including flow rate, speed, and lane occupancy) collected from 170 loop detectors in the San Bernardino area from July 1, 2016, to August 31, 2016. The raw data consists of two parts: one is traffic data, and the other is the distance between each sensor. Data preprocessing involves splitting the dataset to create training and test samples.
[0237] 2. Model Training
[0238] The processed data set is loaded into formula (1) to formula (5) in the above embodiment to obtain the spatiotemporal correlation matrix S′ between nodes.
[0239] Combined with the input road network correlation matrix A, the spatiotemporal correlation matrix S′ is input into formula (6) for model training. Then, the mean absolute error (MAE) and root mean square error (RMSE) are calculated. The two performance indicators are defined as follows:
[0240]
[0241]
[0242] where X i , Represent the i-th element in the true value and the predicted value respectively, and n represents the total number of elements.
[0243] Table 1 Comparison of the present invention with HA, ARIMA and VAR on PEMSD4 data
[0244]
[0245] Table 2 Comparison of the present invention with HA, ARIMA and VAR on PEMSD8 data
[0246]
[0247] It can be found that the present invention has achieved good prediction results at all levels. The graph network that integrates spatiotemporal correlation has achieved good results in prediction accuracy, and has certain reference value and actual economic benefits.
[0248] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0249] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed across multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this embodiment.
[0250] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0251] Those skilled in the art will appreciate that all or part of the steps of the above-mentioned method embodiments may be implemented by hardware associated with program instructions, and the aforementioned program may be stored in a computer-readable storage medium. When the program is executed, the program executes the steps of the above-mentioned method embodiments. The aforementioned storage medium includes various media that can store program codes, such as mobile storage devices, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.
[0252] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
Claims
1. A traffic speed prediction method based on spatiotemporal attention graph convolutional network, characterized in that: The following steps are involved: Sampling the existing velocity data set to obtain a component data matrix of the relevant time series; Constructing a temporal attention network; Inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix; Constructing a spatial attention network; Inputting the temporal correlation matrix into the spatial attention network and fusing them to obtain a spatiotemporal correlation matrix; Inputting the road network topology matrix into the graph convolutional network and combining it with the spatiotemporal association matrix to perform model training; Use the trained model to predict speed; The step of inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix specifically includes: The component data matrix is input into the temporal attention network to obtain the temporal attention matrix T: Among them, K e , L1, L2, L3, V e is a learnable parameter, σ represents the sigmoid activation function, is the component data matrix, C r-1 Indicates the number of channels of the input data of the rth layer, T r-1 Represents the length of the time dimension of the input data of the rth layer; The temporal attention matrix T is normalized to capture the correlation strength between nodes according to the temporal attention matrix: T i,j Reflects the temporal correlation strength between time i and j, and multiplies it with the component data matrix to obtain the temporal correlation matrix The step of inputting the temporal correlation matrix into the spatial attention network and fusing the temporal and spatial correlation matrix specifically includes: The temporal association matrix is input into the spatial attention network to obtain the spatiotemporal attention matrix S: Among them, K s 、H1、H2、H3、V s are learnable parameters; The temporal correlation matrix S′ is calculated based on the spatiotemporal attention matrix S: The road network topology matrix is input into the graph convolutional network, and combined with the spatiotemporal association matrix to perform model training to obtain the predicted speed specifically includes: Input the road network topology matrix into the Laplace matrix L: Among them, A represents the input road network topology matrix, D is the degree matrix, specifically a diagonal matrix, and the elements on the diagonal are A ij represents the element in row i and column j; The graph convolution network is specifically a graph convolution network in the form of Chebyshev polynomials, which can be expressed as: Among them, *G represents a convolution operation of a graph, is the scaled normalized Laplace matrix, λmax is the largest eigenvalue of L, θ′ k (k=0,1,…K) is the coefficient of the kth term of the Chebyshev polynomial, which is a learnable parameter; The definition of the Chebyshev polynomial of order K is as follows: T k (x)=2xT k-1 (x)-T k-2 (x); Combining the input road network topology matrix with the spatiotemporal correlation matrix, the final graph convolution formula is obtained: After model training is performed on the graph convolution formula, speed prediction is performed using the trained model; The sampling of the existing velocity data set to obtain the component data matrix of the relevant time series specifically includes: The existing velocity data set is sampled in three dimensions to obtain the hour component data matrix, day component data matrix and week component data matrix of the time series respectively; The road network topology matrix is input into the graph convolutional network and combined with the spatiotemporal association matrix to perform model training as follows: The road network topology matrix is input into the graph convolutional network, and is respectively combined with the spatiotemporal association matrices of the three dimensions, and the component data matrices of the three dimensions are respectively used for model training, and a fusion output is performed; Before the speed prediction is performed using the trained model, the method further includes: Constructed loss function Among them, Y t represents the actual traffic speed, Indicates the prediction speed, L reg To avoid overfitting parameters, ω is a hyperparameter used to reduce the prediction error.
2. A traffic speed prediction system based on a spatiotemporal attention graph convolutional network, comprising a memory and a processor, wherein the memory comprises a traffic speed prediction method program based on a spatiotemporal attention graph convolutional network, and when the traffic speed prediction method program based on a spatiotemporal attention graph convolutional network is executed by the processor, the following steps are implemented: Sampling the existing velocity data set to obtain a component data matrix of the relevant time series; Constructing a temporal attention network; Inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix; Constructing a spatial attention network; Inputting the temporal correlation matrix into the spatial attention network and fusing them to obtain a spatiotemporal correlation matrix; Inputting the road network topology matrix into the graph convolutional network and combining it with the spatiotemporal association matrix to perform model training; Use the trained model to predict speed; The step of inputting the component data matrix into the temporal attention network to obtain a temporal correlation matrix specifically includes: The component data matrix is input into the temporal attention network to obtain the temporal attention matrix T: Among them, K e , L1, L2, L3, V e is a learnable parameter, σ represents the sigmoid activation function, is the component data matrix, C r-1 Indicates the number of channels of the input data of the rth layer, T r-1 Represents the length of the time dimension of the input data of the rth layer; The temporal attention matrix T is normalized to capture the correlation strength between nodes according to the temporal attention matrix: T i,j Reflects the temporal correlation strength between time i and j, and multiplies it with the component data matrix to obtain the temporal correlation matrix The step of inputting the temporal correlation matrix into the spatial attention network and fusing the temporal and spatial correlation matrix specifically includes: The temporal association matrix is input into the spatial attention network to obtain the spatiotemporal attention matrix S: Among them, K s 、H1、H2、H3、V s are learnable parameters; The temporal correlation matrix S′ is calculated based on the spatiotemporal attention matrix S: The road network topology matrix is input into the graph convolutional network, and combined with the spatiotemporal association matrix to perform model training to obtain the predicted speed specifically includes: Input the road network topology matrix into the Laplace matrix L: Among them, A represents the input road network topology matrix, D is the degree matrix, specifically a diagonal matrix, and the elements on the diagonal are A ij represents the element in row i and column j; The graph convolution network is specifically a graph convolution network in the form of Chebyshev polynomials, which can be expressed as: Among them, *G represents a convolution operation of a graph, is the scaled normalized Laplacian matrix, λ max is the largest eigenvalue of L, θ′ k (k=0,1,…K) is the coefficient of the kth term of the Chebyshev polynomial, which is a learnable parameter; The definition of the Chebyshev polynomial of order K is as follows: T k (x)=2xT k-1 (x)-T k-2 (x); Combining the input road network topology matrix with the spatiotemporal correlation matrix, the final graph convolution formula is obtained: After model training is performed on the graph convolution formula, speed prediction is performed using the trained model; The sampling of the existing velocity data set to obtain the component data matrix of the relevant time series specifically includes: The existing velocity data set is sampled in three dimensions to obtain the hour component data matrix, day component data matrix and week component data matrix of the time series respectively; The road network topology matrix is input into the graph convolutional network and combined with the spatiotemporal association matrix to perform model training as follows: The road network topology matrix is input into the graph convolutional network, and is respectively combined with the spatiotemporal association matrices of the three dimensions, and the component data matrices of the three dimensions are respectively used for model training, and a fusion output is performed; Before the speed prediction is performed using the trained model, the method further includes: Constructed loss function Among them, Y t represents the actual traffic speed, Indicates the prediction speed, L reg To avoid overfitting parameters, ω is a hyperparameter used to reduce the prediction error.
3. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a traffic speed prediction method program based on a spatiotemporal attention graph convolutional network. When the traffic speed prediction method program based on a spatiotemporal attention graph convolutional network is executed by a processor, the steps of a traffic speed prediction method based on a spatiotemporal attention graph convolutional network as claimed in claim 1 are implemented.
