Transform-based bidirectional adaptive multi-view space-time traffic prediction method and system, and electronic equipment

By combining multi-view embedding and a two-layer temporal attention module with a spatiotemporal fusion self-attention mechanism, the limitations of existing traffic prediction models in dealing with complex spatiotemporal features are addressed, and accurate prediction of traffic conditions is achieved.

CN120744598APending Publication Date: 2025-10-03ZHEJIANG GONGSHANG UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510758648.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-09
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

Existing traffic prediction models have limitations in dealing with complex nonlinear relationships and spatiotemporal features. In particular, a single temporal attention module is not sufficient to distinguish between forward and backward time flows, and a fixed mask matrix lacks adaptability.

Method used

A multi-view embedding module is used to generate multiple view embeddings, combined with a two-layer temporal attention method and a spatiotemporal fusion self-attention mechanism, to capture temporal dependencies through forward and reverse temporal attention modules, and an adaptive topology filtering module is used to adjust the relationships between nodes.

Benefits of technology

It achieves accurate prediction of traffic conditions, improves the model's understanding and prediction capabilities of temporal patterns, and enhances the robustness of spatiotemporal feature integration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120744598A_ABST
    Figure CN120744598A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of Transformers, and particularly relates to a two-way self-adaptive multi-view space-time traffic prediction method and system based on Transformers and electronic device.The method comprises the steps that 1, a multi-view embedding module maps input historical traffic data and generates various learnable parameter dimensions according to the time sequence, date attributes and spatial positions of the data, and the learnable parameter dimensions are matched with the historical traffic data; forming multi-view embedding, and outputting the multi-view embedding to a multi-layer space-time encoder; 2, each layer of space-time encoder carries out attention calculation of forward time flow, reverse time flow and space-time fusion, each space-time encoder comprises a forward time attention FTA module, a reverse time attention BTA module and a space-time fusion attention STFA module, the space-time fusion attention module carries out node space position filtering by using an input adjacent matrix, and the space-time fusion attention STFA module carries out node space position calculation; finally, the three are spliced to form output and output to an output layer; and step 3, receiving the output of the space-time encoder by an output layer, projecting the output to a prediction space through linear mapping, and predicting the traffic.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of traffic prediction, relates to a technology combining Transformer and time and space, and specifically relates to a bidirectional adaptive multi-view time and space traffic prediction method, system and electronic equipment based on Transformer. Background Art

[0002] Traffic forecasting, a core research area in multivariate time series prediction, has long garnered widespread attention from both academic and engineering communities. With the accelerating pace of global urbanization and the continued growth of motor vehicle ownership, accurately predicting traffic conditions has become a crucial prerequisite for optimizing urban traffic management efficiency, alleviating road congestion, and improving the public's travel experience.

[0003] Traffic forecasting has evolved from statistical methods to deep learning approaches. Early techniques such as autoregressive integrated moving average (ARIMA) captured temporal trends; however, they struggled with complex nonlinear relationships. Machine learning models, including support vector regression (SVR), enhanced nonlinear pattern recognition but failed to fully exploit spatiotemporal features. Deep learning methods such as long short-term memory (LSTM) networks and convolutional neural networks (CNNs) improved results but encountered limitations in modeling complex spatial relationships and long-range dependencies, respectively. Graph neural networks (GNNs) address the complexity of network complexity; however, they incur higher computational costs.

[0004] In recent years, Transformer-based models have demonstrated remarkable capabilities in traffic forecasting. When integrated with graph neural networks, these methods improve traffic forecasting by enhancing self-attention modeling. Some models also feature gated attention mechanisms and high computational efficiency. However, existing architectures still face limitations. They typically use a single temporal attention module, which is insufficient to distinguish between forward and backward time flows. Furthermore, their fixed mask matrices lack the adaptability required for complex and evolving traffic patterns. Summary of the Invention

