A traffic flow prediction method based on a recurrent spatio-temporal attention mechanism

By using a Transformer model based on a recurrent spatiotemporal attention mechanism, the problems of long-term dependence and feature fusion in traffic flow prediction are solved, resulting in more efficient traffic flow prediction and better accuracy.

CN117576910BActive Publication Date: 2026-11-27CHINA UNIV OF MINING & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311591453.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-27
Publication Date
2026-11-27
Estimated Expiration
2043-11-27

AI Technical Summary

Technical Problem

Existing traffic flow prediction methods are insufficient in terms of long-term reliance and noise interference, and it is difficult to efficiently integrate time series and spatial series features, resulting in decreased computational efficiency and low prediction accuracy.

Method used

A traffic flow prediction method based on a recurrent spatiotemporal attention mechanism is adopted. The Transformer model is used for data embedding and feature extraction. Through parallel computing and spatiotemporal fusion modules, combined with multi-head self-attention and gating mechanisms, long-term dependency and efficient feature fusion are achieved.

Benefits of technology

It improves the accuracy and computational efficiency of traffic flow prediction, better preserves long-term dependency information, reduces noise interference, and enhances the model's parallel computing capabilities and feature fusion performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117576910B_ABST
    Figure CN117576910B_ABST
Patent Text Reader

Abstract

The application discloses a traffic flow prediction method based on a cyclic spatio-temporal attention mechanism and belongs to the field of traffic flow prediction. The prediction method comprises the following steps: firstly, original data from a sensor is subjected to a data preprocessing module to obtain a traffic flow data set; secondly, the divided data set is input into a spatio-temporal feature extraction module based on the cyclic spatio-temporal attention mechanism to fuse learned spatio-temporal features; and finally, the obtained spatio-temporal features are input into a prediction module to predict traffic flow data in a future period of time. In the data filling process in the data preprocessing stage, a forward filling method is designed according to the characteristics of the traffic flow data, and the calculation cost is greatly reduced. The method designs sliding self-attention position coding with a cyclic characteristic, solves the problem that traffic flow prediction performs poorly on long dependence, and supports distributed training on multiple GPUs through a parallel computing architecture skeleton, provides a higher calculation parallel degree than a single GPU, and improves operation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of traffic flow prediction in traffic forecasting tasks, and specifically to a traffic flow prediction method based on a cyclic spatiotemporal attention mechanism. Background Technology

[0002] Traffic flow data encompasses both temporal and spatial information, which are strongly correlated and dynamic. Traffic flow prediction tasks require modeling the correlation between these temporal and spatial information using given temporal and spatial information and specific mechanisms within the given scenario.

[0003] Current traffic flow prediction methods are mostly based on Graph Convolutional Networks (GCNs) or Transformers to model spatiotemporal graphs. GCN models construct a spatial graph based on the distances between sensor nodes or observation points and directly apply graph convolution operations to this graph to extract meaningful patterns and features in the spatial domain. While this approach of treating all sensors as interconnected can effectively extract spatial relationships, it introduces more noise and useless information, leading to overfitting. Methods based on Transformer models, due to their adaptability to various input formats and the introduction of a unique multi-head self-attention mechanism, significantly outperform methods based on GCNs in most tasks, including traffic flow prediction. Transformer-based models often use positional encoding to preserve the sequential information of time series and graph embedding correlation methods to represent spatial series as a series of high-dimensional vectors.

[0004] The Transformer's multi-head self-attention mechanism has strong semantic information extraction capabilities, but its efficiency drops rapidly when long-term dependencies are introduced, making it unable to incorporate longer historical sequence information. Therefore, a recurrent structure needs to be designed to improve the model's accuracy in long-dependency traffic flow prediction. Furthermore, extracting semantic information from long spatiotemporal sequences using efficient and highly parallel computation methods is also a challenge in traffic flow prediction. Finally, a problem that needs to be addressed is cross-modal feature fusion when time-series and spatial-series features are in different modalities. Summary of the Invention

[0005] To address the shortcomings of current traffic flow prediction methods, a traffic flow prediction method based on a cyclic spatiotemporal attention mechanism is proposed. This method can preserve long-term dependencies in the traffic flow prediction task to a greater extent, reduce noise interference, support higher parallelism in model training-related computations, and exhibit good performance in spatiotemporal information correlation and feature fusion capabilities.

