Traffic prediction transfer learning method based on spatiotemporal graph self-attention model

By using a traffic prediction transfer learning method based on a spatiotemporal graph self-attention model, the spatial correlation of traffic data is dynamically modeled, which solves the problem of insufficient prediction in cities with insufficient data by existing methods and achieves more accurate traffic prediction and urban management.

CN115409276BActive Publication Date: 2025-12-09BEIHANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211116536.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-14
Publication Date
2025-12-09
Estimated Expiration
2042-09-14

AI Technical Summary

Technical Problem

Existing traffic forecasting methods struggle to effectively capture short- and long-distance spatial correlations in urban road networks and lack the ability to transfer data across cities, resulting in poor forecasting performance in cities with insufficient data.

Method used

We employ a spatiotemporal graph-based self-attention model, which transforms traffic data into high-dimensional spatiotemporal representation vectors through a data embedding layer. By combining a time-aware spatial self-attention mechanism and a trend-aware temporal self-attention mechanism, we dynamically model the spatial correlation of traffic data. Furthermore, we pre-train the model on the source dataset through autoregressive and autoencoder tasks to achieve transfer learning to the target city.

Benefits of technology

It enables the modeling of dynamic spatial correlation of traffic data, improves the accuracy of traffic forecasting, and solves the forecasting problem in cities with insufficient data. It is applicable to traffic management and planning in different cities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115409276B_ABST
    Figure CN115409276B_ABST
Patent Text Reader

Abstract

The application discloses a traffic prediction transfer learning method based on a space-time graph self-attention model, and comprises the following steps: converting historical traffic data and a city traffic network structure into high-dimensional space-time representation vectors through a data embedding layer; converting the high-dimensional space-time representation vectors into space-time feature vectors after space-time self-attention block coding through a space-time encoder, and obtaining a final space-time feature vector through a skip connection of outputs of first-layer to L-layer space-time encoders; and inputting the final space-time feature vector into an output layer to obtain predicted traffic data. The application can simultaneously capture short-distance and long-distance spatial correlations in a traffic network, complete dynamic modeling of spatial correlations of traffic data, integrate time and space information, and realize a cross-city deep space-time prediction task.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of deep learning, and more particularly to a traffic prediction transfer learning method based on a spatio-temporal graph self-attention model. BACKGROUND

[0002] Modern cities are developing towards smart cities, and various transportation means are increasing, and traffic congestion problems are becoming more and more obvious, which brings great pressure to modern urban traffic management. Intelligent transportation system is an important component of modern smart city, which can analyze and process traffic conditions to avoid traffic congestion.

[0003] Traffic prediction is one of the main functions of intelligent transportation system, and its main purpose is to predict future traffic conditions based on historical traffic data. Accurate traffic prediction can assist vehicles in planning routes, assist relevant departments in commanding vehicle dispatch, and effectively alleviate traffic congestion. For example, accurate prediction of taxi demand for passengers in the city can better pre-allocate and dispatch vehicles to better meet the needs of passengers and avoid unnecessary waste of resources and waiting.

[0004] The difficulty of traffic prediction lies in that traffic conditions are affected by complex spatial correlation, dynamic temporal correlation and various external factors such as weather. The starting point of spatial correlation is that geographical entities in space interact with each other, for example, the traffic flow of upstream road has a great influence on the traffic conditions of downstream road. In addition, different functional areas may have their unique traffic patterns. From the perspective of time correlation, the traffic conditions of a place may show certain trend in a short period of time and certain periodicity in a long period of time. For example, in consecutive working days, the traffic pattern of the same place in the morning rush hour may be similar, and it is repeated every 24 hours, but the traffic pattern of working days and weekends will have obvious differences. Finally, external factors such as extreme weather, traffic control will obviously affect people's travel and in turn affect the traffic conditions on the road.

