A traffic flow prediction method based on a multi-scale space-time transformer and a graph convolution network

CN122551545APending Publication Date: 2026-08-11CHANGCHUN UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-14
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0007]针对现有交通流预测方法在空间建模过程中难以同时兼顾物理拓扑约束与动态语义关联、在时间建模过程中难以有效保留局部高频突变信息、以及在时空融合过程中缺乏节点级动态自适应调节能力等问题,提出一种基于多尺度时空Transformer与图卷积网络的交通流预测方法

Benefits of technology

[0069]1、空间降噪与精准拓扑感知:通过构建融合物理传播延迟信息与动态时间规整语义相似信息的空间注意力机制,对节点间空间依赖关系进行约束与筛选,使模型在保持稀疏连接特性的同时有效抑制无效拓扑干扰。结合图卷积网络分支的显式邻域消息传递机制以及多源拓扑偏置注入方式,提升了模型对复杂路网结构和动态空间关联的建模能力。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure SMS_12
    Figure SMS_12
  • Figure SMS_13
    Figure SMS_13
Patent Text Reader

Abstract

This invention discloses a traffic flow prediction method based on multi-scale spatiotemporal Transformer and graph convolutional networks, addressing the problems of inaccurate spatial correlation modeling, weakened local abrupt change features, and insufficient spatiotemporal fusion adaptation in complex traffic scenarios. The method collects historical traffic flow data, constructs a spatial distance matrix, a dynamic temporal warp similarity matrix, and a network hop count matrix, and fuses traffic flow features, temporal embeddings, and spatial embeddings to generate an initial spatiotemporal state representation. Subsequently, long-range temporal dependencies, local high-frequency changes, and road network spatial topology features are extracted through temporal block attention, multi-scale local trend convolution, adaptive graph attention, and graph convolutional networks, respectively. Finally, a node-level adaptive gating mechanism is used to fuse spatiotemporal features, and residual skip connections and a prediction decoding module are combined to generate future multi-step traffic flow prediction results. This invention improves the accuracy, robustness, and adaptability to complex road conditions in traffic flow prediction and can be applied to the field of intelligent traffic management and scheduling control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of intelligent traffic control and deep learning technology, and in particular to a traffic flow prediction method, system, electronic device, and computer-readable storage medium based on multi-scale spatiotemporal Transformer and graph convolutional network. Background Technology

[0002] With the acceleration of urbanization, traffic congestion is becoming increasingly serious. Intelligent Transportation Systems (ITS) are a key means to alleviate traffic pressure. Their core relies on high-precision traffic flow prediction. Accurate traffic prediction can provide important support for traffic signal control, guidance and issuance, and public travel.

[0003] In recent years, deep learning has made significant progress in traffic flow prediction. Existing prediction models mostly employ graph neural networks to extract spatial topological features and Transformers to extract temporal evolution features. However, current technologies still suffer from the following technical challenges:

[0004] First, existing spatial modeling methods, when processing network topology data, are prone to causing an imbalance in attention distribution due to information interaction between long-distance nodes, and introduce connection relationships that do not conform to the actual traffic propagation mechanism. At the same time, these methods usually rely on a pre-set static physical distance matrix for spatial constraints, making it difficult to accurately characterize the dynamic semantic changes in road network topology relationships under conditions such as traffic accidents and congestion spread.

[0005] Second, in terms of time modeling, traffic sequences exhibit heterogeneous fluctuations at different time scales. Conventional self-attention mechanisms, when processing long sequences, are prone to globally averaging local mutation trends, resulting in the erasure of high-frequency local mutation features caused by morning and evening rush hours or accidents.

[0006] Third, spatiotemporal features in real traffic scenarios are highly dynamic and interactive. Existing models typically use fixed weights to fuse spatiotemporal features, lacking the ability to dynamically and adaptively adjust at the node level, which limits the model's predictive robustness under complex and changing road conditions. Summary of the Invention

[0007] To address the shortcomings of existing traffic flow prediction methods, such as the difficulty in simultaneously considering physical topological constraints and dynamic semantic relationships during spatial modeling, the inability to effectively preserve local high-frequency abrupt changes during temporal modeling, and the lack of node-level dynamic adaptive adjustment capabilities during spatiotemporal fusion, this paper proposes a traffic flow prediction method based on multi-scale spatiotemporal Transformers and graph convolutional networks. By constructing a multi-dimensional feature embedding mechanism, a multi-layer spatiotemporal coding structure, a node-level adaptive gating fusion mechanism, and a residual-enhanced prediction decoding mechanism, this method achieves refined modeling of the spatiotemporal evolution of traffic flow, thereby improving prediction performance and system stability in complex and variable traffic scenarios.