[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows:

[0007] A traffic flow prediction method based on a cyclic spatiotemporal attention mechanism is proposed. This method obtains urban traffic flow data through a set of urban traffic sensor nodes and road network data. A traffic flow prediction model is designed using this data to comprehensively and specifically extract spatial and temporal features, fuse these features, and predict traffic flow data for a future period. The traffic flow prediction model is a Transformer model with spatiotemporal attention and cyclic characteristics. The Transformer model includes: a data embedding layer that represents the input traffic flow data as a high-dimensional vector; a parallel spatial sequence semantic extraction module and a temporal sequence semantic extraction module composed of several Transformers with cyclic characteristics; a spatiotemporal fusion module connected to the spatial sequence semantic extraction module and the temporal sequence semantic extraction module respectively for fusing spatiotemporal features; and an output module that uses skip connections and fully connected layers to reduce the dimensionality of the features obtained from the spatiotemporal feature fusion module and finally outputs the results.

[0008] The specific steps are as follows:

[0009] Step 1: Acquire data from all sensor nodes in the tested urban area and form a dataset. Then, analyze the dataset of all sensor nodes. The data in the dataset is preprocessed to obtain information about the sensor node set. The time series sample set in the data is used as traffic flow data for traffic flow prediction tasks.

[0010] Step 2: Utilize the road network Establish spatial dependencies on traffic flow data, where ε is the set of edges; A is a set of sensor nodes. An adjacency matrix representing the spatial affinity between nodes in the array;

[0011] Step 3: After embedding the preprocessed data obtained in Step 1 and the spatial dependency relationship established in Step 2, the data is processed by the spatial sequence semantic extraction module and the time series semantic extraction module respectively to obtain the spatial structure feature sequence and the time feature sequence with flow data. The extraction process of spatial and time features uses a spatiotemporal attention mechanism with cyclic characteristics.

[0012] Step 4: Construct a spatiotemporal fusion module to filter and model spatial and temporal features. The spatial structure feature sequence and the temporal feature sequence with traffic data obtained in Step 3 are fused through the spatiotemporal fusion module to obtain urban traffic flow data with precise spatiotemporal dependence. The urban traffic flow data with precise spatiotemporal dependence is divided into training set, test set and validation set according to a specific ratio.

[0013] Step 5: Use the training set obtained in Step 4 to train and evaluate the traffic flow prediction model. Input the traffic flow data with accurate spatiotemporal dependence in the training set into the traffic flow prediction model for multi-step prediction to predict the traffic flow in the future time period. Based on the pre-designed loss function, calculate the loss value using the traffic flow value predicted by the model and the actual traffic flow value in the training set. Use minimizing the loss value as the optimization objective to gradually optimize the model parameters of the traffic flow prediction model.

[0014] Step 6: Repeat the steps in step 5 multiple times on the traffic flow prediction model to update the model parameters of the traffic flow prediction model in multiple cycles, so that the loss value of the traffic flow prediction model converges. After completing the preset number of training cycles, the trained traffic flow prediction model is obtained.

[0015] Step 7: Input the real-time traffic flow data into the trained traffic flow prediction model to achieve real-time traffic flow prediction.

[0016] Furthermore, for the entire set of sensor nodes... The preprocessing of the middle nodes includes data cleaning, filling, aggregation, and sequence window partitioning; after window partitioning, it is further split into current and future sub-sequences as input and output windows respectively, to obtain the time series sample set, and then divided into training and test sample sets:

[0017] Each road sensor data point is a tuple (flow, time), representing the traffic flow data value at time time; the processing of sensor node data refers to acquiring the average traffic flow information over a period of time from the road sensors to obtain the raw traffic flow data;

[0018] The data cleaning refers to cleaning up redundant values ​​in the sensor node data by retaining the average value of the redundant values.

[0019] The data filling method uses forward filling to fill missing values, using the value of the most recent time point that appeared before the missing value to fill the current missing value;

[0020] The data aggregation process involves calculating the average value of the cleaned and filled sensor data every M minutes, aggregating the data, and then normalizing it using the z-score method to obtain the aggregated sensor node sequence, thus generating traffic flow data. —Where C = 1 or 2: When C = 1, it means that the flow information in the original input only contains the flow value; when C = 2, the flow information includes the inflow and outflow.

[0021] The preprocessed traffic flow data first needs to pass through a fully connected network to obtain a higher-dimensional representation, defining... Traffic flow data for a specific time period. This refers to the traffic flow data for the i-th sub-time period within this time period. It is the original input A higher-dimensional representation is obtained by fusing temporal and spatial embeddings through a fully connected network consisting of two hidden layers:

[0022]

[0023] The sample set is generated using the sliding window method;

[0024] Define a sliding window of length l = P + F—where P is the length of the input window and F is the length of the output window; make it slide across the dataset. Swipe up to get the set of all sensor samples. For each element of a set, it represents a sequence of flow data within a sliding window. After partitioning, samples are obtained for traffic prediction. Each sample of traffic flow data is then used for this purpose. Based on pre-set input / output window lengths P and F, the time period is divided into two time periods: the current time and the future time period, denoted as:

[0025]

[0026]

[0027] These represent traffic flow sequences on an input window and an output window, respectively; the training set, test set, and validation set are randomly divided on the traffic flow sequences on the input and output windows in a ratio of 7:2:1.

[0028] Finally, time information is constructed. This process is based on existing one-hot coding technology, creating daily and weekly indices according to the unique periodicity of traffic flow data. First, the time period is segmented, and then the daily and weekly indices are designed—dividing a day into Δ... d =M min A time period; a week is divided into Δ t=7 time periods for 1 day, with two indexing methods corresponding to short-dependency traffic flow prediction tasks and long-dependency tasks, respectively; then, one-hot encoding is performed separately for each method and then concatenated to obtain... The sparse matrix represents the discrete features of time information, and similarly, the time embedding is obtained through a fully connected network.

[0029] Furthermore, the process of establishing spatial dependencies in step 2 is as follows:

[0030] First, the spatial information of the road network is defined by the map. It means that among them This represents a finite set of nodes, corresponding to N sensors or observation points in the real world, i.e. ε is the set of edges, representing the relationships between nodes; It is an adjacency matrix used to represent the degree of spatial association between sensor nodes; Figure The traffic dataset includes traffic flow data and a weighted adjacency matrix determined by the distance between sensor nodes, wherein the traffic flow data in the traffic dataset is time-series data;

[0031] Secondly, using the graph Laplacian eigenvectors as spatial embeddings, the normalized Laplacian matrix Δ = ID is first calculated. -1 / 2 AD 1 / 2 Where D is the degree matrix and I is the identity matrix, then perform eigendecomposition Δ = U T ΛU, by performing an affine transformation on the k smallest nontrivial feature vectors, yields the graph Laplacian feature embedding, which is the final constructed spatial feature.

[0032] Furthermore, the processing procedures of the spatial sequence semantic extraction module and the time series semantic extraction module of the model in step 3 are as follows:

[0033] set up and The time embedding information contained in each segment of traffic data is as follows: and Spatial embedding information is indirectly contained in any segment of traffic data.

[0034] The Transformer model includes a multi-head self-attention mechanism, which is used to capture dependencies of various ranges within a sequence, including short and long dependencies.

[0035] Design a spatiotemporal attention Transformer model with cyclic characteristics. This model consists of a cyclic network structure composed of K Transformer units and is used for traffic flow prediction.

[0036] In the time series semantic extraction module of the model, each Transformer unit inherits the state vector of the previous unit;

[0037] In a recurrent network architecture composed of K Transformer units, the state vector H of the m-th Transformer unit is... m The update process is as follows:

[0038] (1) Calculate the previous state H m-1 Self-attention with the current position encoding PE(m):

[0039] First, let's look at the previous state H. m-1 The sum of the current position code PE(m) and S is denoted as S. m :

[0040] S m =H m-1 +PE(m)

[0041] Then calculate S. m On the upside, the self-attention of the bulls:

[0042] Multihead(S m ) = Multihead(H m-1 +PE(m))

[0043] Where Multihead(·) represents multi-head self-attention, let A m =LN(S m +MultiHead(S m )) represents the output of the multi-head self-attention score calculated using Layer Norm.

[0044] (2) Take A from (1) m H is obtained through the following transformation m :

[0045] T m =Conv1d(LeakyRelu(Conv1d(A m )+A m ))

[0046] H m =LN(A m +T m )

[0047] Where Conv1d(·) represents a one-dimensional convolution operation;

[0048] (3) H m Input into the next Transformer unit, repeat (1).

[0049] Furthermore, state H m During the update process, the calculation steps for the location code PE are as follows:

[0050] First, the basic code PE0 is calculated. The basic code PE0 consists of two parts: sine and cosine values ​​of different frequencies and sine and cosine values ​​with cyclic characteristics.

[0051]

[0052]

[0053] Where p is the index of the position, m is the number of steps in the loop, and k is a hyperparameter with a value range of [0,1), which is determined by the hyperparameter optimization experiment;

[0054] Using the basic encoding PE0 for traffic flow prediction tasks that do not involve incremental learning, for incremental data with records increasing over time, a set of relative positional encodings needs to be designed during pre-training to enhance the representational power of the positional encodings, so that the positional encodings can represent a larger set of position vectors. Based on the basic encoding PE0, a relative positional encoding PE is designed to make it as unrestricted as possible by the sequence length; let {PE0(p,m,i)|1≤i≤n} be p1,p2,...,p n Based on this, a new set of encoding vectors q1,q2,...,q is constructed. m Where m>n; let u i ,u j If the basis vectors are for relative position encoding, then the relative position encoding is represented as:

[0055] q (i-1)×n+j =αu i +(1-α)u j

[0056] Where α∈(0,1) and α≠0.5 is a hyperparameter. α=0.5 is removed in this interval because the case of i=j cannot be distinguished at this time;

[0057] When the position index i does not exceed n, the range of the position index is within the range of the index values ​​of the absolute position code, and the relative position code q i Should be combined with absolute position encoding p i They are equal, that is, q should exist. i =p iThis ensures compatibility with pre-trained traffic flow prediction models, at which point:

[0058]

[0059] Based on the above relative position encoding, using p1, p2, ..., p n This set of N absolute position codes serves as a basis vector, representing n 2 A relative positional encoding;

[0060] Encode the above arbitrary position q i Let it be denoted as PE(i), then we have:

[0061]

[0062] The spatiotemporal attention Transformer model consists of a recurrent network structure composed of K Transformer units, used for traffic flow prediction. In the model's time-series semantic extraction module, each Transformer unit inherits the state vector of the previous unit. In the recurrent network architecture composed of K Transformer units, the state vector H of the m-th Transformer unit... m The update process is as follows:

[0063] First, let H be the feature of the m-th Transformer unit. m , record S m =H m-1 +PE(m), It is the projection matrix of the weight parameters. First, calculate the projection matrix of each feature head. i Scaling dot product attention:

[0064]

[0065] Secondly, the K single-head attention connections of this unit are then linked with the weight matrix W. O Taking the dot product, we get S m Multi-head self-attention:

[0066] Multihead(S m )=Concat(head1,head2,…,head K W O

[0067]

[0068] The overall architecture of the spatial sequence semantic extraction module of the model is similar to that of the time series semantic extraction module. The difference lies in the index construction when segmenting the spatial sequence. Each sequence segment uses its corresponding observation point identifier as the index, i.e., the value of i. In the time series semantic extraction module, the index assigned by the segmentation operation when constructing the time information is a series of auto-incrementing positive integers.

[0069] Furthermore, the spatiotemporal fusion module described in step 3 employs a gating mechanism to perform spatiotemporal fusion, thereby fusing temporal and spatial features:

[0070] The spatiotemporal fusion gate g uses the Sigmoid activation function:

[0071] g = Sigmoid(H) S W S +H T W T +b g )

[0072] in These are the learnable spatial and temporal weight matrices, respectively. It is a learnable bias matrix, H S H T These are spatial and temporal characteristics, respectively; the spatiotemporal fusion characteristic H can be represented by the following formula:

[0073] H = Fusion(H) s H T )=g⊙H s +(1-g)⊙H T .