[0005] Currently, the mainstream methods of traffic prediction mainly fall into two categories, namely traditional knowledge-driven methods and data-driven methods. Traditional methods include classical statistical methods and machine learning methods. However, these methods limit the ability to model nonlinear data, so their performance in practice is usually poor. With the advancement of urbanization, traffic data is constantly accumulating, laying a data foundation for this field and providing researchers with a new perspective to solve this problem, namely data-driven methods. In recent years, with the rapid development of deep learning, researchers have proposed a large number of deep learning methods to solve this challenging problem. Specifically, graph neural networks (GNN) can model non-Euclidean data, which is more consistent with the structure of the traffic road network, so GNN-based methods have been widely studied for traffic prediction. These data-driven methods have shown excellent performance due to their ability to model and extract complex data features in traffic flow data, but they still face some limitations.

[0006] Firstly, for GNN-based methods, in most existing research, the spatial structure of the road network is often represented by a static pre-defined or self-learned adjacency matrix. However, due to the dynamic changes of traffic conditions (such as peak hours, weekends, traffic accidents, or congestion), modeling the dynamic spatial and temporal correlation of traffic data is a key challenge. Static adjacency matrices limit the ability to learn dynamic patterns of urban traffic. In addition, existing methods are often designed for local road networks and are not effective in capturing long-distance spatial correlations. RNN-based models have the problem of gradient vanishing or explosion when dealing with long-distance sequences, and GNN-based models aggregate information from their neighborhood, which is also local. In real urban road networks, not only are the traffic flows of adjacent road segments (such as upstream and downstream) related, but also non-adjacent road segments with the same function have similar traffic patterns. Therefore, when predicting traffic flow, it is necessary to consider both short-distance and long-distance correlations. Finally, existing methods rarely consider the problem of data transfer between different cities, making it difficult for existing methods to be applied to cities with less traffic data. Due to the different levels of development of different cities, it is difficult for some small cities to collect enough data to support the training needs of complex deep learning models, resulting in a lack of data. One way to solve this problem is to use transfer learning techniques to perform cross-city deep spatio-temporal prediction tasks to transfer knowledge learned from data-rich cities to data-poor cities.

[0007] Therefore, how to provide a traffic prediction transfer learning method based on a spatio-temporal graph self-attention model to solve at least one of the above technical problems is a problem that those skilled in the art need to solve. SUMMARY

[0008] Therefore, the application provides a traffic prediction transfer learning method based on a space-time graph self-attention model, which can simultaneously capture the short-distance and long-distance spatial correlation in a traffic network, complete dynamic modeling of the spatial correlation of traffic data, integrate time and space information, and realize a cross-city deep space-time prediction task.

[0009] In order to achieve the above object, the application adopts the following technical scheme:

[0010] The traffic prediction transfer learning method based on the space-time graph self-attention model comprises the following steps.

[0011] S1: converting historical traffic data and a city traffic network structure into high-dimensional space-time representation vectors through a data embedding layer;

[0012] S2: inputting the high-dimensional space-time representation vectors into a first layer space-time encoder, and the specific steps are as follows.

[0013] performing layer normalization on the high-dimensional space-time representation vectors to obtain layer-normalized space-time representation vectors;

[0014] inputting the layer-normalized space-time representation vectors into a time-aware spatial self-attention mechanism and a trend-aware temporal self-attention mechanism respectively, and correspondingly obtaining a multi-head spatial feature vector and a multi-head temporal feature vector;

[0015] splicing the multi-head spatial feature vector and the multi-head temporal feature vector, and adding the high-dimensional space-time representation vectors before layer normalization to obtain a space-time feature vector;

[0016] performing layer normalization on the space-time feature vector to obtain a layer-normalized space-time feature vector;

[0017] inputting the layer-normalized space-time feature vector into a fully connected feedforward neural network, and adding the output and the space-time feature vector before layer normalization to obtain a space-time feature vector encoded by a space-time self-attention block;

[0018] S3: inputting the space-time feature vector encoded by the space-time self-attention block and output by the first layer space-time encoder as a high-dimensional space-time representation vector into a second layer space-time encoder, repeating the operation of S2, and in this way, until the output of an Lth layer space-time encoder is obtained;

[0019] S4: obtaining a final space-time feature vector through a skip connection of the outputs of the first layer to the Lth layer space-time encoders;

[0020] S5: inputting the final space-time feature vector into an output layer to obtain a space-time prediction model;

