Traffic flow prediction method and device capable of perceiving local-global spatio-temporal relationship based on transformer

By combining the advantages of TCN, GNN and Transformer, a local-global spatiotemporal relationship module was designed to solve the challenge of learning local-global spatiotemporal dependencies in traffic flow prediction, achieve accurate prediction of traffic flow data, and improve the model's short, medium and long-term prediction performance.

CN119990191BActive Publication Date: 2025-10-24ZHEJIANG UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510050036.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-13
Publication Date
2025-10-24
Estimated Expiration
2045-01-13

AI Technical Summary

Technical Problem

Existing traffic flow prediction methods face challenges in learning the local and global spatiotemporal dependencies of traffic flow. RNNs and GNNs suffer from gradient vanishing and error accumulation problems, while Transformers struggle to effectively model local spatiotemporal features.

Method used

Combining the advantages of TCN and GNN in local spatiotemporal relationship mining with Transformer in global spatiotemporal relationship mining, we designed the local-global temporal dependency module LGTM and the local-global spatial dependency module LGSM. Through multi-scale convolution and self-attention mechanism, we learn the short-term, long-term, local and global spatiotemporal dependencies of traffic flow data.

Benefits of technology

It achieves accurate prediction of traffic flow data, improves short, medium and long-term prediction performance, and can better capture the spatiotemporal dependence of complex time periods, showing better overall prediction performance than other models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119990191B_ABST
    Figure CN119990191B_ABST
Patent Text Reader

Abstract

The application discloses a traffic flow prediction method and device based on a Transformer and capable of perceiving local-global space-time relations, and the method comprises the following steps: firstly, historical traffic data of all road sections to be predicted is acquired, wherein the historical data comprises traffic flow characteristic data of a prediction road section, static adjacency matrix data between road network nodes and sampling timestamp data of the historical data; secondly, a space-time information embedding layer is constructed to provide multiple types of embedding inputs for a model trunk, so as to enhance the learning ability of the model, wherein three different types of embedding are historical data information embedding, time information embedding and spatial node adaptive embedding; then, a local-global time dependence extraction module is constructed, a multi-scale TCN and a self-attention mechanism in the time dimension are utilized to learn short-time and long-time time dependence relations in the data respectively, and a double-path adaptive information gate fusion technology is introduced to realize effective fusion of different hierarchical time features; subsequently, a local-global space dependence extraction module is constructed, a dynamic-static graph convolution network and a self-attention mechanism in the space dimension are utilized to learn local and global space dependence relations in the data respectively, and the double-path adaptive information gate fusion technology is also utilized to realize effective fusion of different hierarchical space features; finally, a full connection layer network is utilized to map potential space-time feature representation to a prediction result.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of data mining and artificial intelligence, in particular to a traffic flow data prediction method, and specifically to a traffic flow prediction method and device capable of perceiving local-global spatio-temporal relationship based on Transformer. BACKGROUND

[0002] Accurate traffic flow data prediction is a key technology of data-driven intelligent transportation system. Traffic flow prediction belongs to a kind of multivariate time series data prediction task, which needs to predict future traffic data according to historical traffic data recorded by traffic sensors, including vehicle flow prediction, road traffic speed prediction, etc., which has important influence on optimizing urban traffic management, travel efficiency, traffic experience, etc.

[0003] In recent years, with the increase of private cars, the contradiction between people and limited road network is becoming more and more serious, and how to alleviate this contradiction has become a research hotspot. In recent years, scholars have proposed a large number of traffic flow prediction methods. In the early development of this field, due to the limitations of technology, only the time dependence of traffic data was considered. Some simple time series models such as recurrent neural network (RNN) and its variants long short-term memory (LSTM) and gate recurrent unit (GRU) were used to model the time dependence of traffic data. However, the spatial dependence between different road network nodes was ignored. The existing view generally believes that in addition to capturing periodic, seasonal and other time dynamic patterns, the spatial dependence under the constraint of road network structure is more important for traffic flow prediction tasks. With the further development of deep learning, inspired by spectral graph neural networks, graph neural networks (GNN) for processing non-Euclidean irregular road network data were proposed. This method is based on the static topology of the road network to construct the spatial connection relationship between different road segment nodes, and realizes the flow of traffic information between nodes through the message propagation mechanism, which has become a classic and widely used model for traffic prediction tasks. For example, spatiotemporal graph convolutional networks (STGCN), spatiotemporal fusion graph convolutional network (STFGCN), dynamic frequency domain graph convolutional network (DFDGCN), etc. Either consider the influence of spatial relationship in time dimension, or try to capture spatial relationship and time relationship simultaneously. On the other hand, with the success of Transformer in many different fields (such as natural language processing, computer vision, data mining, etc.), traffic flow data prediction methods based on Transformer have also been widely studied. This method is fundamentally different from GNN. Transformer benefits from its core self-attention mechanism, which determines the importance of nodes by calculating the weight coefficients between different nodes in different dimensions (Self-attention, SA), and can effectively capture the spatiotemporal dependence in traffic data, which has become a powerful tool for spatiotemporal relationship modeling in traffic flow prediction tasks.For example, Traffic Transformer, Spatiotemporal transformer network (STTN), etc., there are methods to consider embedding spatiotemporal information in the Transformer, combining the time points of historical data and the road network structure or nodes with data into the Transformer structure, such as Spatiotemporal adaptive embedding Transformer (STAEformer), Propagation delay-aware Transformer (PDformer), etc.