[0074] Furthermore, in step 3, the spatial sequence semantic extraction module and the time series semantic extraction module of the traffic flow prediction model are computed in parallel based on sequence segmentation and parameter sharing.

[0075] The spatial sequence semantic extraction module, the time series semantic extraction module, and the spatiotemporal fusion module adopt a parallel computing architecture based on sequence segmentation and parameter sharing, splitting the original sequence according to the sensor / sampling point index. Obtain the set of split sequences in Each subsequence The inputs are fed into a series of parallel recurrent Transformer units, which share parameters and each produce its own prediction results. After the calculation is completed: First, aggregate all the prediction results to obtain the intermediate result. Then, using skip joins, the intermediate results are transformed into... Finally, F intermediate results that have undergone skip connections are concatenated according to the preset output window size, and then subjected to two layers of one-dimensional convolution to reduce the dimensionality, resulting in a value that conforms to the predicted flow dimension C. Its formalized expression is as follows:

[0076]

[0077] in This represents a 3-dimensional tensor of size F×N×C.

[0078] Furthermore, the experimental design for hyperparameter optimization:

[0079] Based on the formal model training experiment design, the number of iterations was reduced according to the performance of the machine used for training; during training, the hyperparameters of the model were adjusted according to the fitting of the validation set; the hyperparameter adjustment process used a grid search algorithm; the optimized hyperparameters included: (1) the α value of the activation function used when updating the Transformer unit state on the negative half axis; (2) updating the Transformer unit state H m (3) Forgetting rate; (4) Global learning rate; (5) Weight allocation parameter k for positional encoding in sliding self-attention; (6) Parameter α in relative positional encoding.

[0080] Furthermore, the design and performance evaluation methods for the loss function during the training of the traffic flow prediction model are as follows:

[0081] Batch continuous sequences After the input data is fed into the traffic flow prediction model, the model prediction results are obtained. Huber Loss is selected as the loss function, and the loss value is calculated based on the model prediction results and label values. The traffic flow prediction model updates each parameter through backpropagation to reduce the loss between the true value and the predicted value, so that the predicted value generated by the traffic flow prediction model converges to the true value. The optimal solution of the traffic flow prediction model parameters is calculated by the mini-batch stochastic gradient descent (SGD) optimization algorithm.

[0082] The loss function for the time interval [K+1, K+T] is as follows:

[0083]

[0084] Where δ is a parameter of Huber Loss;

[0085] Data normalization is performed using a layer normalization algorithm;

[0086] The performance evaluation uses mean absolute error (MAE) and root mean square error (RMSE) as indicators.

[0087] The calculation process for Mean Absolute Error (MAE) is as follows:

[0088]

[0089] The calculation process for the root mean square error (RMSE) is as follows:

[0090]

[0091] In the formula: X Ftr The label values ​​represent an m-row, n-column matrix consisting of the actual traffic flow values ​​from m sensors (observation points) across n time slices. and These represent the traffic flow values ​​of all sensors (observation points) within the time slice range [K+1, K+T]. This represents the predicted value matrix generated by the traffic prediction model, with the same dimension as the label value matrix. and These represent the values ​​of the elements in the i-th row and j-th column of the corresponding matrix. When the dimension C of the traffic flow is greater than 1 (e.g., C = 2 represents inflow and outflow), the corresponding loss is calculated for each traffic flow dimension during the evaluation.

[0092] The beneficial effects of this invention are:

[0093] 1) The traffic prediction model based on the recurrent spatiotemporal attention mechanism disclosed in this invention is obtained by improving the multi-head self-attention model of Transformer, and fully inherits the advantages of Transformer model, such as high computational throughput, high parallelism, and adaptive input.

[0094] 2) The traffic prediction model based on the recurrent spatiotemporal attention mechanism of this invention overcomes the problem of decreased computational efficiency in long spatiotemporal sequence prediction of existing similar models. Specifically, the original sequence is split into multiple sequences and input into a series of Transformer units with shared parameters for parallel computation. The results are then aggregated to obtain features.

[0095] (3) This invention improves the calculation method of position encoding and designs a relative position encoding with cyclic characteristics. The self-attention based on this position encoding is a sliding self-attention with cyclic characteristics, which breaks through the forgetting problem exhibited by existing similar models in long-term spatiotemporal sequence prediction. Attached Figure Description