[0005] To address the aforementioned issues in the prior art, the present invention proposes a Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method, system, and electronic device. The present invention designs a multi-view embedding module (MVE), which uses multi-perspective embedding to provide a robust feature representation for spatiotemporal series prediction by comprehensively encoding historical data, time period information, and weekday / holiday differences. Furthermore, the present invention uses a two-layer temporal attention approach to address the bidirectional dependencies between time steps. This approach includes forward temporal attention (FTA) and backward temporal attention (BTA), which respectively incorporate forward and backward temporal stream biases to enhance the model's understanding and prediction capabilities of temporal patterns. Finally, the present invention designs a spatiotemporal fusion self-attention (STFA) mechanism for spatiotemporal feature integration. This mechanism uses an adaptive topology filtering (ATF) module to gradually narrow the association range of nodes at each layer to eliminate redundant connections and adjust the relationships between nodes.

[0006] In order to achieve the above object, the present invention adopts the following technical solutions:

[0007] A bidirectional adaptive multi-view spatiotemporal traffic prediction method based on Transformer, which follows the following steps:

[0008] Step 1: The multi-view embedding module maps the input historical traffic data and generates multiple learnable parameter dimensions based on the data's time series, date attributes, and spatial location to form multiple view embeddings, which are then output to the multi-layer spatiotemporal encoder.

[0009] Step 2: Each layer of the spatiotemporal encoder includes a forward temporal attention module, a reverse temporal attention module, and a spatiotemporal fusion attention module, which respectively perform attention calculations for the forward temporal flow, reverse temporal flow, and spatiotemporal fusion. The spatiotemporal fusion attention module uses the input adjacency matrix to filter the node spatial position, and finally splices the three to form an output, which is output to the output layer.

[0010] Step 3: The output layer receives the output of the spatiotemporal encoder and projects it into the prediction space through linear mapping to predict traffic.

[0011] Preferably, step 1 is as follows:

[0012] Step 1.1: Input traffic data tensor It is composed of traffic records of T consecutive time slices, where T represents each node, N represents the number of nodes, and F represents the feature dimension of each node;

[0013] Step 1.2: Map historical traffic data into a high-dimensional embedding space and extract basic features:

[0014] X l =XW l+b l

[0015] in, and is a learnable parameter, output

[0016] Step 1.3: Construct a periodic position encoding matrix using sine and cosine functions

[0017]

[0018] Expand the time code H into a space-time tensor Make each node share the same time position code;

[0019] Step 1.4: Temporal Embedding:

[0020] Step 1.4.1: Create a learnable embedding matrix Covering all-day time intervals;

[0021] Step 1.4.2: According to the time range of input data [t b +1,t b +T], intercept the embedding of the corresponding time period:

[0022]

[0023] Step 1.4.3: Output

[0024] Step 1.5: Holiday Embedding:

[0025] Step 1.5.1: Define a learnable holiday embedding matrix

[0026] Step 1.5.2: Select the corresponding embedding based on whether the input data is a holiday:

[0027]

[0028] Step 1.5.3: Expand H to Assign the same holiday characteristics to each time step;

[0029] Step 1.6: Directly introduce learnable tensors Optimize global pattern representation through training;

[0030] Step 1.7: Multi-view feature stitching:

[0031] X s =X l ||X p ||X m||X w ||X g

[0032] X s =X l ||X p ||X m ||X w ||X g : Total embedding dimension, output As input to subsequent modules.

[0033] Preferably, in step 2, each layer of the spatiotemporal encoder STE performs attention calculations for the forward time flow, the reverse time flow, and the spatiotemporal fusion, respectively. The spatiotemporal fusion module uses the input adjacency matrix to filter the node spatial position, and finally splices the three to form the output; specifically as follows:

[0034] Step 2.1: Accept the input tensor as the initial input of the entire spatial-temporal encoder STE (Spatial-Temporal Encoding);

[0035] Step 2.1.1: Accept input tensor It represents the input of the lth layer in STE;

[0036] Step 2.1.2: X e (1) =X s As the initial input of the entire spatiotemporal encoder STE.

[0037] Step 2.2: Use forward temporal attention (FTA) to capture the positive time-varying information in the time series.

[0038] Step 2.2.1: Input tensor X e The first two dimensions (time dimension T and node dimension N) are swapped, keeping the third dimension (feature dimension D) unchanged:

[0039]

[0040] Step 2.2.2: Linear projection to generate Q (f) ,K (f) ,V (f) :