[0004] The essence of spatiotemporal dependency modeling lies in how to describe the transmission of traffic information between different nodes. However, the traffic behavior of the road network usually has great uncertainty, and the transmission of traffic information is not only static and local, but also dynamic and global. The above mainstream traffic flow prediction methods are all effective, but they have challenges in learning the local-global spatiotemporal dependencies of traffic flow. 1) For RNN and TCN, the advantage lies in learning short-time temporal features; when learning long-time temporal features, they often face problems such as gradient disappearance and error accumulation. 2) For GNN, the advantage lies in its ability to capture local spatial features based on the static adjacency relationship of the road network; while learning global spatial features often depends on the quality of the learned global dynamic adjacency relationship matrix. 3) For Transformer, it is good at capturing global spatiotemporal features due to its internal self-attention mechanism SA; however, the influence on local spatiotemporal features often cannot be well modeled. SUMMARY

[0005] The present application is aimed at complex traffic flow data, in order to overcome the above-mentioned shortcomings of the prior art, and to provide a traffic flow prediction method and device based on Transformer that can perceive local-global spatiotemporal relationships, which can realize accurate prediction of future traffic flow data by combining the advantages of TCN and GNN in local spatiotemporal relationship mining and the advantages of Transformer in global spatiotemporal relationship mining.

[0006] The first aspect of the present application relates to a traffic flow prediction method based on Transformer that can perceive local-global spatiotemporal relationships (LGSTformer), comprising the following steps:

[0007] S1: Obtain the historical traffic data of all road segments to be predicted, the historical data including the traffic flow feature data of the predicted road segment, the static adjacency matrix data between the nodes of the road network, and the sampling timestamp data of the historical data. The above data is fused to obtain a historical sample data set, and the historical sample data set is further divided into a training data set, a validation set and a test set.

[0008] S2: Based on the training sample data set, a spatio-temporal information embedding layer is constructed to provide multiple types of embedding inputs for the model backbone, including historical data feature embedding, time periodicity embedding and spatial node adaptive embedding, to enhance the spatio-temporal dependence learning ability of the subsequent spatio-temporal module;

[0009] S3: Based on the embedding data obtained by the embedding layer, a local-global time dependence module is constructed to learn time features, the time features including short-time and long-time time dependence relationships in the traffic flow data;

[0010] S4: Based on the time feature data learned by the time module, a local-global spatial dependence module is constructed to learn spatial features, the spatial features including local and global spatial dependence relationships in the traffic flow data;

[0011] S5: Based on the spatio-temporal features, a fully connected layer network is used to map the future traffic flow data results of the road segment to be predicted;

[0012] S6: Experimental verification, by comparing with multiple types of traffic flow prediction methods on multiple types of traffic flow data sets, it is proved that the present application is effective.

[0013] The third aspect of the present application relates to a traffic flow prediction device based on Transformer capable of perceiving local-global spatio-temporal relationship, comprising a memory and one or more processors, the memory storing executable code, and the one or more processors executing the executable code to implement the traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationship.

[0014] The third aspect of the present application relates to a computer readable storage medium having a program stored thereon, the program being executed by a processor to implement the traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationship.

[0015] The beneficial effects of the present application are as follows:

[0016] 1) A novel traffic data prediction model LGSTfromer based on Transformer is proposed, which can accurately capture the local-global spatio-temporal dependence in historical traffic data.

[0017] 2) Two new spatio-temporal modules LGTM and LGSM are designed to capture different ranges of spatio-temporal dependencies. The former combines TCN and temporal self-attention mechanism to learn short-term and long-term temporal dependencies, while the latter combines DSGCN and spatial self-attention mechanism to learn local-global spatial dependencies.

[0018] 3) Performance comparison experiments are carried out on four real-world datasets with high prediction complexity, and the results show that the method of the present application can have better overall prediction performance than the baseline model in short-medium-long term. The visualization results on different datasets show that the present application can well fit the trend of data change, can accurately capture the spatio-temporal dependencies of complex time periods, and can further verify the effectiveness of the present application. BRIEF DESCRIPTION OF DRAWINGS

[0019] Figure 1 is a structural diagram of the present application.

[0020] Figure 2 is a visualization result diagram of the present application in the dataset METR-LA on the Index=40 node from 2012 / 6 / 8 to 2012 / 6 / 9.

[0021] Figure 3 is a visualization result diagram of the present application in the dataset METR-LA on the Index=120 node from 2012 / 6 / 8 to 2012 / 6 / 9.

[0022] Figure 4 is a visualization result diagram of the present application in the dataset PEMS-BAY on the Index=18 node from 2017 / 4 / 26 to 2017 / 4 / 27.

[0023] Figure 5 is a visualization result diagram of the present application in the dataset PEMS-BAY on the Index=149 node from 2017 / 4 / 26 to 2017 / 4 / 27.

[0024] Figure 6 is a visualization result diagram of the present application in the dataset PEMS04 on the Index=25 node from 2018 / 2 / 18 to 2018 / 2 / 19.