[0096] Figure 1 It is a recurrent structure of multiple Transformer units, each consisting of a multi-head self-attention layer and a feedforward neural network, which are normalized twice.

[0097] Figure 2This is a diagram illustrating the overall structure of the traffic flow prediction model based on the cyclic spatiotemporal attention mechanism in this embodiment of the invention.

[0098] Figure 3 This is a schematic diagram illustrating the implementation of sequence fragmentation and parameter sharing in the traffic flow prediction model of this invention. N units with this parallel computing architecture are connected together. Figure 2 The module includes a spatial sequence semantic extraction module with cyclic characteristics and a time series semantic extraction module. Detailed Implementation

[0099] The specific embodiments of the present invention will be described in detail below with reference to the technical solutions, accompanying drawings and specific examples.

[0100] like Figure 1 and Figure 2 As shown, a traffic flow prediction method based on a cyclic spatiotemporal attention mechanism is implemented through a traffic flow prediction model based on a cyclic spatiotemporal attention mechanism. The steps are as follows:

[0101] Step 1: Acquire data from all sensor nodes in the tested urban area and form a dataset. Then, analyze the dataset of all sensor nodes. The data in the dataset is preprocessed to obtain information about the sensor node set. The time series sample set in the data is used as traffic flow data for traffic flow prediction tasks.

[0102] Step 2: Utilize the road network Establish spatial dependencies on traffic flow data, where ε is the set of edges; A is a set of sensor nodes. An adjacency matrix representing the spatial affinity between nodes in the array;

[0103] Step 3: After embedding the preprocessed data obtained in Step 1 and the spatial dependency relationship established in Step 2, the data is processed by the spatial sequence semantic extraction module and the time series semantic extraction module respectively to obtain the spatial structure feature sequence and the time feature sequence with flow data. The extraction process of spatial and time features uses a spatiotemporal attention mechanism with cyclic characteristics.

[0104] Step 4: Construct a spatiotemporal fusion module to filter and model spatial and temporal features. The spatial structure feature sequence and the temporal feature sequence with traffic data obtained in Step 3 are fused through the spatiotemporal fusion module to obtain urban traffic flow data with precise spatiotemporal dependence. The urban traffic flow data with precise spatiotemporal dependence is divided into training set, test set and validation set according to a specific ratio.

[0105] Step 5: Use the training set obtained in Step 4 to train and evaluate the traffic flow prediction model. Input the traffic flow data with accurate spatiotemporal dependence in the training set into the traffic flow prediction model for multi-step prediction to predict the traffic flow in the future time period. Based on the pre-designed loss function, calculate the loss value using the traffic flow value predicted by the model and the actual traffic flow value in the training set. Use minimizing the loss value as the optimization objective to gradually optimize the model parameters of the traffic flow prediction model.

[0106] Step 6: Train the same model multiple times, with each training session considered as one epoch. Repeat step 5 for 200 to 500 epochs to update the model parameters multiple times and bring the model's loss value to converge.

[0107] Step 7: Input the real-time traffic flow data into the trained traffic flow prediction model to achieve real-time traffic flow prediction.

[0108] Furthermore, the data preprocessing process in step 1 is as follows:

[0109] Each road sensor data point is represented as a tuple (flow, time), indicating the traffic flow value at time time. Sensor node data processing involves acquiring average traffic flow information over a given period from the road sensors. Specifically, this processing method includes: cleaning redundant values ​​(where multiple sensors at the same time point may display different traffic flow values, which can be caused by equipment malfunctions or system errors), retaining the average value of the redundant values; aggregating sensor data every M minutes; and using forward imputation to fill in missing values, considering that traffic flow within a continuous time period typically does not change abruptly. Finally, the imputed sensor data is normalized using the z-score method to obtain the traffic flow data. —Where C = 1 or 2: When C = 1, it means that the flow information in the original input only contains the flow value; when C = 2, the flow information includes both inflow and outflow.

[0110] The preprocessed traffic flow data first needs to pass through a fully connected network to obtain a higher-dimensional representation. Definition Traffic flow data for a specific time period. This represents the traffic flow data for the i-th sub-time period within this time period. It is the original input A higher-dimensional representation is obtained by fusing temporal and spatial embeddings through a fully connected network consisting of two hidden layers:

[0111]

[0112] Then, a sliding window method is used to generate the sample set. A sliding window of length l = P + F is defined—where P is the length of the input window and F is the length of the output window; this window is used to generate the sample set within the dataset. Swipe up to get the set of all samples. Each element of the set represents a sequence of flow data within a sliding window. After partitioning, samples are obtained for traffic prediction. Each sample of traffic flow data is then used for this purpose. Based on the pre-set input / output window lengths P and F, the time period is divided into two time periods: the current time and the future time period, denoted as follows:

[0113]

[0114]

[0115] The training set, test set, and validation set are randomly divided on the traffic flow sequences in the above input and output windows in a ratio of 7:2:1.

[0116] Finally, time information is constructed. This process is based on existing one-hot coding technology, creating daily and weekly indexes according to the unique periodic nature of traffic flow data. First, the time period is segmented, and then the daily and weekly indexes are designed—dividing a day into Δ... d =M min A time period; a week is divided into Δ t =7 time periods for 1 day, with two indexing methods corresponding to short-dependency traffic flow prediction tasks and long-dependency tasks, respectively; then, one-hot encoding is performed separately for each method and then concatenated to obtain... The sparse matrix represents the discrete features of time information, and similarly, the time embedding is obtained through a fully connected network.

[0117] Furthermore, the process of establishing spatial dependencies in step 2 is as follows:

[0118] First, the spatial information of the road network is defined by the map. It means that among them It is a finite set of nodes, corresponding to N sensors or observation points in the real world, that is... ε is the set of edges, representing the relationships between nodes; It is an adjacency matrix used to represent the degree of spatial association between sensor nodes. (Figure) The traffic dataset includes traffic flow data and a weighted adjacency matrix determined by the distances between sensor nodes, wherein the traffic flow data in the traffic dataset is time-series data.

[0119] Secondly, the graph Laplacian eigenvectors are used as spatial embeddings. First, the normalized Laplacian matrix Δ = ID is calculated. -1 / 2 AD 1 / 2 Where D is the degree matrix and I is the identity matrix. Then, perform eigendecomposition Δ = U. T ΛU, by performing an affine transformation on the k smallest nontrivial feature vectors, yields the graph Laplacian feature embedding, which is the final constructed spatial feature.

[0120] Furthermore, the processing procedures of the spatial sequence semantic extraction module and the time series semantic extraction module of the model in step 3 are as follows:

[0121] and The time embedding information contained in each segment of traffic data is as follows: and Spatial embedding information is indirectly contained in any segment of traffic data.

[0122] The time series processing module is based on the Transformer model of recurrent attention. The model is an architecture consisting of K Transformer units, each of which inherits the state vector of the previous unit.