[0021] S6: training the spatio-temporal prediction model on the source dataset through the autoregressive task and the auto-encoding task, obtaining a spatio-temporal graph self-attention model, initializing the spatio-temporal graph self-attention model through the pre-trained parameters when applying the spatio-temporal graph self-attention model on the target city dataset, and fine-tuning the model parameters by using the target city dataset to realize the transfer learning between different cities.

[0022] Preferably, the historical traffic data and the city traffic network structure are converted into high-dimensional spatio-temporal representation vectors through a data embedding layer, and the high-dimensional spatio-temporal representation vectors specifically include:

[0023] The historical traffic data is converted into a traffic data embedding vector through a traffic data embedding module;

[0024] The day-of-week information and the intra-day time information of the historical traffic data are correspondingly converted into a day-of-week embedding vector and an intra-day time embedding vector through a periodic information embedding module;

[0025] The position information of the historical traffic data sequence is output as a sequence position information encoding vector through a sequence position information encoding module;

[0026] The graph Laplacian matrix of the city traffic network structure adjacency matrix is subjected to eigenvalue decomposition to obtain a graph Laplacian eigenvector, and the graph Laplacian eigenvector is subjected to a full connection layer to obtain a node position information embedding vector;

[0027] The traffic data embedding vector, the day-of-week embedding vector, the intra-day time embedding vector, the sequence position information encoding vector and the node position information embedding vector are added to obtain a high-dimensional spatio-temporal representation vector.

[0028] Preferably, the layer-normalized spatio-temporal representation vector is input into a time-aware spatial self-attention mechanism to obtain a multi-head spatial feature vector, and the multi-head spatial feature vector specifically includes:

[0029] The time-aware spatial self-attention mechanism includes h s spatial attention heads;

[0030] In each spatial attention head, the layer-normalized spatio-temporal representation vector is converted into a spatial key matrix K S and a spatial value matrix V S through a causal convolution;

[0031] The layer-normalized spatio-temporal representation vector is converted into a spatial query matrix Q S through a full connection operation;

[0032] The spatial query matrix Q S and the spatial key matrix K S are subjected to matrix multiplication, and then are scaled to obtain an original spatial attention matrix A S ;

[0033] The original spatial attention matrix A is calculated S and the Hadamard product of the spatial mask matrix M is performed, and a softmax operation is performed to obtain the final spatial attention matrix; S

[0034] The final spatial attention matrix and the spatial value matrix V are multiplied by a matrix to obtain a spatial feature vector SSA. S

[0035] The spatial feature vectors SSA output by each spatial attention head are spliced to obtain a multi-head spatial feature vector.

[0036] Preferably, the layer-normalized spatio-temporal representation vector is input into a trend-aware temporal self-attention mechanism to obtain a multi-head temporal feature vector, which specifically includes:

[0037] The trend-aware temporal self-attention mechanism includes h t temporal attention heads;

[0038] In each temporal attention head, the layer-normalized spatio-temporal representation vector is converted into a time query matrix Q T and a time key matrix K T by a causal convolution;

[0039] The layer-normalized spatio-temporal representation vector is converted into a time value matrix V T by a full connection operation;

[0040] The time query matrix Q T and the time key matrix K T are multiplied by a matrix, and then scaled to obtain an original time attention matrix A T ;

[0041] The original time attention matrix A T is subjected to a softmax operation to obtain a final time attention matrix;

[0042] The final time attention matrix and the time value matrix V T are multiplied by a matrix to obtain a time feature vector TSA.

[0043] The time feature vectors TSA output by each temporal attention head are spliced to obtain a multi-head temporal feature vector.

[0044] Preferably, the spatial key matrix K S and the spatial value matrix V S have the following specific expressions:

[0045] K S =Φ SK *X, V​​S = Φ SV *X

[0046] where X is the layer-normalized spatio-temporal representation vector, * is the causal convolution operation, and Φ SK and Φ SV are the parameters of the convolution kernel.

[0047] The spatial query matrix Q S is specifically expressed as:

[0048] Q S = XW SQ

[0049] where W SQ is a learnable parameter matrix.

[0050] The original spatial attention matrix A S is specifically expressed as:

[0051]

[0052] where d k is the feature dimension of the spatial query matrix Q S and the spatial key matrix K S , and T represents matrix transposition. Preferably, the multi-head spatial feature vector SSA is specifically calculated as:

[0053] SSA = softmax(A S ⊙ M S ) V S

[0054] where ⊙ represents Hadamard product.

[0055] The temporal query matrix Q T and the temporal key matrix K T are expressed as:

[0056] Q T = Φ TQ *X, K T = Φ TK *X

[0057] where X is the layer-normalized spatio-temporal representation vector, * is the causal convolution operation, and Φ TQ and Φ TK are the parameters of the convolution kernel.

[0058] The temporal value matrix V T is expressed as:

[0059] V T = XW TV

[0060] wherein W TV is a learnable parameter matrix.

[0061] Preferably, the original time attention matrix A T is expressed as:

[0062]

[0063] wherein d k is a time query matrix Q T and a time key matrix K T characteristic dimension;

[0064] The time feature vector TSA is expressed as:

[0065] TSA = softmax(A T )V T .

[0066] Preferably, the core idea of the autoregressive task is to use the data of the past time to generate the data of the future time, so as to model the context dependence of the traffic data.

[0067] The core idea of the auto-encoding task is to use the data added with the disturbance to restore the original data, so as to generate a more effective data representation of the input data.

[0068] The application discloses a traffic prediction transfer learning method based on a space-time graph self-attention model, which has the following advantages:

[0069] (1) A time-aware space graph self-attention model is designed, and by introducing historical time information, dynamic modeling of the spatial correlation of traffic data is completed.

[0070] (2) A special mask mechanism and a dynamic time normalization algorithm are designed, and modeling of the long-distance and short-distance spatial relationships in the traffic network is completed.

[0071] (3) A variety of space-time embedding encoding schemes are designed, more accurate traffic prediction is realized, and the management and planning of the city are facilitated.

[0072] (4) A pre-training method for model transfer between different cities is designed, and the model is pre-trained by our model and transferred to other city datasets, solving the problem of insufficient data in the city. BRIEF DESCRIPTION OF DRAWINGS

[0073] In order to make the technical solutions in the embodiments of the present application or the prior art clearer, the accompanying drawings needed in the embodiments or prior art description will be briefly introduced. Obviously, the accompanying drawings in the following description only aim to explain part of the embodiments of the present application, and not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.

[0074] Figure 1 The accompanying drawings are principle block diagrams of the traffic prediction transfer learning method based on the spatio-temporal graph self-attention model provided by the present application. DETAILED DESCRIPTION

[0075] The technical solutions in the embodiments of the present application will be described clearly and completely in combination with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, and not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.

[0076] The embodiments of the present application disclose a traffic prediction transfer learning method based on a spatio-temporal graph self-attention model, as shown in Figure 1 The method comprises the following steps:

[0077] S1: converting the historical traffic data and the urban traffic network structure into high-dimensional spatio-temporal representation vectors through a data embedding layer;

[0078] S2: inputting the high-dimensional spatio-temporal representation vectors into a first layer spatio-temporal encoder, and the specific steps are as follows:

[0079] performing layer normalization on the high-dimensional spatio-temporal representation vectors to obtain layer-normalized spatio-temporal representation vectors;

[0080] inputting the layer-normalized spatio-temporal representation vectors into a time-aware spatial self-attention mechanism and a trend-aware temporal self-attention mechanism respectively, and correspondingly obtaining a multi-head spatial feature vector and a multi-head temporal feature vector;

[0081] splicing the multi-head spatial feature vector and the multi-head temporal feature vector, and adding the high-dimensional spatio-temporal representation vectors before layer normalization to obtain a spatio-temporal feature vector;

[0082] performing layer normalization on the spatio-temporal feature vector to obtain a layer-normalized spatio-temporal feature vector;

[0083] inputting the layer-normalized spatio-temporal feature vector into a fully connected feedforward neural network, and adding the output and the spatio-temporal feature vector before layer normalization to obtain a spatio-temporal feature vector after encoding of the spatio-temporal self-attention block;

[0084] S3: input the spatio-temporal feature vector encoded by the spatio-temporal self-attention block of the first layer spatio-temporal encoder into the second layer spatio-temporal encoder as a high-dimensional spatio-temporal representation vector, repeat the operation of S2, and so on until the output of the Lth layer spatio-temporal encoder is obtained;