[0025] Figure 7 is a visualization result diagram of the present application in the dataset PEMS04 on the Index=35 node from 2018 / 2 / 18 to 2018 / 2 / 19.

[0026] Figure 8 is a visualization result diagram of the present application in the dataset PEMS08 on the Index=15 node from 2016 / 8 / 20 to 2016 / 8 / 21.

[0027] Figure 9 This is a visualization result diagram of the present invention on the node with Index=35 in the data set PEMS08 from 2016 / 8 / 20 to 2016 / 8 / 21. DETAILED DESCRIPTION

[0028] In order to make the objectives, technical solutions and advantages of the present invention more clear, specific embodiments of the present invention are further described in detail below with reference to the accompanying drawings.

[0029] Example 1

[0030] This embodiment provides a traffic flow prediction method based on Transformer that can perceive the local-global spatiotemporal relationship. The model structure is as follows: Figure 1 As shown, the method includes:

[0031] S1: Obtain historical traffic data for all road sections to be predicted. The steps are as follows:

[0032] S1.1: The road segments in the road network to be predicted are regarded as basic node units, which are represented as a node set V = {v1, v2, ..., v N}∈R N , where N represents the number of road segments to be predicted. The physical topology of the road can be expressed as G = {V, P, A s}, where P is the edge set that determines the node connection relationship, A s is the static neighbor matrix of the traffic graph structure. T}∈R T The historical traffic flow data is represented as X = {X1, X2, ..., X N}∈R T×N×D , where D represents the number of features. Furthermore, the data to be predicted in the future can be expressed as

[0033] S1.2: Divide the historical dataset into a training dataset, a validation dataset, and a test dataset according to the preset ratio. Establish and train a traffic flow data prediction model based on the preset loss function for the training dataset. The preset loss function for the traffic dormitory dataset is HuberLoss, while the preset loss function for the traffic flow dataset is MAELoss.

[0034] S2: Construct a spatiotemporal information embedding layer to provide various types of embedding inputs for the model backbone. The steps are as follows:

[0035] S2.1: Perform time periodic embedding on the sampling timestamp data. This embedding mainly includes embedding the timestamps within a day. dayand the day of the week E week The former is related to the sampling frequency of the data, if the sampling frequency of the data set is 5 minutes in a day, then a day will be divided into 288 timestamps; the latter is the day of the week, that is, 7 days. First, two learnable parameter matrices W 288×E and W 7×E are defined to represent the embedding dictionary, where E is the dimension size of the embedding. Then the input daily timestamp data X day ∈R T and the weekly data X week ∈R T are used as indexes to obtain E day ∈R T×N×E and E week ∈R T×N×E . Where T and N represent the length of the historical data and the number of nodes, respectively.

[0036] S2.2: Spatial node adaptive embedding of spatial feature data. Traffic flow has dynamic spatio-temporal correlation, and it is insufficient to extract spatial relationships based on only static road network adjacency graphs. In order to better capture the dynamic changes of traffic flow in time and space, a spatial node adaptive embedding matrix e spa ∈R N×ESA is introduced to process the interaction between different nodes, and then the input is aligned through a broadcast mechanism to obtain E spa ∈R T×N×ESA , where ESA represents the dimension size of the spatial node embedding.

[0037] S2.3: High-dimensional feature embedding of historical data information of road segment nodes. In order to maintain the original information of the original data, while maintaining the dimension alignment with the spatio-temporal embedding, only a fully connected layer FC() is used to project the original data into a high-dimensional latent space to obtain a new feature representation H X = FC(X 1:T ) ∈ R T×N×E , where X 1:T represents the historical input data with length T.

[0038] S2.4: Finally, by splicing the four comprehensive embeddings, the spatio-temporal representation of the traffic input data H In = E day || E week || E spa || H X ∈ R T×N×Ein , where E in is the final sum of the embedding dimensions.

[0039] S3: Local-global temporal dependency module LGTM, which realizes the extraction of time dependency in different ranges. Based on the embedding data obtained by the embedding layer, time feature learning is performed by constructing a local-global temporal dependency module, and the time features include short-term and long-term time dependencies in the traffic flow data. The steps are as follows:

[0040] S3.1: Short-term time series dependency extraction. As previously analyzed, the mainstream tools for modeling short-term time dependencies include recurrent neural networks (RNN) and temporal convolution networks (TCN). The sequence-based computing method of RNN faces two problems: gradient vanishing and inability to perform parallel computing. Compared with RNN, TCN has higher computing efficiency. It uses convolution networks (causal convolution and dilated convolution) to process data, which enables it to perform parallel computing and can adjust the perception range of local time series features by changing the size of the receptive field, making it more flexible. Therefore, the present application introduces a multi-scale convolution module (Multi-scale Gated Tanh Unit, M-GTU) to capture the short-term time dynamic information of traffic flow data. It mainly consists of three gated Tanh units (GTUs) with different receptive fields. The mathematical expression of the calculation process of a single GTU is as follows:

[0041]

[0042] wherein is the input of LGTM, Γ K is a convolution kernel with a kernel size of 1xK, and *τis a gated convolution operator. φ() and σ() are nonlinear activation Tanh function and Sigmoid function, respectively, which are used as gating mechanisms to control the output of data flow, which has been proven to be very effective for TCN. The convolution kernel Γ K doubles the channel feature number E in of to 2E in , and then divides F and B in the channel feature to ensure that the output features remain consistent in the channel dimension. Further, the mathematical expression of M-GTU can be obtained using three different convolution kernels:

[0043]

[0044] wherein Γ K1 , Γ K2 and Γ K3 are convolution kernels with a kernel size of 1xK1, 1xK2, and 1xK3, respectively. || represents the connection operation, which connects the outputs of GTUs with three different scales in the time dimension. The fully connected layer FC() is responsible for restoring the time dimension of the connection output to T. is the short-term temporal dependency learned by M-GTU.

[0045] S3.2: Long-term temporal dependency extraction. M-GTU learns short-term sequence changes, but cannot further learn the long-term dependencies of the road network. In order to better capture long-term temporal dependencies, the present application uses the scaled dot-product self-attention mechanism commonly used in classic Transformer models to calculate the importance of each timestamp position in the entire input sequence in the time dimension, and fuses the time information of the entire input sequence through the importance coefficient. According to the formal definition, the query matrix Q temp , the key matrix K temp and the value matrix V temp needed in the self-attention mechanism calculation can be derived through three different linear mapping layers. The mathematical expression of the attention calculation matrix can be expressed as follows:

[0046]

[0047] wherein are different trainable parameters. Then, the self-attention scores Attn temp between different timestamps in the time dimension can be calculated based on Q temp and K temp , so as to realize the extraction of global temporal dependencies. Specifically, matrix multiplication is performed on Q temp and K temp T (the transpose of K temp ), and the result is normalized to [0, 1] through the Softmax function. The mathematical expression of the entire process can be expressed as follows:

[0048]

[0049] In this way, Attn temp (Q temp , K temp ) can adaptively learn the global temporal dependencies between different timestamps. Then, combined with V temp , the representation of long-term temporal dependency features can be obtained. The mathematical expression can be expressed as follows:

[0050]

[0051] wherein, in order to keep consistent with in the dimension, the transpose operation is performed on . Further, the multi-head attention mechanism (MHA) is introduced to capture more diverse temporal features. Specifically, the time self-attention score Attn tempPreviously, the query matrix Q temp , the key matrix K temp and the value matrix V temp are usually divided into some more fine-grained block structures and assigned different trainable parameters. This method is more effective than the non-multi-head attention mechanism. Its mathematical expression can be expressed as follows:

[0052]

[0053] head i =Attn temp,i (Q temp,i ,K temp,i )V temp,i (7)

[0054] where Q temp,i , K temp,i and V temp,i represent the i-th partition block of Q temp , K temp and V temp respectively. Attn temp then represents the weight matrix used to combine the outputs of all attention heads.

[0055] S3.3: After obtaining the short-time temporal dependency and the long-time temporal dependency , the problem to be considered is how to effectively fuse them. On the one hand, the importance of different temporal dependencies needs to be considered, and on the other hand, the proportion of information fusion between the two also needs to be considered. In order to achieve this purpose, the present application introduces a double adaptive information gating fusion mechanism, which mainly consists of two gating mechanisms, namely the hold gate and the reset gate. The hold gate controls the information flow in a single path, and the reset gate controls the fusion ratio of information in different paths. and After passing through the two gating mechanisms, the output fusion obtained temporal dependency feature The mathematical expression of the whole process can be expressed as follows:

[0056]

[0057] where φ() and σ() are nonlinear activation Tanh function and Sigmoid function respectively.

[0058] S3.4: In line with the original Transformer structure design, LGSTformer also retains the original residual connection layer (Add), layer normalization (Norm) and position-level feed-forward layer (FFN) in the LGTM module. Existing experience shows that Add can ensure the flow of input information, avoid gradient disappearance and network degradation; Norm stabilizes the model training process and accelerates convergence; FFN nonlinearly transforms the representation of each position to enhance the expressiveness of the model. Time-dependent features After the above three operations, the input of LGSM is output from the LGTM submodule The mathematical expression of the whole process can be represented as follows:

[0059]

[0060] Where LN and Dropout are LayerNorm and Dropout method functions respectively. FFN consists of two linear layers with ReLU nonlinear operators.

[0061] S4: Local-global time-dependent module LGSM, which realizes the extraction of spatial dependency relationships in different ranges. Based on the time feature data learned by the time module, spatial feature learning is performed by constructing a local-global spatial dependency module, which includes local and global spatial dependency relationships in traffic flow data, as follows:

[0062] S4.1: Local spatial dependency extraction. In recent years, using graph convolutional neural network (GCN) based on adjacency matrix to model local spatial dependency of traffic data is one of the most commonly used modeling methods. GCN can handle direct connections between nodes and model local dependencies by propagating information between adjacent nodes. Therefore, in the same way, this method is also used to handle local dependencies, which can be mathematically expressed as follows:

[0063]

[0064] Where GCN() represents the graph convolution operation, represents the input of the Lth layer LGSM, A s The static adjacency matrix of the road network node. On the other hand, the local spatial structure may be affected by short-term external factors such as bad weather and traffic accidents. This may cause the dependency relationship between local nodes to change. Considering that this influence is also conducive to modeling traffic data, a spatial node adaptive embedding based method is also used to model this irregular local change in spatial relationship as a supplement to A s , while GCN() is used for node information propagation. Its mathematical expression can be represented as follows:

[0065]

[0066] A d = Softmax(relu(φ(ΦΦ T ))) ∈ R N×N (16)

[0067]

[0068] where φ(), relu() and softmax() represent Tanh, ReLU and Softmax method functions, respectively. are learnable parameters. Then, a simple fully connected layer FC() is used to extract local spatial information of different representations. The mathematical expression can be represented as follows:

[0069]

[0070] where denotes the learned local spatial dependency features.

[0071] S4.2: Global spatial dependency extraction. Another feature of the traffic network is the high dynamic change of traffic flow, which changes widely in multiple areas with mutual influence. Some traffic patterns (such as overall traffic flow, the influence of major traffic events, etc.) involve the interaction of all nodes or multiple areas in the network and they can be indirectly dependent on each other. Similar to the global temporal dependency learning method, we use a scaled dot-product self-attention mechanism to better capture the global spatial dependency. Given the input First, it is mapped to different feature spaces using three different linear layers to obtain the query matrix Q spa , the key matrix K spa and the value matrix V spa . The mathematical expression of the attention calculation matrix can be represented as follows:

[0072]

[0073] where are all different trainable parameters. Then, based on Q spa and K spa , the self-attention score Attn spa between different nodes in the spatial dimension can be calculated to achieve the extraction of global spatial dependency. The mathematical expression of the whole process can be represented as follows:

[0074]

[0075] Thus, Attn spa (Q spa , K spa) can learn global spatial dependencies between different nodes adaptively. Then, combined with V spa The representation of global spatial dependency features can be obtained The mathematical expression can be represented as follows:

[0076]

[0077] Further, as in LGTM, a multi-head attention mechanism MHA is introduced to capture more rich spatial information from different representation subspaces. The mathematical expression can be represented as follows:

[0078]

[0079] head i = Attn spa,i (Q spa,i , K spa,i ) V spa,i (26)

[0080] where Q spa,i , K spa,i and V spa,i represent the i-th partition block of Q spa , K spa and V spa respectively. Attn spa then represents the weight matrix used to combine the outputs of all attention heads.

[0081] S4.3: After obtaining local spatial dependency and global spatial dependency , it is also necessary to consider how to effectively fuse them. As in the same way as the fusion of short-term and long-term temporal dependencies in LGTM, the fusion of and also adopts a two-path adaptive information gating fusion method. and After passing through two gating mechanisms, the spatial dependency features outputted by fusion can be obtained. The mathematical expression of the whole process can be represented as follows:

[0082]

[0083] where φ() and σ() are nonlinear activation Tanh function and Sigmoid function respectively.

[0084] S4.4: As done in LGTM, residual connection layers (Add), layer normalization (Norm) and position-level feed-forward layers (FFN) are introduced to stabilize the training of the whole module. Spatial dependency features After the above three operations, output from the LGSM submodule The mathematical expression of the whole process can be represented as follows:

[0085]

[0086] where LN and Dropout are LayerNorm and Dropout method functions respectively. FFN consists of two linear layers with ReLU non-linear operator.

[0087] S5: Output layer. After capturing short-long term temporal dependencies and local-global spatial dependencies by the two submodules LGTM and LGSM, the latent spatio-temporal feature representation is mapped to the prediction result of future data through a fully connected layer network. The mathematical expression of the whole process can be represented as follows:

[0088]

[0089] where W out is the learnable parameter, and b out is the bias.

[0090] S6: Experimental verification. The present application will evaluate the prediction traffic capacity of the output results of multiple types of traffic prediction models (including traditional methods, STGNN-based methods, spatio-temporal regularization-based methods, linear-based methods, and Transformer-based methods) on different traffic flow datasets (including flow datasets and speed datasets) to prove the effectiveness of the present application.

[0091] S6.1: Dataset. The present application conducts experiments on four real-world datasets PEMS-BAY, METR-LA, PEMS04 and PEMS08, which are all one of the benchmark test sets for traffic prediction. It is worth noting that short (15min)-medium (30min)-long (60min) period prediction is performed on PEMS-BAY and METR-LA, while long (60min) period prediction is performed on PEMS04 and PEMS08. PEMS-BAY, PEMS04 and PEMS08 are all collected by the Performance Measurement System (PeMS) of the United States, but the collection locations are different. METR-LA is the Los Angeles freeway dataset in the United States. The basic information of the four datasets is shown in the following table:

[0092]

[0093] S6.2: Evaluation index. In order to evaluate the prediction data x pred and the true value x trueTo quantify the difference between the proposed method and the baseline methods, the proposed method uses three commonly used evaluation indicators, mean absolute error (MAE), root mean square error (RMSE), and mean absolute percentage error (MAPE), to quantify all experimental results. The mathematical expressions of these indicators are as follows:

[0094]

[0095]