[0123] The state vector H of the m-th Transformer unit in the above loop structure m The update process is as follows:

[0124] (1) Calculate the previous state H m-1 Self-attention with the current position encoding PE(m):

[0125] First, let's look at the previous state H. m-1 The sum of the current position code PE(m) and S is denoted as S. m :

[0126] S m =H m-1 +PE(m)

[0127] Then calculate S. m On the upside, the self-attention of the bulls:

[0128] Multihead(S m ) = Multihead(H m-1 +PE(m))

[0129] Where Multihead(·) represents multi-head self-attention, let A m =LN(S m +MultiHead(S m )) represents the output of the multi-head self-attention score calculated using Layer Norm.

[0130] (2) Take A from (1) m H is obtained through the following transformation m :

[0131] T m =Conv1d(LeakyRelu(Conv1d(A m )+A m ))

[0132] H m =LN(A m +T m )

[0133] Where Conv1d(·) represents a one-dimensional convolution operation;

[0134] (3) H m Input into the next Transformer unit, repeat (1).

[0135] H m During the update process, the location code PE is calculated as follows:

[0136] First, the basic code PE0 is calculated. The basic code PE0 consists of two parts: sine and cosine values ​​of different frequencies and sine and cosine values ​​with cyclic characteristics.

[0137]

[0138]

[0139] Where p is the index of the position, m is the number of steps in the loop, and k is a hyperparameter with a value range of [0,1), which is determined by the hyperparameter optimization experiment;

[0140] The basic encoding PE0 can be used for traffic flow prediction tasks that do not involve incremental learning. For incremental data with increasing records over time, a set of relative positional encodings needs to be designed during pre-training to enhance the representational power of the positional encodings, enabling them to represent a larger set of position vectors. Based on the basic encoding PE0, a relative positional encoding PE is designed to be as unrestricted by sequence length as possible; let {PE0(p,m,i)|1≤i≤n} be p1,p2,...,p nBased on this, a new set of encoding vectors q1,q2,...,q is constructed. m Where m>n; let u i ,u j If the basis vectors are for relative position encoding, then the relative position encoding is represented as:

[0141] q (i-1)×n+j =αu i +(1-α)u j

[0142] Where α∈(0,1) and α≠0.5 is a hyperparameter. α=0.5 is removed in this interval because the case of i=j cannot be distinguished at this time;

[0143] When the position index i does not exceed n, the range of the position index is within the range of the index values ​​of the absolute position code, and the relative position code q i Should be combined with absolute position encoding p i They are equal, that is, q should exist. i =p i This ensures compatibility with pre-trained traffic flow prediction models, at which point:

[0144]

[0145] Based on the above relative position encoding, using p1, p2, ..., p n This set of n absolute position codes serves as a basis vector, representing n 2 A relative positional encoding;

[0146] Encode the above arbitrary position q i Let it be denoted as PE(i), then we have:

[0147]

[0148] H calculated by the m-th Transformer m During the update process, the calculation process of Multihead attention is as follows:

[0149] First, let H be the feature of the m-th unit. m , record S m =H m-1 +PE(m), It is the projection matrix of the weight parameters. First, calculate the feature head. i Scaling dot product attention:

[0150]

[0151] Secondly, the K single-head attention connections of this unit are then linked with the weight matrix W.O Taking the dot product, we can obtain S. m Multi-head self-attention:

[0152] Multihead(S m )=Concat(head1,head2,…,head K W O

[0153]

[0154] The overall architecture of the spatial sequence semantic extraction module is similar to that of the time series semantic extraction module. The difference lies in the index construction when segmenting the spatial sequence. In the spatial sequence module, each segment uses its corresponding observation point identifier as the index (i.e., the value of i). In the time series semantic extraction module, the index assigned during the segmentation operation based on time information is a series of auto-incrementing positive integers, specifically as follows: Figure 3 As shown.

[0155] To address the issue of decreased computational efficiency due to long dependencies, the spatial sequence semantic extraction module, time series semantic extraction module, and spatiotemporal fusion module are designed with a parallel computing architecture based on sequence segmentation and parameter sharing, which transforms the original sequence... The sequences are split according to the sensor / sampling point index to obtain the split sequence set. in Each subsequence The inputs are fed into a series of parallel recurrent Transformer units, which share parameters and each produce its own prediction results. After the calculation is completed: First, aggregate all the prediction results to obtain the intermediate result. Then, using skip joins, the intermediate results are transformed into... Finally, F intermediate results that have undergone skip connections are concatenated according to the preset output window size, and then subjected to two layers of one-dimensional convolution to reduce the dimensionality, resulting in a value that conforms to the predicted flow dimension C. Its formalized expression is as follows:

[0156]

[0157] in This represents a 3-dimensional tensor of size F×N×C;

[0158] Furthermore, the spatiotemporal fusion module of the model in step 4 processes the model as follows:

[0159] The core of the spatiotemporal fusion module is a gating module. This method introduces a gating mechanism to learn long-term dependencies in spatiotemporal sequences, addressing the efficiency degradation exhibited by similar models in predicting long sequences. In this method, the spatiotemporal fusion module uses a gating mechanism to perform spatiotemporal fusion, fusing temporal and spatial features. The spatiotemporal fusion gate g uses the Sigmoid activation function.

[0160] g = Sigmoid(H) S W S +H T W T +b g )

[0161] in These are the learnable spatial and temporal weight matrices, respectively. It is a learnable bias matrix, H S H T These are spatial and temporal characteristics, respectively.

[0162] Furthermore, the spatiotemporal fusion feature H in step 3 can be represented by the following formula:

[0163] H = Fusion(H) s H T )=g⊙H s +(1-g)⊙H T

[0164] Where ⊙ represents the Hadamarda.

[0165] Furthermore, the training evaluation process in step 5 is as follows:

[0166] Hyperparameter optimization experiment. Based on the formal model training experiment design, the number of iterations was reduced according to the performance of the machine used for training. During training, the hyperparameters of the model were adjusted according to the fitting of the validation set. The hyperparameter adjustment process used a grid search algorithm. The optimized hyperparameters included: (1) the α value of the activation function used when updating the Transformer unit state on the negative half axis; (2) the update of the Transformer unit state H m (3) Forgetting rate; (4) Global learning rate; (5) Weight allocation parameter k for positional encoding in sliding self-attention; (6) Parameter α in relative positional encoding.

[0167] Model training. This involves training batches of continuous sequences. The input data is fed into the spatiotemporal continuous encoder-decoder model to obtain the model prediction results. Huber Loss is selected as the loss function, and the loss value is calculated based on the model prediction results and label values. The model updates each parameter through backpropagation to reduce the loss between the true value and the predicted value, so that the predicted value generated by the model converges to the true value. The mini-batch stochastic gradient descent (SGD) optimization algorithm is selected to calculate the optimal solution of the model parameters.

[0168] Furthermore, the loss function design and performance evaluation in step 6 are as follows:

[0169] The loss function for the interval [K+1, K+T] calculated using this method is as follows:

[0170]

[0171] Where δ is a parameter of Huber Loss.

[0172] Data normalization. This step uses a layer normalization algorithm.

[0173] Performance evaluation uses mean absolute error (MAE) and root mean square error (RMSE) as metrics.

[0174] The formula for calculating MAE is as follows:

[0175]

[0176] The formula for calculating RMSE is as follows:

[0177]

[0178] In the formula: X Ftr The label values ​​represent an m-row, n-column matrix consisting of the actual traffic flow values ​​from m sensors (observation points) across n time slices. and These represent the traffic flow values ​​of all sensors (observation points) within the time slice range [K+1, K+T]. This represents the predicted value matrix generated by the traffic prediction model, with the same dimension as the label value matrix. and These represent the values ​​of the elements in the i-th row and j-th column of the corresponding matrix. When the dimension C of the traffic flow is greater than 1 (e.g., C = 2 represents inflow and outflow), the corresponding loss is calculated for each traffic flow dimension during the evaluation.

[0179] Example 1: A traffic flow prediction method based on a cyclic spatiotemporal attention mechanism.

[0180] The first step is to preprocess the raw traffic flow data.

[0181] The invention will be further illustrated using the PeMS08 dataset provided by California Transportation Corporation (PeMS). The PeMS0x series datasets are widely used in research related to traffic forecasting and time-series forecasting. The PeMS08 dataset contains traffic flow data from 170 nodes over 62 consecutive days, collected starting July 1, 2016, with data collected every 5 minutes. Therefore, its data shape is (170, 17856, 3) – where the 3-dimensional features are (flow, occupy, speed). The original adjacency matrix data is a distance.csv file, which contains data in the format (from, to, distance).

[0182] This method uses the PeMS series dataset and does not require additional cleaning and padding work.

[0183] Construct the temporal and spatial information of the PeMS08 dataset, and use the sliding window method to generate the sample set to obtain all sample sets.

[0184] Each sample in the sample set The model is divided into two parts of a specific length: an input window (P) and an output window (F) for training. and Obtain the original dataset after partitioning

[0185] The second step is to divide the training set, validation set, and test set.

[0186] The original dataset was randomly divided into three parts in a 7:2:1 ratio, which were used as the training set, validation set, and test set, respectively.

[0187] The third step is to optimize the training process of the attention mechanism model.

[0188] A complete training process for a traffic prediction model is as follows:

[0189] (1) Utilizing the road network Establish spatial dependencies on traffic flow data, where ε is the set of edges; A is a set of sensor nodes. An adjacency matrix representing the spatial association between nodes in a dataset; on the PeMS08 dataset, the node set... The set {0,1,2,…,169} contains 170 sensor nodes numbered from 0 to 169; the set of edges ε is a set of triples (src,dst,cost), representing the cost of moving from node src to node dst as cost; the adjacency matrix A is based on the node set. The set of edges ε is given.

[0190] (2) Sample set data obtained after preprocessing the original traffic flow data and utilizing the road network After the spatial dependency relationship is embedded, it is processed by the spatial sequence semantic extraction module and the time sequence semantic extraction module to obtain the spatial structure feature sequence and the time feature sequence with flow data. The extraction process of spatial and time features uses a spatiotemporal attention mechanism with cyclic characteristics.

[0191] (3) Construct a spatiotemporal fusion module to filter and model spatial and temporal features. The spatial structure feature sequence obtained by the spatial sequence semantic extraction module and the temporal sequence semantic extraction module and the temporal feature sequence with traffic data are fused by the spatiotemporal fusion module to obtain urban traffic flow data with precise spatiotemporal dependence.

[0192] (4) Train and evaluate the traffic flow prediction model. Input the traffic flow data with accurate spatiotemporal dependence obtained after the fusion of spatiotemporal features into the traffic flow prediction model for multi-step prediction in order to predict the traffic flow in a certain period of the future.

[0193] Hyperparameter optimization experiments were conducted following the above procedure. Based on the complete training of the traffic prediction model, the number of iterations was reduced according to the performance of the machine used for training. The training GPU used was one NVIDIA GeForce RTX2080Ti with 11GB of available GPU memory. To maximize GPU throughput when there were no bottlenecks in on-device RAM and CPU throughput, the batch size was fixed at 8 samples per training iteration. The number of epochs was 400 during formal training and adjusted to 20 during the optimization experiments.

[0194] During training, the model's hyperparameters are adjusted based on the validation set fit. The hyperparameter tuning process uses a grid search algorithm. The optimized hyperparameters include:

[0195] (1) When updating the Transformer unit state, the activation function used has an α value on the negative half-axis. The LeakyReLU activation function is used, with α = 0.01.

[0196]

[0197] (2) Update the Transformer unit state H m The forgetting rate is dropout. The main basis for adjusting dropout is the degree of overfitting of the model, which involves ill-posed problems. Start from 0 and try to slowly increase dropout. Since the dataset is large enough and the model overfitting is not serious, set dropout = 0.0.

[0198] (3) Global learning rate: The learning rate α = 0.001 is commonly used in similar models. The model of this method performs well enough on the PEMS08 dataset when α = 0.001.

[0199] (4) In absolute position encoding, the weight parameter k for index embedding and cyclic embedding performs better when k = 0.5.

[0200]

[0201]

[0202] (5) The parameter α in the relative position encoding is set to α = 0.4.

[0203]

[0204] Step 4: Model Training and Performance Evaluation

[0205] The formal model training follows the training process described in step three. In this example, the present invention will be applied for short-term traffic flow prediction. That is, traffic flow data for a fixed time period and traffic flow data for that time period in historical cycles will be used to predict traffic flow data for that time period in the next cycle. For example, to predict the traffic flow from 11:00 to 12:00 on July 30, 2016 (future data), the traffic flow data from 11:00 to 12:00 on July 16, 2016 will be used as historical data, and the traffic flow data from 11:00 to 12:00 on July 23, 2016 will be used as current data.

[0206] Batch continuous sequences The input data is fed into the spatiotemporal continuous encoder-decoder model to obtain the model prediction results. The Huber Loss loss function is selected, and the loss value is calculated based on the model prediction results and label values. The model updates each parameter through backpropagation to reduce the loss between the true value and the predicted value, so that the predicted value generated by the model converges to the true value. An optimizer based on the mini-batch stochastic gradient descent algorithm was used for 400 epochs of mean squared error loss training.

[0207] The data was normalized using a hierarchical normalization algorithm, followed by performance evaluation using mean absolute error (MAE) and root mean square error (RMSE) as metrics. The calculation method is as follows:

[0208]

[0209]

[0210] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and are included within the protection scope of the present invention.

Claims