[0008] To achieve the above objectives, this invention employs a traffic flow prediction method based on multi-scale spatiotemporal Transformer and graph convolutional networks, the specific steps of which include:

[0009] S1: First, data acquisition and preprocessing are carried out. Historical traffic flow data sequences are acquired, multivariate features of sequence elements are extracted, and spatial distance matrix, dynamic time warping (DTW) similarity matrix and network hop count (Hop) matrix are constructed according to the organization form of traffic data. The traffic data includes point-level road network node traffic data or gridded regional traffic data.

[0010] S2: Embed and fuse multi-dimensional features of data, linearly project the input historical traffic flow features, and concatenate and non-linearly map them with time feature embedding and spatial node embedding features to obtain the initial hidden state;

[0011] S3: Dual-stream feature extraction based on spatiotemporal coding blocks. The initial hidden state is input into stacked multi-layer spatiotemporal coding blocks. Global temporal dependence and local multi-scale trend features are extracted through the temporal coding module, and topological dependence, physical propagation constraint relationship and semantic similarity relationship are extracted through the spatial coding module.

[0012] S4: Spatiotemporal fusion is performed based on node-level adaptation. A gated network is used to adaptively weight and fuse the extracted temporal and spatial features, and output the spatiotemporal fusion hidden state.

[0013] S5: The spatiotemporal fusion hidden state is mapped to traffic flow features of future time windows using the prediction decoding module, and residual jump connection features based on recent historical input are superimposed to output the final future traffic flow prediction sequence.

[0014] Furthermore, the specific steps for multidimensional feature embedding and fusion in step S2 include:

[0015] S21: Feature projection and interaction;

[0016] Determine whether the input historical traffic flow data sequence contains multi-channel features. If it does, implicitly correlate and extract the features of each channel through the channel interaction module, and then map the features to a high-dimensional hidden space through a linear projection layer.

[0017] S22: Spatiotemporal external dimension embedding;

[0018] Extract the time of day (TOD) and day of the week (DOW) from traffic flow data, and convert them into corresponding time feature vectors and spatial feature vectors respectively through a learnable embedding layer with preset spatial node indices;

[0019] S23: Multi-source feature concatenation and state initialization;

[0020] The high-dimensional hidden state is concatenated with the temporal feature vector and the spatial feature vector, and then input into a multilayer perceptron to generate an initial hidden state with spatiotemporal prior information.

[0021] According to the method described in claim 1, the spatial coding module in step S3 adopts a spatial modeling method adapted to the traffic data topology, specifically including:

[0022] The spatial coding module adaptively adopts different spatial modeling paths according to the topological organization of traffic data: for point-level road network node traffic data, it adopts adaptive graph sparse spatial attention and graph convolution parallel modeling; for gridded area traffic data, it adopts local spatial branch and delay perception branch parallel modeling, and obtains the final spatial representation through a gating mechanism.

[0023] S31: Physical Delay and Semantic Similarity Mask Construction;

[0024] Spatial effective connectivity relationships are generated based on the time difference matrix, expected delay matrix, and dynamic time warping (DTW) similarity matrix, and spatiotemporal effectiveness masks are generated. The calculation formula is:

[0025]

[0026] in, Indicates the query position AND key position Time difference, This represents the expected delay determined by spatial distance and propagation speed. The time tolerance constant is... The semantic similarity threshold. For indicator functions;

[0027] S32: Adaptive graphs and attention computation in sparse spaces;

[0028] For traffic data at point-level road network nodes, an adaptive graph is constructed based on node embedding. Furthermore, one-hop relationships, two-hop relationships, DTW semantic similarity, and Hop decay information are injected into the sparse spatial attention score to obtain spatial attention features. :

[0029]

[0030]

[0031]

[0032] In the formula, The matrix representing the two-hop relation of the adaptive graph. For multi-hop decay term, All are learnable parameters; For the reason The resulting bias mask; This represents the sparse spatial attention output feature; These represent the query matrix, key matrix, and value matrix obtained by projecting the input features, respectively, and are used to calculate node relevance and perform weighted summation. For the attention head dimension, its square root Used for scaling to prevent gradient saturation; is the spatiotemporal mask bias matrix, which is 0 at valid connections and negative infinity at invalid connections; The normalized activation function ensures that the weights of invalid connections corresponding to negative infinity are strictly zero, thereby precisely cutting off interference and achieving network sparsity.