[0041] Q (f) =X e 'W Q (f) +b Q ,K (f) =X e 'W K (f) +b K ,V(f) =X e 'W V (f) +b V

[0042] in, is a learnable parameter, Represents the dimension of the feature space after transformation;

[0043] Step 2.2.3: Calculate the embedding similarity matrix:

[0044]

[0045] It's X e '(t,:,:)'s flattened vector, It is an upper triangular matrix t1<t2;

[0046] Step 2.2.4: Calculate the raw attention scores and overlay the similarity matrix:

[0047]

[0048] in, represents the self-attention score;

[0049] Step 2.2.5: Weighted summation to get the output:

[0050] Z f =A (f) V (f)

[0051] in,

[0052] Step 2.3: Use reverse temporal attention (BTA) to capture reverse time-varying information in the time series.

[0053] Step 2.3.1: Generate similar to step 2.2.2

[0054] Step 2.3.2: Create the Transpose to get It is a lower triangular matrix;

[0055] Step 2.3.3: Calculate the raw attention scores and overlay the similarity matrix:

[0056]

[0057] in, represents the self-attention score;

[0058] Step 2.3.4: Weighted summation to get the output:

[0059] Z b =A (b) V (b)

[0060] in,

[0061] Step 2.4: Use spatiotemporal fusion attention (STFA) to capture spatial information in the road network.

[0062] Step 2.4.1: Generate Q similar to step 2.2.2 (s) ,

[0063] Step 2.4.2: Use the Floyd or Dijkstra algorithm to calculate the shortest path matrix based on the road topology network P(i,j) represents the shortest path between node i and node j;

[0064] Step 2.4.3: The adaptive topology filter ATF generates a mask matrix based on the layer number l of the current STE

[0065]

[0066] where δ l Indicates adaptive adjustment of topology calculation:

[0067] δ l =N·exp(-λl)+ε

[0068] Among them, λ∈[0,1] represents the attenuation coefficient, and ε>0 ensures that the threshold remains stable;

[0069] Step 2.4.4: Calculate the raw attention score and filter with mask:

[0070]

[0071] in, represents the self-attention score, The BTA module in the first layer STE Transposing the first two dimensions yields;

[0072] Step 2.4.5: Weighted summation to get the output:

[0073] Z s (l) =A l (s) V l (s)

[0074] in,

[0075] Step 2.4.6: Stack the outputs of the FTA, BTA and STFA modules of each layer of the STE encoder and add a residual connection as

[0076] Z o (l) =X e (l+1) =Z f +Z b +Z s (l) +X e (l)

[0077] Preferably, step 3 is as follows:

[0078] The high-dimensional features Z from the spatiotemporal encoder STE stack are transformed using a linear transformation o (L) Mapping to prediction space:

[0079]

[0080] in, represents the predicted value of the model, and is a learnable parameter;

[0081] Among them, the loss function is defined using the mean absolute error MAE:

[0082]

[0083] The present invention also discloses a Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction system for executing the above method, comprising the following modules:

[0084] Multi-view embedding module: This module maps the input historical traffic data and generates multiple learnable parameter dimensions based on the data's time series, date attributes, and spatial location to form a multi-view embedding, which is then output to a multi-layer spatiotemporal encoder.

[0085] Spatiotemporal encoder: It includes the forward temporal attention module, the reverse temporal attention module, and the spatiotemporal fusion attention module, which respectively perform attention calculations for the forward temporal flow, the reverse temporal flow, and the spatiotemporal fusion. The spatiotemporal fusion attention module uses the input adjacency matrix to filter the spatial positions of nodes, and finally concatenates the three to form an output, which is output to the output layer.

[0086] Output layer: accepts the output of the spatiotemporal encoder, projects it into the prediction space through linear mapping, and predicts traffic.

[0087] The present invention also discloses a readable medium storing instructions, which, when executed on an electronic device, enables the electronic device to execute the above method or system.

[0088] The present invention also discloses an electronic device, comprising:

[0089] a memory for storing instructions to be executed by a processor of the electronic device;

[0090] A processor is used to execute the above method or system.

[0091] The present invention has the following significant technical effects:

[0092] This paper designs a Multi-View Embedding (MVE) module that uses multi-view embedding to provide a robust feature representation for spatiotemporal series prediction by comprehensively encoding historical data, time period information, and weekday / holiday differences. Furthermore, a two-layer temporal attention approach is used to address bidirectional dependencies between time steps. Finally, a Spatiotemporal Fusion Self-Attention (STFA) mechanism is used to integrate spatiotemporal features, ultimately achieving accurate traffic prediction. BRIEF DESCRIPTION OF THE DRAWINGS

[0093] Figure 1 This is a flow chart of a Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method according to an embodiment of the present invention;

[0094] Figure 2 This is a block diagram of a Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction system according to an embodiment of the present invention. DETAILED DESCRIPTION

[0095] The preferred embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0096] This embodiment is a bidirectional adaptive multi-view spatiotemporal traffic prediction method based on Transformer. Figure 1 As shown, proceed as follows:

[0097] Step 1: The Multi-View Embedding Module (MVE) maps the input historical traffic data and generates multiple learnable parameter dimensions based on the time series, date attributes, and spatial location of the data to form multiple view embeddings and splice them into Output to the multi-layer spatiotemporal encoder, see step 1.7, Figure 1We have released the BAMSFormer (directional Adaptive Multi-view Spatiotemporal Transformer for Traffic Flow Prediction), which consists of a multi-view embedding module, a spatiotemporal encoder, and an output layer.

[0098] The multi-view embedding module in this step generates tensors from multiple dimensions, such as T×N×C1 and T×N×C2, and then concatenates them to form T×N×C3. This module stacks and concatenates multiple learned embeddings. This method of stacking and concatenating information has been widely used, including existing feature embeddings such as raw data linear mapping embedding and time embedding. This embodiment considers and adds more embeddings, such as holiday and global embeddings, while abandoning the widely used weekly period embeddings. This enriches the information it contains and conveys, thereby increasing prediction accuracy.

[0099] The details of this step are as follows:

[0100] Step 1.1: Input traffic data tensor It is composed of traffic records of T consecutive time slices, where T represents each node, N represents the number of nodes, and F represents the feature dimension of each node;

[0101] Step 1.2: Map historical traffic data into a high-dimensional embedding space and extract basic features:

[0102] X l =XW l +b l

[0103] in, and is a learnable parameter, output

[0104] Step 1.3: Construct a periodic position encoding matrix using sine and cosine functions

[0105]

[0106] Expand the time code H into a space-time tensor Make each node share the same time position code;

[0107] Step 1.4: Temporal Embedding:

[0108] Step 1.4.1: Create a learnable embedding matrix Covers all-day time intervals.

[0109] Step 1.4.2: According to the time range of input data [t b +1,t b +T], intercept the embedding of the corresponding time period:

[0110]

[0111] Among them,: refers to the overall parameters of other dimensions;

[0112] Step 1.4.3: Output

[0113] Step 1.5: Holiday Embedding:

[0114] Step 1.5.1: Define a learnable holiday embedding matrix

[0115] Step 1.5.2: Select the corresponding embedding based on whether the input data is a holiday:

[0116]

[0117] The data of X corresponds to holidays marked as H w , otherwise H o ;

[0118] Step 1.5.3: Expand H to Assign the same holiday characteristics to each time step;

[0119] Step 1.6: Directly introduce learnable tensors Optimize global pattern representation through training;

[0120] Step 1.7: Multi-view feature stitching:

[0121] X s =X l ||X p ||X m ||X w ||X g

[0122] X s =X l ||X p ||X m ||X w ||X g : Total embedding dimension, output As input to subsequent modules.

[0123] Step 2: Each layer of the spatial-temporal encoder (STE) includes a forward time attention module, a reverse time attention module, and a spatio-temporal fusion attention module, which respectively calculate the forward time stream attention (FAT), the reverse time stream attention (BAT), and the spatio-temporal fusion self-attention (STFA). The spatio-temporal fusion module uses the input adjacency matrix to filter the node spatial position, and finally splices the three to form the output. Output to the output layer, see step 2.4.6.