[0085] S4: obtain the final spatio-temporal feature vector through the jump connection of the outputs of the first layer to the Lth layer spatio-temporal encoder;

[0086] S5: input the final spatio-temporal feature vector into the output layer to obtain the spatio-temporal prediction model;

[0087] S6: train the spatio-temporal prediction model on the source data set through the autoregressive task and the auto-encoding task, obtain the spatio-temporal graph self-attention model, and when the spatio-temporal graph self-attention model is applied to the target city data set, the pre-trained parameters are used for initialization, and then the model parameters are fine-tuned by using the target city data set to realize the transfer learning between different cities.

[0088] Specifically, in S1, the data embedding layer needs to retain as much spatial structure information and time series information in the original data as possible in the process of converting the original input into a high-dimensional spatio-temporal representation vector. Therefore, the data embedding layer includes the following 4 modules:

[0089] (1) Traffic data embedding module: similar to the traditional Transformer model, the input of this module is historical traffic data, which is projected into a traffic data embedding vector through a fully connected layer.

[0090] (2) Periodic information embedding module: since traffic data is generated by human daily activities, traffic data usually has obvious periodicity. Therefore, the input of this module is the week information and the time information of the historical traffic data within a day, and the week information and the time information within a day are retained through two learnable periodic information embedding vectors, and the week embedding vector and the time embedding vector within a day are output.

[0091] (3) Sequence position information encoding module: since the self-attention mechanism is used in the spatio-temporal encoder, the self-attention mechanism cannot retain the position information of the sequence, so the input of this module is the position information of the traffic data sequence, and the position information of the sequence is encoded through different frequency sine and cosine functions, and a sequence position information encoding vector is output.

[0092] (4) Node position information embedding module: This module hopes to save the position information of each node in the graph. Graph Laplacian Eigen vectors are a spectral technique for embedding graphs into Euclidean space, which form a local coordinate system that preserves both the global graph structure and the distance information between nodes. Therefore, this module performs eigenvalue decomposition on the Laplacian matrix of the adjacency matrix of the urban traffic network structure to obtain the graph Laplacian Eigen vectors, and then obtains the node position information embedding vector through the fully connected layer.

[0093] Finally, the outputs of the various modules are added to obtain the high-dimensional spatio-temporal representation vector X of the original traffic data.

[0094] Specifically, how to model the spatial correlation and temporal correlation of traffic data is a key technical difficulty in the traffic prediction task. The present application proposes a new spatio-temporal encoder to better learn the spatio-temporal representation of traffic data. The spatio-temporal encoder in S2 contains two sub-layers: a spatio-temporal self-attention block and a fully connected feedforward neural network, and layer normalization and residual connection operations are applied around each sub-layer. However, unlike the traditional multi-head self-attention mechanism, the model decomposes the multi-head dot-product attention operation in the spatio-temporal encoder. Specifically, the model uses a spatial attention head to perform a time-aware spatial self-attention mechanism, and uses a temporal attention head to perform a trend-aware temporal self-attention mechanism. The results of these attention heads are concatenated and projected again to obtain the output of the final spatio-temporal attention block, which allows the model to integrate spatial and temporal information simultaneously.

[0095] Among them, the time-aware spatial self-attention mechanism: if the traditional self-attention operation is performed in the spatial dimension, each node will only pay attention to the information of other nodes at the same time period, which ignores the propagation delay of traffic conditions. For example, when a traffic accident occurs in an area, it may take some time to affect the traffic conditions of neighboring areas. To solve this problem, the present application proposes to use a causal convolution operation instead of a traditional fully connected operation to introduce the influence of time information to dynamically calculate the attention between nodes, that is, each node will pay different attention to other nodes at different times. In addition, the present application also introduces a spatial mask matrix to highlight the spatial correlation from the perspectives of short distance and long distance. From the perspective of short distance, this matrix filters the attention between nodes that are far apart by setting a threshold. From the perspective of long distance, the present application first calculates a similarity matrix according to the historical data time series of each node through the dynamic time warping algorithm (DTW), and selects a number of traffic patterns and the most similar nodes to the current node. Therefore, for each node, the spatial mask matrix not only retains its short-distance neighbors, but also retains those nodes that are long-distance but have similar traffic patterns.