[0096] S6.3: Comparison model. To demonstrate the performance of the proposed method in predicting different types of traffic data, the proposed method will be compared with five different types of traffic prediction models. 1) The traditional prediction method HA (Historical Average) takes the historical average as the prediction value. 2) The STGNN-based method includes GWNet, DCRNN, AGCRN, GTS, SGODE, STFGCN, DFDGCN, etc. The characteristic of this kind of method is to use graph structure as spatial information, and combine it with time information to extract spatio-temporal dependence. 3) The method based on spatio-temporal regularization STNorm, this kind of method focuses on using normalization technology to balance the different characteristics of time and space dimensions in traffic flow data. 4) The linear-based method STID, this kind of method tries to use multi-layer perceptron (MLP) to design a simple and effective model comparable to STGNN. 5) The Transformer-based method includes PDformer, STAEformer, MTESformer, etc. This kind of method uses spatio-temporal self-attention mechanism to learn the spatio-temporal dependence in traffic data.

[0097] S6.4: Experimental results. The proposed method is evaluated on the short-medium-long three prediction dimensions (horizons) of the METR-LA and PEMS-BAY two speed data sets. It is worth noting that the best results are bolded, the suboptimal results are underlined, and the suboptimal results are starred. The comparison results are as follows:

[0098]

[0099]

[0100] From the experimental results table analysis on the speed dataset, we can find that: 1) For the traditional HA method, the prediction performance is the worst in both METR-LA and PEMS-BAY. This is because it only averages historical data and cannot effectively extract spatial and temporal dependencies in non-stationary data. 2) For the STGNN-based method, SGODE achieves the best performance in short-term and medium-term length prediction in METR-LA, and DFDGCN is only second to LGSTformer in short-term and medium-term length prediction in PEMS-BAY. Other methods perform generally. 3) For the spatiotemporal regularization-based method, STNorm performs better in PEMS-BAY than in METR-LA. In addition, the performance of STNorm in METR-LA is lower than that of the STGNN-based method, while the performance in PEMS-BAY is better than that of the STGNN-based method. This is because METR-LA has more complex changes and spatiotemporal relationships, making it more difficult to balance spatiotemporal features. 4) For the linear-based method, STID performs better than STNorm in PEMS-BAY, which is due to the spatiotemporal embedding technique of STID. 5) For the Transformer-based method, the overall performance of the proposed LGSTformer method is the best among all models, and it also performs the best in long-term prediction. Compared with STAEformer, the RMSE index of LGSTformer is reduced by 0.43% and 2.3% in long-term prediction in METR-LA and PEMS-BAY, the MAE index is relatively reduced by 0.3% and 2.13%, and the MAPE index is relatively reduced by -0.40% and 3.17%. This proves that considering local dependency is effective. Compared with MTESformer, the RMSE index of LGSTformer is reduced by 2.10% and 3.20%, the MAE index is relatively reduced by 1.19% and 1.60%,

[0101]

[0102]

[0103] The MAPE index is relatively reduced by -1.25% and 1.84%. This proves the effectiveness of the dual-path adaptive information fusion method introduced for local-global information fusion. Then according to the experimental results on the traffic data set analysis can be found: 1) for the traditional method HA, the prediction performance on the speed data set is similar, and the results on PEMS04 and PEMS08 are the worst. 2) for the STGNN-based method, DFDGCN performs best on PEMS04, while STFGCN performs better on PEMS08. Compared with the early GWNet, DCRNN and AGCRN methods, STFGCN and DFDGCN use more complex dynamic graph construction methods to model the dynamic spatial dependence of traffic data. 3) for the space-time regularization-based method, STNorm performs better than GWNet, DCRNN and AGCRN on PEMS04, but worse than DFDGCN and STFGCN; while it is slightly lower than the STGNN method on the PEMS08 data set. 4) for the linear-based method, STID performs better on the PEMS04 data set than the STGNN-based method and the data decomposition-based method; and its performance on the PEMS08 data set is similar to DFDGCN. This further proves that good results can be achieved by embedding time and space information in the model. 5) for the Transformer-based method, this type of method performs better on the PEMS04 and PEMS08 data sets than other methods. This shows that the self-attention mechanism of the Transformer model can better capture the spatio-temporal dependence. The LGSTformer proposed in the present application performs best on PEMS04. Compared with STAEformer, the RMSE index is reduced by 0.70%, the MAE index is relatively reduced by -0.05%, and the MAPE index is relatively reduced by 0.33%.

[0104]

[0105]

[0106] S6.5: Visualization. In order to further prove the prediction performance of the present application, the prediction results are visualized on the four data sets. As shown in the accompanying drawings, Figures 2-8 The data of two nodes are selected for display on each data set, the prediction length is Horizon 12 (60min), and the visualized data time range is 2 days. It can be seen that the LGSTformer model can well fit the trend of data change, whether it is the trend of change on the speed data set or the flow data set, which shows that it can accurately capture the spatio-temporal dependence of complex time periods.

[0107] In summary, the application case shows that the traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationship is effective. Compared with other design methods, the application fully considers the spatio-temporal dynamics of traffic data. For the time series dependence relationship of traffic data, multi-scale time series convolution and self-attention mechanism in the time dimension are used to learn short-term and long-term time dependence respectively; for the dynamic spatial dependence relationship of traffic data, dynamic-static graph convolution and self-attention mechanism in the spatial dimension are used to learn local and global spatial dependence respectively. In order to more effectively fuse the dependence relationship of different levels, a double adaptive information gating fusion mechanism is introduced to realize it. The experiment uses multiple real traffic flow data, and the results fully prove the feasibility and superiority of the model.