[0124] In this step, the STE (Spatial-Temporal Encoding) layer of the spatiotemporal encoder is repeated L times in the figure, consistent with the multi-layer encoder structure of the Transformer. Each STE layer contains three modules, which extract and enhance spatiotemporal features layer by layer.

[0125] The details of this step are as follows:

[0126] Step 2.1: Accept the input tensor as the initial input of the entire spatiotemporal encoder STE;

[0127] Step 2.1.1: Accept input tensor It represents the input of the lth layer in STE;

[0128] Step 2.1.2: X e (1) =X s As the initial input of the entire STE encoder.

[0129] Step 2.2: Use forward temporal attention (FTA) to capture the positive time-varying information in the time series.

[0130] Step 2.2.1: Input tensor X e The first two dimensions (time dimension T and node dimension N) are swapped, keeping the third dimension (feature dimension D) unchanged:

[0131]

[0132] Step 2.2.2: Linear projection to generate Q (f) ,K (f) ,V (f) :

[0133] Q (f) =X e 'W Q(f) +b Q ,K (f) =X e 'W K (f) +b K ,V (f) =X e 'W V (f) +b V

[0134] in, Q (query): Query vector, representing the information required at a specific position in the current input sequence. K (key): Key vector, encoding the features of each position in the input sequence for matching against the query. V (value): Value vector, carrying the actual content of the input sequence, which is ultimately weighted and aggregated through the attention mechanism. is a learnable parameter, Represents the dimension of the feature space after transformation;

[0135] The linear transformation of Q (Query), K (Key), and V (Value) is the core operation of Transformer self-attention. Similarity is calculated by taking the dot product of Q and K, which is then scaled to obtain the attention weight. Finally, the weighted sum V is taken, directly replicating the Transformer's attention formula.

[0136] Step 2.2.3: Calculate the embedding similarity matrix:

[0137]

[0138] It's X e '(t,:,:)'s flattened vector, It is an upper triangular matrix t1<t2;

[0139] Step 2.2.4: Calculate the raw attention scores and overlay the similarity matrix:

[0140]

[0141] Among them, S is the first letter of similarity, which means the similarity matrix. represents the self-attention score;

[0142] Step 2.2.5: Weighted summation to get the output:

[0143] Z f =A (f) V (f)

[0144] in,

[0145] Step 2.3: Use reverse temporal attention (BTA) to capture reverse time-varying information in the time series.

[0146] Step 2.3.1: Generate similar to step 2.2.2 Among them, Q (query): query vector, used to represent the information required for a certain position in the current input sequence; K (key): key vector, used to encode the features of each position in the input sequence and match it with the query; V (value): value vector, carrying the actual content information of the input sequence, and finally weighted aggregation through the attention mechanism.

[0147] Step 2.3.2: Create the Transpose to get It is a lower triangular matrix;

[0148] Step 2.3.3: Calculate the raw attention scores and overlay the similarity matrix:

[0149]

[0150] in, represents the self-attention score;

[0151] Step 2.3.4: Weighted summation to get the output:

[0152] Z b =A (b) V (b)

[0153] in,

[0154] Step 2.4: Use spatiotemporal fusion attention (STFA) to capture spatial information in the road network.

[0155] Step 2.4.1: Generate similar to step 2.2.2 Among them, Q (query) is the query vector, which is used to represent the information required at a certain position in the current input sequence; K (key) is the key vector, which is used to encode the features of each position in the input sequence and match it with the query.

[0156] Step 2.4.2: Use the Floyd or Dijkstra algorithm to calculate the shortest path matrix based on the road topology network P(i,j) represents the shortest path between node i and node j;

[0157] Among them, the Floyd-Warshall algorithm pseudo code is as follows:

[0158]

[0159] The pseudo code of Dijkstra algorithm is as follows:

[0160]

[0161] Step 2.4.3: The adaptive topology filter ATF generates a mask matrix based on the layer number l of the current STE

[0162]

[0163] The filter ATF separates two l The node information of M l (i,j)=1 node relationship; δ l Indicates adaptive adjustment of topology calculation:

[0164] δ l =N·exp(-λl)+ε

