Traffic flow prediction method
By introducing adaptive spatiotemporal embedding and dynamic adjacency matrix into the traffic flow prediction model, combining the maximum mutual information coefficient matrix and diffusion graph convolution, the problem of insufficient utilization of spatiotemporal correlation and periodic features in traditional methods is solved, and the prediction is significantly improved Accuracy and model understanding of traffic network dependence.
Patent Information
- Application Number
- CN202411060551.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-11-15
AI Technical Summary
Traditional traffic flow prediction methods are difficult to capture complex spatial and temporal correlations and dynamic spatial dependencies, and fail to fully utilize the periodic features in the traffic network, resulting in insufficient prediction accuracy.
The traffic flow prediction model is adopted, including an embedding layer, a multi-graph convolution layer and a spatiotemporal multi-head self-attention layer. The space-time features are captured through adaptive spatiotemporal embedding and dynamic adjacency matrix, combined with the maximum mutual information coefficient matrix and diffusion graph convolution, and extracted Real-time changes in traffic networks and dependencies between nodes.
It significantly improves the accuracy of traffic flow prediction, especially in the mid-term prediction task, which can more comprehensively understand and predict traffic flow fluctuations, and enhances the model's modeling ability on space-time dependence.
Smart Images

Figure CN118968756A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent transportation technology, and in particular to a traffic flow prediction method. Background Art
[0002] With the acceleration of urbanization, urban traffic congestion has become an increasingly prominent problem, and has become an important factor affecting urban operation efficiency and residents' quality of life. As a key technology in intelligent transportation systems, traffic flow prediction is of great significance for traffic management and planning. However, traffic flow prediction faces many challenges, including how to effectively alleviate urban traffic congestion, how to extract and utilize spatiotemporal information in traffic data, and how to deal with dynamically changing spatial dependencies in traffic networks.
[0003] Traditional traffic flow prediction methods, such as Kalman filtering and autoregressive integrated moving average (ARIMA), are mainly based on linear models and are difficult to capture complex spatiotemporal correlations. In recent years, deep learning-based methods, especially graph neural networks (GNNs), have been widely used in traffic flow prediction due to their advantages in extracting spatial features of graph-structured data. However, these methods usually rely on static adjacency matrices to capture spatial dependencies, ignoring the dynamic nature of traffic relationships between nodes in traffic networks. In addition, existing models often ignore the long-term temporal correlations between nodes at different time steps when extracting temporal features.
[0004] In order to solve the above problems, researchers have proposed a variety of improvement methods, such as dynamic graph convolution and attention mechanism, to improve the accuracy of traffic prediction. Although these methods have improved the model performance to a certain extent, they still have limitations. For example, the stacking of spatiotemporal graph modules makes the model complex, with a large number of parameters, and the performance improvement is limited. In addition, the existing models are also insufficient in processing the periodic characteristics of traffic flow data, and fail to fully utilize these characteristics to improve the prediction accuracy. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides a traffic flow prediction method, comprising the following steps:
[0006] S1. Construct a traffic flow prediction model. The traffic flow prediction model includes an embedding layer, a multi-graph convolution layer, a spatiotemporal multi-head self-attention layer, and an output layer. The embedding layer includes original feature embedding, period embedding, and adaptive spatiotemporal embedding. The period embedding includes daily embedding and weekly embedding.
[0007] S2, obtain the historical traffic data of the urban area traffic network and the traffic congestion situation, and send the historical traffic data to the embedding module in the embedding layer, and fuse the original traffic flow sequence to obtain a new traffic flow sequence containing spatiotemporal information features. The historical traffic data includes traffic flow, traffic speed and road occupancy rate;
[0008] S3. Train the traffic flow prediction model, input the original traffic flow sequence into the embedding layer in sequence to fuse the spatiotemporal information, extract the original feature embedding, daily embedding, weekly embedding and adaptive spatiotemporal feature embedding in the traffic data respectively, and splice the four embeddings together to get the output of the embedding layer;
[0009] The spatial features are extracted through multi-graph convolutional layers, which include adjacency matrix, maximum mutual information coefficient matrix, dynamic adaptive adjacency matrix and diffusion graph convolution operation. The dynamic adaptive adjacency matrix is used to capture the real-time changes in the traffic network and the dependencies between nodes.
[0010] Capturing spatiotemporal correlations through a spatiotemporal multi-head self-attention layer, which includes temporal multi-head self-attention and spatial multi-head self-attention.
[0011] In the output layer, the extracted spatiotemporal information is passed through a fully connected layer, and finally the final prediction result is output through the activation function and linear transformation layer;
[0012] S4. Obtain the current traffic data, input the obtained current traffic data into the trained traffic flow prediction model, and output the traffic flow in the future time period.
[0013] The technical solution further defined in the present invention is:
[0014] Furthermore, in step S2, the acquired historical traffic data is divided into a training set, a validation set, and a test set in a ratio of 6:2:2.
[0015] As described above, in a traffic flow prediction method, in step S2, based on the acquired historical traffic data, its traffic network is modeled as a directed weighted graph G = (V, E, A), wherein V and E represent the set of nodes and edges of the graph respectively, and in the traffic network, V and E represent the set of sensors and roads; |V| = N represents the number of sensors; A represents the adjacency matrix of the graph, which is used to describe the relationship between nodes; and the processed traffic data is regarded as a graph signal sequence on the directed weighted graph.
[0016] As described above, in a traffic flow prediction method, in step S2, the processed historical traffic data is regarded as a graph signal sequence on a directed weighted graph. Specifically, in a window [t+1, t+T] with a time step of T, the traffic data is represented as Xt+1:t+T =[X t+1 , X t+2 , ...X t+T ]∈R N×T×F , where X t+T ∈R N×F represents the features of N nodes at time T, t represents the current time step, R represents a set of real numbers, and F represents the number of features, including speed and traffic flow;
[0017] Assuming that the number of features F only includes traffic flow, then F = 1, and the data of the past T′ time steps are represented by X t-T′+1:t =[X t+1 , X t+2 , ...X t+T ]∈R N×T×1 The goal of traffic prediction is to learn a mapping f given a directed weighted graph G and historical traffic data to transform past data X t-T′+1:t Mapping to future data is as follows:
[0018] f(X t-T′+1:t , G) = X t+1:t+T
[0019] Among them, t represents the current time step.
[0020] As described above, in a traffic flow prediction method, in step S2, the past 12 time steps are used to predict the data of the next 12 time steps, so T′=T=12.
[0021] As described above, in a traffic flow prediction method, in step S3, in the embedding layer, a full connection method is used to obtain the original feature embedding Among them, D da represents the embedding dimension, then the formula for embedding the original feature is:
[0022] C da =linear embedding (X t-T+1:t )
[0023] Among them, linear represents the linear layer, X t-T+1:t Represents the characteristics of the input;
[0024] Embed by day and weekly embeds The specific extraction method is as follows: First, initialize two trainable embedding matrices and Among them, D d and D w Respectively represent the dimensions of day embedding and week embedding, N d Indicates the number of samples of traffic time series per day, N wIndicates the number of days per week, that is, N w =7; the input time series is used as the index of the embedding layer, and the final period embedding C is obtained by extracting the embedding matrix d and C w ;
[0025] Then embed the adaptive spatiotemporal features into The output C of the embedding layer is obtained by concatenating the original feature embedding, daily embedding, and weekly embedding. O ∈R T×N×D :
[0026] C O =C da ||C d ||C w ||C a
[0027] Among them, || represents the concatenation operation, and the final embedded dimension is D = D da +D d +D w +D a .
[0028] As described above, in a traffic flow prediction method, in step S3, in the multi-image convolution layer, the data output by integrating the features of the embedding layer is input into the multi-image convolution layer to extract spatial features. First, the adjacency matrix is defined:
[0029]
[0030] Where A represents the adjacency matrix, which is a square array used to represent the structure of the graph. Each element in the matrix represents the link status between nodes in the graph. ij represents an element in the adjacency matrix A, e ij ∈E means that there is an edge connecting the two nodes, otherwise a ij is 0;
[0031] The maximum mutual information coefficient matrix is in, represents the sequence of sensor i of feature F, represents the sequence of j sensors of feature F, and A mic ∈R N×N×F ; In multi-graph convolution, each feature vector is weighted and concatenated, and then passed to the diffusion graph convolution operation for processing;
[0032] In the dynamic adaptive adjacency matrix, two embedding matrices W1 and W2 are constructed for learning spatial features. Among them, C emb Represents the dimension of embedding, which is a fixed value; dynamic adaptive weighting matrix Aadp Calculated from W1 and W2:
[0033] A adp =softmax(relu(W1W2 T ))
[0034] Among them, relu() represents the activation function, softmax() is used to normalize the matrix, and W1 and W2 are randomly initialized.
[0035] As described above, in a traffic flow prediction method, in a multi-graph convolution layer, the adjacency matrix is first normalized before the multi-graph convolution operation is performed. First, the degree matrix D is calculated. The degree matrix D is a diagonal matrix with diagonal elements D ii The value of is the in-degree of each row of the adjacency matrix, that is, D ii =Rowsum(A i ); the Laplacian matrix is L = DA, and the symmetric normalized Laplacian matrix is defined as A SYS =ID -1 / 2 AD -1 / 2 , and the random walk matrix is defined as A r =D -1 A, among which, A i represents the i-th row of the adjacency matrix A, I represents the identity matrix, and r represents a random walk; if is the normalized adjacency matrix, For input, is a learnable weight, then the multi-graph convolution is represented as
[0036] As mentioned above, a traffic flow prediction method uses diffusion graph convolution to associate traffic flow with the diffusion process in the multi-graph convolution layer to model spatial correlation. The diffusion process is described in the form of random walks and includes forward propagation P f =A / rowsum(A) and back propagation P b =A T / rowsum(A T ) in two directions, the multi-graph convolution layer combines the diffusion graph convolution and the adaptive adjacency matrix A in each graph convolution layer. adp and A mic Combined with the previous one, and using the second-order diffusion convolution (K=2) to mine the spatial information, we get the final multi-graph convolution formula:
[0037]
[0038] Among them, Z represents the final feature representation, represents the forward propagation matrix of the kth layer, represents the back propagation matrix of the kth layer, represents the adaptive adjacency matrix of the kth layer, represents the maximum mutual information coefficient matrix of the kth layer, X represents the input feature matrix, W k1 Represents the kth layer and The associated weight matrix, W k2 Represents the kth layer and and The associated weight matrix.
[0039] As described above, in a traffic flow prediction method, in step S3, in the spatiotemporal multi-head self-attention layer, the output of the multi-graph convolution layer is mapped to a higher dimensional space using three linear changes to obtain three matrices Q, K, and V. Multi-head self-attention is applied on the time axis and the space axis respectively. The temporal self-attention mechanism is specifically as follows: first, the input input∈R T×N×D Mapping obtains the values of matrices Q, K, and V: as well as Where Z represents the final feature representation of the multi-image convolutional layer, Q, K, Q (t) , K (t) and V (te) Represents the query, key and value of the node respectively; All represent learnable parameters;
[0040] Q and K T Divide by matrix multiplication Scale it and then perform a Softmax on it to get the time attention score:
[0041]
[0042] Among them, A (t) ∈R N×T×T , multiplied by the value valeus, the final time attention output is: Z (t) =A (t) V (t) :
[0043] Expand the temporal self-attention to multi-head self-attention, map the input to h groups of matrices Q, K, V, get the output of multiple groups of attention, and splice them together to get the final temporal multi-head self-attention output: in, D t Set as D / h;
[0044] The spatial self-attention score Z is obtained by the same method as above (S)=SelfAttention(Z (t) ), the output of spatial multi-head self-attention is
[0045] The beneficial effects of the present invention are:
[0046] (1) In the present invention, for the task of traffic flow prediction, traditional embedding technology mainly focuses on the static properties of data, while the embedding strategy proposed in the present invention not only covers the embedding of basic features, but also incorporates the capture of the dynamic characteristics of time series and the periodic characteristics of spatial data; specifically, the present invention includes a fully connected layer to extract the original features, and introduces adaptive spatiotemporal embedding and periodic embedding, which correspond to the periodicity and dynamics of time series respectively; the periodic embedding is further refined into daily cycles and weekly cycles to capture the cyclical pattern of traffic flow; this multi-angle embedding technology enables the model to more comprehensively understand and predict the fluctuation of traffic flow;
[0047] (2) In the present invention, when processing traffic flow data, the traditional graph convolutional network relies on a static adjacency matrix, which limits the model's ability to capture the dynamic spatial relationship of the traffic network. To solve this problem, the present invention introduces a novel dynamic adaptive adjacency matrix that can adjust the connection weights between nodes based on real-time traffic data. Combined with the concept of maximum mutual information coefficient (MIC) and an adaptive weighting mechanism, this matrix can more accurately map the similarity and correlation of traffic patterns between nodes in the traffic network, thereby enhancing the graph convolutional network's ability to capture the dynamic spatial dependencies of traffic flows.
[0048] (3) In the present invention, in terms of capturing the long-term dependency of traffic flow time series and the global dependency of spatial data, existing models face challenges in simultaneously processing these two dependencies. To this end, the present invention integrates a multi-head spatiotemporal self-attention mechanism, which can process long-term dependencies in parallel in the temporal dimension and dynamically update node weights in the spatial dimension. This design not only enhances the model's understanding of direct interactions between nodes, but also enables it to identify and utilize indirect and remote node relationships, thereby more comprehensively predicting changes in traffic flow. The multi-head self-attention mechanism significantly improves the model's ability to model the spatiotemporal dependencies of traffic data, especially in medium-term prediction tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 It is a schematic diagram of the overall process of the present invention;
[0050] Figure 2 It is a structural schematic diagram of a flow prediction model in an embodiment of the present invention;
[0051] Figure 3 It is a heat map of the MIC matrix in the embodiment of the present invention;
[0052] Figure 4 This is an adaptive visualization scatter plot in an embodiment of the present invention. DETAILED DESCRIPTION
[0053] This embodiment provides a traffic flow prediction method, such as Figure 1 As shown, the following steps are included
[0054] S1. Construct a traffic flow prediction model. The traffic flow prediction model includes an embedding layer, a multi-graph convolution layer, a spatiotemporal multi-head self-attention layer, and an output layer. The embedding layer includes original feature embedding, periodic embedding, and adaptive spatiotemporal embedding. The periodic embedding includes daily embedding and weekly embedding.
[0055] S2. Obtain historical traffic data and traffic congestion conditions of the urban area traffic network, and send the historical traffic data to the embedding module in the embedding layer. On the basis of the original traffic flow sequence, a new traffic flow sequence containing spatiotemporal information features is obtained by fusion. The historical traffic data includes traffic flow, traffic speed and road occupancy rate. The acquired historical traffic data is divided into a training set, a validation set and a test set in a ratio of 6:2:2, where the training set is used as the input data of the traffic flow prediction model.
[0056] Before step S3, the acquired traffic data is modeled in the form of a graph, so as to establish a directed weighted graph corresponding to each moment of the data, and determine the adjacency matrix of the directed weighted graph; based on the acquired historical traffic data, the traffic network is modeled as a directed weighted graph G = (V, E, A), wherein V and E represent the set of nodes and edges of the graph, respectively. In the traffic network, V and E represent the set of sensors and roads; |V| = N represents the number of sensors; A represents the adjacency matrix of the graph, which is used to describe the relationship between nodes, and the weight of the edge is usually determined according to connectivity or distance; and the processed traffic data is regarded as a graph signal sequence on the directed weighted graph.
[0057] For example, in a window [t+1, t+T] with a time step of T, the traffic data can be represented as X t+1:t+T =[X t+1 , X t+2 , ...X t+T ]∈R N×T×F , where X t+T ∈R N×F represents the features of N nodes at time T, t represents the current time step, R represents a real number set, and F represents the number of features, usually including speed and traffic flow, etc.; in this embodiment, only traffic flow data is used, so F=1.
[0058] Then the data of the past T′ time steps can be expressed as X t-T′+1:t =[X t+1 , X t+2 , ...X t+T ]∈R N×T×1 The goal of traffic prediction is to learn a mapping f given a directed weighted graph G and historical traffic data to transform past data X t-T′+1:t Mapping to future data is as follows:
[0059] f(X t-T′+1:t,G )=X t+1:t+T
[0060] Where t represents the current time step, and the past 12 time steps are used to predict the data of the next 12 time steps, so T′=T=12.
[0061] S3. Train the traffic flow prediction model, input the original traffic flow sequence into the embedding layer in sequence to fuse the spatiotemporal information, extract the original feature embedding, daily embedding, weekly embedding and adaptive spatiotemporal feature embedding in the traffic data respectively, and splice the four embeddings together to get the output of the embedding layer.
[0062] In order to extract the original features in the traffic data, this embodiment adopts a fully connected method in the embedding layer to obtain the original feature embedding Among them, D da represents the embedding dimension, then the formula for embedding the original feature is:
[0063] C da =linear embedding (X t-T+1:t )
[0064] Among them, linear represents the linear layer, X t-T+1:t Represents the characteristics of the input.
[0065] Cycle embedding includes daily embedding and weekly embeds The specific extraction methods of the two are as follows: First, initialize two trainable embedding matrices and Among them, D d and D w Represent the dimensions of day embedding and week embedding respectively; N d represents the number of samples of the traffic time series in one day. In this embodiment, the data set obtained is sampled every 5 minutes, so N d =288;N w Indicates the number of days per week, that is, N w =7; the input time series is used as the index of the embedding layer, and the final period embedding C is obtained by extracting the embedding matrix dand C w .
[0066] Traffic flow data is recorded in chronological order, showing differences in time correlation under various time frames. In addition, traffic flows in different regions may show similar patterns, while nodes with close geographical locations may have completely different flow characteristics, which reflects that traffic flow information has significant spatiotemporal connections. In order to comprehensively obtain temporal and spatial information, extract the mutual connections between them, and build a spatiotemporal correlation framework, this embodiment adds adaptive spatiotemporal embedding Adaptive spatiotemporal feature embedding Among them C a Randomly initialized and trainable, its embedding dimension is D a .
[0067] Then embed the adaptive spatiotemporal features into The output C of the embedding layer is obtained by concatenating the original feature embedding, daily embedding, and weekly embedding. O ∈R T×N×D :
[0068] C O =C da ||C d ||C w ||C a
[0069] Among them, || represents the concatenation operation, and the final embedded dimension is D = D da +D d +D w +D a ; At the end of training, C O It will contain rich spatiotemporal information, thus helping the model better capture spatiotemporal correlation.
[0070] In this embodiment, the multi-graph convolutional layer uses a dynamic adaptive adjacency matrix to focus on solving the impact of traffic congestion on traffic flow prediction. The dynamic adaptive adjacency matrix is dynamically updated according to real-time traffic conditions to reflect traffic congestion and other influencing factors. The dynamic adaptive adjacency matrix dynamically adjusts the connection weights between nodes by considering real-time changes and historical patterns of traffic flow, thereby more accurately simulating congestion in urban traffic networks.
[0071] This implementation method extracts spatial features through a multi-graph convolution layer, which includes an adjacency matrix, a maximum mutual information coefficient matrix, a dynamic adaptive adjacency matrix, and a diffusion graph convolution operation. The dynamic adaptive adjacency matrix is used to capture real-time changes in the traffic network and dependencies between nodes.
[0072] In the multi-graph convolution layer, the data processed by the embedding layer and fused with features are sent to the multi-graph convolution layer to extract spatial features. This process first involves the construction of the adjacency matrix, which is a square array used to represent the structure in the graph. Specifically, each element in the matrix represents the link status between nodes in the graph. First, define the adjacency matrix:
[0073]
[0074] Among them, A represents the adjacency matrix, a ij represents an element in the adjacency matrix A, e ij ∈E means that there is an edge connecting the two nodes, otherwise a ij is 0.
[0075] In this embodiment, the maximum mutual information (MIC) matrix constructed is intended to quantify the correlation of data between node pairs, which is achieved by calculating their maximum mutual information values. The core concept of MIC is that for the relationship between two variables, the relationship is first discretized on a two-dimensional plane and visualized in the form of a scatter plot. This visualization process includes dividing the two-dimensional space into multiple small segments according to the x-axis and y-axis, and then analyzing the distribution of these scattered points in different segments.
[0076] Specifically, if two data sequences are divided into a and b parts in the positive direction of the x-axis and y-axis respectively, their maximum mutual information coefficient can be calculated by the following formula:
[0077]
[0078] Among them, B is the parameter that controls the grid distribution and is set to 0.6 of the data volume; I(X, Y) is the mutual information, which can be calculated by p(X, Y) is the joint probability of X and Y, and p(X) and p(Y) are the marginal probabilities when the grid (a, b) is chosen.
[0079] if is the sequence of the i sensors of feature F, that is, a vector, then the maximum mutual information coefficient matrix A mic middle element a ij It can be given by the following formula:
[0080]
[0081] in, represents the sequence of sensor i of feature F, The sequence of j sensors representing feature F.
[0082] In this embodiment, the maximum mutual information coefficient matrix is And A mic ∈R N×N×F In the multi-graph convolution, each feature vector is weighted and concatenated, and then passed to the diffusion graph convolution operation for processing. The matrix A used here mic As a fine measure of similarity, its element value range is between 0 and 1. The closer the value is to 1, the higher the consistency and close correlation of the traffic patterns between sensors; and the closer the value is to 0, the greater the difference in traffic patterns between sensors and the weaker the correlation.
[0083] In the dynamic adaptive adjacency matrix, two learnable embedding matrices W1 and Among them C emb Represents the dimension of embedding, which is a fixed value; through training, W1 and W2 can learn certain spatial features; dynamic adaptive weighting matrix A adp Calculated from W1 and W2:
[0084] A adp =softmax(relu(W1W2 T ))
[0085] Among them, relu() represents the activation function, softmax() is used to normalize the matrix, and W1 and W2 are randomly initialized.
[0086] Before performing multi-graph convolution operations, the adjacency matrix needs to be normalized to prevent erroneous learning during the multi-graph convolution process. Commonly used normalization methods include symmetric normalized Laplace matrix, random walk matrix, etc.
[0087] First, calculate the degree matrix D, which is a diagonal matrix with diagonal elements D ii The value of is the in-degree of each row of the adjacency matrix, that is, D ii =Rowsum(A i ); the Laplacian matrix is L = DA, and the symmetric normalized Laplacian matrix is defined as A SYS =ID -1 / 2 AD -1 / 2 , and the random walk matrix is defined as A r =D -1 A, among which, A i represents the i-th row of the adjacency matrix A, I represents the identity matrix, and r represents a random walk; if is the normalized adjacency matrix, For input, is a learnable weight, then the multi-graph convolution is represented as
[0088] Diffusion graph convolution technology effectively models spatial correlation by combining traffic flow with the diffusion process, thereby significantly improving the accuracy of the graph convolution model. In this process, the diffusion process is accurately described by the random walk matrix. For directed graphs, the diffusion process includes not only forward propagation but also reverse propagation. The two directions work together to further improve the performance of the model. The forward propagation matrix is P f =A / rowsum(A), the back propagation matrix is P b =A T / rowsum(A T ), so in order to better model the traffic flow, the diffusion graph convolution formula is defined as:
[0089] The multi-graph convolution layer combines the diffusion graph convolution and adaptive adjacency matrix A in each graph convolution layer. adp and A mic Combined with the previous one, and using the second-order diffusion convolution (K=2) to mine the spatial information, we get the final multi-graph convolution formula:
[0090]
[0091] Among them, Z represents the final feature representation, represents the forward propagation matrix of the kth layer, represents the back propagation matrix of the kth layer, represents the adaptive adjacency matrix of the kth layer, represents the maximum mutual information coefficient matrix of the kth layer, X represents the input feature matrix, W k1 Represents the kth layer and The associated weight matrix, W k2 Represents the kth layer and and The associated weight matrix.
[0092] After the diffusion graph convolution operation, the learned spatial features are residually connected with the data input by the embedding layer, and the obtained output data is used as input data to the spatiotemporal multi-head self-attention layer. The spatiotemporal correlation is captured by the spatiotemporal multi-head self-attention layer, which includes temporal multi-head self-attention and spatial multi-head self-attention. In the output layer, the extracted spatiotemporal information is passed through a fully connected layer, and finally the final prediction result is output through the activation function and linear transformation layer.
[0093] The multi-head attention mechanism was first introduced in the field of natural language processing to deeply explore the connections between words. Under this mechanism, the input of the attention layer is divided into three parts: query Q, key K, and value V through different feature maps. In the multi-head self-attention model, there are multiple independent weight matrices, which are responsible for learning the Q, K, and V representations of the input data, and each matrix is independently randomly initialized. These weight matrices project the input vector into different subspaces, allowing the model to focus on multiple key information points at the same time.
[0094] In the spatiotemporal multi-head self-attention layer, the output of the multi-graph convolutional layer is mapped to a higher-dimensional space using three linear changes to obtain three matrices Q, K, and V. The value of a single attention head is calculated, and then multiple attention heads are merged to obtain the output.
[0095] Multi-head self-attention is applied on the time axis and space axis respectively. The temporal self-attention mechanism is as follows: first, input ∈ R T×N×D Mapping obtains the values of matrices Q, K, and V: as well as Where Z represents the final feature representation of the multi-image convolutional layer, Q, K, Q (t) , K (t) and V (te) Respectively represent the queries, keys, and values of a node; They all represent learnable parameters.
[0096] Q and K T Divide by matrix multiplication Scaling is performed to control the problem of gradient disappearance after Softmax, and then a Softmax is performed to obtain the temporal attention score:
[0097]
[0098] Among them, A (t) ∈R N×T×T , multiplied by the value valeus, the final time attention output is: Z (t) =A (t) V (t) .
[0099] In order to make the model pay attention to richer spatiotemporal information, the temporal self-attention is expanded to multi-head self-attention, the input is mapped to h groups of matrices Q, K, V, and the output of multiple groups of attention is obtained, which are then concatenated together to obtain the final temporal multi-head self-attention output: in, Dt Set as D / h.
[0100] In this embodiment, spatial self-attention is similar to temporal self-attention. The spatial self-attention score Z is obtained by the above similar method. (S) =SelfAttention(Z (t) ), the output of spatial multi-head self-attention is
[0101] The self-attention mechanism enables the representation of each data point to be directly influenced by the representations of all other data points in the sequence, allowing the model to gain a global perception range. Based on this, the model proposed in this example can reveal potential long-range patterns and capture global dependencies beyond neighboring nodes. Even when traffic flow fluctuates drastically, the model can still make effective predictions.
[0102] In this embodiment, Figure 2 As shown in the figure, in each layer, the data first undergoes multi-head self-attention processing in time and space. Then, in order to increase the complexity of the model and alleviate the problem of gradient disappearance, the data will pass through a feedforward network layer. During this process, the data will undergo two residual connections and layer normalization operations. The first is before the feedforward network layer, and the second is after the feedforward network layer. After this series of processing steps, the output data is finally obtained.
[0103] S4. Obtain the current traffic data, input the obtained current traffic data into the trained traffic flow prediction model, and output the traffic flow in the future time period.
[0104] In this embodiment, in order to evaluate the performance of the model, the mean absolute error (MAE), mean absolute percentage error (MAPE) and root mean square error (RMSE) are used as evaluation criteria to evaluate the performance of the prediction method. The smaller the values of the three, the better. The specific formulas are as follows:
[0105]
[0106]
[0107] Where n represents the number of samples, yi represents the i-th actual observation value, represents the i-th predicted value.
[0108] The method of this embodiment obtains historical urban traffic network data, captures the complex temporal and spatial characteristics and their correlations in the data, and uses a dynamic adjacency matrix to capture real-time changes in the traffic network and complex dependencies between nodes. It can improve the accuracy of urban traffic flow prediction values, better solve urban traffic congestion problems, and improve the operating efficiency of urban roads.
[0109] like Figure 3 The MIC matrix heat map shown shows the visualization result of the maximum mutual information coefficient matrix, which is usually presented in the form of a heat map. The MIC matrix is used to quantify the correlation between different sensors or nodes in traffic flow data; in the heat map, the depth of the color can represent the strength of the correlation, and the darker the color, the stronger the correlation.
[0110] like Figure 4 The adaptive visualization scatter plot shown presents the visualization result of the adaptive adjacency matrix in the form of a scatter plot; the adaptive adjacency matrix is a key technology used in this embodiment to capture the dynamic changes and complex dependencies between nodes in the transportation network; the scatter plot can display the connection weights between nodes. It can be seen that after embedding, the nodes in the space are automatically clustered, and the closer the nodes are, the stronger the correlation is, which is consistent with the idea of graph convolution, indicating that the embedding method proposed in this embodiment is effective.
[0111] In addition to the above embodiments, the present invention may also have other implementation modes. Any technical solution formed by equivalent replacement or equivalent transformation falls within the protection scope required by the present invention.
Claims
1. A traffic flow prediction method, characterized in that: The following steps are included S1. Construct a traffic flow prediction model. The traffic flow prediction model includes an embedding layer, a multi-graph convolution layer, a spatiotemporal multi-head self-attention layer, and an output layer. The embedding layer includes original feature embedding, period embedding, and adaptive spatiotemporal embedding. The period embedding includes daily embedding and weekly embedding. S2, obtain the historical traffic data of the urban area traffic network and the traffic congestion situation, and send the historical traffic data to the embedding module in the embedding layer, and fuse the original traffic flow sequence to obtain a new traffic flow sequence containing spatiotemporal information features. The historical traffic data includes traffic flow, traffic speed and road occupancy rate; S3. Train the traffic flow prediction model, input the original traffic flow sequence into the embedding layer in sequence to fuse the spatiotemporal information, extract the original feature embedding, daily embedding, weekly embedding and adaptive spatiotemporal feature embedding in the traffic data respectively, and splice the four embeddings together to get the output of the embedding layer; The spatial features are extracted through multi-graph convolutional layers, which include adjacency matrix, maximum mutual information coefficient matrix, dynamic adaptive adjacency matrix and diffusion graph convolution operation. The dynamic adaptive adjacency matrix is used to capture the real-time changes in the traffic network and the dependencies between nodes. Capturing spatiotemporal correlations through a spatiotemporal multi-head self-attention layer, which includes temporal multi-head self-attention and spatial multi-head self-attention. In the output layer, the extracted spatiotemporal information is passed through a fully connected layer, and finally the final prediction result is output through the activation function and linear transformation layer; S4. Obtain the current traffic data, input the obtained current traffic data into the trained traffic flow prediction model, and output the traffic flow in the future time period.
2. A traffic flow prediction method according to claim 1, characterized in that: In step S2, the acquired historical traffic data is divided into a training set, a validation set and a test set in a ratio of 6:2:
2.
3. A traffic flow prediction method according to claim 1, characterized in that: In step S2, based on the acquired historical traffic data, the traffic network is modeled as a directed weighted graph G=(V, E, A), wherein V and E represent the set of nodes and edges of the graph respectively. In the traffic network, V and E represent the set of sensors and roads; |V|=N represents the number of sensors; A represents the adjacency matrix of the graph, which is used to describe the relationship between nodes; and the processed traffic data is regarded as a graph signal sequence on the directed weighted graph.
4. A traffic flow prediction method according to claim 3, characterized in that: In step S2, the processed historical traffic data is regarded as a graph signal sequence on a directed weighted graph. Specifically, in a window [t+1, t+T] with a time step of T, the traffic data is represented by X t+1:t+T =[X t+1 , X t+2 , ...X t+T ]∈R N×T×F , where X t+T ∈R N×F represents the features of N nodes at time T, t represents the current time step, R represents a set of real numbers, and F represents the number of features, including speed and traffic flow; Assuming that the number of features F only includes traffic flow, then F = 1, and the data of the past T′ time steps are represented by X t-T′+1:t =[X t+1 , X t+2 , ...X t+T ]∈R N×T×1 The goal of traffic prediction is to learn a mapping f given a directed weighted graph G and historical traffic data to transform past data X t-T′+1:t Mapping to future data is as follows: f(X t-T′+1:t ,G)=X t+1:t+T Among them, t represents the current time step.
5. A traffic flow prediction method according to claim 4, characterized in that: In step S2, the past 12 time steps are used to predict the data of the future 12 time steps, so T′=T=12.
6. A traffic flow prediction method according to claim 1, characterized in that: In step S3, in the embedding layer, the original feature embedding is obtained by fully connecting Among them, D da represents the embedding dimension, then the formula for embedding the original feature is: C da =linear embedding (X t-T+1:t ) Among them, linear represents the linear layer, X t-T+1:t Represents the characteristics of the input; Embed by day and weekly embeds The specific extraction method is as follows: First, initialize two trainable embedding matrices and Among them, D d and D w Respectively represent the dimensions of daily embedding and weekly embedding, N d Indicates the number of samples of traffic time series per day, N w Indicates the number of days per week, that is, N w =7; the input time series is used as the index of the embedding layer, and the final period embedding C is obtained by extracting the embedding matrix d and C w ; Then embed the adaptive spatiotemporal features into The output C of the embedding layer is obtained by concatenating the original feature embedding, daily embedding, and weekly embedding. O ∈R T×N×D : C O =C da ||C d ||C w ||C a Among them, || represents the concatenation operation, and the final embedded dimension is D = D da +D d +D w +D a .
7. A traffic flow prediction method according to claim 1, characterized in that: In step S3, in the multi-image convolution layer, the data output by integrating the features of the embedding layer is input into the multi-image convolution layer to extract spatial features. First, the adjacency matrix is defined: Where A represents the adjacency matrix, which is a square array used to represent the structure of the graph. Each element in the matrix represents the link status between nodes in the graph. ij represents an element in the adjacency matrix A, e ij ∈E means that there is an edge connecting the two nodes, otherwise a ij is 0; The maximum mutual information coefficient matrix is in, represents the sequence of sensor i of feature F, represents the sequence of j sensors of feature F, and A mic ∈R N×N×F ; In multi-graph convolution, each feature vector is weighted and concatenated, and then passed to the diffusion graph convolution operation for processing; In the dynamic adaptive adjacency matrix, two embedding matrices W1 and W2 are constructed for learning spatial features. Among them, C emb Represents the dimension of embedding, which is a fixed value; dynamic adaptive weighting matrix A adp Calculated from W1 and W2: A adp =softmax(relu(W1W2 T )) Among them, relu() represents the activation function, softmax() is used to normalize the matrix, and W1 and W2 are randomly initialized.
8. A traffic flow prediction method according to claim 7, characterized in that: In the multi-image convolution layer, the adjacency matrix is first normalized before the multi-image convolution operation is performed. The degree matrix D is first calculated. The degree matrix D is a diagonal matrix with diagonal elements D ii The value of is the in-degree of each row of the adjacency matrix, that is, D ii =Rowsum(A i ); the Laplacian matrix is L = DA, and the symmetric normalized Laplacian matrix is defined as A SYS =ID -1 / 2 AD -1 / 2 , and the random walk matrix is defined as A r =D -1 A, among which, A i represents the i-th row of the adjacency matrix A, I represents the identity matrix, and r represents a random walk; if is the normalized adjacency matrix, For input, is a learnable weight, then the multi-graph convolution is represented as 9. A traffic flow prediction method according to claim 8, characterized in that: In the multi-graph convolution layer, diffusion graph convolution is used to associate traffic flow with the diffusion process to model spatial correlation. The diffusion process is described in the form of random walks and includes forward propagation P f =A / rowsum(A) and back propagation P b =A T / rowsum(A T ) in two directions, the multi-graph convolution layer converts the diffusion graph convolution and adaptive adjacency matrix A in each graph convolution layer adp and A mic Combined with the previous one, and using the second-order diffusion convolution (K=2) to mine the spatial information, we get the final multi-graph convolution formula: Among them, Z represents the final feature representation, represents the forward propagation matrix of the kth layer, represents the back propagation matrix of the kth layer, represents the adaptive adjacency matrix of the kth layer, represents the maximum mutual information coefficient matrix of the kth layer, X represents the input feature matrix, W k1 Represents the kth layer and The associated weight matrix, W k2 Represents the kth layer and and The associated weight matrix.
10. A traffic flow prediction method according to claim 1, characterized in that: In step S3, in the spatiotemporal multi-head self-attention layer, the output of the multi-image convolution layer is mapped to a higher-dimensional space using three linear changes to obtain three matrices Q, K, and V, and multi-head self-attention is applied on the time axis and the space axis respectively. The temporal self-attention mechanism is specifically as follows: first, input ∈ R T×N×D Mapping obtains the values of matrices Q, K, and V: as well as Where Z represents the final feature representation of the multi-image convolutional layer, Q, K, Q (t) , K (t) and V (te) Represents the query, key and value of the node respectively; All represent learnable parameters; Q and K T Divide by matrix multiplication Scale it and then perform a Softmax on it to get the time attention score: Where A(t)∈R N×T×T , multiplied by the value valeus, the final time attention output is: Z (t) =A (t) V (t) ; Expand the temporal self-attention to multi-head self-attention, map the input to h groups of matrices Q, K, V, get the output of multiple groups of attention, and splice them together to get the final temporal multi-head self-attention output: in, D t Set as D / h; The spatial self-attention score Z is obtained by the same method as above (S) =SelfAttention(Z (t) ), the output of spatial multi-head self-attention is
Citation Information
Cited By
DSTMAN-based traffic prediction method
CN119028127A
Lightweight space-time traffic flow prediction method based on GAT and Mama
CN119625981A
Complex traffic flow prediction method based on dynamic graph convolution and interactive learning
CN119784195A
Traffic flow prediction method based on sparse attention mechanism
CN120260300A
Traffic flow prediction method and device based on multi-level space-time and perception fusion
CN121092937A