[0096] The execution process of the time-aware spatial self-attention mechanism is as follows: the module contains h s In each spatial attention head, the model first converts the layer-normalized spatio-temporal representation vector of the input at the moment into a spatial key matrix K S and a spatial value matrix V S using causal convolution, converts the layer-normalized spatio-temporal representation vector into a spatial query matrix Q S using a full connection operation, and the specific calculation is as shown in the following formula:

[0097] Q S =XW SQ , K S =Φ SK *X, V S =Φ SV *X

[0098] Where X is the layer-normalized spatio-temporal representation vector, W SQ is a learnable parameter matrix, * is a causal convolution operation, and Φ SK and Φ SV are parameters of the convolution kernel.

[0099] The matrix multiplication of the spatial query matrix Q S and the spatial key matrix K S is performed, and then scaling is performed to obtain the original spatial attention matrix A S , and the specific calculation is as shown in the following formula:

[0100]

[0101] Where d k is the feature dimension of the spatial query matrix Q S and the spatial key matrix K S .

[0102] The Hadamard product of the original spatial attention matrix A S and the spatial mask matrix M S is calculated, and then the result is subjected to a softmax operation to obtain the final spatial attention matrix.

[0103] The matrix multiplication of the final spatial attention matrix and the spatial value matrix V S is performed to obtain the spatial feature vector SSA, and the specific calculation is as shown in the following formula:

[0104] SSA=softmax(A S ⊙M S )V S

[0105] Where ⊙ represents the Hadamard product.

[0106] Finally, the results SSA of each spatial attention head are spliced to obtain a multi-head spatial feature vector.

[0107] Trend-aware temporal self-attention mechanism: the model uses a trend-aware temporal self-attention mechanism to mine the time patterns of traffic data. Simple point-by-point self-attention operations cannot consider the local context information of traffic data and will confuse the judgment of the trend of traffic data changes. Therefore, the invention uses a causal convolution to replace the traditional fully connected layer to introduce the trend in the history of the time series.

[0108] The execution process of the trend-aware temporal self-attention mechanism is as follows: the module contains h t time attention heads. In each time attention head, the model first uses a causal convolution to convert the input spatio-temporal representation vector into a time query matrix Q T and a time key matrix K T , uses a fully connected operation to convert the input spatio-temporal representation vector into a time value matrix V T , and the specific calculation is as follows:

[0109] Q T =Φ TQ *X, K T =Φ TK *X, V T =XW TV

[0110] Where X is the input spatio-temporal representation vector, * is the causal convolution operation, Φ TQ and Φ TK are the parameters of the convolution kernel, and W TV is a learnable parameter matrix.

[0111] The matrix multiplication is performed on the time query matrix Q T and the time key matrix K T , and then scaled to obtain the original time attention matrix A T , and the specific calculation is as follows:

[0112]

[0113] Where d k is the feature dimension of the time query matrix Q T and the time key matrix K T . The softmax operation is performed on A T to obtain the final time attention matrix.

[0114] The matrix multiplication of the final time attention matrix and the time value matrix is performed to obtain a time feature vector TSA, and the specific calculation is as shown in the following formula:

[0115] TSA = softmax(A T )V T

[0116] Finally, the results TSA of each time attention head are spliced to obtain a multi-head time feature vector.

[0117] In S5, the output layer is implemented by two fully connected layers to realize multi-step prediction and convert the feature dimension into the required output dimension, respectively.

[0118] Further, in S6, pre-training and transfer learning: for the problem of insufficient data existing in some cities, pre-training the model and performing transfer learning is an effective solution. Although there may be great differences in data distribution and road network topology between different cities, the overall traffic mode of the city has obvious similarities. Migrating the model pre-trained on a large data set to a small data set can improve its prediction performance on the small data set, and the traffic prediction related knowledge learned from the data-rich source city can also be transferred to the data-sparse target city. The model proposed in the application is completely based on the self-attention mechanism and does not contain any graph convolution operation, so the pre-trained traffic Transformer model can be directly and conveniently migrated to other data sets. In order to learn the transferable traffic prediction knowledge from the source data set and improve the performance of the model on the target data set, the application designs two pre-training tasks: (a) autoregressive task: the core idea of this task is to use the data at past time to generate the data at future time, thereby modeling the context dependency of traffic data. (b) auto-encoding task: the core idea of this task is to use the data with noise disturbance to restore the original data, thereby generating a more effective data representation of the input data. The specific data disturbance method is to randomly select 15% of the data to be set to 0, and use the model to restore the values set to 0 according to the traffic data that has not been replaced. In order to avoid the shortcomings of different pre-training tasks, we fuse the auto-encoding task and the autoregressive task in the pre-training stage, that is, both pre-training tasks are performed at the same time to complete the pre-training of the model on the source data set. Then, when the model is applied to the data set of the target city, the pre-trained parameters are used for initialization, and the model parameters are fine-tuned using the data set of the target city, so as to realize the transfer learning between different cities.