[0033] S33: Graph convolution with explicit message passing and two-branch fusion;

[0034] For point-level road network node traffic data, a graph convolutional network is used to perform explicit message passing on the physical adjacency graph or adaptive graph, and then gating and fusing it with the spatial attention features to obtain a point-level spatial feature representation. :

[0035]

[0036]

[0037]

[0038] in, The output features of the graph convolution branch, For branch fusion gating weights, This is the normalized adjacency matrix; For learnable parameter scalars, It is the Sigmoid activation function. These are the input features for the spatial coding module.

[0039] in, The output features of the graph convolution branch, For branch fusion gating weights, This is the normalized adjacency matrix; For learnable parameter scalars, It is the Sigmoid activation function. These are the input features for the spatial coding module.

[0040] According to the method described in claim 1, the step S3, in which the time encoding module extracts dynamic time change features, includes dual-track parallel multi-scale local trend convolution and time block processing, specifically comprising:

[0041] S34: Temporal Blocking and Global Long-Range Dependency Extraction;

[0042] The input time series is divided into multiple time blocks according to a preset step size. After dimensionality reduction by linear projection, the blocks are input into a multi-head self-attention module to calculate the interaction weights of each time block in order to extract global temporal dependency features. ;

[0043] S35: Multi-scale local trend convolution extraction;

[0044] Multiple one-dimensional convolutional kernels with different receptive field sizes are set in parallel to extract local trend dynamic features. The set of receptive field sizes is as follows: After acquiring local trend features at multiple receptive field scales in parallel, to avoid feature redundancy caused by the direct superposition of multi-scale features, this invention designs a local averaging gated fusion mechanism, the specific formula of which is as follows:

[0045]

[0046]

[0047]

[0048] in, The convolution output features represent the corresponding scale. This is the average aggregation result of multi-scale features; This represents the splicing of multi-scale features. and These are the parameters used to calculate the gating weights. For the Sigmoid function, Original input features, This represents the local dynamic trend characteristics of the final output.

[0049] S36: Dual-track time feature fusion;

[0050] The global time dependency feature Local trend characteristics The original input features are element-wise summed, and the combined time features are represented by layer normalization and feedforward neural network output. .

[0051] Furthermore, the specific calculation process and expression for fusing spatiotemporal features using a node-level adaptive gating network in step S4 are as follows:

[0052] S41: Spatiotemporal feature splicing and node-level gating weight generation;

[0053] Characterize the comprehensive time features Comprehensive spatial feature representation The input is concatenated along the feature dimension, and a gating mechanism driven by a multilayer perceptron is used to calculate adaptive node-level gating weights. :

[0054]

[0055] S42: Dynamic weighting of features and normalization of residuals;

[0056] Based on the aforementioned gating weights, spatiotemporal features are weighted and interacted to avoid mutual interference between features, and the final spatiotemporal fusion hidden state is output. :

[0057]

[0058] in, Indicates feature concatenation operation; and This indicates a feature concatenation operation. and For gating network parameters, Represents the Sigmoid activation function. It represents the Hadamah accumulation. For projection weights.

[0059] Furthermore, the specific steps of prediction decoding and output in step S5 include:

[0060] S51: Predictive decoding and residual skip connection;

[0061] The raw data of the most recent prediction window length in the historical input sequence is extracted and a baseline prediction value is generated through a linear mapping layer; for point-level road network node traffic data, a fully connected prediction layer is used to generate basic traffic flow prediction values; for gridded area traffic data, a three-dimensional convolutional decoding module is used to generate basic traffic flow prediction values; and the basic traffic flow prediction values ​​are added to the baseline prediction values ​​to generate the final multi-step traffic flow prediction sequence.

[0062] S52: Based on comprehensive loss calculation and optimization;

[0063] A comprehensive loss function is used for backpropagation and model optimization. For gridded regional traffic data, the comprehensive loss function... This includes the masked Huber loss, the MAPE loss term, and the extreme value penalty term for traffic flow abrupt changes. For point-level road network node traffic data, smoothed L1 loss is used for optimization:

[0064]

[0065]

[0066]

[0067] in, This represents the actual traffic volume. To predict flow rates, and For dynamic weighting coefficients, This is an indicator function, used when the actual traffic flow value is greater than or equal to a preset extreme threshold. The extreme value penalty term is calculated when the time is right. A mask matrix for filtering invalid data. To prevent the minimum value constant from being divided by zero.