[0165] Among them, l indicates that the distance between two nodes is far and needs to be shielded, λ∈[0,1] represents the attenuation coefficient, and ε>0 ensures that the threshold remains stable;

[0166] Step 2.4.4: Calculate the raw attention score and filter with mask:

[0167]

[0168] in, represents the self-attention score, The BTA module in the first layer STE Transposing the first two dimensions yields;

[0169] Step 2.4.5: Weighted summation to get the output:

[0170] Z s (l) =A l (s) V l (s)

[0171] in,

[0172] Step 2.4.6: Stack the outputs of the FTA, BTA and STFA modules of each layer of the STE encoder and add a residual connection as

[0173] Z o(l) =X e (l+1) =Z f +Z b +Z s (l) +X e (l)

[0174] In the present invention, the residual connection and forward feedback are consistent with the residual connection and LayerNorm in the Transformer Encoder combined with the feedforward network (FFN).

[0175] Step 3: The output layer receives the output of the spatiotemporal encoder and projects it into the prediction space through linear mapping to predict traffic. The details are as follows:

[0176] The high-dimensional features Z from the encoder STE stack are transformed using a linear transformation o (L) Mapping to prediction space:

[0177]

[0178] in, represents the predicted value of the model, and is a learnable parameter;

[0179] Among them, the loss function is defined using the mean absolute error MAE:

[0180]

[0181] The following is an experimental comparison between this embodiment and the prior art.

[0182] This experiment was conducted on a Windows 11 computer equipped with a GeForce RTX 3080Ti GPU card and running an Intel Core i7-11700 CPU @ 3.6-GHz.

[0183] In the experiment, the data of the previous hour is used to predict the data of the next hour. In the experiment, the number of layers l of STC is set to 5, the attenuation coefficient λ in step 2.4.3 is set to 0.6, the threshold ε is set to 6, and the original data embedding dimension D l is 24, the time embedding dimension D m is 24, and holidays are embedded in dimension D w is 12, the global embedding dimension D gThe training was performed with the Adam optimizer, an initial learning rate of 0.001, and a fine-tuning learning rate of 0.00001. The batch size for all tests was set to 16, and the model was trained for a maximum of 200 epochs. If there was no improvement after 20 consecutive epochs, early stopping was initiated.

[0184] The experimental results are shown in Table 1. The results in Table 1 show that the Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method (BAMSFormer) proposed in this invention has better prediction results than other baseline models in the prior art.

[0185] Table 1 Comparison of the embodiment of the present invention with other existing models on different data sets

[0186] Table2:Comparison between the proposed model and baseline methods

[0187]

[0188] like Figure 2 As shown, this embodiment discloses a Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction system, which is used to execute the above method and includes the following modules:

[0189] Multi-view embedding module: This module maps the input historical traffic data and generates multiple learnable parameter dimensions based on the data's time series, date attributes, and spatial location to form a multi-view embedding, which is then output to a multi-layer spatiotemporal encoder.

[0190] Spatiotemporal encoder: It includes the forward temporal attention module, the reverse temporal attention module, and the spatiotemporal fusion attention module, which respectively perform attention calculations for the forward temporal flow, the reverse temporal flow, and the spatiotemporal fusion. The spatiotemporal fusion attention module uses the input adjacency matrix to filter the spatial positions of nodes, and finally concatenates the three to form an output, which is output to the output layer.

[0191] Output layer: accepts the output of the spatiotemporal encoder, projects it into the prediction space through linear mapping, and predicts traffic.

[0192] A preferred embodiment of the present invention discloses a readable medium storing instructions, which, when executed on an electronic device, enables the electronic device to execute the above method or system.

[0193] A preferred embodiment of the present invention discloses an electronic device, comprising:

[0194] a memory for storing instructions to be executed by a processor of the electronic device;

[0195] A processor is used to execute the above method or system.