[0119] The various embodiments described in this specification are implemented in a progressive manner, each embodiment focusing on the differences from other embodiments, and the same or similar parts between embodiments can be mutually referred to. For the apparatus disclosed by the embodiments, since it corresponds to the method disclosed by the embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method part.

[0120] The above description of disclosed embodiments enables a person skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A traffic prediction transfer learning method based on a spatiotemporal graph self-attention model, characterized in that, The method comprises the following steps: S1: converting historical traffic data and urban traffic network structure into high-dimensional spatiotemporal representation vectors through a data embedding layer; S2: inputting the high-dimensional spatiotemporal representation vectors into a first layer spatiotemporal encoder, and the specific steps are as follows: performing layer normalization on the high-dimensional spatiotemporal representation vectors to obtain layer-normalized spatiotemporal representation vectors; inputting the layer-normalized spatiotemporal representation vectors into a time-aware spatial self-attention mechanism and a trend-aware temporal self-attention mechanism respectively, and obtaining multi-head spatial feature vectors and multi-head temporal feature vectors correspondingly; splicing the multi-head spatial feature vectors and the multi-head temporal feature vectors, and adding the high-dimensional spatiotemporal representation vectors before layer normalization to obtain spatiotemporal feature vectors; performing layer normalization on the spatiotemporal feature vectors to obtain layer-normalized spatiotemporal feature vectors; inputting the layer-normalized spatiotemporal feature vectors into a fully connected feedforward neural network, and adding the spatiotemporal feature vectors before layer normalization to obtain spatiotemporal feature vectors after spatiotemporal self-attention block encoding; S3: inputting the spatiotemporal feature vectors after spatiotemporal self-attention block encoding output by the first layer spatiotemporal encoder into a second layer spatiotemporal encoder as high-dimensional spatiotemporal representation vectors, repeating the operation of S2, and in this way, the output of the Lth layer spatiotemporal encoder is obtained; S4: connecting the outputs of the first layer to the Lth layer spatiotemporal encoder through a skip connection to obtain a final spatiotemporal feature vector; S5: inputting the final spatiotemporal feature vector into an output layer to obtain a spatiotemporal prediction model; S6: training the spatiotemporal prediction model on a source data set through a self-recurrent task and a self-encoding task to obtain a spatiotemporal graph self-attention model, initializing the spatiotemporal graph self-attention model by using pre-trained parameters when the spatiotemporal graph self-attention model is applied to a target city data set, and fine-tuning the model parameters by using the target city data set to realize transfer learning between different cities; The method for converting historical traffic data and urban traffic network structure into high-dimensional spatiotemporal representation vectors through a data embedding layer specifically comprises the following steps: converting historical traffic data into traffic data embedding vectors through a traffic data embedding module; converting week information and time information of historical traffic data into week embedding vectors and time embedding vectors correspondingly through a periodic information embedding module; outputting position information of a historical traffic data sequence as a sequence position information encoding vector through a sequence position information encoding module; performing eigenvalue decomposition on a Laplacian matrix of an adjacency matrix of a city traffic network structure to obtain graph Laplacian eigenvectors, and obtaining node position information embedding vectors through a fully connected layer from the graph Laplacian eigenvectors; adding the traffic data embedding vectors, the week embedding vectors, the time embedding vectors, the sequence position information encoding vector and the node position information embedding vectors to obtain high-dimensional spatiotemporal representation vectors; inputting the layer-normalized spatiotemporal representation vectors into a time-aware spatial self-attention mechanism to obtain multi-head spatial feature vectors, and the specific steps are as follows: The time-aware spatial self-attention mechanism includes h s a spatial attention head; In each spatial attention head, the layer-normalized spatio-temporal representation vector is converted into a spatial key matrix K by a causal convolution S and a spatial value matrix V S ; The layer-normalized spatio-temporal representation vector is converted to a spatial query matrix Q by a fully connected operation S ; Q = Q * K S A = Q * K S A = Q * K S ; The original spatial attention matrix A is calculated S and the Hadamard product of the spatial mask matrix M S , and then a softmax operation is performed to obtain the final spatial attention matrix The final spatial attention matrix and the spatial value matrix V S Matrix multiplication is performed to obtain a spatial feature vector SSA; splicing the spatial feature vectors SSA output by each spatial attention head to obtain multi-head spatial feature vectors.