[0068] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0069] 1. Spatial Denoising and Precise Topology Awareness: By constructing a spatial attention mechanism that integrates physical propagation delay information and dynamic temporal warping semantic similarity information, spatial dependencies between nodes are constrained and filtered, enabling the model to effectively suppress invalid topological interference while maintaining sparse connectivity characteristics. Combined with the explicit neighborhood message passing mechanism of graph convolutional network branches and multi-source topology bias injection, the model's ability to model complex road network structures and dynamic spatial relationships is enhanced.

[0070] 2. Effective Preservation of High-Frequency Temporal Abrupt Features: By constructing a dual-track temporal coding structure that combines global temporal block modeling with local multi-scale convolutional modeling, a joint characterization of long-range temporal dependencies and local abrupt change trends is achieved. Utilizing multi-receptive field convolution and gating fusion mechanisms, the model's adaptability to traffic dynamics at different time scales is enhanced, thus enabling more accurate characterization of both stable and high-frequency abrupt change processes.

[0071] 3. Deep adaptive fusion of spatiotemporal features: A node-level adaptive gating mechanism driven by a multilayer perceptron is introduced. Based on the real-time traffic status of each node, the fusion weights of time period inertia and spatial road network diffusion are dynamically allocated, realizing efficient decoupling of spatiotemporal heterogeneous data and significantly improving the robustness of the prediction system under varied and complex road conditions.

[0072] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Attached Figure Description

[0073] Figure 1 The flowchart illustrates the traffic flow prediction method based on multi-scale spatiotemporal Transformer and graph convolutional network provided in this embodiment of the invention. Detailed Implementation

[0074] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Those skilled in the art can easily understand other advantages and effects of this disclosure from the content disclosed herein. It should be emphasized that the described embodiments are only a part of the embodiments of this disclosure. The present invention can also be applied through other different implementations, and the details in this specification can be adjusted or changed based on different viewpoints and applications without departing from the basic concept of the present invention. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of this disclosure.

[0075] As shown in the figure, an embodiment of the present invention provides a traffic flow prediction method based on multi-scale spatiotemporal Transformer and graph convolutional network, including the following steps:

[0076] S1: Data acquisition and preprocessing;

[0077] Historical traffic flow data sequences are acquired, multivariate features of sequence elements are extracted, and spatial distance matrices, dynamic time warping (DTW) similarity matrices, and network hop count (Hop) matrices are constructed. Specifically, point-level road network node traffic sequences can be obtained through traffic network sensors, or gridded traffic flow models of urban areas can be used to obtain gridded traffic sequences. For point-level road network node traffic data, physical distance matrices and Hop matrices are constructed based on sensor geographic coordinates and road network connectivity. For gridded regional traffic data, grid distance matrices are constructed based on grid row and column positions, and a DTW semantic similarity matrix is ​​constructed in conjunction with historical traffic flow changes.

[0078] S2: Multidimensional feature embedding fusion;

[0079] The input historical traffic flow features are linearly projected and then concatenated and nonlinearly mapped with temporal feature embeddings and spatial node embeddings to obtain the initial hidden state, including the following steps:

[0080] S21: Feature projection and interaction;

[0081] The system determines whether the input historical traffic flow data sequence contains multi-channel features. When the input is gridded multi-channel traffic data, the multi-channel input is first spatially mixed, then channel interaction is performed through a multilayer perceptron, and finally the features are mapped to a high-dimensional hidden space through a linear projection layer. The expression for the channel interaction model is as follows:

[0082]

[0083]

[0084]

[0085] in, This indicates a spatial blending operation for multi-channel grid input. Represents a multilayer perceptron mapping. Output features for channel interaction;

[0086] S22: Spatiotemporal external dimension embedding;

[0087] Extract the time of day (TOD) and day of the week (DOW) from traffic flow data, and convert them into corresponding time feature vectors and spatial feature vectors respectively through a learnable embedding layer, along with preset spatial node indices.

[0088] S23: Multi-source feature concatenation and state initialization;

[0089] The high-dimensional hidden state is concatenated with the temporal feature vector and the spatial feature vector, and then input into a multilayer perceptron to generate an initial hidden state with spatiotemporal prior information.

[0090] S3: Dual-stream feature extraction based on spatiotemporal coding blocks;

[0091] The hidden state is input into a stacked multi-layer spatiotemporal coding block. The time coding module extracts the long and short periods and local trend dynamics of the sequence, and the spatial coding module extracts the complex topological dependencies between traffic network nodes. The process includes the following steps:

[0092] S31: Construct physical propagation constraints and semantic similarity constraints;

[0093] The time difference matrix, expected delay matrix, and dynamic time warping (DTW) semantic similarity matrix are calculated and fused to generate a spatiotemporal validity mask. The logical expression is as follows:

[0094]

[0095] in, Indicates the query position AND key position Time difference, This represents the expected delay determined by spatial distance and propagation speed. The time tolerance constant is... The semantic similarity threshold. For indicator functions;

[0096] S32: Adaptive graphs and attention computation in sparse spaces;

[0097] For traffic data at point-level road network nodes, an adaptive graph is constructed based on node embedding. Furthermore, one-hop relationships, two-hop relationships, DTW semantic similarity, and Hop decay information are injected into the sparse spatial attention score to obtain spatial attention features. ;

[0098]

[0099]

[0100]

[0101] In the formula, The two-hop relation matrix represents the adaptive graph. For multi-hop decay term, All are learnable parameters; For the reason The resulting bias mask; This represents the sparse spatial attention output feature; These represent the query matrix, key matrix, and value matrix obtained by projecting the input features, respectively, and are used to calculate node relevance and perform weighted summation. For the attention head dimension, its square root Used for scaling to prevent gradient saturation; is the spatiotemporal mask bias matrix, which is 0 at valid connections and negative infinity at invalid connections; The normalized activation function ensures that the weights of invalid connections corresponding to negative infinity are strictly zero, thereby precisely cutting off interference and achieving network sparsity.

[0102] S33: Graph convolution with explicit message passing and two-branch fusion;

[0103] For point-level road network node traffic data, a graph convolutional network is used to perform explicit message passing on the physical adjacency graph or adaptive graph, and then gating and fusing it with the spatial attention features to obtain a point-level spatial feature representation. :

[0104]

[0105]

[0106]

[0107] in, The output features of the graph convolution branch, For branch fusion gating weights, This is the normalized adjacency matrix; For learnable parameter scalars, It is the Sigmoid activation function. These are the input features for the spatial coding module.

[0108] S34: Temporal Blocking and Global Long-Range Dependency Extraction;

[0109] The input time series is divided into multiple time blocks according to a preset step size. After dimensionality reduction by linear projection, the blocks are input into a multi-head self-attention module to calculate the interaction weights of each time block in order to extract global temporal dependency features. ;

[0110] S35: Multi-scale local trend convolution extraction;

[0111] Multiple one-dimensional convolutional kernels with different receptive field sizes are set in parallel to extract local trend dynamic features. The set of receptive field sizes is as follows: After acquiring local trend features at multiple receptive field scales in parallel, to avoid feature redundancy caused by the direct superposition of multi-scale features, this invention designs a local averaging gated fusion mechanism, the specific formula of which is as follows:

[0112]

[0113]

[0114]

[0115] in, The convolution output features represent the corresponding scale. This is the average aggregation result of multi-scale features; This represents the splicing of multi-scale features. and These are the parameters used to calculate the gating weights. For the Sigmoid function, Original input features, This represents the local dynamic trend characteristics of the final output.

[0116] S36: Dual-track time feature fusion;

[0117] The global time dependency feature Local trend characteristics The original input features are element-wise summed, and the combined time features are represented by layer normalization and feedforward neural network output. .

[0118] S4: Node-level adaptive spatiotemporal fusion;

[0119] A gated network is used to concatenate and adaptively weight the extracted temporal and spatial features, achieving deep fusion of the temporal and spatial dimensions and outputting the spatiotemporal fusion hidden state. The process includes the following steps:

[0120] S41: Spatiotemporal feature splicing and node-level gating weight generation;

[0121] Characterize the comprehensive time features Comprehensive spatial feature representation The input is concatenated along the feature dimension, and a gating mechanism driven by a multilayer perceptron is used to calculate adaptive node-level gating weights. :

[0122]

[0123] S42: Dynamic weighting of features and normalization of residuals;

[0124] Based on the aforementioned gating weights, spatiotemporal features are weighted and interacted to avoid mutual interference between features, and the final spatiotemporal fusion hidden state is output. :

[0125]

[0126] in, and This indicates a feature concatenation operation. and For gating network parameters, Represents the Sigmoid activation function. It represents the Hadamah accumulation. For projection weights.

[0127] S5: Predictive decoding and output;

