Traffic prediction method based on multi-scale space-time attention mechanism

By introducing multi-scale spatiotemporal attention mechanism and graph convolutional neural network into traffic prediction methods, the problem that existing methods are difficult to capture the spatiotemporal dependence of traffic data is solved, and more accurate and efficient traffic prediction is achieved.

CN119516785APending Publication Date: 2025-02-25ANHUI NORMAL UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411681248.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-22
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

Existing traffic prediction methods are difficult to effectively capture the multi-scale spatio-temporal dependence of traffic data, resulting in insufficient accuracy and efficiency of prediction results.

Method used

The traffic prediction method based on multi-scale spatiotemporal attention mechanism is adopted, and dynamic adjacency matrices of different scales are constructed and attention mechanism fusion is used, dynamic spatial dependence is captured in combination with graph convolutional neural networks, and temporal features are fused through multi-head self-attention mechanisms.

Benefits of technology

It improves the space-time-dependence representation ability of traffic data, enhances the accuracy and efficiency of prediction results, and can better cope with the time transformation of traffic state.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119516785A_ABST
    Figure CN119516785A_ABST
Patent Text Reader

Abstract

The invention provides a traffic prediction method (MSTMA) based on a multi-scale spatio-temporal attention mechanism model, modeling spatio-temporal dependence is crucial to improvement of model prediction traffic state performance, most of existing methods only perform modeling on time dependence, the spatial feature expression ability of traffic data is insufficient, and the model prediction performance is poor. The invention aims to improve the spatial perception capability of a model on traffic data and the capture capability on time dependence. According to the method, adjacent matrixes of different scales are constructed and fused into a dynamic adjacent matrix through an attention mechanism, and dynamic spatial dependency is captured through a graph convolutional neural network. And meanwhile, the day time and week time characteristics of the original data are multiplied by the dynamic parameter matrix, so that the dynamic time dependence can be better captured, and the original data is fused with the time characteristics and the space characteristics by utilizing a multi-head attention mechanism, so that the method has the capability of better representing the real data space-time level.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of traffic prediction, and in particular to a traffic prediction method based on a multi-scale spatiotemporal attention mechanism. Technical Background

[0002] With the increasing number of urban vehicles, urban air pollution, energy consumption, the burden on the traffic network and the increase in travel time have been caused. Intelligent transportation systems can use widely existing sensors deployed in the road network with spatial locations to collect traffic data for analysis and prediction. Traffic prediction is an important part of the intelligent transportation system (ITS). Its prediction results can be used to dispatch traffic vehicles in a timely manner to reduce congestion rates, traffic accidents and other abnormal traffic conditions. While promoting the improvement of services such as traffic management and public safety, traffic prediction research is also considered to be a key method to improve the efficiency of the transportation system and alleviate transportation road problems. Traffic prediction tasks can be mainly divided into traffic flow prediction, traffic speed prediction, travel demand prediction, etc. Summary of the invention

[0003] The present invention provides a traffic prediction method based on a multi-scale temporal feature and spatial feature attention mechanism model, which has the ability to represent the spatiotemporal level of real data. By proposing a new dynamic adjacency matrix construction method, the attention mechanism is used to fuse adjacency matrices of different correlations and the dynamic spatial dependency is captured through a graph convolutional neural network. The spatial features of different scales are captured and respectively embedded with the day and week time through a multi-head self-attention mechanism for weighted fusion, and the spatiotemporal dependency of traffic data at multiple scales is represented through a gated fusion mechanism.

[0004] The present invention provides a method for capturing dynamic spatial dependency and dynamic temporal dependency and a method for fusing original data with temporal features and spatial features, which mainly include:

[0005] The adjacency matrices of different correlations are respectively dynamic adjacency matrices generated from the original historical data , dynamic adjacency matrix generated by adaptive parameter matrix And the adjacency matrix generated by distance similarity .

[0006] Preferably, the adjacency matrix is ​​normalized by using prior knowledge and Z-Score, and the adjacency matrix is ​​constructed by calculating the distance similarity between paired road network sensors. :

[0007] in Sensors in the road network arrive The distance between is the standard deviation of the distance, Yes Control The sparsity threshold.

[0008] Preferably, the attention matrix that focuses on the correlation between different features is used by performing dot product operations on the features. :

[0009] in, They are trainable parameters, biases, trainable dynamic parameters, matrix activation functions, and matrix dot products.

[0010] Preferably, a dynamic parameter matrix for adaptive traffic data dynamic relationship :

[0011] in, They are activation function, trainable initialization and trainable vector respectively.

[0012] Preferably, the adjacency matrices of different relevance are fused through an attention mechanism to obtain a dynamic adjacency matrix ;

[0013] Preferably, the dynamic adjacency matrix It can be expressed by the following formula:

[0014] Preferably, the multi-scale adjacency matrix and the traffic data transformed by the fully connected layer are used to obtain spatial features through a graph convolutional neural network. ;

[0015] Preferably, the spatial feature It can be expressed by the following formula:

[0016] The time embedding is to generate two time embedding matrices in sequence according to the sampling order. Day time embedding, Weekly time embedding, matched with trainable initialization parameters to obtain trainable dynamic time embedding, dynamic time embedding and three trainable node embedding vectors Perform Hadamard product to get trainable day and week time embeddings ;

[0017] Preferably, the process of embedding the day and week time can be expressed by the following formula:

[0018] in, are the number of samples collected by each sensor in a day and the number of days in a week, respectively. For the modulo operation, is the batch size, is the number of channels.

[0019] The multi-head attention is composed of multiple single-head attentions, and the feature vector can be divided into multiple heads. Each head can focus on the information at different positions in the feature vector. By weighted aggregation of information at different positions, the dependency relationship in the features can be better captured, thereby improving the memory ability of the feature vector.

[0020] The temporal attention mechanism consists of a multi-layer structure of a fully connected layer (FC) and two multi-head self-attention mechanisms stacked together.

[0021] Preferably, the multi-head attention mechanism is composed of (queries), (keys) and (values) are calculated together, in the invention The dimensions of , by calculating and The dot product of Dimensions , and in the application After the function Multiply to get the attention weight, the calculation process can be expressed as follows:

[0022] Preferably, the multi-head attention calculation process of each bath in the multi-head attention can be expressed as follows:

[0023] in, For each single-head attention, For the The weight matrix of each head, is the weight matrix of the linear transformation.

[0024] The spatial characteristics Embedded with day time , Weekly Time Embedding Through the fusion of multi-head attention mechanism, we can obtain the spatiotemporal dependency , Obtained through the gated fusion mechanism , the process can be expressed by the following formula:

[0025] in, They are vector concatenation, trainable parameters, and bias respectively.

[0026] The present invention provides a traffic prediction method, which constructs adjacency matrices of different scales and fuses them into dynamic adjacency matrices through an attention mechanism, captures dynamic spatial dependencies through a graph convolutional neural network, and obtains dynamically trainable time embedding by utilizing the day and week time features of the original data. This allows the model to have more flexibility in dealing with the temporal changes in traffic conditions, and utilizes a multi-head attention mechanism to fuse the data of spatial features captured by dynamic graph convolution operations with the time embedding, so that it has the ability to better represent the spatiotemporal aspects of real data. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 Schematic diagram of a multi-scale spatiotemporal multi-head attention mechanism model provided for the implementation of the present invention;

[0028] Figure 2 The prediction results of the control model and MSTMA at the 15th, 30th and 60th minutes on the METR-LA dataset provided for the implementation of the present invention;

[0029] Figure 3 The control model provided for the implementation of the present invention and the prediction results of MSTMA on the PEMS04 and PEMS08 data sets;

[0030] Figure 4 Visualization of trainable dynamic adjacency at 10th, 30th, and 60th epochs provided for the implementation of the present invention;

[0031] Figure 5 Visualization of the 15th minute prediction results of MSTMA on METR-LA, PEMS04 and PEMS08 on the test set provided for the implementation of the present invention;

[0032] Figure 6 Visualization of the 30th minute prediction results of MSTMA on METR-LA, PEMS04 and PEMS08 on the test set provided for the implementation of the present invention;

[0033] Figure 7 Visualization of the 60th minute prediction results of MSTMA on METR-LA, PEMS04 and PEMS08 on the test set provided for the implementation of the present invention.

[0034] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0035] like Figure 1As shown, the present invention is mainly composed of a graph convolutional neural network, a fully connected layer, a time embedding module (TEmbedding) and a time attention module (TAttBlock).

[0036] Step 1: The traffic network composed of sensor nodes can be described as an undirected graph Represents the relationship between different nodes within a specific time and space range, where is the vertex feature set, is the edge feature set, represents the adjacency matrix, so we have The node features collected by the sensor nodes are expressed as , Node feature dimensions collected for each sensor node.

[0037] Step 2: The purpose of traffic prediction is to build a map , with historical feature information As input, get output , are the length of the historical sequence used for training and the length of the sequence of predicted output, respectively. Therefore, the traffic prediction problem can be expressed as:

[0038] in, Represents a model that captures both spatial and temporal features.

[0039] Step 3: In order to represent the spatial relationship of traffic data, the present invention fuses three adjacency matrices to obtain the required dynamic adjacency matrix , three adjacency matrix generation methods are as follows:

[0040] in Sensors in the road network arrive The distance between is the standard deviation of the distance, Yes Control The sparsity threshold.

[0041]