[0196] In summary, the present invention designs a multi-view embedding module (MVE), which adopts multi-perspective embedding to provide a robust feature representation for spatiotemporal series prediction by comprehensively encoding historical data, time period information and working day / holiday differences. At the same time, the present invention uses a two-layer temporal attention method to solve the bidirectional dependency between time steps, combining forward and backward time flow deviations respectively to enhance the model's understanding and prediction ability of temporal patterns. Finally, the present invention uses a spatiotemporal fusion self-attention (STFA) mechanism for spatiotemporal feature integration. This mechanism gradually narrows the association range of nodes at each layer, eliminates redundant connections and adjusts the relationship between nodes, thereby improving the prediction accuracy. Experiments on real data sets have verified the accuracy of the proposed technical solution of the present invention.

[0197] The above embodiments will help those skilled in the art further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that those skilled in the art may make various modifications and improvements without departing from the scope of the present invention. These modifications and improvements are all within the scope of protection of the present invention.

Claims

1. A bidirectional adaptive multi-view spatiotemporal traffic prediction method based on Transformer, characterized by: The following steps are involved: Step 1: The multi-view embedding module maps the input historical traffic data and generates multiple learnable parameter dimensions based on the data's time series, date attributes, and spatial location to form a multi-view embedding, which is then output to the multi-layer spatiotemporal encoder. Step 2: Each layer of the spatiotemporal encoder includes a forward temporal attention module, a reverse temporal attention module, and a spatiotemporal fusion attention module, which respectively perform attention calculations for the forward temporal flow, reverse temporal flow, and spatiotemporal fusion. The spatiotemporal fusion attention module uses the input adjacency matrix to filter the node spatial position, and finally splices the three to form an output, which is output to the output layer. Step 3: The output layer receives the output of the spatiotemporal encoder and projects it into the prediction space through linear mapping to predict traffic.

2. The Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method according to claim 1 is characterized in that: Step 1 specifically includes the following steps: Step 1.1: Input traffic data tensor It is composed of traffic records of T consecutive time slices, where T represents each node, N represents the number of nodes, and F represents the feature dimension of each node; Step 1.2: Map historical traffic data into a high-dimensional embedding space and extract basic features: X l =XW l +b l in, and is a learnable parameter, output D l Represents the feature dimension after linear mapping; Step 1.3: Construct a periodic position encoding matrix using sine and cosine functions Where i and j are D l The feature dimension subscript of D is odd, and even represents an even number. p Represents the feature dimension after linear mapping; Expand the time code H into a space-time tensor Make each node share the same time position code; Step 1.4: Temporal embedding, as follows: Step 1.4.1: Create a learnable embedding matrix T d represents the dth time step in a day, D m The number of learnable parameters representing the temporal embedding, covering the entire day's time intervals; Step 1.4.2: According to the time range of input data [t b +1,t b +T], intercept the embedding of the corresponding time period: Step 1.4.3: Output Step 1.5: Embed holidays as follows: Step 1.5.1: Define a learnable holiday embedding matrix D w The number of learnable parameters representing the holiday embedding dimension; Step 1.5.2: Select the corresponding embedding based on whether the input data is a holiday: Step 1.5.3: Expand H to Assign the same holiday characteristics to each time step; Step 1.6: Introducing Learnable Tensors D g The number of learnable parameters representing the global embedding, which is trained to optimize the global pattern representation; Step 1.7: Multi-view feature stitching: X s =X l ||X p ||X m ||X w ||X g X s =X l ||X p ||X m ||X w ||X g represents the total embedding dimension, output 3. The Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method according to claim 2 is characterized in that: Step 2 specifically includes the following steps: Step 2.1: Accept the input tensor as the initial input of the entire spatiotemporal encoder STE; Step 2.2: Use the forward temporal attention (FTA) module to capture the positive time-varying information in the time series. Step 2.3: Use the reverse temporal attention (BTA) module to capture the reverse time-varying information in the time series; Step 2.4: Use the spatiotemporal fusion attention (STFA) module to capture the spatial information in the road network.

4. The Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method according to claim 3 is characterized by: Step 2.1 is as follows: Step 2.1.1: Accept input tensor Represents the input of the lth layer in the spatiotemporal encoder STE; Step 2.1.2: X e (1) =X s As the initial input of the entire spatiotemporal encoder STE.