[0128] The spatiotemporal fusion hidden state is mapped to traffic flow features of future time windows using a fully connected prediction layer, and residual skip connection features based on recent historical inputs are superimposed. Optimization is performed based on a comprehensive loss function to output the final future traffic flow prediction sequence, including the following steps:

[0129] S51: Predictive decoding and residual skip connection;

[0130] The raw data of the most recent prediction window length in the historical input sequence is extracted and a baseline prediction value is generated through a linear mapping layer; for point-level road network node traffic data, a fully connected prediction layer is used to generate basic traffic flow prediction values; for gridded area traffic data, a three-dimensional convolutional decoding module is used to generate basic traffic flow prediction values; and the basic traffic flow prediction values ​​are added to the baseline prediction values ​​to generate the final multi-step traffic flow prediction sequence.

[0131] S52: Based on comprehensive loss calculation and optimization;

[0132] A comprehensive loss function is used for backpropagation and model optimization; specifically, for gridded regional traffic data, the comprehensive loss function... This includes the masked Huber loss, the MAPE loss term, and the extreme value penalty term for traffic flow abrupt changes. For point-level road network node traffic data, smoothed L1 loss is used for optimization:

[0133]

[0134]

[0135]

[0136] in, This represents the actual traffic volume. To predict flow rates, and For dynamic weighting coefficients, This is an indicator function, used when the actual traffic flow value is greater than or equal to a preset extreme threshold. The extreme value penalty term is calculated when the time is right. A mask matrix for filtering invalid data. To prevent the minimum value constant from being divided by zero.

[0137] To comprehensively evaluate the predictive performance of the model under different traffic flow scenarios, this invention adopts three standard evaluation metrics commonly used in the field of traffic flow prediction: Mean Absolute Error (MAE), Mean Absolute Percentage Error (MAPE), and Root Mean Square Error (RMSE). The specific calculation formulas are as follows:

[0138]

[0139]

[0140]

[0141] in, The total number of test samples; MAE is used to reflect the actual absolute situation of the prediction error, MAPE is used to measure the relative percentage of the prediction error, and RMSE is more sensitive to abnormally large errors. The combination of the three can comprehensively verify the prediction accuracy and robustness of the model.

[0142] This invention addresses the issue of attention distraction caused by long-distance spatial node interactions by introducing a spatial modeling mechanism with dual constraints of physical propagation and DTW semantic similarity. This mechanism accurately filters out invalid topological noise while maintaining network sparsity. The invention also constructs a temporal model based on a dual-track mechanism, coupling global temporal block attention with multi-receptive field parallel convolution, balancing peak-hour gradual changes with high-frequency abrupt changes. Furthermore, this invention introduces a node-level adaptive gating mechanism into the spatiotemporal fusion stage, dynamically allocating fusion weights for temporal dependence and spatial diffusion based on the real-time state of nodes. Combined with residual skip connections and scenario-specific prediction decoding strategies, this significantly improves the accuracy of traffic flow prediction and its robustness under complex road conditions.

[0143] Another embodiment of the present invention provides a traffic flow prediction method based on multi-scale spatiotemporal Transformer and graph convolutional network, applied to implement the above prediction method. The system includes: a data acquisition module for acquiring point-level road network node traffic data or gridded regional traffic data; a feature embedding module for performing input projection, temporal embedding, spatial embedding, and multi-source feature fusion; a spatiotemporal encoding module for extracting global temporal dependence, local multi-scale trend features, and spatial topological dependence features; a spatiotemporal fusion module for achieving adaptive fusion of temporal and spatial features through a node-level gating mechanism; a prediction decoding module for outputting a future traffic flow prediction sequence; and a training optimization module for updating model parameters based on a comprehensive loss function.

[0144] This invention addresses the issue of attention distraction caused by long-distance spatial node interactions by introducing spatial attention with dual constraints of physical delay and DTW semantics. It forces the matching of distance and speed time windows and assigns semantic similarity weights to similar hubs, filtering out invalid noise. This invention constructs a time model based on a dual-track mechanism, coupling long-range self-attention with parallel convolution of multiple receptive fields (3,5,7,11), taking into account both the gradual trend of off-peak traffic and the high-frequency abrupt changes of morning and evening peaks. This invention introduces an adaptive gating mechanism into the spatiotemporal fusion stage, dynamically allocating fusion weights of time period and spatial diffusion according to the real-time status of nodes, achieving efficient decoupling of spatiotemporal heterogeneous data, and significantly improving the accuracy of traffic flow prediction and robustness under complex road conditions.