1. A traffic flow prediction method based on a cyclic spatiotemporal attention mechanism, characterized in that: Urban traffic flow data is obtained through a set of urban traffic sensor nodes and road network data. A traffic flow prediction model is designed using this data to comprehensively and specifically extract spatial and temporal features, fuse these features, and predict traffic flow data for a future period. The traffic flow prediction model is a Transformer model with spatiotemporal attention and cyclic characteristics. The Transformer model includes: a data embedding layer that represents the input traffic flow data as a high-dimensional vector; a spatial sequence semantic extraction module and a temporal sequence semantic extraction module composed of several Transformers with cyclic characteristics, set in parallel; a spatiotemporal fusion module connected to the spatial sequence semantic extraction module and the temporal sequence semantic extraction module respectively to achieve spatiotemporal feature fusion; and an output module that uses skip connections and fully connected layers to reduce the dimensionality of the features obtained by the spatiotemporal feature fusion module and finally outputs the results. The specific steps are as follows: Step 1: Acquire data from all sensor nodes in the tested urban area and form a dataset. Then, analyze the dataset of all sensor nodes. The data in the dataset is preprocessed to obtain information about the sensor node set. The time series sample set in the data is used as traffic flow data for traffic flow prediction tasks. Step 2: Utilize the road network Establish spatial dependencies on traffic flow data, where It is the set of edges; It is used to represent a set of sensor nodes. An adjacency matrix representing the spatial affinity between nodes in the array; Step 3: After embedding the preprocessed data obtained in Step 1 and the spatial dependency relationship established in Step 2, the data is processed by the spatial sequence semantic extraction module and the time series semantic extraction module respectively to obtain the spatial structure feature sequence and the time feature sequence with flow data. The extraction process of spatial and time features uses a spatiotemporal attention mechanism with cyclic characteristics. Processing procedures of the spatial sequence semantic extraction module and the time series semantic extraction module: set up and The time embedding information contained in each segment of traffic data is as follows: and Any segment of traffic data indirectly contains spatial embedding information. ; The Transformer model includes a multi-head self-attention mechanism, which is used to capture dependencies of various ranges within a sequence, including short and long dependencies. Design a spatiotemporal attention Transformer model with cyclic characteristics. This model consists of a cyclic network structure composed of K Transformer units and is used for traffic flow prediction. In the time series semantic extraction module of the model, each Transformer unit inherits the state vector of the previous unit; In a recurrent network architecture composed of K Transformer units, the first... The state vector of each Transformer unit The update process is as follows: (1) Calculate the previous state and current position encoding Self-attention: First, let's look at the previous state. Encoding with current position The sum of is recorded as : , Then calculate On the upside, the self-attention of the bulls: , in This indicates that the bulls are paying attention, causing... , representing the output of the multi-head self-attention score after layer standardization; (2) Take the part in (1) The following transformation is obtained : , , in This represents a one-dimensional convolution operation; (3) Input into the next Transformer unit, repeat (1); state During the update process, position encoding The calculation steps are as follows: First, calculate the basic encoding. Basic coding It consists of two parts: sine and cosine values ​​of different frequencies and sine and cosine values ​​with cyclic characteristics. , , Where p is the index of the position, m is the number of steps in the loop, and k is a hyperparameter with a value range of [0,1), which is determined by the hyperparameter optimization experiment; Basic encoding For traffic flow prediction tasks that do not involve incremental learning, and given the incremental data that accumulates over time, a set of relative positional codes needs to be designed during pre-training to enhance the representational power of the positional codes, enabling them to represent a larger set of positional vectors; in the basic encoding Based on this, a relative position encoding PE is designed to be as unrestricted as possible by the sequence length; [The remaining text appears to be a fragment and requires further context for accurate translation.] for Based on this, a new set of encoding vectors is constructed. ,in ;set up , If the basis vectors are for relative position encoding, then the relative position encoding is represented as: , in and It is a hyperparameter, and it is used to remove parameters within this range. Because it is impossible to distinguish at this time. The situation; At position index i not exceeding At this time, the range of the position index is within the range of the index values ​​of the absolute position code, while the relative position code... Should be encoded with absolute position Equal, that is, should have This ensures compatibility with pre-trained traffic flow prediction models, at which point: , Based on the above relative position encoding, using This group Each absolute position code is used as a basis vector to represent A relative positional encoding; Encode the above relative positions Record Then we have: , The spatiotemporal attention Transformer model consists of a recurrent network structure composed of K Transformer units for traffic flow prediction. In the model's time-series semantic extraction module, each Transformer unit inherits the state vector of the previous unit. In the recurrent network architecture composed of K Transformer units, the state vector of the first unit... The state vector of each Transformer unit The update process is as follows: First, let the feature of the m-th Transformer unit be denoted as ,remember , , , , It is the projection matrix of the weight parameters. First, calculate each feature head. Scaling dot product attention: , Secondly, the K single-head attention connections of this unit are then linked to the weight matrix. Taking the dot product, we get Multi-head self-attention: , , The overall architecture of the spatial sequence semantic extraction module of the model is similar to that of the time series semantic extraction module. The difference lies in the index construction when segmenting the spatial sequence. Each sequence segment uses its corresponding observation point identifier as the index, i.e., the value of i. In the time series semantic extraction module, the index assigned by the segmentation operation when constructing the time information is a series of auto-incrementing positive integers. Step 4: Construct a spatiotemporal fusion module to filter and model spatial and temporal features. The spatial structure feature sequence and the temporal feature sequence with traffic data obtained in Step 3 are fused through the spatiotemporal fusion module to obtain urban traffic flow data with precise spatiotemporal dependence. The urban traffic flow data with precise spatiotemporal dependence is divided into training set, test set and validation set according to a specific ratio. Step 5: Use the training set obtained in Step 4 to train and evaluate the traffic flow prediction model. Input the traffic flow data with accurate spatiotemporal dependence in the training set into the traffic flow prediction model for multi-step prediction to predict the traffic flow in the future time period. Based on the pre-designed loss function, calculate the loss value using the traffic flow value predicted by the model and the actual traffic flow value in the training set. Use minimizing the loss value as the optimization objective to gradually optimize the model parameters of the traffic flow prediction model. Step 6: Repeat the steps in step 5 multiple times on the traffic flow prediction model to update the model parameters of the traffic flow prediction model in multiple cycles, so that the loss value of the traffic flow prediction model converges. After completing the preset number of training cycles, the trained traffic flow prediction model is obtained. Step 7: Input the real-time traffic flow data into the trained traffic flow prediction model to achieve real-time traffic flow prediction.