5. The Transformer-based bidirectional adaptive multi-view spatiotemporal prediction method according to claim 4, characterized in that: Step 2.2 is as follows: Step 2.2.1: Input tensor X e The time dimension T and node dimension N are swapped, keeping the feature dimension D unchanged: Step 2.2.2: Linear projection to generate Q (f) ,K (f) ,V (f) : Q (f) =X e 'W Q (f) +b Q ,K (f) =X e 'W K (f) +b K ,V (f) =X e 'W V (f) +b V in, Represents the weights of the three linear projections; is a learnable parameter, Represents the dimension of the feature space after transformation; Step 2.2.3: Calculate the embedding similarity matrix: It's X e '(t,:,:)'s flattened vector, It is an upper triangular matrix t1<t2; Step 2.2.4: Calculate the raw attention scores and overlay the similarity matrix: in, represents the self-attention score; Step 2.2.5: Weighted summation to get the output: in, 6. The Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method according to claim 5, characterized in that: Step 2.3 is as follows: Step 2.3.1: Linear projection generation Q (b) =X e 'W Q (b) +b Q ,K (b) =X e 'W K (b) +b K ,V (b) =X e 'W V (b) +b V in, Represents the weights of the three linear projections; is a learnable parameter, Represents the dimension of the feature space after transformation; Step 2.3.2: Create the Transpose to get It is a lower triangular matrix; Step 2.3.3: Calculate the raw attention scores and overlay the similarity matrix: in, represents the self-attention score; Step 2.3.4: Weighted summation to get the output: From b =A (b) In (b) in, 7. The Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method according to claim 6, characterized in that: Step 2.4 is as follows: Step 2.4.1: Linear projection generation Q (s) =X e 'W Q (s) +b Q ,K (s) =X e 'W K (s) +b K in, is a learnable parameter, Represents the dimension of the feature space after transformation; Step 2.4.2: Use the Floyd or Dijkstra algorithm to calculate the shortest path matrix based on the road topology network P(i,j) represents the shortest path between node i and node j; Step 2.4.3: The adaptive topology filter ATF generates a mask matrix based on the layer number l of the current STE Among them, δ l Indicates adaptive adjustment of topology calculation: d l =N·exp(-λl)+ε Among them, λ∈[0,1] represents the attenuation coefficient, and ε>0 ensures that the threshold remains stable; Step 2.4.4: Calculate the raw attention score and filter with mask: in, represents the self-attention score, The BTA module in the first layer STE Transposing the first two dimensions yields; Step 2.4.5: Weighted summation to get the output: From s (l) =A l (s) In l (s) in, Step 2.4.6: Stack the outputs of the FTA, BTA and STFA modules of each layer of the STE encoder and add a residual connection as Z o (l) =X e (l+1) =Z f +Z b +Z s (l) +X e (l) 。 8. The Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction method according to claim 7, characterized in that: Step 3 is as follows: The high-dimensional features Z from the spatiotemporal encoder STE stack are transformed using a linear transformation o (L) Mapping to prediction space: in, represents the predicted value of the model, and is a learnable parameter; Among them, the loss function is defined using the mean absolute error MAE: Among them, Y represents the true value and T' represents the predicted time series.

9. A Transformer-based bidirectional adaptive multi-view spatiotemporal traffic prediction system, configured to execute the method according to any one of claims 1 to 8, characterized in that: Includes the following modules: Multi-view embedding module: This module maps the input historical traffic data and generates multiple learnable parameter dimensions based on the data's time series, date attributes, and spatial location to form a multi-view embedding, which is then output to a multi-layer spatiotemporal encoder. Spatiotemporal encoder: It includes the forward temporal attention module, the reverse temporal attention module, and the spatiotemporal fusion attention module, which respectively perform attention calculations for the forward temporal flow, the reverse temporal flow, and the spatiotemporal fusion. The spatiotemporal fusion attention module uses the input adjacency matrix to filter the spatial positions of nodes, and finally concatenates the three to form an output, which is output to the output layer. Output layer: accepts the output of the spatiotemporal encoder, projects it into the prediction space through linear mapping, and predicts traffic.

10. An electronic device, characterized in that: include: a memory for storing instructions to be executed by a processor of the electronic device; A processor, configured to execute the method according to any one of claims 1 to 8 or the system according to claim 9.