[0145] The embodiments of the present invention have been described in detail above. For those skilled in the art, after understanding the basic principles of the present invention, various modifications, equivalent substitutions, improvements, etc., can be made to the present invention without departing from the concept of the present invention, and these should all be included within the protection scope of the present invention.

Claims

1. A traffic flow prediction method based on multi-scale spatiotemporal Transformer and graph convolutional network, the specific steps of which include: S1: First, data acquisition and preprocessing are carried out. Historical traffic flow data sequences are acquired, multivariate features of sequence elements are extracted, and spatial distance matrix, dynamic time warping (DTW) similarity matrix and network hop count (Hop) matrix are constructed according to the organization form of traffic data. The traffic data includes point-level road network node traffic data or gridded regional traffic data. S2: Embed and fuse multi-dimensional features of data, linearly project the input historical traffic flow features, and concatenate and non-linearly map them with time feature embedding and spatial node embedding features to obtain the initial hidden state; S3: Dual-stream feature extraction based on spatiotemporal coding blocks. The hidden state is input into stacked multi-layer spatiotemporal coding blocks. Global temporal dependence and local multi-scale trend features are extracted through the temporal coding module, and topological dependence, physical propagation constraint relationship and semantic similarity relationship between traffic network nodes are extracted through the spatial coding module. S4: Spatiotemporal fusion is performed based on node-level adaptation. A gated network is used to adaptively weight and fuse the extracted temporal and spatial features, and output the spatiotemporal fusion hidden state. S5: The spatiotemporal fusion hidden state is mapped to traffic flow features of future time windows using the prediction decoding module, and residual jump connection features based on recent historical input are superimposed to output the final future traffic flow prediction sequence.

2. The method according to claim 1, characterized in that, Step S1 specifically involves: obtaining historical traffic flow sequences from point-level road network traffic datasets or gridded traffic datasets, and extracting at least one feature including traffic volume, vehicle speed, occupancy rate, or inbound / outbound traffic volume; for point-level road network traffic data, constructing a spatial distance matrix and a Hop matrix based on the geographic coordinates of sensor nodes or road network connectivity; for gridded traffic data, constructing a grid distance matrix based on grid row and column positions.

3. The method according to claim 1, characterized in that, The specific steps for multidimensional feature embedding and fusion in step S2 include: S21: Feature projection and interaction; Determine whether the input historical traffic flow data sequence contains multi-channel features. If it does, implicitly correlate and extract the features of each channel through the channel interaction module, and then map the features to a high-dimensional hidden space through a linear projection layer. S22: Spatiotemporal external dimension embedding; Extract the time of day (TOD) and day of the week (DOW) from traffic flow data, and convert them into corresponding time feature vectors and spatial feature vectors respectively through a learnable embedding layer with preset spatial node indices; S23: Multi-source feature concatenation and state initialization; The high-dimensional hidden state is concatenated with the temporal feature vector and the spatial feature vector, and then input into a multilayer perceptron to generate an initial hidden state with spatiotemporal prior information.

4. The method according to claim 1, characterized in that, In step S3, the spatial coding module adopts a spatial modeling method adapted to the traffic data topology, specifically including: S31: Construct physical propagation constraints and semantic similarity constraints; Spatial effective connectivity relationships are generated based on the time difference matrix, expected delay matrix, and dynamic time warping (DTW) similarity matrix, and spatiotemporal effectiveness masks are generated. The calculation formula is: in, Indicates the query position AND key position Time difference, This represents the expected delay determined by spatial distance and propagation speed. The time tolerance constant is... The semantic similarity threshold. For indicator functions; S32: Adaptive graphs and spatial attention computation; For traffic data at point-level road network nodes, an adaptive graph is constructed based on node embedding. Furthermore, one-hop relationships, two-hop relationships, DTW semantic similarity, and Hop decay information are injected into the sparse spatial attention score to obtain spatial attention features. : In the formula, The matrix representing the two-hop relation of the adaptive graph. For multi-hop decay term, All are learnable parameters; For the reason The resulting bias mask; This represents the sparse spatial attention output feature; These represent the query matrix, key matrix, and value matrix obtained by projecting the input features, respectively, and are used to calculate node relevance and perform weighted summation. For the attention head dimension, its square root Used for scaling to prevent gradient saturation; is the spatiotemporal mask bias matrix, which is 0 at valid connections and negative infinity at invalid connections; The normalized activation function ensures that the weights of invalid connections corresponding to negative infinity are strictly zero, thereby precisely cutting off interference and achieving network sparsity. S33: Graph convolution with explicit message passing and two-branch fusion; For point-level road network node traffic data, a graph convolutional network is used to perform explicit message passing on the physical adjacency graph or adaptive graph, and then gating and fusing it with the spatial attention features to obtain a point-level spatial feature representation. : in, The output features of the graph convolution branch, For branch fusion gating weights, This is the normalized adjacency matrix; For learnable parameter scalars, It is the Sigmoid activation function. These are the input features for the spatial coding module.