[0108] Embodiment 2

[0109] The third aspect of the application relates to a traffic flow prediction device based on Transformer capable of perceiving local-global spatio-temporal relationship, comprising a memory and one or more processors, the memory stores executable code, and the one or more processors execute the executable code to implement the traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationship in embodiment 1.

[0110] Embodiment 3

[0111] The embodiment relates to a computer readable storage medium, which stores a program, and the program is executed by a processor to implement the traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationship in embodiment 1.

[0112] The above is the specific embodiment of the application and the technical principle used, if the change is made according to the concept of the application, the function generated still does not exceed the spirit covered by the specification and drawings, and still belongs to the protection range of the application.

Claims

1. A traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationship, comprising the following steps: S1: obtaining historical traffic data of all road segments to be predicted, the historical traffic data including traffic flow feature data of the predicted road segment, static adjacency matrix data between road network nodes, and sampling timestamp data of the historical data; fusing the above data to obtain a historical sample data set, and further dividing the historical sample data set into a training data set, a validation set, and a test set; S2: based on the training data set, a spatio-temporal information embedding layer is constructed to provide multiple types of embedding inputs for the model backbone, including historical data feature embedding, time periodicity embedding, and spatial node adaptive embedding, to enhance the spatio-temporal dependence learning ability of the subsequent spatio-temporal module; S3: based on the embedding data obtained by the embedding layer, a local-global temporal dependence module is constructed for time feature learning, the time feature including short-time and long-time temporal dependence relationships in the traffic flow data; The local-global temporal dependence module extracts short-time temporal dependence using a multi-scale convolution module MGTU and extracts long-time temporal dependence using a multi-head attention mechanism MHA based on the embedding data; a double-path adaptive information gate fusion mechanism is used to fuse the short-time temporal dependence and the long-time temporal dependence to obtain temporal dependence features, the double-path adaptive information gate fusion mechanism consisting of a hold gate and a reset gate; S4: based on the time feature data learned by the local-global temporal dependence module, a local-global spatial dependence module is constructed for spatial feature learning, the spatial feature including local and global spatial dependence relationships in the traffic flow data; the local-global spatial dependence module is based on the temporal dependence feature, uses a GCN based on static graph structure and dynamic graph structure to model local spatial dependence relationships, and extracts local spatial dependence features through a fully connected layer FC(); A scaled dot-product self-attention mechanism is used to extract global spatial dependence features; a double-path adaptive information gate fusion mechanism is used to fuse the local spatial dependence and the global spatial dependence to obtain spatial dependence features; S5: based on the spatial dependence features, a fully connected layer network is used to map out the future traffic flow data results of the final predicted road segment.

2. The traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationships according to claim 1, wherein: Step S1 includes the following steps: S1.1: The road segments in the road network to be predicted are regarded as basic node units, which are represented as a node set V = {v1, v2, ..., v N }∈R N , where N represents the number of road segments to be predicted; the physical topology of the road can be expressed as G = {V, P, A s }, where P is the edge set that determines the node connection relationship, A s is the static neighbor matrix of the traffic graph structure; the road section is divided into two groups within a specific time period T = {t1, t2, ..., t T }∈R T The historical traffic flow data is represented as X = {X1, X2, ..., X N }∈R T×N×D , where D represents the number of features; further, the data to be predicted in the future can be expressed as S1.2: dividing the above historical data set into a training data set, a validation data set, and a test data set according to a preset ratio; based on the preset loss function of the training data set, a traffic flow data prediction model is established and trained; the preset loss function on the traffic flow data set is HuberLoss, and the preset loss function on the traffic flow data set is MAELoss.

3. The traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationships according to claim 1, wherein: Step S2 includes the following steps: S2.1: Time periodicity embedding on the sampled timestamp data, mainly including embedding of the timestamps within a day E day and the day of the week within a week E week ; two learnable parameter matrices W 288×E and W 7×E are defined to represent the embedding dictionary; then using the input daily timestamp data X day ∈R T and the weekly data X week ∈R T as the index, get E day ∈R T×N×E and E week ∈R T×N×E ; S2.2: Spatial node-adaptive embedding on spatial feature data, introducing a spatial node-adaptive embedding matrix e with trainable parameters spa ∈R N×ESA to handle the interaction between different nodes, followed by a broadcast mechanism to align the inputs to obtain E spa ∈R T×N×ESA ; S2.3: High-dimensional feature embedding on historical data information of road segment nodes, using a fully connected layer FC() to project the original data into a high-dimensional latent space to obtain a new feature representation H X = FC(X 1:T ) ∈ R T×N×E ; S2.4: concatenating the above four embeddings to get the comprehensive embedding H In The obtained spatio-temporal representation for the input data is The comprehensive embedding is subsequently input into the spatio-temporal dependency extraction module.