2. The traffic prediction transfer learning method based on the spatio-temporal graph self-attention model according to claim 1, characterized in that, The normalized spatio-temporal representation vector is input into a trend-aware time self-attention mechanism to obtain a multi-head time feature vector, and the multi-head time feature vector specifically includes: The trend-aware temporal self-attention mechanism comprises h t a temporal attention head; In each temporal attention head, the layer-normalized spatio-temporal representation vector is converted into a time query matrix Q by a causal convolution T and a time key matrix K T ; The layer-normalized spatio-temporal representation vector is converted into a matrix of time values V by a fully connected operation T ; Query matrix Q for time T and key matrix K for time T Matrix multiplication is performed, and scaling is performed to obtain the original time attention matrix A T ; A original time attention matrix A T performing a softmax operation to obtain a final time attention matrix; The final time attention matrix and time value matrix V T Matrix multiplication is performed to obtain a time feature vector TSA; The time feature vectors TSA output by each time attention head are spliced to obtain a multi-head time feature vector.

3. The traffic prediction transfer learning method based on the spatio-temporal graph self-attention model according to claim 1, characterized in that, The spatial key matrix K S and the spatial value matrix V S The specific expression is: K S = Φ SK * X, V S = Φ SV * X where X is the layer-normalized spatio-temporal representation vector, ★ is the causal convolution operation, Φ SK and Φ SV are parameters of the convolution kernel; Spatial query matrix Q S The specific expression is: Q S = XW SQ where W SQ is a learnable parameter matrix.

4. The traffic prediction transfer learning method based on the spatio-temporal graph self-attention model according to claim 3, characterized in that, Original spatial attention matrix A S The specific expression is: where d k is the feature dimension of the spatial query matrix Q S and the spatial key matrix K S , and T denotes matrix transpose.

5. The traffic prediction transfer learning method based on the spatio-temporal graph self-attention model according to claim 4, characterized in that, The multi-head space feature vector SSA has a specific calculation formula as follows: SSA = softmax(A S M S V S Wherein, represents Hadamard product.

6. The traffic prediction transfer learning method based on the spatio-temporal graph self-attention model according to claim 2, characterized in that, The time query matrix Q T and the time key matrix K T The expression is: Q T = Φ TQ * X, K T = Φ TK * X where X is the layer-normalized spatio-temporal representation vector, ★ is the causal convolution operation, Φ TQ and Φ TK are parameters of the convolution kernel; The time value matrix V T The expression is: V T = XW TV where W TV is a learnable parameter matrix.

7. The traffic prediction transfer learning method based on the spatio-temporal graph self-attention model according to claim 6, characterized in that, Original time attention matrix A T The expression is: where d k is the feature dimension of the time query matrix Q T and the time key matrix K T . The time feature vector TSA has an expression as follows: TSA = softmax(A T V T .

8. The traffic prediction transfer learning method based on the spatio-temporal graph self-attention model according to claim 1, characterized in that, The core idea of the autoregressive task is to use the data at past time to generate the data at future time, thereby modeling the context dependency of the traffic data. The core idea of the auto-encoding task is to use the data with added disturbance to restore the original data, thereby generating a more effective data representation of the input data.

Citation Information

Patent Citations

  • Traffic prediction method based on graph transfer learning

    CN113128783A

  • Space-time combined traffic flow prediction method and device

    CN114529081A