2. The traffic flow prediction method based on a cyclic spatiotemporal attention mechanism according to claim 1, characterized in that: For all sensor node sets The preprocessing of the middle nodes includes data cleaning, filling, aggregation, and sequence window partitioning; after window partitioning, it is further split into current and future sub-sequences as input and output windows respectively, to obtain the time series sample set, and then divided into training and test sample sets: Each road sensor data point is a tuple (flow, time), representing the traffic flow data value at time time; the processing of sensor node data refers to acquiring the average traffic flow information over a period of time from the road sensors to obtain the raw traffic flow data; The data cleaning refers to cleaning up redundant values ​​in the sensor node data by retaining the average value of the redundant values. The data filling method uses forward filling to fill missing values, using the value of the most recent time point that appeared before the missing value to fill the current missing value; The data aggregation process involves calculating the average value of the cleaned and filled sensor data every M minutes, aggregating the data, and then normalizing it using the z-score method to obtain the aggregated sensor node sequence, thus generating traffic flow data. --in or :when When, it means that the original input flow information only contains flow values; when At that time, the flow information includes inflow and outflow. The preprocessed traffic flow data first needs to pass through a fully connected network to obtain a higher-dimensional representation, defining... Traffic flow data for a specific time period. This refers to the traffic flow data for the i-th sub-time period within this time period. It is the original input A higher-dimensional representation is obtained by fusing temporal and spatial embeddings through a fully connected network consisting of two hidden layers: , The sample set is generated using the sliding window method; Define a length of A sliding window—where P is the length of the input window and F is the length of the output window—is used to make the sliding window fit within the dataset. Swipe up to get the set of all sensor samples. , For each element of a set, it represents a sequence of flow data within a sliding window. After partitioning, samples are obtained for traffic prediction. Each sample of traffic flow data is then used for this purpose. Based on pre-set input / output window lengths P and F, the time period is divided into two time periods: the current time and the future time period, denoted as: , , These represent traffic flow sequences on an input window and an output window, respectively; the training set, test set, and validation set are randomly divided on the traffic flow sequences on the input and output windows in a ratio of 7:2:

1. Finally, time information is constructed. This process is based on existing one-hot coding technology, creating daily and weekly indexes according to the unique periodic nature of traffic flow data. First, the time period is segmented, and then the daily and weekly indexes are designed—dividing the day into... of A week is divided into time periods; The seven time periods are divided into two indexing methods, which correspond to short-dependency traffic flow prediction tasks and long-dependency tasks, respectively. Then, one-hot encoding is performed in both methods and then concatenated to obtain... The sparse matrix represents the discrete features of time information, and similarly, the time embedding is obtained through a fully connected network. .

3. The traffic flow prediction method based on a cyclic spatiotemporal attention mechanism according to claim 1, characterized in that: The process of establishing spatial dependencies in step 2 is as follows: First, the spatial information of the road network is defined by the map. It means that among them Represents a finite set of nodes, corresponding to the real world... One sensor or observation point, i.e. ; It is a set of edges, representing the relationships between nodes; It is an adjacency matrix used to represent the degree of spatial association between sensor nodes; Figure The traffic dataset includes traffic flow data and a weighted adjacency matrix determined by the distance between sensor nodes, wherein the traffic flow data in the traffic dataset is time-series data; Secondly, using the graph Laplacian eigenvectors as spatial embeddings, the normalized Laplacian matrix is ​​first calculated. ,in It is a degree matrix. It is an identity matrix, then eigenvalue decomposition is performed. Affine transformations are performed on the k smallest nontrivial feature vectors to obtain the graph Laplacian feature embedding, which is the final constructed spatial feature. .

4. The traffic flow prediction method based on a cyclic spatiotemporal attention mechanism according to claim 1, characterized in that: The spatiotemporal fusion module described in step 3 employs a gating mechanism to perform spatiotemporal fusion, thereby fusing temporal and spatial features: The spacetime fusion gate Using the Sigmoid activation function: , in , These are the learnable spatial and temporal weight matrices, respectively. It is a learnable bias matrix. , These are spatial and temporal characteristics, respectively. Spatiotemporal fusion features It can be expressed by the following formula: 。 5. The traffic flow prediction method based on a cyclic spatiotemporal attention mechanism according to claim 1, characterized in that: In step 3, the spatial sequence semantic extraction module and the time series semantic extraction module of the traffic flow prediction model are computed in parallel based on sequence segmentation and parameter sharing. The spatial sequence semantic extraction module, the time series semantic extraction module, and the spatiotemporal fusion module adopt a parallel computing architecture based on sequence segmentation and parameter sharing, splitting the original sequence according to the sensor / sampling point index. The resulting set of split sequences is obtained. ,in Each subsequence The inputs are fed into a series of parallel recurrent Transformer units, which share parameters and each produce its own prediction results. After the calculation is completed: First, all prediction results are aggregated to obtain intermediate results. Then, using skip joins, the intermediate results are transformed into... Finally, F intermediate results that have undergone skip connections are concatenated according to the preset output window size, and then subjected to two layers of one-dimensional convolution to reduce the dimensionality, resulting in a value that conforms to the predicted flow dimension C. Its formalized expression is as follows: , in Represents a 3-dimensional object of size . Tensor.

6. The traffic flow prediction method based on a cyclic spatiotemporal attention mechanism according to claim 1, characterized in that: Hyperparameter optimization experimental design: Based on the formal model training experiment design, the number of iterations is reduced according to the performance of the machine used for training. During training, the model's hyperparameters are adjusted based on the validation set fit. The hyperparameter tuning process uses a grid search algorithm; the optimized hyperparameters include: (1) the activation function used when updating the Transformer unit state on the negative half-axis. Value; (2) Update Transformer unit state (3) Global learning rate; (4) The weight allocation parameter k for positional encoding in sliding self-attention; (5) Parameters in relative positional encoding .

7. The traffic flow prediction method based on a cyclic spatiotemporal attention mechanism according to claim 1, characterized in that: The design and performance evaluation methods for the loss function during the training of the traffic flow prediction model are as follows: Batch continuous sequences After the input data is fed into the traffic flow prediction model, the model prediction results are obtained. Huber Loss is selected as the loss function, and the loss value is calculated based on the model prediction results and label values. The traffic flow prediction model updates each parameter through backpropagation to reduce the loss between the true value and the predicted value, so that the predicted value generated by the traffic flow prediction model converges to the true value. The mini-batch stochastic gradient descent (SGD) optimization algorithm is selected to calculate the optimal solution of the traffic flow prediction model parameters. The loss function for the time interval [K+1, K+T] is as follows: , in For Huber Loss parameters; Data normalization is performed using a layer normalization algorithm; The performance evaluation uses mean absolute error (MAE) and root mean square error (RMSE) as indicators. The calculation process for Mean Absolute Error (MAE) is as follows: , The calculation process for the root mean square error (RMSE) is as follows: , In the formula: This represents the label value, i.e., the actual value. One sensor in Composed of traffic flow values ​​at each time slice OK Column matrix; and These represent the traffic flow values ​​of all sensors within the time slice range [K+1, K+T]. This represents the predicted value matrix generated by the traffic prediction model, with the same dimension as the label value matrix. and They respectively represent the first and second matrices of the corresponding matrix. OK The values ​​of column elements; when the dimension of traffic flow... When it is greater than 1, such as This represents inflow and outflow, and the corresponding loss is calculated separately for each traffic flow dimension during the evaluation.