[0042] in, They are trainable parameters, biases, trainable dynamic parameters, matrix activation functions, and matrix dot products.

[0043]

[0044] in, They are activation function, trainable initialization and trainable vector respectively.

[0045] Step 4: Use the three obtained adjacency matrices to fuse the dynamic adjacency matrix through the attention mechanism , the process can be expressed by the following formula:

[0046] Step 5: Using the obtained dynamic adjacency matrix Perform dynamic graph convolution to obtain spatial features , the process can be expressed by the following formula:

[0047] in, are trainable parameters and biases respectively. First, the dynamic adjacency matrix Combined with historical traffic data Perform matrix multiplication and normalize it to get the intermediate output variable Finally, they are added after passing through two fully connected layers to get the output .

[0048] Step 6: Generate three time embedding matrices in sequence according to the sampling order: Day time embedding, Weekly time embedding, its generation process can be expressed by the following formula:

[0049] in, are the number of samples collected by each sensor in a day and the number of days in a week, respectively. It is a modulo operation.

[0050] Step 6.1: Since traffic data is generated by long-term human activities, it exhibits daily and weekly periodic changes. In order to represent the periodicity and volatility of the time dimension of traffic data, the time information needs to be multiplied by the trainable node embedding matrix.

[0051] Step 6.2: In order to express the dynamic time information of each node, with trainable initialization parameters Matching to obtain trainable dynamic temporal embedding , and then With three trainable node embedding vectors Perform Hadamard product to get trainable time embeddings for days, weeks, and months , the process can be expressed as follows:

[0052] in, is the batch size, is the number of channels.

[0053] Step 7: The multi-head attention mechanism consists of feature vectors (queries), (keys) and (values) are calculated together, in the present invention The dimensions of , the number of multi-head attention is , after splitting the last dimension of the feature vector, its dimension is changed to , and then transformed into ,in For each bath size, is the historical time step size, is the number of nodes, is the size of the channel, is the number of single heads, For the size of a single head, set in the invention , by calculating and The dot product of Dimensions , and in the application After the function Multiply to get the attention weight, the calculation process can be expressed as follows:

[0054] Step 8: The multi-head attention calculation process of each bath can be expressed as follows:

[0055] in, For each single-head attention, For the The weight matrix of each head, is the weight matrix of the linear transformation.

[0056] Step 9: As attached Figure 5 The temporal attention mechanism shown in the figure consists of a fully connected layer (FC) and a multi-layer structure stacked by two multi-head self-attention mechanisms. In TAttBlock, the present invention Embedded with day time , Weekly Time Embedding Fusion gets features With features , and are weighted and summarized through the multi-head self-attention mechanism to obtain , and After gated fusion, the output is The specific process can be expressed as follows:

[0057] in, They are vector concatenation, trainable parameters, and bias respectively.

[0058] Step 10: As attached Figure 2 and attached Figure 3 As shown, the present invention uses the evaluation indicators used in the control model paper, namely, mean absolute error (MAE), root mean square error (RMSE) and mean absolute percentage error (MAPE), which can be expressed by the following formula:

[0059] Among them, MAE measures the average of the absolute differences between the predicted value and the actual value, while RMSE measures the size of the difference between the predicted value and the actual value, and MAPE is used to evaluate the degree of error between the predicted value and the actual value. Represents the model output value of each bath, It represents the label value. is the historical time index. .

[0060] Step 11: In order to balance the advantages and disadvantages of mean square error (MSE) and MAE, this experiment selects the Huber Loss loss function, which combines the advantages of MSE and MAE and has a certain robustness to outliers. It can be expressed by the following formula:

[0061] in, is the predicted value, is the label value, N is the number of samples, is the threshold parameter.

[0062] In order to demonstrate the effectiveness of the present invention, Figure 4 The visualization result is the dynamic adjacency matrix on the PEMS08 dataset. , 25 nodes are selected for visualization, and the dynamic adjacency matrix at the 10th, 30th and 60th epochs are displayed in turn. From the change status, we can see that the interaction relationship between nodes is changing significantly with the increase of training cycle. Nodes with strong interaction are assigned higher weights, and the weights between nodes with weaker interaction gradually increase with the increase of epoch iterations, which proves that It captures the hidden interactive relationships in spatial information. Figure 5-7 The prediction results of MSTMA for the future 15, 30, and 60 minutes on the traffic speed dataset and traffic flow dataset are displayed. Through the visualization results, it can be seen that the shorter the prediction time, the smaller the difference between the prediction result and the true value, and the prediction result is consistent with the objective result.

