A state-aware dynamic asymmetric spatio-temporal transformer long-term traffic speed prediction method and system
Patent Information
- Application Number
- CN202610642021.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-11
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2046-05-11
AI Technical Summary
[0006]针对现有技术的不足,本发明旨在解决长期交通速度预测中静态空间结构无法适配交通流动态非对称传播、自回归结构误差累积的核心问题,提出一种状态感知的动态非对称时空Transformer(SDA-STT)长期交通速度预测方法,将宏观交通流理论深度融入深度学习模型设计,实现高精度、高稳定性的长期交通速度预测
1、本发明将宏观交通流理论深度融入注意力机制设计,精准捕捉交通流上下游非对称的动态传播特性,在PeMS-BAY公开数据集上,6小时长期预测的MAE相比先进的理论融合基线ALT-GMAN降低19.75%,RMSE降低13.92%,MAPE降低19.82%,在1小时以上的长期预测场景中显著优于现有主流模型。
Smart Images

Figure CN122157505B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of intelligent transportation systems, traffic flow prediction and deep learning technology, and specifically relates to a state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method and system. Background Technology
[0002] Accurate traffic speed prediction is a core foundation of Intelligent Transportation Systems (ITS), providing data support for proactive traffic management, forward-looking route planning, and congestion mitigation. It is a key technology for improving urban traffic efficiency and travel safety. Traffic speed prediction is typically divided into short-term prediction (minutes to one hour) and long-term prediction (more than one hour), with one hour as the dividing line. Existing research mostly focuses on short-term predictions within 30 minutes, which can only support passive real-time traffic management; while long-term traffic speed prediction can realize proactive congestion management and long-distance travel planning, and has greater engineering application value.
[0003] Current traffic speed prediction technology has evolved from classical statistical models to deep learning models. Early parametric models such as ARIMA and Kalman filtering were limited by linear assumptions and could not capture the complex nonlinear evolution of urban traffic flow; nonparametric models such as k-nearest neighbors and support vector regression relied on manual feature engineering and lacked generalization ability in complex spatiotemporal prediction tasks. With the development of deep learning technology, recurrent neural networks (LSTM, GRU) can effectively model temporal dependencies, while graph convolutional networks (GCN) are adapted to the non-Euclidean characteristics of urban road networks and have become the mainstream technology for traffic prediction, giving rise to classic spatiotemporal graph models such as STGCN, DCRNN, GraphWaveNet, and GMAN.
[0004] However, existing technologies still face two major bottlenecks in long-term traffic speed prediction: First, most purely data-driven graph models are black-box models, lacking explicit constraints from traffic flow theory. Existing models that incorporate traffic flow theory typically use static spatial convolution kernels, which cannot adapt to the spatiotemporal dynamic evolution characteristics of traffic flow. In both free-flow and congested flow states, the influence direction and range of upstream and downstream road segments exhibit significant asymmetry. Static graph structures cannot capture this dynamic spatial dependence, leading to a substantial decrease in long-term prediction accuracy.
[0005] Second, existing Transformer-based long-term prediction models mostly adopt autoregressive encoding and decoding structures. Their stepwise prediction mode leads to the continuous accumulation of errors over the prediction period, and the prediction performance decays rapidly as the prediction window lengthens. At the same time, the unconstrained self-attention mechanism is prone to generating results that do not conform to the basic laws of traffic flow in long-term prediction, and cannot guarantee the stability and reliability of long-term prediction. Summary of the Invention
[0006] To address the shortcomings of existing technologies, this invention aims to solve the core problems of static spatial structure being unable to adapt to the dynamic asymmetric propagation of traffic flow and the accumulation of autoregressive structure errors in long-term traffic speed prediction. It proposes a state-aware dynamic asymmetric spatiotemporal Transformer (SDA-STT) long-term traffic speed prediction method, which deeply integrates macroscopic traffic flow theory into the design of deep learning models to achieve high-precision and high-stability long-term traffic speed prediction.
[0007] The technical solution of this invention is as follows: A state-aware, dynamic, asymmetric, spatiotemporal Transformer method for long-term traffic speed prediction, with the following specific steps: Step 1: Construction of a directed graph of the transportation network and formalization of the long-term prediction problem; including: abstracting the transportation network into a directed graph structure and completing the mathematical formalization definition of the prediction problem; Step 2: Preprocessing of traffic speed time series data; Step 3: Spatiotemporal embedding feature mapping; including: mapping the low-dimensional traffic speed input features to a high-dimensional hidden space, while preserving the topological spatial attributes of the road network and the temporal order attributes of the traffic data, to generate initial embedding features; Step 4: State-aware dynamic asymmetric spatial feature extraction; including: deeply integrating macroscopic traffic flow theory into the attention mechanism design, and capturing the time-varying asymmetric spatial dependencies of traffic flow through four sub-steps: traffic state discrimination, dynamic mask generation, bi-branch feature extraction, and adaptive gating fusion. Step 5: Lightweight multi-scale temporal Transformer feature extraction; including: designing a non-autoregressive encoder-only architecture, and extracting multi-scale temporal dependencies in parallel through a lightweight multi-scale temporal Transformer module; Step 6: End-to-end training and direct multi-step prediction of output using the dynamic asymmetric spatiotemporal Transformer: Based on the deep spatiotemporal features of the output, the future is directly generated through a linear mapping layer. Traffic speed prediction results for each time step.
[0008] According to a preferred embodiment of the present invention, step 1 specifically includes: A directed graph of a transportation network is defined as follows: ,in, for A set of traffic sensor nodes, each node corresponding to a one-way urban road segment; a set of directed edges. The path representing the actual traffic flow is defined if and only if the traffic flow can originate from the road segment. Drive directly to the section of road At that time, on the side Directed adjacency matrix The connectivity of the coded road network, among which If and only if ,otherwise ; Traffic time-series data definition: At each time step t, the traffic feature map signals of all nodes are collected as follows: ,in For traffic feature dimensions; Input and output definitions: Given a length of Historical observation window at each time step, historical traffic time series for: (1); The goal of long-term traffic speed prediction is to learn a nonlinear mapping function. Based on historical traffic time series Directed graph of transportation network Predicting the future Traffic speeds at all nodes at each time step, outputting the predicted sequence. for: (2); in For time step The predicted traffic speed, and the corresponding actual speed sequence are: .
[0009] According to a preferred embodiment of the present invention, step 2 includes the following specific implementation process: The collected traffic speed time-series data undergoes standardization processing and dataset partitioning. Traffic speed time-series data refers to continuous records of traffic speeds on each one-way road segment of the urban road network, collected by traffic sensors at fixed time granularities; it represents the time-series speed value of each node in the road network. The specific process is as follows: Data standardization: Z-score standardization is performed on the traffic speed time series data. The calculation formula is as follows: ,in σ represents the original traffic speed value, μ represents the mean of the traffic speed in the training set, and σ represents the standard deviation of the traffic speed in the training set. Dataset partitioning: The preprocessed dataset is divided into training set, validation set and test set according to the time sequence; According to a preferred embodiment of the present invention, step 3 specifically includes the following steps: The spatiotemporal embedding module includes a linear projection layer, a learnable spatial embedding layer, and a sinusoidal position coding layer; In the linear projection layer, a fully connected linear layer maps the single-dimensional traffic speed feature to a predefined model hidden dimension. This completes the dimensionality upgrade of the features. In the learnable spatial embedding layer, a unique learnable feature vector is generated for each node in the road network, capturing the fixed topological connectivity characteristics of the road network and providing prior information for spatial feature extraction; In the sinusoidal location coding layer, a fixed location code is generated for each time step of the time series using a sinusoidal function, preserving the temporal order information of traffic data and making up for the Transformer architecture's deficiency in perceiving temporal location.
[0010] Finally, the linear projection features, learnable spatial embedding features, and sinusoidal positional codes are added element by element to obtain the initial embedding features that retain complete spatiotemporal attributes.
[0011] According to a preferred embodiment of the present invention, step 4 includes the following specific implementation process: Step 4.1: Real-time traffic state determination based on traffic flow theory; Based on the classic macroscopic traffic flow triangle basic graph, a discrimination logic is constructed for traffic flow. ,speed ,density The following basic relations must be satisfied: (3); First, traffic density is calculated by back-calculating the real-time observed speed at each node. At time step observation speed Traffic density The calculation formula is: (4); in, The free-flow velocity of the road segment. To congest the shock wave velocity, It is the critical density; Introducing a hysteresis threshold Traffic conditions are divided into three categories: (5); in, For nodes At time step Traffic status labels When =0, it is a free flow state; When =1, it is a critical flow state; When the value is 2, it is a congested flow state; Step 4.2: Dynamic asymmetric attention mask, i.e., dynamic mask generation; Based on the real-time traffic state obtained from the discrimination, a dynamic attention mask is generated for each node and each time step. This mask applies hard constraints based on traffic physics to the subsequent spatial attention calculation. The specific process is as follows: Step 4.2.1: Pre-calculate the shortest path step size matrix of the road network: Upstream step size matrix :in Indicates upstream node To the target node along the traffic flow direction Shortest path step size; downstream step size matrix :in Indicates downstream node Reverse traffic flow to the target node The number of steps in the shortest path; Step 4.2.2: Dynamically adjust the upstream and downstream influence ranges: Based on the real-time observation speed, adaptively calculate the upstream influence range UIA and the downstream influence range DIA, using the following formula: (6); in, For the time granularity of the dataset, This represents the average length of the road segment corresponding to the sensor. , The preset maximum influence step size, Indicates the scope of upstream influence. Indicates the downstream impact range. Indicates the target node. Indicates the current time step; Step 4.2.3: Dynamic Mask Generation Rules: Generate an attention mask for each time step. When a mask element has a value of 1, it indicates that the corresponding node can participate in the attention calculation of the target node; when the value is 0, it is prohibited from participating in the calculation. The mask generation strictly follows the asymmetric propagation law of traffic flow. Free-flow state: Only upstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Congested flow status: Only downstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Critical flow state: Upstream and downstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Step 4.3: Dual-branch feature extraction; The design incorporates a dual-branch structure to jointly capture the dynamic state perception spatial dependence of traffic flow and the static topological spatial dependence of the road network. Step 4.4: Adaptive gated feature fusion, also known as adaptive gated fusion; Design a learnable gating mechanism to adaptively adjust the fusion weights of dynamic and static spatial features, and automatically balance the contributions of the first and second branches based on real-time traffic conditions.
[0012] According to a preferred embodiment of the present invention, the specific implementation process of step 4.3 includes: The first branch is the dynamic attention branch, which adopts a multi-head self-attention mechanism with dynamic asymmetric masking. It includes a linear transformation layer, multi-head attention splitting, dynamic mask-constrained attention calculation, multi-head output concatenation, and a linear mapping layer. The specific implementation process is as follows: Linear transformation: initial embedding features of the input Through 3 independent learnable weight matrices , , Linear transformation to generate the query matrix Key matrix Value matrix The formula is: (7); Query Matrix Key matrix Value matrix All dimensions are ; Multi-head attention split: , , By number of spatial attention heads Split into There are n parallel submatrices, each with a feature dimension of n. ; Dynamic mask-constrained attention computation: dynamic asymmetric mask The formula is used for attention score calculation: (8); Multi-head output splicing and linear mapping: The outputs of each attention head are concatenated along the feature dimension, and then the concatenated features are mapped back to the hidden dimensions of the original model through a linear mapping layer. Ultimately, dynamic space features are obtained. ; The second branch is the static graph convolution branch, which is a 3rd-order Chebyshev graph convolutional network, including: dimension merging, 3rd-order Chebyshev graph convolution, dimension reduction, and linear mapping layer. The specific implementation process is as follows: Dimension merging: initial embedding features of the input Batch dimension With the time dimension Merging, we get the dimension as The fusion features enable parallel convolution computation across all time steps; 3rd-order Chebyshev graph convolution: Constructing a normalized graph Laplacian matrix based on the directed adjacency matrix A of the road network A third-order Chebyshev diagram convolution operation is performed on the fused features. The convolution formula is as follows: ; in, For Chebyshev polynomials Order term, Learnable convolutional weights; Dimension reduction: the result obtained after convolution 1D feature splitting and restoration to batch dimension With the time dimension The dimension is obtained as Intermediate features; Linear mapping: Mapping intermediate features to the model's hidden dimensions through a single linear mapping layer. Finally, static spatial features are obtained. .
[0013] According to a preferred embodiment of the present invention, in step 4.4, the fusion formula is as follows: (9); (10); in, , For learnable weight matrix, For learnable bias, It is the Sigmoid activation function. For Hadama accumulation, As a dynamic spatial feature, It is a static spatial feature. The final spatial characteristics after fusion These are gating weights used to automatically balance the feature contributions of the two branches.
[0014] According to a preferred embodiment of the present invention, step 5 includes the following specific implementation process: The final spatial features of the input are first normalized by a pre-layer, and then a time-series query matrix is generated through a linear transformation. Key matrix Value matrix The projected matrix is then split into two parallel attention heads, each corresponding to a specific time scale of traffic flow evolution: Short-term trend head: A sliding window mask with a duration of 30 minutes to 2 hours is used. This sliding window mask is a causal constraint window, which only allows the current time step to focus on the features of historical time steps within the window; it is used to capture the local temporal dependencies of short-term fluctuations. Long-term dependent head: Employs a full causal mask covering the entire 2-hour input observation window to capture the daily periodic segment features of traffic flow, the road segment-specific long-term evolution pattern, and the overall trend throughout the entire observation period; Multi-head temporal attention computation is performed independently for each road network node to capture the temporal evolution pattern specific to each road segment. After the attention computation is completed, residual connections and layer normalization are added, and then the feature is passed through a position-wise feedforward network consisting of two fully connected linear layers and a ReLU activation function. The feature of each time step and each node is independently transformed nonlinearly, and residual connections and layer normalization are added. Finally, the deep spatiotemporal features with multi-scale periodic dependence are output.
[0015] According to a preferred embodiment of the present invention, step 6 includes the following specific implementation process: Based on the deep spatiotemporal features of the output, the future is directly generated through a linear mapping layer. Traffic speed prediction results for each time step; The linear mapping layer is a single-layer fully connected linear mapping layer with no activation function. It achieves direct multi-step prediction based on the deep spatiotemporal features output by the LMSTT module. The specific implementation process includes: Input features: Deep spatiotemporal features fused with multi-scale spatiotemporal dependencies, output by the LMSTT module, with dimensions of [dimensionality missing]. ; Feature Dimension Adaptation: Historical window dimensions are adapted through global pooling and linear transformation. Compressed to 1, the resulting dimension is Global spatiotemporal characteristics; Linear mapping generates predictions: global spatiotemporal features are input into a single fully connected linear mapping layer, and the output dimension is... Where Q is the number of future prediction time steps, obtained through linear transformation. Generate the future in one go Traffic speed predictions for all nodes at each time step For learnable weight matrix , For bias; Output: Final output predicted sequence , dimension That is, the future Traffic speed prediction results for each time step.
[0016] A state-aware, dynamic, asymmetric spatiotemporal Transformer long-term traffic speed prediction system includes: The module for formalizing the construction of directed graphs of transportation networks and long-term prediction problems is configured to: abstract the transportation network into a directed graph structure and complete the mathematical formal definition of the prediction problem; The preprocessing module is configured to preprocess traffic speed time-series data. The spatiotemporal embedding feature mapping module is configured to: map low-dimensional traffic speed input features to a high-dimensional hidden space, while preserving the topological spatial attributes of the road network and the temporal sequence attributes of traffic data, and generate initial embedding features; The state-aware dynamic asymmetric spatial feature extraction module is configured to: deeply integrate macroscopic traffic flow theory into the attention mechanism design; and capture the time-varying asymmetric spatial dependencies of traffic flow through four sub-steps: traffic state discrimination, dynamic mask generation, bi-branch feature extraction, and adaptive gating fusion. The lightweight multi-scale temporal Transformer feature extraction module is configured to: design a non-autoregressive encoder-only architecture to extract multi-scale temporal dependencies in parallel through the lightweight multi-scale temporal Transformer module; The traffic speed prediction module is configured as follows: end-to-end training of a dynamic asymmetric spatiotemporal Transformer and direct multi-step prediction output: based on the deep spatiotemporal features of the output, future speeds are directly generated through a linear mapping layer. Traffic speed prediction results for each time step.
[0017] Compared with the prior art, the present invention has the following significant advantages: 1. This invention deeply integrates macroscopic traffic flow theory into the attention mechanism design, accurately capturing the asymmetric dynamic propagation characteristics of traffic flow upstream and downstream. On the PeMS-BAY public dataset, the MAE of the 6-hour long-term prediction is reduced by 19.75%, RMSE by 13.92%, and MAPE by 19.82% compared with the advanced theoretical fusion baseline ALT-GMAN. It significantly outperforms existing mainstream models in long-term prediction scenarios of more than 1 hour.
[0018] 2. This invention adopts a direct multi-step prediction architecture with only encoders to replace the traditional autoregressive stepwise prediction mode. Combined with a lightweight multi-scale time Transformer to extract hierarchical periodic dependencies in parallel, the prediction time is extended from 15 minutes to 6 hours. The model's MAE only increases by 52.5%, which is far lower than the baseline model's 123.5%, greatly improving the stability and reliability of long-term prediction.
[0019] 3. By using a dynamic asymmetric mask driven by traffic conditions, a hard constraint of traffic physics laws is imposed on spatial attention, breaking the black box limitation of pure data-driven models. The model prediction results conform to the basic laws of traffic flow evolution. The dual-branch structure integrates dynamic traffic dependence and static road network topology, and can still maintain stable prediction performance under sudden congestion and extreme traffic scenarios.
[0020] 4. The lightweight model design of this invention significantly reduces computational redundancy and can adapt to the real-time prediction needs of intelligent transportation systems. The model input only requires traffic speed data and road network topology, and the data acquisition threshold is low. It can be directly deployed in scenarios such as urban traffic management platforms and vehicle navigation systems, providing accurate long-term prediction support for proactive traffic management and long-distance travel planning. Attached Figure Description
[0021] Figure 1 This is a diagram of the overall architecture of the SDA-STT model proposed in this invention; Figure 2 This is the basic diagram of the traffic flow triangle. Figure 3 The figure shows the single-node continuous velocity prediction results of the SDA-STT model of this invention under prediction durations of 1 hour, 3 hours, and 6 hours. Figure 4 This is a comparison chart of the MAE, RMSE, and MAPE performance of the SDA-STT model and the ALT-GMAN baseline model under different prediction durations. Detailed Implementation
[0022] The present invention will be further defined below with reference to the accompanying drawings and embodiments, but is not limited thereto.
[0023] Example 1 A state-aware, dynamic, asymmetric, spatiotemporal Transformer method for long-term traffic speed prediction, with the following specific steps: Step 1: Construction of a directed graph of the transportation network and formalization of the long-term prediction problem; including: abstracting the transportation network into a directed graph structure and completing the mathematical formalization definition of the prediction problem; Step 2: Preprocessing of traffic speed time series data; Step 3: Spatiotemporal embedding feature mapping; including: mapping the low-dimensional traffic speed input features to a high-dimensional hidden space, while preserving the topological spatial attributes of the road network and the temporal order attributes of the traffic data, to generate initial embedding features; Step 4: State-aware dynamic asymmetric spatial feature extraction; including: deeply integrating macroscopic traffic flow theory into the attention mechanism design, and capturing the time-varying asymmetric spatial dependencies of traffic flow through four sub-steps: traffic state discrimination, dynamic mask generation, bi-branch feature extraction, and adaptive gating fusion. Step 5: Lightweight multi-scale temporal Transformer feature extraction; including: In order to capture the strong multi-scale periodic characteristics of traffic speed (short-term trend, daily period, weekly period) and eliminate the error accumulation of autoregressive structures, this invention designs a non-autoregressive architecture with only encoders, and extracts multi-scale temporal dependencies in parallel through a lightweight multi-scale temporal Transformer module; Step 6: End-to-end training and direct multi-step prediction of output using the State-aware Dynamic Asymmetric Spatial-Temporal Transformer (SDA-STT): Based on the deep spatiotemporal features of the output, the future is directly generated through a linear mapping layer. Traffic speed prediction results for each time step.
[0024] Dynamic asymmetric spacetime Transformer, such as Figure 1 As shown, the overall architecture consists of: a spatiotemporal embedding (STEmbedding) module, a state-aware dynamic asymmetric spatiotemporal (SDA-ST) module, a lightweight multiscale time (LMSTT) module, and a linear mapping output layer.
[0025] Example 2 The difference between the state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method described in Example 1 and the one described in Example 1 is as follows: The specific implementation of step 1 includes: Urban traffic networks naturally conform to the topological characteristics of directed graphs. This invention first abstracts the traffic network into a directed graph structure, thus completing the mathematical formalization of the prediction problem.
[0026] A directed graph of a transportation network is defined as follows: ,in, for A set of traffic sensor nodes, each node corresponding to a one-way urban road segment; a set of directed edges. The path representing the actual traffic flow is defined if and only if the traffic flow can originate from the road segment. Drive directly to the section of road At that time, on the side Directed adjacency matrix The connectivity of the coded road network, among which If and only if ,otherwise ; Traffic time-series data definition: At each time step t, the traffic feature map signals of all nodes are collected as follows: ,in Traffic feature dimension; this invention uses traffic speed as the sole prediction target, therefore it sets... .
[0027] Input and output definitions: Given a length of Historical observation window at each time step, historical traffic time series for: (1); The goal of long-term traffic speed prediction is to learn a nonlinear mapping function. Based on historical traffic time series Directed graph of transportation network Predicting the future Traffic speeds at all nodes at each time step, outputting the predicted sequence. for: (2); in For time step The predicted traffic speed, and the corresponding actual speed sequence are: .
[0028] The specific implementation process of step 2 includes: To ensure the stability and convergence of model training, the collected traffic speed time-series data undergoes standardization and dataset partitioning. Traffic speed time-series data refers to continuous records of traffic speeds on each one-way segment of the urban road network, collected by traffic sensors at fixed time granularities. It represents the time-series speed values for each node (sensor / one-way segment) in the road network. The specific process is as follows: The collected traffic speed time-series data corresponds to the data defined in step 1. At each time step t, the traffic feature map signals of all nodes are collected. ,in As a traffic feature dimension, this invention uses traffic speed as the sole prediction target, therefore setting... Historical observation sequence Where N is the number of sensor nodes, P is the number of time steps in the historical observation window, and the time granularity in the experiment is 5 minutes.
[0029] Data standardization: Z-score standardization is performed on the traffic speed time series data. The calculation formula is as follows: ,in σ represents the original traffic speed value, μ represents the mean of traffic speed in the training set, and σ represents the standard deviation of traffic speed in the training set. The mean and standard deviation are calculated only from the training set to avoid data leakage.
[0030] The training set refers to the dataset used for training model parameters, partitioned chronologically from the preprocessed complete traffic speed time-series data. Only this dataset is used to calculate the standardized mean and standard deviation to avoid data leakage. It corresponds to the set of all historical observation sequences χ and the true future sequences Y from step 1, and is a subset of the overall traffic time-series data. The preprocessed data is divided into training, validation, and test sets in a 7:1:2 ratio. The validation set is used for early stopping strategies to prevent overfitting, and the test set is used for final model performance evaluation.
[0031] Dataset partitioning: The preprocessed dataset is divided into training, validation and test sets in a 7:1:2 ratio according to the time sequence. The time granularity of the dataset is 5 minutes, and the prediction duration is set to 1 hour, 3 hours and 6 hours, which correspond to 12, 36 and 72 prediction time steps respectively.
[0032] The specific implementation process of step 3 includes: The spatiotemporal embedding module includes a linear projection layer, a learnable spatial embedding layer, and a sinusoidal position coding layer; In the linear projection layer, a fully connected linear layer maps the single-dimensional traffic speed feature to a predefined model hidden dimension. This completes the dimensionality upgrade of the features. In the learnable spatial embedding layer, a unique learnable feature vector is generated for each node in the road network, capturing the fixed topological connectivity characteristics of the road network and providing prior information for spatial feature extraction; In the sinusoidal location coding layer, a fixed location code is generated for each time step of the time series using a sinusoidal function, preserving the temporal order information of traffic data and making up for the Transformer architecture's deficiency in perceiving temporal location.
[0033] Finally, the linear projection features, learnable spatial embedding features, and sinusoidal positional codes are added element-wise to obtain the initial embedding features that retain complete spatiotemporal attributes. These are then input into the subsequent spatiotemporal feature extraction module. Specifically, this includes:
[0034] The linear projection layer is a single fully connected linear layer with no activation function. Its input dimension is 1 (single-dimensional traffic speed), and its output dimension is the model's hidden feature dimension. (In this embodiment) ).
[0035] In the linear projection layer, the single-dimensional velocity value of each time step and each node is transformed linearly by the fully connected layer. Complete feature dimensionality upscaling, among which For learnable weight matrix , For bias.
[0036] The feature acquisition process includes: the feature meridians output by the linear projection layer are the linear projection features, with dimensions of . ( For batch size, For the number of steps in the historical window, (Number of nodes).
[0037] The learnable spatial embedding layer assigns a unique learnable feature vector to each node in the road network, with a vector dimension of [missing information]. It has no additional network layers and updates vector parameters only through model training.
[0038] In the learnable space embedding layer, N random values are initialized for N nodes. The 3D feature vectors, as learnable parameters of the model, are optimized along with the model during training to capture the fixed topological connectivity characteristics of the road network.
[0039] The feature acquisition process includes: the learnable feature vector of each node is the learnable space embedding feature, with a dimension of [missing information]. Expanded through broadcast mechanism It matches the feature dimension of the linear projection.
[0040] The sinusoidal position coding layer uses the classic sinusoidal position coding formula of Transformer to generate a fixed position coding vector for each time step. It has no learning parameters, and the vector dimension is [missing value]. The encoding formula uses sine and cosine functions for even / odd dimensions respectively to ensure that the relative position information of the time step can be captured by the model.
[0041] In the sinusoidal position coding layer, based on the number of time steps P of the historical observation window, each time step... Generate the corresponding A sinusoidal position encoding vector with fixed encoding values is used to compensate for the Transformer's deficiency in perceiving temporal position.
[0042] The feature acquisition process includes: the fixed-position encoding vector at each time step is the sinusoidal positional encoding feature, with a dimension of... Expanded through broadcast mechanism It matches the dimensions of the previous two.
[0043] The initial embedding features are generated by summing the linear projection features, learnable spatial embedding features, and sinusoidal positional encoding features element-wise to obtain the initial embedding features that retain complete spatiotemporal attributes, with a dimension of [missing value]. This serves as the input for the subsequent SDA-ST module.
[0044] The specific implementation process of step 4 includes: Step 4.1: Real-time traffic state determination based on traffic flow theory; The discrimination logic is constructed based on the classic macroscopic traffic flow triangle basic diagram, such as... Figure 2 As shown, the three core parameters of traffic flow are: flow rate and volume. ,speed ,density The following basic relations must be satisfied: (3); With critical density As a boundary, traffic flow is divided into two states with completely different propagation characteristics: in the free flow state, traffic impact propagates forward along the direction of traffic flow, and the speed of downstream road segments is determined by the inflow of upstream traffic; in the congested flow state, congestion shock waves propagate backward against the direction of traffic flow, and the speed of upstream road segments is constrained in the opposite direction by the degree of downstream congestion. First, traffic density is calculated based on the real-time observed speed of the nodes, providing a physical basis for state determination. For nodes... At time step observation speed Traffic density The calculation formula is:
[0045] (4); in, The free-flow velocity of the road segment. To congest the shock wave velocity, The above parameters are all calibrated using training set data and are consistent with the actual road network characteristics.
[0046] The calibration is achieved through the training set. Specifically, this can be based on parameter fitting methods from the macroscopic traffic flow triangulation diagram in the field of traffic engineering. The steps are as follows: Data preparation: Extract the speed of all time steps and all road segments from the training set. (Dataset provided directly) and traffic Through formula Calculate the density.
[0047] Drawing the basic diagram: using density For the horizontal axis, velocity Plot a scatter plot with the vertical axis as the y-axis: Free flow section: When smaller, Approximately constant (close to free flow velocity) ); Congested sections: When it is large, Follow It increases and then decreases linearly.
[0048] Piecewise fitting: Free flow section: Fitting Data from a smaller area yields a horizontal line ; Congested flow section: Fitting Data from a larger area yields a straight line with a negative slope. ( To congest the shock wave velocity, (Clogging density).
[0049] Determine the critical density : The first method: Find the traffic The largest point, corresponding to That is (Peak flow is the boundary between free flow and congested flow.) The second method: The x-coordinate of the intersection of the free-flow line and the congested-flow line is... .
[0050] Synchronous calibration: Simultaneously obtain free flow velocity Congestion shock wave velocity All three are parameters specific to this road network.
[0051] To avoid frequent state fluctuations in the critical flow region, a hysteresis threshold is introduced. Traffic conditions are divided into three categories: (5); in, For nodes At time step Traffic status labels When =0, it is a free flow state; When =1, it is a critical flow state; When the value is 2, it is a congested flow state; Step 4.2: Dynamic asymmetric attention mask, i.e., dynamic mask generation; Based on the real-time traffic state obtained from the discrimination, a dynamic attention mask is generated for each node and each time step. This mask applies hard constraints based on traffic physics to the subsequent spatial attention calculation. The specific process is as follows: Step 4.2.1: Pre-calculate the shortest path step size matrix of the road network: Upstream step size matrix :in Indicates upstream node To the target node along the traffic flow direction Shortest path step size; downstream step size matrix :in Indicates downstream node Reverse traffic flow to the target node The shortest path step size; the step size is the number of edges in the shortest path in the directed graph, not the actual geographical distance. Upstream step size matrix. and downstream step size matrix Before model training, the system pre-computes the directed graph of the traffic network, and the core algorithm used is Dijkstra's algorithm, the shortest path search algorithm for directed graphs.
[0052] Step 4.2.2: Dynamically adjust upstream and downstream influence areas: Based on real-time observation speed, adaptively calculate the upstream influence area (UIA) and downstream influence area (DIA), as shown in the following formula: (6); in, For the time granularity of the dataset, This represents the average length of the road segment corresponding to the sensor. , This is the preset maximum impact step size, used to control computational complexity. Indicates the scope of upstream influence. Indicates the downstream impact range. Indicates the target node. Indicates the current time step;
[0053] Step 4.2.3: Dynamic Mask Generation Rules: Generate an attention mask for each time step. When a mask element has a value of 1, it indicates that the corresponding node can participate in the attention calculation of the target node; when the value is 0, it is prohibited from participating in the calculation. The mask generation strictly follows the asymmetric propagation law of traffic flow. Free-flow state: Only upstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Congested flow status: Only downstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Critical flow state: Upstream and downstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Step 4.3: Dual-branch feature extraction; The design employs a dual-branch structure to jointly capture the dynamic state-aware spatial dependency of traffic flow and the static topological spatial dependency of the road network; these two aspects complement each other to enhance the model's robustness and generalization ability. Step 4.4: Adaptive gated feature fusion, also known as adaptive gated fusion; Design a learnable gating mechanism to adaptively adjust the fusion weights of dynamic and static spatial features, and automatically balance the contributions of the first and second branches based on real-time traffic conditions.
[0054] The specific implementation process of step 4.3 includes: The first branch is the dynamic attention branch, which adopts a multi-head self-attention mechanism with dynamic asymmetric masking. It includes a linear transformation layer, multi-head attention splitting, dynamic mask-constrained attention calculation, multi-head output concatenation, and a linear mapping layer. The specific implementation process is as follows: Linear transformation: initial embedding features of the input Through 3 independent learnable weight matrices , , Linear transformation to generate the query matrix Key matrix Value matrix The formula is: (7); Query Matrix Key matrix Value matrix All dimensions are ; Multi-head attention split: , , By number of spatial attention heads (In the example) ) split into There are n parallel submatrices, each with a feature dimension of n. Achieve parallel capture of multi-scale spatial dependencies.
[0055] Dynamic mask-constrained attention computation: dynamic asymmetric mask (Generated from traffic condition assessment results: activating the upstream influence area mask during free flow and activating the downstream influence area mask during congested flow) Applied to attention score calculation, the formula is: (8); The mask sets the attention score of invalid nodes to 0. After being activated by Softmax, the corresponding weights approach 0, thus realizing the hard constraint of traffic physics on spatial attention, and retaining only the effective node dependencies that conform to the direction of traffic flow propagation.
[0056] Multi-head output splicing and linear mapping: The outputs of each attention head are concatenated along the feature dimension, and then the concatenated features are mapped back to the hidden dimensions of the original model through a linear mapping layer. Ultimately, dynamic space features are obtained. ; The second branch is the static graph convolution branch, which is a 3rd-order Chebyshev graphical convolutional network (ChebyshevGCN). It includes: dimension merging, 3rd-order Chebyshev graphical convolution, dimension reduction, and linear mapping layers. The specific implementation process is as follows: Dimension merging: initial embedding features of the input Batch dimension With the time dimension Merging, we get the dimension as The fusion features enable parallel convolution computation at all time steps, improving model inference efficiency.
[0057] 3rd-order Chebyshev graph convolution: Constructing a normalized graph Laplacian matrix based on the directed adjacency matrix A of the road network A third-order Chebyshev diagram convolution operation is performed on the fused features. The convolution formula is as follows: ; in, For Chebyshev polynomials Rank term ( (corresponding to 3rd order convolution) The convolution weights are learnable; the third-order neighborhood topological dependency of nodes is captured by polynomial expansion, and the static spatial features of the road network are extracted.
[0058] Dimension reduction: the result obtained after convolution 1D feature splitting and restoration to batch dimension With the time dimension The dimension is obtained as Intermediate features; Linear mapping: Mapping intermediate features to the model's hidden dimensions through a single linear mapping layer. Finally, static spatial features are obtained. It is consistent with the dynamic space feature dimension, which facilitates subsequent gating fusion operations.
[0059] In step 4.4, the fusion formula is as follows: (9); (10); in, , For learnable weight matrix, For learnable bias, It is the Sigmoid activation function. This is the Hadamard product (element-by-element multiplication). As a dynamic spatial feature, It is a static spatial feature. The final spatial characteristics after fusion These are gating weights used to automatically balance the feature contributions of the two branches.
[0060] The specific implementation process of step 5 includes: The encoder-only non-autoregressive architecture differs from the traditional Transformer's encoder-decoder autoregressive architecture. It consists only of stacked encoder modules (SDA-ST+LMSTT). All feature extraction is performed within the encoder, employing a direct multi-step prediction mode. Through the final linear mapping layer, the future features are generated in a single step from the deep spatiotemporal features output by the encoder. Instead of predicting step by step, the prediction results are calculated at each time step, thus avoiding the accumulation of autoregressive errors at the source.
[0061] The Lightweight Multiscale Temporal Transformer (LMSTT) module includes: multi-head temporal self-attention with dual attention heads, residual connections, layer normalization, and a position-wise feedforward network (FFN). It follows the classic Transformer encoder block structure and employs node-independent temporal attention computation. The specific structure is shown below:
[0062] Pre-layer normalization: normalization of the final spatial features of the input. Execution layer normalization eliminates the influence of units and improves training stability; Linear Transformation Layer: Generates a temporal query matrix from the normalized features through a linear transformation. Key matrix Value matrix All dimensions ; Dual attention head splitting: , , Split into There are several parallel attention heads. Each head corresponds to a time scale and independently calculates temporal attention. The short-term trend head captures short-term local fluctuations in traffic flow such as congestion formation and dissipation and peak surges; the long-term dependency head captures long-term periodic patterns of traffic flow in daily and weekly cycles.
[0063] Residual connection + layer normalization: After concatenating the outputs of the dual attention heads, a residual connection is made with the input features of LMSTT, and then layer normalization is performed to avoid gradient vanishing or exploding. Location-wise feedforward network (FFN): A lightweight FFN with two fully connected layers and ReLU activation is used to process the features of each time point independently; Final residual connection + layer normalization: The output of FFN is residually connected with the features from the previous step, and then layer normalization is performed to obtain deep spatiotemporal features that fuse multi-scale periodic dependencies, with dimensions of .
[0064] Core lightweight design: Only two temporal attention heads, lightweight FFN, and node-independent attention computation are used, which greatly reduces computational redundancy and adapts to real-time prediction requirements.
[0065] The final spatial features of the input are first normalized by a pre-layer, and then a time-series query matrix is generated through a linear transformation. Key matrix Value matrix The projected matrix is then split into two parallel attention heads, each corresponding to a specific time scale of traffic flow evolution: Short-term trend head: A sliding window mask with a duration of 30 minutes to 2 hours is used. This sliding window mask is a causal constraint window, which only allows the current time step to focus on the features of historical time steps within the window; it is used to capture the local temporal dependencies of short-term fluctuations; such as the formation and dissipation of congestion, sudden increases in morning and evening peak hours, the decline of traffic flow after the peak, slow traffic on local road sections, and sudden disturbances caused by temporary acceleration, deceleration or avoidance. Long-term dependency head: Employs a fully causal mask covering the entire 2-hour input observation window. This mask ensures that the model learns using only historical information and does not leak future information. Captures daily periodic segment features of traffic flow, road segment-specific long-term evolution patterns, and overall trends throughout the entire observation period, such as continuous congestion, continuous smooth flow, and slow flow followed by congestion.
[0066] Multi-head temporal attention computation is performed independently for each road network node to capture the temporal evolution pattern specific to each road segment. After the attention computation is completed, residual connections and layer normalization are added, and then the feature is passed through a position-wise feedforward network (FFN) consisting of two fully connected linear layers and a ReLU activation function. The feature of each time step and each node is independently transformed nonlinearly, and residual connections and layer normalization are added. Finally, the deep spatiotemporal features with multi-scale periodic dependence are output.
[0067] The specific implementation process of step 6 includes: Based on the deep spatiotemporal features of the output, the future is directly generated through a linear mapping layer. Traffic speed prediction results at each time step; no stepwise autoregressive decoding is required, thus avoiding error accumulation at the source.
[0068] The linear mapping layer is a single-layer fully connected linear mapping layer with no activation function. It is the final output layer of the model and achieves direct multi-step prediction based on the deep spatiotemporal features output by the LMSTT module. The specific implementation process (fitting the non-autoregressive architecture of the encoder-only module) includes: Input features: After stacking L layers of spatiotemporal modules, the LMSTT module outputs deep spatiotemporal features that fuse multi-scale spatiotemporal dependencies, with dimensions of... ; Feature Dimension Adaptation: Historical window dimensions are adapted through global pooling and linear transformation. Compressed to 1, the resulting dimension is The global spatiotemporal characteristics; eliminating dimensional differences in historical time steps and focusing on core spatiotemporal patterns; Linear mapping generates predictions: global spatiotemporal features are input into a single fully connected linear mapping layer, and the output dimension is... Where Q is the number of future prediction time steps, the maximum Q is set to 72 in the experiment, corresponding to 6 hours, through linear transformation. Generate the future in one go Traffic speed predictions for all nodes at each time step For learnable weight matrix , For bias; Output: Final output predicted sequence , dimension That is, the future Traffic speed prediction results for each time step.
[0069] The model is trained in an end-to-end manner with the following settings: Evaluation metrics: Three commonly used quantitative metrics in the field of traffic prediction are used to evaluate model performance: Mean Absolute Error (MAE), Root Mean Square Error (RMSE), and Mean Absolute Percentage Error (MAPE). The calculation formulas are as follows: (11); (12); (13); in, For nodes At time step Prediction speed, This corresponds to the actual speed.
[0070] Training configuration: End-to-end training is performed using the Adam optimizer, with an initial learning rate of 0.001, a batch size of 24, and a maximum training epoch of 100. An early stopping strategy is used to prevent overfitting, and training is terminated when the validation set loss does not decrease for 10 consecutive epochs.
[0071] Example 3 The difference between the state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method described in Embodiment 1 or 2 is that: (I) Setting up the operating environment: The hardware and software operating environment configuration for this embodiment is as follows: (1) Hardware environment: The training server uses an AMD EPYC 7742 processor and is equipped with an NVIDIA A100-SXM4-40GB for end-to-end training and inference verification of the model; (2) Operating system: Ubuntu 20.04.4; (3) Software environment: Python 3.12, PyTorch 2.10.0+cu128 deep learning framework, NumPy numerical computing library, Pandas data processing library, Scikit-learn machine learning library.
[0072] (ii) Dataset and Data Preprocessing; This embodiment uses the PeMS-BAY public dataset, which is widely used in the field of traffic prediction. This dataset was collected by the California Department of Transportation Performance Measurement System (PeMS) and contains 5-minute granular traffic speed records from 325 sensors in the San Francisco Bay Area from January to June 2017. It covers frequent and sudden congestion scenarios on urban expressways and can fully verify the long-term predictive performance of the model.
[0073] The data preprocessing process is as follows: (1) Data cleaning: missing values in the dataset are filled in using linear interpolation, and outlier data caused by sensor failure are removed; (2) Standardization: Z-score standardization is performed on traffic speed data, and the mean and standard deviation are calculated only from the training set to avoid data leakage; (3) Data set partitioning: The dataset is divided into training set, validation set and test set in chronological order with a ratio of 7:1:2; (4) Sample construction: Set the historical observation window length P=24, corresponding to 2 hours of historical observation data, and the maximum prediction step size Q=72, corresponding to 6 hours of prediction duration.
[0074] (III) Configuration of core hyperparameters of the model; In this embodiment, the core hyperparameter configuration of the model is shown in Table 1 below: Table 1. Configuration of the core hyperparameters of the model;
[0075] Among them, free flow velocity Congestion shock wave velocity Critical density Based on the training set data, they were respectively set as follows: , , .
[0076] (iv) Complete model implementation process; (1) Construction of directed graph of traffic network: Based on the sensor network topology of PeMS-BAY dataset, a directed graph containing 325 nodes is constructed. A directed adjacency matrix is generated according to the actual traffic flow direction of the road segment. The upstream step length matrix and the downstream step length matrix are pre-calculated, and the shortest path step length between each node along the traffic flow and reverse traffic flow direction is stored.
[0077] (2) Spatiotemporal embedding feature mapping: First, the single-dimensional traffic speed feature is mapped to a 64-dimensional hidden space through a linear projection layer, generating a 64-dimensional learnable spatial embedding vector for 325 nodes and a 64-dimensional sinusoidal position code for 24 time steps. After the three are added element by element, the output is an initial embedding feature with a dimension of B×24×325×64 (B is the batch size).
[0078] (3) State-aware dynamic asymmetric spatial feature extraction: (3.1) Traffic state discrimination: For the observed speed of each node at each time step, the traffic density is calculated based on the triangular basic graph. Combined with the hysteresis threshold α, the traffic state is divided into three categories: free flow, critical flow, and congested flow. (3.2) Dynamic mask generation: Calculate the dynamic UIA and DIA of each node based on the real-time speed, and generate a dynamic attention mask with dimensions B×24×325×325 according to the traffic state rules; (3.3) Dual-branch feature extraction: The dynamic attention branch splits the initial embedded features into 4 attention heads, substitutes them into the attention formula with dynamic mask to calculate, and outputs dynamic spatial features; the static graph convolution branch uses 3rd order Chebyshev graph convolution to output static topological features. (3.4) Gated fusion: The fusion weights are calculated by using Sigmoid gating to weight and fuse dynamic and static features to output the final spatial features.
[0079] (4) Lightweight multi-scale temporal Transformer feature extraction: The spatial features are first normalized by layer and then transformed by linear transformation to generate temporal Q, K, V matrices, which are split into two parallel attention heads: the short-term trend head uses a sliding window mask with 12 time steps and the long-term dependency head uses a fully causal mask covering 24 time steps; the temporal attention calculation is performed independently for each node, and after residual connection, layer normalization and feedforward network, the deep spatiotemporal features are output.
[0080] (5) Model training and prediction output: The deep spatiotemporal features output by the stacked spatiotemporal modules are directly mapped to 72 prediction time steps through a linear mapping layer, and the traffic speed prediction results with dimensions of B×72×325×1 are output. The model adopts end-to-end training with MAE as the core loss function. When the validation set loss does not decrease for 10 consecutive rounds, early stopping is triggered to complete the model training.
[0081] (v) Experimental verification results; This embodiment compares and validates the SDA-STT model proposed in this invention with mainstream baseline models such as ARIMA, SVR, FC-LSTM, STGCN, DCRNN, GraphWaveNet, GMAN, and ALT-GMAN. Figure 3The figure shows the single-node continuous velocity prediction results of the SDA-STT model of this invention under prediction durations of 1 hour, 3 hours, and 6 hours. Figure 3 In the image, (a) shows the single-node continuous velocity prediction result for a 1-hour prediction duration, (b) shows the single-node continuous velocity prediction result for a 3-hour prediction duration, and (c) shows the single-node continuous velocity prediction result for a 6-hour prediction duration. Figure 3 In the graph, the horizontal axis represents the Time step, corresponding to a 5-minute time granularity. The values on the horizontal axis are consecutive time step numbers (such as 3000, 3500, 4000, etc.), covering a week of continuous traffic speed observation / prediction time. The vertical axis represents Speed (mph), which is the original speed unit of the PeMS-BAY dataset, reflecting the real-time traffic speed value of that node. The blue line represents the ground truth traffic speed, which is the actual time-series traffic speed value collected by the sensor at this node, serving as the reference benchmark for model prediction. The red line represents the model-predicted traffic speed (SDA-STTPrediction), which is the traffic speed prediction value output by the model in this paper for this node, visually demonstrating the degree of fit between the predicted trajectory and the actual trajectory. The core experimental results are as follows:
[0082] (1) Short-term prediction performance: In the 15-minute and 30-minute prediction tasks, the accuracy of the model of this invention is comparable to that of mainstream models such as GraphWaveNet and GMAN, and it has highly competitive short-term prediction performance. In the 1-hour prediction task, the MAE of the model of this invention drops to 1.80, which is 3.2% lower than that of the GMAN model, demonstrating a significant advantage in medium and long-term prediction.
[0083] (2) Long-term prediction performance: In the 6-hour long-term prediction task, compared with the advanced theoretical fusion baseline ALT-GMAN, the model of this invention reduces MAE by 19.75%, RMSE by 13.92%, and MAPE by 19.82%. The predicted trajectory is highly consistent with the actual value, and can accurately capture the entire process of the occurrence, development and dissipation of sudden congestion without significant phase shift.
[0084] (3) Error accumulation suppression effect: When the prediction duration is extended from 15 minutes to 6 hours, the MAE of the ALT-GMAN baseline increases by 123.5%, while the MAE of the model of this invention only increases by 52.5%, which fully verifies the effective suppression effect of non-autoregressive architecture and dynamic asymmetric design on error accumulation and has extremely strong long-term prediction reliability.
[0085] Figure 4This is a comparison chart of the MAE, RMSE, and MAPE performance of the SDA-STT model and the ALT-GMAN baseline model under different prediction durations. Figure 4 In the figure, (a) is a comparison of MAE performance between the SDA-STT model of the present invention and the ALT-GMAN baseline model under different prediction durations, (b) is a comparison of RMSE performance between the SDA-STT model of the present invention and the ALT-GMAN baseline model under different prediction durations, and (c) is a comparison of MAPE performance between the SDA-STT model of the present invention and the ALT-GMAN baseline model under different prediction durations.
[0086] Table 2 compares the prediction performance of the model of this invention with eight baseline models: ARIMA, SVR, Feedforward Neural Network (FNN), FC-LSTM, STGCN, DCRNN, Graph WaveNet, and GMAN.
[0087] Table 2
[0088] Example 4 A state-aware, dynamic, asymmetric spatiotemporal Transformer long-term traffic speed prediction system includes: The module for formalizing the construction of directed graphs of transportation networks and long-term prediction problems is configured to: abstract the transportation network into a directed graph structure and complete the mathematical formal definition of the prediction problem; The preprocessing module is configured to preprocess traffic speed time-series data. The spatiotemporal embedding feature mapping module is configured to: map low-dimensional traffic speed input features to a high-dimensional hidden space, while preserving the topological spatial attributes of the road network and the temporal sequence attributes of traffic data, and generate initial embedding features; The state-aware dynamic asymmetric spatial feature extraction module is configured to: deeply integrate macroscopic traffic flow theory into the attention mechanism design; and capture the time-varying asymmetric spatial dependencies of traffic flow through four sub-steps: traffic state discrimination, dynamic mask generation, bi-branch feature extraction, and adaptive gating fusion. The lightweight multi-scale temporal Transformer feature extraction module is configured to: design a non-autoregressive encoder-only architecture to extract multi-scale temporal dependencies in parallel through the lightweight multi-scale temporal Transformer module; The traffic speed prediction module is configured as follows: end-to-end training of a dynamic asymmetric spatiotemporal Transformer and direct multi-step prediction output: based on the deep spatiotemporal features of the output, future speeds are directly generated through a linear mapping layer. Traffic speed prediction results for each time step.
Claims
1. A state-aware dynamic asymmetric spatio-temporal Transformer long-term traffic speed prediction method, characterized in that, The specific steps are as follows: Step 1: Construction of a directed graph of the transportation network and formalization of the long-term prediction problem; including: abstracting the transportation network into a directed graph structure and completing the mathematical formalization definition of the prediction problem; Step 2: Preprocessing of traffic speed time series data; Step 3: Spatiotemporal embedding feature mapping; including: mapping the low-dimensional traffic speed input features to a high-dimensional hidden space, while preserving the topological spatial attributes of the road network and the temporal order attributes of the traffic data, to generate initial embedding features; Step 4: State-aware dynamic asymmetric spatial feature extraction; including: deeply integrating macroscopic traffic flow theory into the attention mechanism design, and capturing the time-varying asymmetric spatial dependencies of traffic flow through four sub-steps: traffic state discrimination, dynamic mask generation, bi-branch feature extraction, and adaptive gating fusion. Step 5: Lightweight multi-scale temporal Transformer feature extraction; including: designing a non-autoregressive encoder-only architecture, and extracting multi-scale temporal dependencies in parallel through a lightweight multi-scale temporal Transformer module; Step 6: End-to-end training and direct multi-step prediction of output using the dynamic asymmetric spatiotemporal Transformer: Based on the deep spatiotemporal features of the output, the future is directly generated through a linear mapping layer. Traffic speed prediction results for each time step; The specific implementation process of step 4 includes: Step 4.1: Real-time traffic state determination based on traffic flow theory; Based on the classic macroscopic traffic flow triangle basic graph, a discrimination logic is constructed for traffic flow. ,speed ,density The following basic relations must be satisfied: (3); First, traffic density is calculated by back-calculating the real-time observed speed at each node. At time step observation speed Traffic density The calculation formula is: (4); in, The free-flow velocity of the road segment. To congest the shock wave velocity, It is the critical density; Introducing a hysteresis threshold Traffic conditions are divided into three categories: (5); in, For nodes At time step Traffic status labels When =0, it is a free flow state; When =1, it is a critical flow state; When the value is 2, it is a congested flow state; Step 4.2: Dynamic asymmetric attention mask, i.e., dynamic mask generation; Based on the real-time traffic state obtained from the discrimination, a dynamic attention mask is generated for each node and each time step. This mask applies hard constraints based on traffic physics to the subsequent spatial attention calculation. The specific process is as follows: Step 4.2.1: Pre-calculate the shortest path step size matrix of the road network: Upstream step size matrix :in Indicates upstream node To the target node along the traffic flow direction Shortest path step size; downstream step size matrix :in Indicates downstream node Reverse traffic flow to the target node The number of steps in the shortest path; Step 4.2.2: Dynamically adjust the upstream and downstream influence ranges: Based on the real-time observation speed, adaptively calculate the upstream influence range UIA and the downstream influence range DIA, using the following formula: (6); in, For the time granularity of the dataset, This represents the average length of the road segment corresponding to the sensor. , The preset maximum influence step size, Indicates the scope of upstream influence. Indicates the downstream impact range. Indicates the target node. Indicates the current time step; Step 4.2.3: Dynamic Mask Generation Rules: Generate an attention mask for each time step. When a mask element has a value of 1, it indicates that the corresponding node can participate in the attention calculation of the target node; when the value is 0, it is prohibited from participating in the calculation. The mask generation strictly follows the asymmetric propagation law of traffic flow. Free-flow state: Only upstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Congested flow status: Only downstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Critical flow state: Upstream and downstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Step 4.3: Dual-branch feature extraction; The design incorporates a dual-branch structure to jointly capture the dynamic state perception spatial dependence of traffic flow and the static topological spatial dependence of the road network. Step 4.4: Adaptive gated feature fusion, also known as adaptive gated fusion; Design a learnable gating mechanism to adaptively adjust the fusion weights of dynamic and static spatial features, and automatically balance the contributions of the first and second branches based on real-time traffic conditions.
2. The state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method according to claim 1, characterized in that, The specific implementation of step 1 includes: A directed graph of a transportation network is defined as follows: ,in, for A set of traffic sensor nodes, each node corresponding to a one-way urban road segment; a set of directed edges. The path representing the actual traffic flow is defined if and only if the traffic flow can originate from the road segment. Drive directly to the section of road At that time, on the side Directed adjacency matrix The connectivity of the coded road network, among which If and only if ,otherwise ; Traffic time-series data definition: At each time step t, the traffic feature map signals of all nodes are collected as follows: ,in For traffic feature dimensions; Input and output definitions: Given a length of Historical observation window at each time step, historical traffic time series for: (1); The goal of long-term traffic speed prediction is to learn a nonlinear mapping function. Based on historical traffic time series Directed graph of transportation network Predicting the future Traffic speeds at all nodes at each time step, outputting the predicted sequence. for: (2); in For time step The predicted traffic speed, and the corresponding actual speed sequence are: .
3. The state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method according to claim 1, characterized in that, The specific implementation process of step 2 includes: The collected traffic speed time-series data undergoes standardization processing and dataset partitioning. Traffic speed time-series data refers to continuous records of traffic speeds on each one-way road segment of the urban road network, collected by traffic sensors at fixed time granularities; it represents the time-series speed value of each node in the road network. The specific process is as follows: Data standardization: Z-score standardization is performed on the traffic speed time series data. The calculation formula is as follows: ,in σ represents the original traffic speed value, μ represents the mean of the traffic speed in the training set, and σ represents the standard deviation of the traffic speed in the training set. Dataset partitioning: The preprocessed dataset is divided into training set, validation set and test set according to the time sequence.
4. The state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method according to claim 1, characterized in that, The specific implementation process of step 3 includes: The spatiotemporal embedding module includes a linear projection layer, a learnable spatial embedding layer, and a sinusoidal position coding layer; In the linear projection layer, a fully connected linear layer maps the single-dimensional traffic speed feature to a predefined model hidden dimension. This completes the dimensionality upgrade of the features. In the learnable spatial embedding layer, a unique learnable feature vector is generated for each node in the road network, capturing the fixed topological connectivity characteristics of the road network and providing prior information for spatial feature extraction; In the sinusoidal location coding layer, a fixed location code is generated for each time step of the time series using a sinusoidal function, preserving the temporal order information of traffic data and making up for the Transformer architecture's deficiency in perceiving temporal location. Finally, the linear projection features, learnable spatial embedding features, and sinusoidal positional codes are added element by element to obtain the initial embedding features that retain complete spatiotemporal attributes.
5. The state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method according to claim 1, characterized in that, The specific implementation process of step 4.3 includes: The first branch is the dynamic attention branch, which adopts a multi-head self-attention mechanism with dynamic asymmetric masking. It includes a linear transformation layer, multi-head attention splitting, dynamic mask-constrained attention calculation, multi-head output concatenation, and a linear mapping layer. The specific implementation process is as follows: Linear transformation: initial embedding features of the input Through 3 independent learnable weight matrices , , Linear transformation to generate the query matrix Key matrix Value matrix The formula is: (7); Query Matrix Key matrix Value matrix All dimensions are ; Multi-head attention split: , , By number of spatial attention heads Split into There are n parallel submatrices, each with a feature dimension of n. ; Dynamic mask-constrained attention computation: dynamic asymmetric mask The formula is used for attention score calculation: (8); Multi-head output splicing and linear mapping: The outputs of each attention head are concatenated along the feature dimension, and then the concatenated features are mapped back to the hidden dimensions of the original model through a linear mapping layer. Ultimately, dynamic space features are obtained. ; The second branch is the static graph convolution branch, which is a 3rd-order Chebyshev graph convolutional network, including: dimension merging, 3rd-order Chebyshev graph convolution, dimension reduction, and linear mapping layer. The specific implementation process is as follows: Dimension merging: initial embedding features of the input Batch dimension With the time dimension Merging, we get the dimension as The fusion features enable parallel convolution computation across all time steps; 3rd-order Chebyshev graph convolution: Constructing a normalized graph Laplacian matrix based on the directed adjacency matrix A of the road network A third-order Chebyshev diagram convolution operation is performed on the fused features. The convolution formula is as follows: ; in, For Chebyshev polynomials Order term, Learnable convolutional weights; Dimension reduction: the result obtained after convolution 1D feature splitting and restoration to batch dimension With the time dimension The dimension is obtained as Intermediate features; Linear mapping: Mapping intermediate features to the model's hidden dimensions through a single linear mapping layer. Finally, static spatial features are obtained. .
6. The state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method according to claim 1, characterized in that, In step 4.4, the fusion formula is as follows: (9); (10); in, , For learnable weight matrix, For learnable bias, It is the Sigmoid activation function. For Hadama accumulation, As a dynamic spatial feature, It is a static spatial feature. The final spatial characteristics after fusion These are gating weights used to automatically balance the feature contributions of the two branches.
7. The state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method according to claim 1, characterized in that, The specific implementation process of step 5 includes: The final spatial features of the input are first normalized by a pre-layer, and then a time-series query matrix is generated through a linear transformation. Key matrix Value matrix The projected matrix is then split into two parallel attention heads, each corresponding to a specific time scale of traffic flow evolution: Short-term trend head: A sliding window mask with a duration of 30 minutes to 2 hours is used. This sliding window mask is a causal constraint window, which only allows the current time step to focus on the features of historical time steps within the window; it is used to capture the local temporal dependencies of short-term fluctuations. Long-term dependent head: Employs a full causal mask covering the entire 2-hour input observation window to capture the daily periodic segment features of traffic flow, the road segment-specific long-term evolution pattern, and the overall trend throughout the entire observation period; Multi-head temporal attention computation is performed independently for each road network node to capture the temporal evolution pattern specific to each road segment. After the attention computation is completed, residual connections and layer normalization are added, and then the feature is passed through a position-wise feedforward network consisting of two fully connected linear layers and a ReLU activation function. The feature of each time step and each node is independently transformed nonlinearly, and residual connections and layer normalization are added. Finally, the deep spatiotemporal features with multi-scale periodic dependence are output.
8. A state-aware dynamic asymmetric spatiotemporal Transformer long-term traffic speed prediction method according to any one of claims 1-7, characterized in that, The specific implementation process of step 6 includes: Based on the deep spatiotemporal features of the output, the future is directly generated through a linear mapping layer. Traffic speed prediction results for each time step; The linear mapping layer is a single-layer fully connected linear mapping layer with no activation function. It achieves direct multi-step prediction based on the deep spatiotemporal features output by the LMSTT module. The specific implementation process includes: Input features: Deep spatiotemporal features fused with multi-scale spatiotemporal dependencies, output by the LMSTT module, with dimensions of [dimensionality missing]. ; Feature Dimension Adaptation: Historical window dimensions are adapted through global pooling and linear transformation. Compressed to 1, the resulting dimension is Global spatiotemporal characteristics; Linear mapping generates predictions: global spatiotemporal features are input into a single fully connected linear mapping layer, and the output dimension is... Where Q is the number of future prediction time steps, obtained through linear transformation. Generate the future in one go Traffic speed predictions for all nodes at each time step For learnable weight matrix , For bias; Output: Final output predicted sequence , dimension That is, the future Traffic speed prediction results for each time step.
9. A state-aware, dynamic, asymmetric spatiotemporal Transformer long-term traffic speed prediction system, characterized in that, include: The module for formalizing the construction of directed graphs of transportation networks and long-term prediction problems is configured to: abstract the transportation network into a directed graph structure and complete the mathematical formal definition of the prediction problem; The preprocessing module is configured to preprocess traffic speed time-series data. The spatiotemporal embedding feature mapping module is configured to: map low-dimensional traffic speed input features to a high-dimensional hidden space, while preserving the topological spatial attributes of the road network and the temporal sequence attributes of traffic data, and generate initial embedding features; The state-aware dynamic asymmetric spatial feature extraction module is configured to: deeply integrate macro traffic flow theory into the attention mechanism design, and capture the time-varying asymmetric spatial dependencies of traffic flow through four sub-steps: traffic state discrimination, dynamic mask generation, dual-branch feature extraction, and adaptive gating fusion. The specific implementation process includes: Step 4.1: Real-time traffic state determination based on traffic flow theory; Based on the classic macroscopic traffic flow triangle basic graph, a discrimination logic is constructed for traffic flow. ,speed ,density The following basic relations must be satisfied: (3); First, traffic density is calculated by back-calculating the real-time observed speed at each node. At time step observation speed Traffic density The calculation formula is: (4); in, The free-flow velocity of the road segment. To congest the shock wave velocity, It is the critical density; Introducing a hysteresis threshold Traffic conditions are divided into three categories: (5); in, For nodes At time step Traffic status labels When =0, it is a free flow state; When =1, it is a critical flow state; When the value is 2, it is a congested flow state; Step 4.2: Dynamic asymmetric attention mask, i.e., dynamic mask generation; Based on the real-time traffic state obtained from the discrimination, a dynamic attention mask is generated for each node and each time step. This mask applies hard constraints based on traffic physics to the subsequent spatial attention calculation. The specific process is as follows: Step 4.2.1: Pre-calculate the shortest path step size matrix of the road network: Upstream step size matrix :in Indicates upstream node To the target node along the traffic flow direction Shortest path step size; downstream step size matrix :in Indicates downstream node Reverse traffic flow to the target node The number of steps in the shortest path; Step 4.2.2: Dynamically adjust the upstream and downstream influence ranges: Based on the real-time observation speed, adaptively calculate the upstream influence range UIA and the downstream influence range DIA, using the following formula: (6); in, For the time granularity of the dataset, This represents the average length of the road segment corresponding to the sensor. , The preset maximum influence step size, Indicates the scope of upstream influence. Indicates the downstream impact range. Indicates the target node. Indicates the current time step; Step 4.2.3: Dynamic Mask Generation Rules: Generate an attention mask for each time step. When a mask element has a value of 1, it indicates that the corresponding node can participate in the attention calculation of the target node; when the value is 0, it is prohibited from participating in the calculation. The mask generation strictly follows the asymmetric propagation law of traffic flow. Free-flow state: Only upstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Congested flow status: Only downstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Critical flow state: Upstream and downstream nodes within the effective step size are marked as 1, and all other nodes are marked as 0; Step 4.3: Dual-branch feature extraction; The design incorporates a dual-branch structure to jointly capture the dynamic state perception spatial dependence of traffic flow and the static topological spatial dependence of the road network. Step 4.4: Adaptive gated feature fusion, also known as adaptive gated fusion; Design a learnable gating mechanism to adaptively adjust the fusion weights of dynamic and static spatial features, and automatically balance the contributions of the first and second branches based on real-time traffic conditions. The lightweight multi-scale temporal Transformer feature extraction module is configured to: design a non-autoregressive encoder-only architecture to extract multi-scale temporal dependencies in parallel through the lightweight multi-scale temporal Transformer module; The traffic speed prediction module is configured as follows: end-to-end training of a dynamic asymmetric spatiotemporal Transformer and direct multi-step prediction output: based on the deep spatiotemporal features of the output, future speeds are directly generated through a linear mapping layer. Traffic speed prediction results for each time step.
Citation Information
Patent Citations
Space-time Transform traffic flow prediction method based on dynamic correlation
CN116543554A
Pre-training enhanced space-time Transform network traffic flow prediction method
CN120148236A