4. The traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationships according to claim 3, characterized in that: Step S3 includes the following steps: S3.1: Based on the comprehensive embedding H In To extract short-time time-dependent information, a multi-scale convolution module MGTU is introduced to capture the short-time time dynamic information of traffic flow data. The mathematical expression of the calculation process of a single GTU is as follows: wherein is the input of the local-global temporal module, Γ K is a convolution kernel with size 1 x K, *τis a gated convolution operator; φ() and σ() are the nonlinear activation Tanh and Sigmoid functions, respectively; further, then the mathematical expression for the M-GTU can be obtained using three different convolution kernels: where Γ K1 , Γ K2 and Γ K3 are convolution kernels with a kernel size of 1 x K1, 1 x K2, 1 x K3, respectively; || represents a concatenation operation to concatenate the outputs of GTUs of three different scales in the time dimension; and the fully connected layer FC() is responsible for restoring the time dimension of the concatenated output to T. S3.2: based on the comprehensive embedding H In To extract long-time sequence dependencies, the scaling dot-product self-attention mechanism commonly used in classic Transformer models is used to calculate the importance of each timestamp position in the entire input sequence in the time dimension, and the time information of the entire input sequence is fused through the importance coefficient. The query matrix Q required in the self-attention mechanism calculation is derived through three different linear mapping layers temp , the key matrix K temp , and the value matrix V temp ; then, the self-attention scores Attn temp between different timestamps in the time dimension can be calculated based on Q temp and K temp , so as to realize the extraction of global time dependence; then, in combination with V temp , the representation of long-time time series dependence features can be obtained The mathematical expression of the whole process can be represented as follows: wherein, are different trainable parameters; further, a multi-head attention mechanism (MHA) is introduced to capture more diverse temporal features; the mathematical expression can be represented as follows: head i = Attn temp,i (Q temp,i , K temp,i , V temp,i ) (7) where Q temp,i , K temp,i and V temp,i represent the i-th partition of Q temp , K temp and V temp , respectively; Attn temp denotes the weight matrix for combining the outputs of all attention heads; S3.3: on the short temporal dependency and long temporal dependency fusion to obtain time-dependent features, a dual adaptive information gating fusion mechanism is introduced, which mainly consists of two gating mechanisms, namely the hold gate and the reset gate; the hold gate controls the information flow on a single path, and the reset gate controls the fusion ratio of information on different paths; and After passing through the two gating mechanisms, the output is the time-dependent feature obtained by fusion The mathematical expression of the whole process can be represented as follows: Wherein, φ() and σ() are nonlinear activation Tanh function and Sigmoid function respectively; S3.4: In order to keep consistent with the original Transformer structure design, the local-global space-time Transformer also retains the original residual connection layer (Add), layer normalization (Norm) and position-level feed-forward layer (FFN) in the local-global time module; time-dependent features After the above three operations, the input of the local-global space module is output from the local-global time module 5. The traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationships according to claim 1, wherein: Step S4 includes the following steps: S4.1: based on the time dependence feature, a GCN based on static graph structure is used to process local dependence relationships, which is mathematically expressed as follows: where GCN() represents a graph convolution operation, denotes the input of the L-th local-global spatial module, A s denotes the static adjacency matrix of the road network nodes; the spatial node adaptive embedding is used to model the locally changed spatial relationship, which is used as a supplement to A s , and GCN() is used for node information propagation; the mathematical expression can be represented as follows: A d = Softmax(relu(φ(ΦΦ T ))) e R N×N (16) where φ(), relu() and softmax() represent the Tanh, ReLU and Softmax method functions, respectively; are learnable parameters; then, a simple fully connected layer FC() is used to extract local spatial information of different representations; the mathematical expression can be represented as follows: wherein, represents the learned local spatial dependency features; S4.2: Extract global spatial dependencies based on the time-dependent features, use a scaled dot-product self-attention mechanism to better capture global spatial dependencies, and calculate the correlation between all nodes in the road network in the spatial dimension; the overall calculation process is similar to S3.2; S4.3: local spatial dependency and global spatial dependency fused spatial dependency feature, introducing a two-path adaptive information gating fusion mechanism in S3.3, and output the fused spatial dependency feature after two gating mechanisms S4.4: Consistent with the design of the local-global temporal module, the local-global spatial module also retains the original residual connection layer (Add), layer normalization (Norm), and position-level feed-forward layer (FFN); spatial-dependent features After the above three operations, the output from the local-global spatial module is 6. The traffic flow prediction method based on Transformer capable of perceiving local-global spatio-temporal relationships according to claim 1, wherein: The step S5 specifically comprises: After capturing short-long term temporal dependencies and local-global spatial dependencies through the local-global temporal module and the local-global spatial module, the potential spatio-temporal feature representation is mapped to the prediction result of the future data through a fully connected layer network; the mathematical expression of the whole process can be represented as follows: where W out are learnable parameters, and b out is a bias.

7. The traffic flow prediction device capable of perceiving local-global spatio-temporal relationship based on Transformer, characterized in that, The memory and one or more processors, the memory has stored executable code, the one or more processors execute the executable code, and the method for predicting traffic flow based on Transformer capable of perceiving local-global spatio-temporal relationship in any one of claims 1-6 is implemented.

8. A computer-readable storage medium, characterized in that, A program is stored thereon, which is executed by a processor to implement the method for predicting traffic flow based on Transformer capable of perceiving local-global spatio-temporal relationship in any one of claims 1-6.

Citation Information

Patent Citations

  • Trajectory prediction method for multi-dimensional spatio-temporal feature fusion for automatic driving

    CN118296090A

  • Space-time adaptive dynamic graph convolutional network traffic flow prediction method

    CN118629226A