5. The method according to claim 1, characterized in that, The time encoding module in step S3 extracts dynamic time-varying features by including dual-track parallel multi-scale local trend convolution and time block processing, specifically including: S34: Temporal Blocking and Global Long-Range Dependency Extraction; The input time series is divided into multiple time blocks according to a preset step size. After dimensionality reduction by linear projection, the blocks are input into a multi-head self-attention module to calculate the interaction weights of each time block in order to extract global temporal dependency features. ; S35: Multi-scale local trend convolution extraction; Multiple one-dimensional convolutional kernels with different receptive field sizes are set in parallel to extract local trend dynamic features. The set of receptive field sizes is as follows: Generate local trend features ; S36: Dual-track time feature fusion; The global time dependency feature Local trend characteristics The original input features are element-wise summed, and the combined time features are represented by layer normalization and feedforward neural network output. .

6. The method according to claim 1, characterized in that, The specific calculation process and expression for fusing spatiotemporal features using a node-level adaptive gating network in step S4 are as follows: S41: Spatiotemporal feature splicing and node-level gating weight generation; Characterize the comprehensive time features Comprehensive spatial feature representation The input is concatenated along the feature dimension, and a gating mechanism driven by a multilayer perceptron is used to calculate adaptive node-level gating weights. : S42: Dynamic weighting of features and normalization of residuals; Based on the aforementioned gating weights, spatiotemporal features are weighted and interacted to avoid mutual interference between features, and the final spatiotemporal fusion hidden state is output. : in, Indicates feature concatenation operation; and This indicates a feature concatenation operation. and For gating network parameters, Represents the Sigmoid activation function. It represents the Hadamah accumulation. For projection weights.

7. The method according to claim 1, characterized in that, The specific steps of prediction decoding and output in step S5 include: S51: Predictive decoding and residual skip connection; The raw data of the most recent prediction window length in the historical input sequence is extracted and a baseline prediction value is generated through a linear mapping layer; for point-level road network node traffic data, a fully connected prediction layer is used to generate basic traffic flow prediction values; for gridded area traffic data, a three-dimensional convolutional decoding module is used to generate basic traffic flow prediction values; and the basic traffic flow prediction values ​​are added to the baseline prediction values ​​to generate the final multi-step traffic flow prediction sequence. S52: Based on comprehensive loss calculation and optimization; A comprehensive loss function is used for backpropagation and model optimization; specifically, for gridded regional traffic data, the comprehensive loss function... This includes the masked Huber loss, the MAPE loss term, and the extreme value penalty term for traffic flow abrupt changes. For point-level road network node traffic data, smoothed L1 loss is used for optimization: in, This represents the actual traffic volume. To predict flow rates, and For dynamic weighting coefficients, This is an indicator function, used when the actual traffic flow value is greater than or equal to a preset extreme threshold. The extreme value penalty term is calculated at the time of triggering. A mask matrix for filtering invalid data. To prevent the minimum value constant from being divided by zero.

8. A traffic flow prediction method based on multi-scale spatiotemporal Transformer and graph convolutional network, characterized in that, The system is applied to implement the method as described in any one of claims 1 to 7, the system comprising: a data acquisition module for acquiring raw multi-source traffic flow data sequences and road network topology physical distance data of the traffic network; The data processing module includes a feature embedding unit and a spatiotemporal coding network. The spatiotemporal coding network performs temporal segmentation and multi-scale convolution in parallel to extract temporal dynamic features, and extracts topological features through a dual-branch spatial module containing a graph convolutional network. At the same time, it achieves node-level fusion of spatiotemporal features through an adaptive gating network. The prediction output module is used to introduce residual skip connections to decode the fused features into a future traffic flow prediction sequence, and to perform error calculation and model update based on a comprehensive loss function that includes an extreme value penalty term.

9. An electronic device and a computer-readable storage medium, characterized in that: The electronic device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the program to implement the method as described in any one of claims 1 to 7; The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1 to 7.