[0063] As described above, the embodiments of the present invention can be implemented not only in hardware but also in the form of software, and those skilled in the art can easily implement the exemplary embodiments of the present invention according to the description of the above exemplary embodiments. However, the above embodiments and the methods described in the specification do not limit the present invention. The scope of the present invention is determined by the attached claims, and various modifications and changes can be made to the present invention, and these modifications or changes do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. Traffic prediction method based on multi-scale spatiotemporal attention mechanism model, characterized by Includes the following parts: In order to improve the model's perception of the spatiotemporal characteristics of real data, the present invention expresses the spatial dependency of traffic data by constructing adjacency matrices of different scales, and thus proposes a new dynamic adjacency matrix construction method, which fuses adjacency matrices of different correlations through an attention mechanism to better influence the training process. At the same time, the original data is encoded into daily time features and weekly time features by time index and represented as trainable daily and weekly time embeddings by multiplying them by a dynamic parameter matrix, thereby expressing the time dependencies of different scales. The spatial features captured at different scales are weightedly fused with the daily and weekly time embeddings through a multi-head self-attention mechanism to express the spatiotemporal dependency of traffic data at multiple scales. Finally, the final prediction result is obtained through a gated fusion mechanism and a fully connected layer.

2. The traffic prediction method based on the multi-scale spatiotemporal attention mechanism according to claim 1 is characterized in that: The three adjacency matrices are respectively the dynamic adjacency matrices generated by the original historical data , dynamic adjacency matrix generated by adaptive parameter matrix And the adjacency matrix generated by distance similarity , the dynamic adjacency matrix is obtained by fusing three adjacency moments through the attention mechanism matrix; the dynamic adjacency matrix The traffic data transformed by the fully connected layer is used to obtain spatial features through the graph convolutional neural network. ; The time embedding is to generate two time embedding matrices in sequence according to the sampling order, namely, the day time embedding and week time embedding , and then match it with the trainable initialization parameters to obtain the trainable dynamic time embedding and the two trainable node embedding vectors Perform Hadamard products respectively to obtain trainable day and week time embeddings ; The multi-head attention mechanism is composed of multiple single-head attention mechanisms, which can divide the feature vector into multiple heads. Each head can focus on the information at different positions in the feature vector. By weighted aggregation of information at different positions, the dependency relationship in the features can be better captured, thereby improving the memory ability of the feature vector; The temporal attention mechanism is composed of a fully connected layer (FC) and a multi-layer structure stacked by two multi-head self-attention mechanisms; The spatial feature Embedded with day time , Weekly Time Embedding Through the fusion of multi-head attention mechanism, we can obtain the spatiotemporal dependency ; Obtained through the gated fusion mechanism ; Get the final prediction value through the fully connected layer .

3. The three adjacency matrix generation methods according to claim 2 can be expressed by the following formula: ,in Sensors in the road network arrive The distance between is the standard deviation of the distance, Yes Control The sparsity threshold, ,in, They are trainable parameters, biases, trainable dynamic parameters, matrix activation functions, and matrix dot products. ,in, They are activation function, trainable initialization and trainable vector respectively.

4. The dynamic adjacency matrix according to claim 2 It is necessary to fuse the three adjacency matrices described in right 3 through the attention mechanism, and the process can be expressed as follows: , where Linear transformation, and Both are activation functions.

5. Spatial characteristics according to claim 2 The dynamic adjacency matrix obtained from right 4 The dynamic graph convolution process is performed. First, the dynamic adjacency matrix Combined with historical traffic data Perform matrix multiplication and normalize it to get the intermediate output variable Finally, they are added after passing through two fully connected layers to get the output , the process can be expressed by the following formula: ,in, are trainable parameters and biases respectively.

6. The time embedding matrix according to claim 2 Day time embedding, Weekly time embedding, the process can be expressed as follows: ,in, are the number of samples collected by each sensor in a day and the number of days in a week, respectively. For the modulo operation, is the batch size, is the number of channels.

7. According to claim 2, the multi-head attention mechanism is composed of (queries), (keys) and (values) are calculated together, in the present invention The dimensions of , by calculating and The dot product of Dimensions , and in the application After the function Multiply them to obtain the attention weight. The attention weight and the multi-head attention calculation process of each bath can be expressed as follows: ,in, For each single-head attention, For the The weight matrix of each head, is the weight matrix of the linear transformation.

8. Output of the temporal attention mechanism according to claim 2 is the spatial feature obtained by right 5 The time embedding obtained with right 7 , Fusion and weighted aggregation through multi-head self-attention mechanism are obtained respectively , and After gated fusion, the process can be expressed as follows: ,in, They are vector concatenation, trainable parameters, and bias respectively.

9. Obtain the final prediction value through the fully connected layer according to claim 2 , is obtained by right 8 The output obtained through multiple layers of fully connected layers.

Citation Information

Cited By

  • PM2.5 and ozone concentration prediction method and device and storage medium

    CN120654873A