A traffic flow prediction method, device, equipment, medium and product
Patent Information
- Application Number
- CN202611169389.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-03
- Publication Date
- 2026-11-03
AI Technical Summary
Existing traffic flow prediction methods rely on fixed graph structures or a single adaptive adjacency matrix, resulting in limited prediction accuracy and generalization ability, and are unable to effectively handle the non-stationarity, dynamics, and heterogeneity of real traffic systems.
By acquiring historical traffic sequence data from sensor nodes, patching and mapping are performed to construct a multi-scale dynamic graph structure. By utilizing a gated routing mask matrix and multi-scale fusion output, time, space, and cross-temporal dependencies are explicitly decoupled, and effective connections are dynamically selected to enhance the model's adaptability.
It significantly improves the accuracy and generalization robustness of traffic flow forecasting, and can capture subtle local changes and global macro trends, enhancing forecasting capabilities under different road network structures and time periods.
Smart Images

Figure CN123033378A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of intelligent transportation and traffic flow prediction technology, and in particular to a traffic flow prediction method, device, equipment, medium and product. Background Technology
[0002] Traffic flow prediction is a key task in intelligent transportation systems and is of great significance for urban traffic management and congestion relief. Real traffic systems exhibit significant non-stationarity, dynamism, and heterogeneity. Traffic flow data simultaneously contains long-term cyclical trends, short-term local fluctuations, and anomalous changes caused by sudden events, making accurate modeling of complex spatiotemporal dependencies still challenging.
[0003] Most existing methods rely on fixed graph structures or a single adaptive adjacency matrix to model temporal, spatial, and cross-temporal dependencies in a unified representation space. This can easily lead to heterogeneous relationships and the propagation of redundant information, thus limiting the accuracy and generalization ability of traffic flow prediction. Summary of the Invention
[0004] This application provides a traffic flow prediction method, apparatus, device, medium, and product to solve the technical problem that existing methods are limited in accuracy and generalization ability due to their reliance on fixed graph structures or single adaptive adjacency matrices.
[0005] In a first aspect, embodiments of this application provide a traffic flow prediction method, including:
[0006] Historical traffic sequence data from multiple sensor nodes are acquired, and the historical traffic sequence data from multiple sensor nodes is segmented into patches to obtain multiple patch data.
[0007] Multiple patch data are mapped to obtain the word vector of each patch data.
[0008] Obtain the target dimension spatiotemporal vector for each of the aforementioned word vectors;
[0009] Multiple patch data are segmented into multi-scale segments to obtain the input for each scale;
[0010] Based on the target dimension spatiotemporal vector of each lexical vector, multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-spatiotemporal dependency matrices are obtained.
[0011] Based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices, multiple gated routing mask matrices are obtained;
[0012] Multiple graph header outputs are obtained based on multiple gated routing mask matrices, and the graph propagation result is obtained by splicing the multiple graph header outputs.
[0013] Based on the graph propagation results and the input at each scale, the output at each scale is obtained;
[0014] Based on the output of each scale, the fused output of each scale is obtained;
[0015] Based on the fusion output of each scale, a multi-scale fusion output is obtained;
[0016] The predicted input is obtained from the multi-scale fusion output, and the predicted traffic flow corresponding to multiple sensor nodes is obtained from the predicted input.
[0017] In one possible implementation, obtaining the target dimension spatiotemporal vector for each of the lexical vectors includes:
[0018] Obtain the target dimension vector for each of the given word vectors;
[0019] Obtain the sinusoidal position code for each of the target dimension vectors;
[0020] Based on the target dimension vector of each lexical vector and the sine position encoding of each target dimension vector, the target dimension spatiotemporal vector of each lexical vector is obtained.
[0021] In one possible implementation, obtaining multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices based on the target dimension spatiotemporal vector of each lexical vector includes:
[0022] Based on the target dimension spatiotemporal vector of each lexical vector, multiple global original similarity matrices are obtained;
[0023] Based on multiple global original similarity matrices and a preset sparse mask matrix, multiple global sparse similarity matrices are obtained;
[0024] Based on the sensor node index and patch index of each lexical vector, a global temporal relation binary mask matrix, a global spatial relation binary mask matrix, and a global cross-temporal and spatial relation binary mask matrix are obtained.
[0025] Based on multiple global sparse similarity matrices, global temporal relation binary mask matrices, global spatial relation binary mask matrices, and global cross-temporal relation binary mask matrices, multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices are obtained.
[0026] In one possible implementation, the step of obtaining multiple gated routing mask matrices based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices includes:
[0027] Based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices, multiple original relation selection score matrices are obtained;
[0028] Based on the selection score matrix of multiple original relations, a selection probability matrix of multiple relations is obtained;
[0029] Multiple binary routing mask matrices are obtained by selecting probability matrices and preset probability thresholds based on multiple relationships;
[0030] Multiple gated routing mask matrices are obtained from multiple binary routing mask matrices.
[0031] In one possible implementation, obtaining multiple header outputs based on multiple gated routing mask matrices includes:
[0032] Based on multiple gated routing mask matrices, multiple dynamic graph adjacency matrices are obtained;
[0033] Multiple graph headers are output based on multiple dynamic graph adjacency matrices.
[0034] In one possible implementation, obtaining the output for each scale based on the graph propagation results and the input for each scale includes:
[0035] Based on the graph propagation results and the input at each scale, the residual connection results at each scale are obtained;
[0036] The residual connection results at each scale are normalized to obtain the normalized residual connection results at each scale.
[0037] The normalized residual connection results for each scale are input into the feedforward network to obtain the feedforward output for each scale.
[0038] The output for each scale is obtained based on the residual connection results and the feedforward output for each scale.
[0039] Secondly, embodiments of this application provide a traffic flow prediction device, comprising:
[0040] The first data processing module is used to acquire historical traffic sequence data from multiple sensor nodes and perform patching segmentation on the historical traffic sequence data from multiple sensor nodes to obtain multiple patch data.
[0041] The first mapping module is used to map multiple patch data to obtain the word vector of each patch data.
[0042] The second mapping module is used to obtain the target dimension spatiotemporal vector of each of the lexical vectors;
[0043] The segmentation module is used to perform multi-scale segmentation on multiple patch data to obtain the input for each scale;
[0044] The dependency matrix acquisition module is used to obtain multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices based on the target dimension spatiotemporal vector of each lexical vector.
[0045] The gated routing mask matrix acquisition module is used to obtain multiple gated routing mask matrices based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal and spatial dependency matrices.
[0046] The splicing module is used to obtain multiple graph header outputs based on multiple gated routing mask matrices, and to splice the multiple graph header outputs to obtain the graph propagation result;
[0047] The second data processing module is used to obtain the output of each scale based on the graph propagation results and the input of each scale;
[0048] The fusion output acquisition module is used to obtain the fusion output for each scale based on the output for each scale.
[0049] The multi-scale fusion output acquisition module is used to obtain the multi-scale fusion output based on the fusion output of each scale;
[0050] The prediction module is used to obtain the prediction input based on the multi-scale fusion output, and to obtain the predicted traffic flow corresponding to multiple sensor nodes based on the prediction input.
[0051] Thirdly, embodiments of this application provide an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0052] The memory stores computer-executed instructions;
[0053] The processor executes computer execution instructions stored in the memory to implement the traffic flow prediction method provided in the first aspect of this application.
[0054] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the traffic flow prediction method provided in the first aspect of this application.
[0055] Fifthly, embodiments of this application provide a computer program product, including a computer program, which, when executed by a processor, is used to implement the traffic flow prediction method provided in the first aspect of this application.
[0056] This application provides a traffic flow prediction method, apparatus, device, medium, and product, comprising: acquiring historical traffic sequence data from multiple sensor nodes, and performing patching segmentation on the historical traffic sequence data from multiple sensor nodes to obtain multiple patch data; mapping the multiple patch data to obtain a word vector for each patch data; acquiring the target dimension spatiotemporal vector of each word vector; performing multi-scale segmentation on the multiple patch data to obtain the input for each scale; obtaining multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-spatiotemporal dependency matrices based on the target dimension spatiotemporal vector of each word vector; obtaining multiple gated routing mask matrices based on the multiple gated routing mask matrices; obtaining multiple graph header outputs based on the multiple gated routing mask matrices, and splicing the multiple graph header outputs to obtain a graph propagation result; obtaining the output for each scale based on the graph propagation result and the input for each scale; obtaining the fusion output for each scale based on the output for each scale; obtaining a multi-scale fusion output based on the fusion output for each scale; obtaining the prediction input based on the multi-scale fusion output, and obtaining the predicted traffic flow corresponding to multiple sensor nodes based on the prediction input. The above methods achieve the following technical effects: By decomposing the temporal, spatial, and cross-temporal dependencies between word vectors from a unified relation space, global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices are obtained. This effectively avoids mutual interference and redundant coupling of heterogeneous relations in the shared embedding space, allowing each type of dependency to be modeled independently and purely, thereby reducing noise propagation. Simultaneously, a gated routing mechanism is introduced to dynamically select effective connections, resulting in a gated routing mask matrix. This enables the model to adaptively retain key dependencies and suppress irrelevant or spurious associations based on the actual state of the input data, further enhancing its adaptability to complex traffic pattern changes. Furthermore, by combining multi-scale segment inputs to complete intra-scale and cross-scale fusion, the final prediction results are obtained. This ensures that the model can capture both subtle local changes and take into account global macro trends, ultimately significantly improving prediction accuracy and enhancing generalization robustness under different road network structures and time periods. Attached Figure Description
[0057] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0058] Figure 1 This is a schematic diagram illustrating an application scenario of a traffic flow prediction method provided in an embodiment of this application.
[0059] Figure 2 A flowchart illustrating a traffic flow prediction method provided in an embodiment of this application;
[0060] Figure 3 This illustration shows the comparison results of different models under the MAE evaluation index provided in the embodiments of this application. Figure 1 ;
[0061] Figure 4 This illustration shows the comparison results of different models under the MAE evaluation index provided in the embodiments of this application. Figure 2 ;
[0062] Figure 5 This illustration shows the comparison results of different models under the MAE evaluation index provided in the embodiments of this application. Figure 3 ;
[0063] Figure 6 This illustration shows the comparison results of different models under the MAE evaluation index provided in the embodiments of this application. Figure 4 ;
[0064] Figure 7 This illustration shows the comparison results of different models under the MAPE evaluation index provided in the embodiments of this application. Figure 1 ;
[0065] Figure 8 This illustration shows the comparison results of different models under the MAPE evaluation index provided in the embodiments of this application. Figure 2 ;
[0066] Figure 9 This illustration shows the comparison results of different models under the MAPE evaluation index provided in the embodiments of this application. Figure 3 ;
[0067] Figure 10 This illustration shows the comparison results of different models under the MAPE evaluation index provided in the embodiments of this application. Figure 4 ;
[0068] Figure 11 This illustration shows the comparison results of different models under the RMSE evaluation index provided in the embodiments of this application. Figure 1 ;
[0069] Figure 12 This illustration shows the comparison results of different models under the RMSE evaluation index provided in the embodiments of this application. Figure 2 ;
[0070] Figure 13 This illustration shows the comparison results of different models under the RMSE evaluation index provided in the embodiments of this application. Figure 3 ;
[0071] Figure 14 This illustration shows the comparison results of different models under the RMSE evaluation index provided in the embodiments of this application. Figure 4 ;
[0072] Figure 15 A schematic diagram illustrating the impact of batch size on MAE and MAPE provided in this application embodiment;
[0073] Figure 16 A schematic diagram illustrating the impact of the number of headers on MAE and MAPE provided in the embodiments of this application;
[0074] Figure 17 This is a schematic diagram illustrating the effect of the total number of filter layers on MAE and MAPE in an embodiment of this application.
[0075] Figure 18 A schematic diagram illustrating the impact of hidden dimensions on MAE and inference time in an embodiment of this application;
[0076] Figure 19 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0077] Explanation of reference numerals in the attached figures:
[0078] 120 - Terminal; 130 - Server; 801 - Processor; 802 - Memory; 803 - Communication Components; 804 - Bus.
[0079] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation
[0080] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this application.
[0081] In the embodiments of this application, the terms "first" and "second" are used to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that "first" and "second" do not necessarily imply difference. It should be noted that in the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner. In the embodiments of this application, "at least one" refers to one or more, and "more than one" refers to two or more.
[0082] It should be noted that the traffic flow prediction method provided in this application embodiment is only an example, and the traffic flow prediction method may include more or less content.
[0083] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with relevant laws, regulations and standards, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0084] In order to clearly understand the technical solution of this application, the solutions of related technologies are described in detail.
[0085] Most existing methods rely on fixed graph structures or a single adaptive adjacency matrix to model temporal, spatial, and cross-temporal dependencies in a unified representation space. This can easily lead to heterogeneous relationships and the propagation of redundant information, thus limiting the accuracy and generalization ability of traffic flow prediction.
[0086] In summary, the key challenge of this application is to design a technical solution that addresses the limitations in traffic flow prediction accuracy and generalization ability caused by existing methods relying on fixed graph structures or single adaptive adjacency matrices.
[0087] Therefore, in view of the above-mentioned technical problems existing in the related technologies, the embodiments of this application provide a traffic flow prediction method, device, equipment, medium and product, which aims to effectively improve the accuracy of traffic flow prediction.
[0088] The following describes the application scenarios of a traffic flow prediction method, apparatus, device, medium, and product provided in the embodiments of this application. These application scenarios are merely examples, intended to help those skilled in the art understand the technical content of this application, but do not imply that the embodiments of this application cannot be used in other devices, systems, environments, or scenarios.
[0089] Intelligent Transportation Systems (ITS): Traffic flow prediction is a core task in ITS, aiming to predict traffic conditions within a specific future time window by analyzing historical traffic data. It is widely applied in urban traffic management, congestion mitigation, and autonomous driving path optimization. The traffic flow prediction method, apparatus, device, medium, and product provided in this application provide a model that can capture both subtle local changes and global macro trends, ultimately significantly improving prediction accuracy and enhancing generalization robustness under different road network structures and time periods.
[0090] Figure 1 This is a schematic diagram illustrating an application scenario of a traffic flow prediction method provided in an embodiment of this application, such as... Figure 1 As shown, it includes: terminal 120 and server 130.
[0091] Terminal 120 can be a user device that initiates the traffic flow prediction process. Server 130 is used to control the predicted traffic flow corresponding to multiple sensor nodes based on the prediction input.
[0092] Figure 2 This is a flowchart illustrating a traffic flow prediction method provided in an embodiment of this application. The traffic flow prediction method provided in this embodiment includes the following steps:
[0093] S101. Obtain historical traffic sequence data from multiple sensor nodes, and perform patching segmentation on the historical traffic sequence data from multiple sensor nodes to obtain multiple patch data.
[0094] In this embodiment, the sensor node is a traffic sensor node, which can acquire historical traffic sequence data from multiple sensor nodes via a wired private network, message queue interface, or streaming data bus: X∈R (B×T×N×C) Where B is the batch size, T is the length of the historical time window, N is the number of sensor nodes, and C is the input feature dimension of each sensor node.
[0095] To capture local temporal patterns while maintaining computational efficiency, this embodiment first performs patching segmentation on the historical traffic sequence data of each sensor node along the time dimension. Let the patch length be P and the step size be S. p Then the number of time patches for each sensor node can be obtained:
[0096]
[0097] Where T is the total number of continuous time step data for each sensor node; for example, if the historical traffic sequence data for a sensor node is data from the past 60 minutes, with one sampling point every 5 minutes, then the total number of continuous time step data for that sensor node is 12; P is the patch length, i.e., the number of continuous time step data included in each patch; S p is the sliding step size, which is the data interval between consecutive time steps at the start time of two adjacent patches; M is the total number of patches for each sensor node.
[0098] Patch data for sensor node index i and patch index m can be represented as:
[0099]
[0100] Where m is the patch index, m = 0, 1, ..., M-1; S p x is the sliding step size; P is the patch length; x i,m x represents the continuous time step data corresponding to the patch with sensor node index i and patch index m. (i,m) ∈R B×P×C For example, T=12, P=4, S p =2, then M=5. For a patch with sensor node index 2 and patch index 2: the starting index is m×S p =2×2=4, the ending index is Therefore, x (2,2) The data is taken from the four time points with indices 4, 5, 6, and 7 on the timeline.
[0101] By stacking the historical time steps corresponding to all patches of historical traffic sequence data from all sensor nodes according to the node dimension and the patch dimension, the patched tensor X can be obtained. patch :
[0102]
[0103] Where X represents historical traffic sequence data from multiple sensor nodes; S p X is the sliding step size; P is the patch length; X is the sliding step size. patch For the patched tensor after stacking, X patch ∈R B×N×M×P×C .
[0104] S102. Map multiple patch data to obtain the word vector of each patch data.
[0105] In this embodiment, each time patch data is subsequently mapped to a word vector with a hidden dimension of d, i.e., a spatiotemporal token vector:
[0106]
[0107] Where, x i,m This provides the continuous time step data corresponding to the patch with sensor node index i and patch index m; Flatten() is the flattening operation; Proj() is the projection operation; z i,m This is the token vector corresponding to the patch with sensor node index i and patch index m.
[0108] Ultimately, the time patch data from all sensor nodes was rearranged into a unified spatiotemporal token sequence:
[0109]
[0110] Among them, z i,m z is the token vector corresponding to the patch with sensor node index i and patch index m. i,m ∈R B ×d L = N × M, where L represents the total number of spatiotemporal tokens in the graph; d is the hidden dimension of the token vector; B is the batch size; N is the number of sensor nodes; M is the total number of patches for each sensor node; i is the sensor node index; m is the patch index; and Z is the unified spatiotemporal token sequence.
[0111] To clarify the correspondence between the spatiotemporal token vector and the original traffic sequence, this application defines a bijective mapping between the token vector index l and the original spatiotemporal coordinates (i, m):
[0112]
[0113] The reverse mapping is:
[0114]
[0115] Where i is the sensor node index, i∈{0,…,N-1}; m is the patch index; M is the total number of patches for each sensor node; and l is the token vector index.
[0116] Based on this mapping, the subsequent dynamic graph learning module can construct a unified graph structure on L spatiotemporal token vectors. For any two token vectors l a and l b Their corresponding spacetime coordinates are (i a ,m a ) and (ib ,m b ). If i a =i b And m a ≠m b Then the two correspond to time dependence; if i a ≠i b And m a =m b Then the corresponding space dependency; if i a ≠i b And m a ≠m b This corresponds to a cross-temporal dependency.
[0117] This application's embodiments not only learn the dynamic graph structure related to the input state, but also further divide the dynamic graph relationships into three complementary relationship spaces: temporal relationships, spatial relationships, and cross-temporal-spatial relationships. Through this relationship space decomposition, the model can explicitly distinguish different types of spatiotemporal dependencies and provide structural priors for subsequent region-aware graph expert routing.
[0118] Transportation systems naturally contain various heterogeneous dependencies. From a propagation mechanism perspective, the connections between the same node at different time steps mainly reflect temporal evolution patterns; the connections between different nodes at the same moment mainly correspond to spatial propagation relationships; and the connections between different nodes at different time locations characterize cross-temporal and spatial propagation patterns. These three types of dependencies have different information propagation mechanisms, characteristics, and scopes of action, jointly determining the complex dynamic evolution process of traffic flow. This application's embodiments, starting from the inherent dependency types of transportation systems, propose a dependency decoupling approach oriented towards relational spaces. Specifically, the dynamic graph connections are divided into three types of relational regions: temporal, spatial, and cross-temporal and spatial. Different relational spaces are explicitly modeled through a dependency-guided masking mechanism. This design not only reduces mutual interference between heterogeneous dependencies but also helps alleviate information congestion problems in unified message channels.
[0119] This application's embodiments map historical traffic sequences uniformly into a structured spatiotemporal token representation space. Specifically, each token corresponds to a local dynamic representation of a traffic node at a certain time segment. In this way, the model can simultaneously model the temporal dependencies between different time segments of the same node, the spatial dependencies between different nodes at the same time segment, and the cross-spatiotemporal dependencies between different nodes at different time segments in a unified graph space.
[0120] S103. Obtain the target dimension spatiotemporal vector of each word vector.
[0121] In this embodiment, the target dimension vector is a high-dimensional vector, where D is the dimension of the high-dimensional vector. To enhance the representational capability of the patched sequence, this embodiment maps each token vector to a high-dimensional space.
[0122] S104. Perform multi-scale segmentation on multiple patch data to obtain the input for each scale.
[0123] In this embodiment, traffic flow exhibits significant multi-scale dynamic characteristics. On a short timescale, traffic conditions are typically influenced by traffic light control, local congestion propagation, and sudden disturbances, manifesting as rapid fluctuations and local anomalies. On a medium- to long-term timescale, traffic flow exhibits commuting cycles, regional co-evolution, and trend changes. Therefore, relying solely on a single timescale for modeling makes it difficult to simultaneously capture both short-term local dynamics and long-term global trends. To address this, the embodiment designs a scale-specific multi-scale spatiotemporal coding module, enabling the model to learn dynamic graph structures and propagation patterns at different time granularities. For the s-th scale, the time patch dimension is divided as follows:
[0124]
[0125] Where s is the scale number, and s generally takes a maximum value of 3; K s M represents the number of time segments into which the patch sequence is divided at the s-th scale; M is the total number of patches for each sensor node; M s represents the number of patches contained in each segment after segmentation at the s-th scale. When s=1, the model retains the complete historical sequence to capture global trends; when s>1, the model recursively segments the sequence into multiple local segments to capture fine-grained local dynamics. The input of the local spatiotemporal segment at the s-th scale can be represented as:
[0126]
[0127] Where s is the scale number; K s H represents the number of time segments into which the patch sequence is divided at the s-th scale; st A patch sequence consisting of multiple patch data from multiple sensor nodes; H (s,0) This is the input to the first graph filter layer at the s-th scale. For example, with 3 sensor nodes, each corresponding to 4 patch data points, and 1 batch, the patch sequence consisting of 12 patch data points corresponding to the 3 sensor nodes is [A0, A1, A2, A3, B0, B1, B2, B3, C0, C1, C2, C3]. When s=1, K... s =1,M s =4, then the input of the first graph filter layer at the first scale is [A0, A1, A2, A3, B0, B1, B2, B3, C0, C1, C2, C3]; when s=2, K s =2,M s=2, at the second scale, the position 0 of the first graph filter layer input corresponds to segment 1: [A0, A1, B0, B1, C0, C1], and at the second scale, the position 1 of the first graph filter layer input corresponds to segment 2: [A2, A3, B2, B3, C2, C3]; when s=3, K s =4,M s =1, the position 0 of the first image filter layer input at the 3rd scale corresponds to segment 1: [A0, B0, C0], the position 1 of the first image filter layer input at the 3rd scale corresponds to segment 2: [A1, B1, C1], the position 2 of the first image filter layer input at the 3rd scale corresponds to segment 3: [A2, B2, C2], the position 3 of the first image filter layer input at the 3rd scale corresponds to segment 4: [A3, B3, C3].
[0128] S105. Based on the target dimension spatiotemporal vector of each word vector, obtain multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-spatiotemporal dependency matrices.
[0129] In this embodiment, a dynamic dependency graph is further constructed in the spatiotemporal token vector space. Unlike traditional traffic prediction methods that only construct spatial graphs at the sensor node dimension, this embodiment treats each "node-time patch" as a graph node, thereby enabling the simultaneous modeling of temporal, spatial, and cross-spatiotemporal dependencies within a unified graph structure. Traffic dependencies exhibit significant heterogeneity, including temporal continuity, spatial correlation, and cross-spatiotemporal propagation patterns. Existing dynamic graph learning methods typically mix these dependencies within a unified graph structure, leading to relationship coupling. To address this, this embodiment divides the dynamic graph into three complementary relation spaces: temporal, spatial, and cross-spatiotemporal relationships, and assigns them to specialized graph experts for modeling through adaptive routing. For each token vector, only its strongly correlated connections are retained, while the remaining connections are set to zero. This operation effectively suppresses noisy edges and redundant propagation paths, allowing the model to focus more on key spatiotemporal dependencies.
[0130] S106. Based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices, obtain multiple gated routing mask matrices.
[0131] In this embodiment, the spatiotemporal dependency types that need to be considered are different under different traffic conditions in the traffic flow prediction task. Traditional Top-K routing mechanisms typically select a fixed number of K experts for each input. This assumption of a fixed number of experts is difficult to adapt to the dynamic changes in dependency complexity in traffic scenarios. For example, during morning and evening rush hours, multiple travel demands such as commuting and going to school overlap, and the target node may be simultaneously affected by its own short-term evolution, the propagation of congestion on neighboring roads, and the diffusion of cross-regional traffic flow. At this time, the model needs to jointly perceive temporal, spatial, and cross-spatiotemporal dependencies. When sudden events such as accidents, traffic control, or local congestion occur, local spatial dependencies or cross-spatiotemporal propagation relationships may dominate. Therefore, a fixed number of experts may not be able to provide adaptive relationship modeling capabilities for different nodes and different traffic conditions. To address this, this application proposes a Noisy Top-p MoE gated routing mechanism for dynamic graph structures. Unlike traditional MoE which applies experts to feature transformation or prediction branches, this application directly applies expert routing to the relationship selection process of the dynamic graph, enabling the model to dynamically select temporal, spatial, and cross-spatiotemporal relationships based on the current traffic conditions.
[0132] S107. Obtain multiple graph header outputs based on multiple gated routing mask matrices, and concatenate the multiple graph header outputs to obtain the graph propagation result.
[0133] In this embodiment, the multi-head outputs are concatenated to obtain the graph propagation result. The multi-head graph propagation mechanism can capture diverse spatiotemporal dependency patterns from different representation subspaces, thereby enhancing the model's ability to express complex traffic conditions.
[0134] S108. Based on the graph propagation results and the input at each scale, obtain the output at each scale.
[0135] In this embodiment, n g Given the total number of filter layers at the s-th scale, we obtain the n-th filter layer at the s-th scale. g After the output of the image filtering layer, the nth image at the s-th scale will be... g The output of the graph filter layer is used as the output of the s-th scale.
[0136] S109. Based on the output of each scale, obtain the fused output of each scale.
[0137] In this embodiment, the output E of the first scale is... (1) The fusion output G of the first scale (1) .
[0138] Since parameters are not shared between different scales, the model can learn the corresponding dynamic graph topology and dependency propagation patterns at different time granularities. To achieve information interaction between adjacent scales, this application further introduces a cross-scale gating fusion mechanism. For the s-th scale (s>1), the previous scale's fused representation G is first... (s-1) Align to the current scale structure, denoted as Subsequently, the fusion output at the s-th scale is defined as:
[0139]
[0140] Among them, E (s) This is the output of the s-th scale; This is the fused output after alignment to the current scale structure at the (s-1)th scale; and Let G be the learnable parameter matrix at the s-th scale; ⊙ represents element-wise multiplication; G (s) This is the fusion output for the s-th scale.
[0141] This gating mechanism can dynamically control the injection intensity of information from the previous scale based on the current input state, so that the local scale can capture short-term disturbances while retaining global context information.
[0142] S110. Based on the fusion output of each scale, obtain the multi-scale fusion output.
[0143] In this embodiment, the fused outputs of all scales are finally restored to a uniform length and then stitched together. The multi-scale fused output is then obtained through linear projection.
[0144]
[0145] Among them, G (1) This is the fusion output for the first scale; G (2) For the fusion output of the second scale; G (s) H is the fusion output at the s-th scale; out This is for multi-scale fusion output.
[0146] In summary, this module offers three advantages. First, the global scale captures long-term trends and overall traffic conditions, while the local scale captures short-term fluctuations and sudden disturbances. Second, the scale-specific encoder enables the model to learn dynamic graph structures at different temporal granularities, rather than sharing the same topological assumptions across all scales. Finally, cross-scale gating fusion avoids redundant information interference caused by simple splicing or addition, allowing the model to adaptively integrate global context and local dynamic information.
[0147] S111. Obtain the predicted input based on the multi-scale fusion output, and obtain the predicted traffic flow corresponding to multiple sensor nodes based on the predicted input.
[0148] In this embodiment, in order to generate future traffic state predictions, the multi-scale fusion output is first restored to a node-time patch structure, and then expanded along the patch dimension:
[0149]
[0150] Among them, H out For multi-scale fusion output; B is the batch size; N is the number of sensor nodes; M is the total number of patches per sensor node; D is the high-dimensional vector dimension corresponding to the token vector; H pred To predict the input.
[0151] Subsequently, the multi-scale patch representation of each sensor node is mapped to the future prediction window using a linear prediction head:
[0152]
[0153] Among them, H pred For the predicted input; W8 and b8 are learnable parameter matrices; For predicted traffic flow corresponding to multiple sensor nodes, B represents the batch size; N represents the number of sensor nodes; and H represents the prediction step size. For example, if predicting data for the next 60 minutes, with one sampling point every 5 minutes, the prediction step size is 12. Finally, the hidden representations of each sensor node across all time patches are concatenated and directly mapped to the future prediction sequence.
[0154] Total loss function Loss predicted by the master and auxiliary load balancing losses constitute:
[0155]
[0156] Where B is the batch size; N is the number of sensor nodes; and H is the prediction step size. For the b-th batch of samples, the actual traffic flow of the i-th traffic sensor node at the h-th future time step; For the b-th batch of samples, the predicted traffic flow of the i-th traffic sensor node at the h-th future time step; The primary prediction loss value.
[0157] Furthermore, since this application's embodiments introduce a Mixture of Experts (MoE) routing mechanism during the dynamic graph structure selection process, an auxiliary loss for MoE is introduced to avoid excessive concentration of expert selection and enhance the diversity of route distribution:
[0158]
[0159] in, The auxiliary regularization loss value for expert routing. For the weighting factor; The primary prediction loss value; This represents the total loss value.
[0160] In summary, the prediction layer transforms multi-scale spatiotemporal representations into future traffic states through lightweight linear mapping. The training objective simultaneously constrains the prediction error and expert route distribution, enabling the model to maintain the stability and diversity of expert selection while ensuring prediction accuracy.
[0161] Given a city transportation network in This represents N traffic sensor nodes. This represents the potential connections between sensor nodes. For each time step t, the traffic state can be represented as: Where C represents the input feature dimension of each sensor node, such as traffic flow, speed, or occupancy. Given a historical observation sequence of the past T time steps: .
[0162] The traffic flow prediction task aims to learn a mapping function. Used to predict traffic conditions in the next H time steps: C o This represents the output feature dimension, typically the dimension of the target traffic variable. Unlike static graph prediction methods, node dependencies in real traffic systems change dynamically with time and traffic conditions. Therefore, this embodiment does not assume the adjacency matrix is fixed, but rather adaptively learns the dynamic graph structure from the input sequence. ,in This represents the dynamic dependencies under the current traffic conditions. This is a dynamic graph learning function. Furthermore, to characterize the heterogeneous spatiotemporal propagation patterns in the transportation system, this paper divides spatiotemporal dependencies into three types of relation spaces: temporal dependency, spatial dependency, and cross-spatiotemporal dependency, and models them separately in subsequent modules.
[0163] This application proposes a spatiotemporal multi-scale dynamic graph hybrid expert network for traffic flow prediction. First, the model maps historical traffic sequences to a unified spatiotemporal token graph and captures key spatiotemporal dependencies through dynamic graph learning and bottom-k sparsity adaptive mapping. Second, this application designs three types of structured relation masks—temporal, spatial, and cross-spatiotemporal—to achieve explicit decoupling of heterogeneous spatiotemporal dependencies. Based on this, a Noisy Top-p hybrid expert routing mechanism is introduced, enabling the model to dynamically select different relation experts based on the current traffic state, thereby improving its adaptability and interpretability to complex traffic patterns. Furthermore, this application constructs a scale-specific multi-scale graph encoding structure, configuring independent dynamic graph encoders for different time scales, and integrating global trend and local dynamic information through a cross-scale gating fusion mechanism.
[0164] This application proposes a multi-scale dynamic sparse spatiotemporal filtering framework. The framework first maps the input traffic sequence to a hidden representation and constructs multiple scale-specific views based on different time scales. For each scale, the model generates input-related adjacency relations through a dynamic graph learning module and further divides the dynamic graph into three relation spaces: temporal, spatial, and cross-spatiotemporal, using different relation masks. Subsequently, a region-aware MoE router adaptively selects different relation experts based on the current graph structure to obtain a sparse relation-aware dynamic graph. Finally, the model performs topology-guided information propagation through graph filtering blocks and integrates representations from different scales using a cross-scale gating fusion mechanism for future traffic flow prediction. These collaborative strategies construct a robust spatiotemporal prediction framework that effectively balances model complexity and generalization ability, significantly improving prediction performance on non-stationary traffic data.
[0165] By decomposing the temporal, spatial, and cross-temporal dependencies between word vectors from a unified relation space, global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices are obtained. This effectively avoids mutual interference and redundant coupling of heterogeneous relations in a shared embedding space, allowing each type of dependency to be modeled independently and purely, thereby reducing noise propagation. Simultaneously, a gated routing mechanism is introduced to dynamically select effective connections, resulting in a gated routing mask matrix. This enables the model to adaptively retain key dependencies and suppress irrelevant or spurious associations based on the actual state of the input data, further enhancing its adaptability to complex traffic pattern changes. Furthermore, by combining multi-scale segment inputs to complete intra-scale and cross-scale fusion, the final prediction results are obtained. This ensures that the model can capture both subtle local changes and global macro trends, ultimately significantly improving prediction accuracy and enhancing generalization robustness under different road network structures and time periods.
[0166] This application provides a traffic flow prediction method, comprising: acquiring historical traffic sequence data from multiple sensor nodes, and performing patching segmentation on the historical traffic sequence data from multiple sensor nodes to obtain multiple patch data; mapping the multiple patch data to obtain a word vector for each patch data; acquiring the target dimension spatiotemporal vector of each word vector; performing multi-scale segmentation on the multiple patch data to obtain the input for each scale; obtaining multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-spatiotemporal dependency matrices based on the target dimension spatiotemporal vector of each word vector; obtaining multiple gated routing mask matrices based on the multiple gated routing mask matrices; obtaining multiple graph header outputs based on the multiple gated routing mask matrices, and concatenating the multiple graph header outputs to obtain a graph propagation result; obtaining the output for each scale based on the graph propagation result and the input for each scale; obtaining the fusion output for each scale based on the output for each scale; obtaining a multi-scale fusion output based on the fusion output for each scale; obtaining the prediction input based on the multi-scale fusion output, and obtaining the predicted traffic flow corresponding to multiple sensor nodes based on the prediction input. The above methods achieve the following technical effects: By decomposing the temporal, spatial, and cross-temporal dependencies between word vectors from a unified relation space, global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices are obtained. This effectively avoids mutual interference and redundant coupling of heterogeneous relations in the shared embedding space, allowing each type of dependency to be modeled independently and purely, thereby reducing noise propagation. Simultaneously, a gated routing mechanism is introduced to dynamically select effective connections, resulting in a gated routing mask matrix. This enables the model to adaptively retain key dependencies and suppress irrelevant or spurious associations based on the actual state of the input data, further enhancing its adaptability to complex traffic pattern changes. Furthermore, by combining multi-scale segment inputs to complete intra-scale and cross-scale fusion, the final prediction results are obtained. This ensures that the model can capture both subtle local changes and take into account global macro trends, ultimately significantly improving prediction accuracy and enhancing generalization robustness under different road network structures and time periods.
[0167] Based on the above embodiments, this application provides a traffic flow prediction method. In the traffic flow prediction method provided in this embodiment, step S103 includes the following steps:
[0168] S201. Obtain the target dimension vector for each word vector.
[0169] In this embodiment, low-dimensional patch sequences are insufficient to fully express complex time dependencies and nonlinear relationships. Therefore, a learnable linear projection layer is introduced for a given token vector z:
[0170]
[0171] Where z is a token vector; W1 and b1 are training parameters, W1∈R P×D b1∈R D H (0) This is the high-dimensional vector corresponding to the token vector z.
[0172] S202. Obtain the sinusoidal position code of each target dimension vector.
[0173] In this embodiment, considering that the Transformer self-attention mechanism itself does not possess sequence information, and that the temporal order of traffic flow is crucial for prediction, this embodiment introduces sinusoidal positional encoding (PE) to preserve spatiotemporal position information. This encoding has relative position awareness and multi-scale characteristics, and can take into account both the periodicity and local proximity of traffic flow. In sinusoidal positional encoding, for any fixed offset m, PE(pos+m) can be expressed as a linear function of PE(pos):
[0174]
[0175]
[0176] Where pos is the index of the token vector corresponding to token vector z; j is the dimension index in the vector, j=0,1,…,D / 2-1; D is the dimension of the high-dimensional vector corresponding to token vector z; PE(pos,2j) is the specific value of the high-dimensional vector corresponding to token vector z in the 2j-th dimension; PE(pos,2j+1) is the specific value of the high-dimensional vector corresponding to token vector z in the (2j+1)-th dimension. By substituting j into the calculation, we can obtain the specific values of the high-dimensional vector corresponding to token vector z in dimensions 0 to (D-1). By forming a vector from the specific values of the high-dimensional vector corresponding to token vector z in dimensions 0 to (D-1), we can obtain the sinusoidal position code PE(H) of the high-dimensional vector corresponding to token vector z. (0) ).
[0177] S203. Based on the target dimension vector of each word vector and the sine position encoding of each target dimension vector, obtain the target dimension spatiotemporal vector of each word vector.
[0178] In this embodiment, the target dimension spatiotemporal vector is a high-dimensional spatiotemporal vector. The formula for calculating the target dimension spatiotemporal vector is:
[0179]
[0180] Among them, H(0) PE(H) is the high-dimensional vector corresponding to the token vector z; (0) ) is the sinusoidal positional encoding of the high-dimensional vector corresponding to the token vector z; H is the target-dimensional spatiotemporal vector corresponding to the token vector z.
[0181] The above methods enable the model to learn relative positional relationships and extract features related to the prediction task through linear transformation. The final input high-dimensional spatiotemporal vector is represented as a superposition of linear projection and positional encoding. This operation enhances feature representation by mapping the patch sequence to a high-dimensional space while preserving temporal order information, providing a common spatiotemporal input representation for subsequent dynamic graph learning, dependency decomposition, and graph filtering blocks.
[0182] The target-dimensional spatiotemporal vector can simultaneously carry the dimensional semantics of the lexical units, their temporal order, and spatial identification information related to the patch location. It serves as the input basis for constructing the subsequent global temporal dependency matrix, global spatial dependency matrix, and global cross-spatiotemporal dependency matrix. Since sinusoidal positional encoding characterizes positional information as a periodic function, the model can maintain consistency in positional representation when processing sequences of different lengths. This makes the representation of local fluctuations, periodic changes, and cross-spatiotemporal propagation relationships more stable during traffic flow prediction, and correspondingly reduces the deviation between the predicted traffic flow and the actual traffic conditions.
[0183] Based on the above embodiments, this application provides a traffic flow prediction method. In the traffic flow prediction method provided in this embodiment, step S105 includes the following steps:
[0184] S301. Based on the target dimension spatiotemporal vector of each word vector, obtain multiple global original similarity matrices.
[0185] In this embodiment, under the multi-graph head learning setting, the input features are first divided into multiple subspaces, and different graph heads learn the dynamic graph structure under different subspaces. For each graph filtering layer, the high-dimensional spatiotemporal vectors corresponding to all token vectors are divided into different feature input vectors, which are then input into different graph heads of the graph filtering layer. Optionally, features can be grouped according to semantic features, such as speed, flow, and occupancy, and sent to different graph heads; features can also be divided according to nodes, assigning all features of different nodes or different regional subgraphs to the corresponding graph heads; features can also be divided according to time steps, inputting slices at different times into different graph heads to capture temporally differentiated patterns; features can also be divided according to periods, separating fragment features at different time scales such as recent, daily, and weekly periods; random shuffling followed by grouping or soft partitioning based on learnable attention weights can also be used, allowing each graph head to adaptively focus on specific feature subsets; in addition, multiple partitioning strategies can be superimposed, such as grouping by time first and then segmenting by features, to achieve multi-level subspace extraction, thereby allowing each graph head to independently model local dependencies from different perspectives.
[0186] For the h-th image header, the feature input vector H is based on the u-th token vector corresponding to the h-th image header. u The feature input vector H corresponding to the v-th token vector v First, the query matrix corresponding to the u-th token vector and the key matrix corresponding to the v-th token vector are obtained through two learnable linear projections. Specifically:
[0187]
[0188] Among them, H u h The input vector is the feature vector corresponding to the u-th token vector of the h-th image header, where h = 1, 2, ..., H. g H g H represents the total number of headers; v h W is the feature input vector corresponding to the v-th token vector of the h-th image header; Q h W is the query parameter matrix corresponding to the h-th image header. Q h ∈R D×Dh Dh is the hidden dimension of the h-th graph head; W K h W is the key parameter matrix corresponding to the h-th header. K h ∈R D×Dh Dh is the hidden dimension of the h-th graph head; Q u hThe query matrix corresponding to the u-th token vector of the h-th image header is input; K v h This is the key matrix corresponding to the v-th token vector of the h-th graph header. Since both Q and K are generated from the current input state, this adjacency matrix can adaptively adjust the graph structure according to different traffic states, thereby capturing the dynamic association patterns that change over time in the traffic system.
[0189] After obtaining the query matrix corresponding to the u-th token vector of the h-th image header and the key matrix corresponding to the v-th token vector of the h-th image header, this embodiment of the application obtains the dynamic correlation between the u-th token vector and the v-th token vector through similarity calculation:
[0190]
[0191] Among them, Q u h The query matrix corresponding to the u-th token vector of the h-th image header is input; K v h The input is the key matrix corresponding to the v-th token vector of the h-th image header; A (u,v) h The similarity, i.e., the dynamic dependency strength, is between the u-th token vector of the h-th graph header and the v-th token vector of the h-th graph header.
[0192] After obtaining the similarity between all pairwise token vectors using the above method, we can obtain the global original similarity matrix A corresponding to the h-th header of all token vectors. h A h ∈R B×L×L By calculating the global original similarity matrix corresponding to all token vectors in different image headers, multiple global original similarity matrices can be obtained.
[0193] S302. Based on multiple global original similarity matrices and a preset sparse mask matrix, multiple global sparse similarity matrices are obtained.
[0194] In this embodiment, multi-head dynamic graph learning enables the model to capture diverse spatiotemporal dependency patterns from different representation subspaces, enhancing the model's ability to represent complex traffic states. However, directly using the complete dynamic graph for information propagation generates a large number of redundant connections. On the one hand, the fully connected graph structure significantly increases computational overhead; on the other hand, weakly correlated or noisy connections may introduce invalid information propagation, exacerbating dependency confounding and information crowding problems. Therefore, this embodiment introduces a sparse filtering operation after dynamic graph construction, retaining only the important neighbor connections of each spatiotemporal token vector:
[0195]
[0196] Among them, A h M is the global original similarity matrix corresponding to the h-th image header of all token vectors; bottom-k M is the preset sparse mask matrix. bottom-k ∈{0,1} B×L×L For bottom-k sparse masks, given a given token vector, find the k token vectors with the lowest similarity to that token vector, and their corresponding masks are 0. The masks for the remaining token vectors are 1. k is typically 3 or 4; ⊙ represents element-wise multiplication; A sp Let be the global sparse similarity matrix corresponding to the h-th graph header for all token vectors. By calculating the global sparse similarity matrices corresponding to all token vectors in different graph headers, multiple global sparse similarity matrices can be obtained. For each token vector, only its strongly correlated connections are retained, and the remaining connections are set to zero. This operation can effectively suppress noisy edges and redundant propagation paths, making the model more focused on key spatiotemporal dependencies.
[0197] S303. Based on the sensor node index and patch index of each word vector, obtain the global temporal relationship binary mask matrix, the global spatial relationship binary mask matrix, and the global cross-temporal relationship binary mask matrix.
[0198] In this embodiment, further considering that the connections in the spatiotemporal token vector graph are not homogeneous, this embodiment divides the dynamic graph into three types of relation regions based on the original spatiotemporal coordinates corresponding to the token vectors. For any two token vectors: token vector u and token vector v, their corresponding sensor node indices and patch indices are respectively: (i u ,m u ), (i v ,m v If both satisfy: i u =i v And m u ≠m v This indicates that the connection between token vector u and token vector v represents a dependency between traffic nodes of the same sensor at different time patches, which is a temporal relationship; if i u ≠i v m u =m v If the connection between token vector u and token vector v is a dependency between different traffic sensor nodes under the same time patch, it belongs to a spatial relationship; if i u ≠i v mu ≠m v This indicates that the connection between token vector u and token vector v represents the dependency between different sensor nodes at different time patches, which is a cross-temporal and spatial relationship.
[0199] Based on the above rules, three types of relation masks can be constructed: a global temporal relation binary mask matrix M. T Global spatial relation binary mask matrix M S And the global spatiotemporal relationship binary mask matrix M ST M T M S and M ST ∈{0,1} L×L In the global temporal binary mask matrix M T In the context of the global spatial relationship binary mask matrix M, if token vector u and token vector v have a temporal relationship, the corresponding temporal relationship binary mask is 1; if token vector u and token vector v do not have a temporal relationship, the corresponding temporal relationship binary mask is 0. S In the context of the global spatiotemporal relationship binary mask matrix M, if token vector u and token vector v have a spatial relationship, the corresponding spatial relationship binary mask is 1; if token vector u and token vector v do not have a spatial relationship, the corresponding spatial relationship binary mask is 0. ST In the context of token vector u and token vector v, if there is a spatiotemporal relationship between them, the corresponding spatiotemporal relationship binary mask is 1; if there is no spatiotemporal relationship between them, the corresponding spatiotemporal relationship binary mask is 0.
[0200] The three types of masks together constitute a complementary partition of the spatiotemporal token vector relation space:
[0201]
[0202] Among them, M T M is a global temporal relation binary mask matrix. S M is a binary mask matrix representing global spatial relationships. ST Let I be the global cross-temporal relationship binary mask matrix, and let I be the self-connection matrix.
[0203] This application proposes a dependency-oriented spatiotemporal modeling framework for traffic flow prediction from the perspective of dependency decoupling. By designing three types of dependency-oriented mechanisms—time (T), space (S), and cross-spatiotemporal (ST)—different types of spatiotemporal dependencies are explicitly separated. Simultaneously, by combining multi-scale temporal filtering and expert routing mechanisms, adaptive modeling and fusion of cross-scale and multi-modal information are achieved, effectively alleviating dependency confounding and information crowding problems, and improving the model's ability to model complex traffic dynamics and its predictive performance.
[0204] S304. Based on multiple global sparse similarity matrices, global temporal relation binary mask matrices, global spatial relation binary mask matrices, and global cross-temporal relation binary mask matrices, multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices are obtained.
[0205] In this embodiment, the dynamic graph can be further decomposed into three types of relational subgraphs:
[0206]
[0207]
[0208]
[0209] Among them, A sp M is the global sparse similarity matrix corresponding to the h-th graph header of all token vectors. T M is a global temporal relation binary mask matrix. S M is a binary mask matrix representing global spatial relationships. ST A is a global, spatiotemporal relation binary mask matrix. T Let A be the global temporal dependency matrix corresponding to the h-th graph header of all token vectors. S Let A be the global spatial dependency matrix corresponding to the h-th graph header of all token vectors. ST Let be the global spatiotemporal dependency matrix corresponding to the h-th graph header for all token vectors; ⊙ represents element-wise multiplication. By calculating the global temporal dependency matrix, global spatial dependency matrix, and global spatiotemporal dependency matrix corresponding to all token vectors at different graph headers, multiple global temporal dependency matrices, global spatial dependency matrices, and global spatiotemporal dependency matrices can be obtained.
[0210] Through the aforementioned dynamic spatiotemporal graph construction method, the model can not only adaptively learn the spatiotemporal dependency strength based on the input state, but also explicitly distinguish different types of dependencies. Compared with the traditional unified adjacency matrix modeling method, this design provides a clearer, sparser graph structure foundation with traffic semantics for subsequent region-aware MoE routing and graph filtering propagation.
[0211] This application's embodiments map historical traffic sequences to a unified spatiotemporal token graph and adaptively learn a dynamic graph structure based on the input traffic state. Unlike methods that rely on a fixed topology or a single adaptive adjacency matrix, this application's embodiments further introduce a bottom-k sparsity mechanism to filter weakly related edges and noisy connections, enabling the model to focus more efficiently on key spatiotemporal dependencies, thereby alleviating the problems of redundant computation and information interference caused by dense graph propagation.
[0212] This application constructs three types of structured masks—temporal relationships, spatial relationships, and cross-temporal-spatial relationships—to achieve explicit decoupling of heterogeneous spatiotemporal dependencies. Based on this, a Noisy Top-p MoE dynamic routing mechanism is proposed, enabling the model to adaptively select different relationship experts based on the current dynamic graph connectivity distribution and dynamically determine the number of activated experts, thereby improving the model's adaptability and interpretability to complex traffic conditions.
[0213] By employing the above processing methods, different types of dependencies are distinguished during the construction phase, and effective associations are retained through sparse filtering. This provides a clearer relational input for subsequent gated routing and graph propagation, thereby reducing the interference of redundant connections on spatiotemporal modeling and enabling a clearer expression of temporal evolution, spatial propagation, and cross-spatiotemporal coupling relationships.
[0214] Based on the above embodiments, this application provides a traffic flow prediction method. In the traffic flow prediction method provided in this embodiment, S106 includes the following steps:
[0215] S401. Based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices, multiple original relation selection score matrices are obtained.
[0216] In this embodiment, the global time dependency matrix A corresponding to the h-th graph header of all token vectors is obtained. T The global spatial dependency matrix A corresponding to the h-th graph header of all token vectors. S The global spatiotemporal dependency matrix A corresponding to the h-th graph header of all token vectors. ST Then, the original relation selection score matrix is obtained. Each element of the original relation selection score matrix represents the time expert original selection score, spatial expert original selection score, and cross-temporal and spatial expert original selection score of the corresponding token vector. Specifically:
[0217]
[0218] Among them, A knn flatTo assign the A corresponding to the h-th image header T A S and A ST The concatenated matrix; W2 is the learnable parameter matrix; g clean Select the original relation selection score matrix corresponding to the h-th graph header. By calculating the original relation selection score matrix corresponding to all token vectors in different graph headers, multiple original relation selection score matrices can be obtained.
[0219] S402. Select the score matrix based on multiple original relations to obtain the probability matrix of multiple relation selections.
[0220] In this embodiment, after obtaining the original relation selection score matrix corresponding to the h-th header, the relation selection probability matrix corresponding to the h-th header is calculated. Each element of the relation selection probability matrix represents the temporal expert selection probability, spatial expert selection probability, and cross-temporal expert selection probability of the corresponding token vector. Specifically:
[0221]
[0222] Among them: A knn flat To assign the A corresponding to the h-th image header T A S and A ST The resulting matrix after concatenation; W3 is the noise projection parameter matrix; Used to ensure that the noise standard deviation is positive. σ is the activation function; ⊙ is element-wise multiplication; g clean Select a score matrix for the original relation corresponding to the h-th graph header; g h Choose a probability matrix g for the relationship corresponding to the h-th graph header. hl =[g hl T g hl S g hl ST ] represents the confidence level of the l-th token vector in selecting temporal, spatial, and cross-temporal relationships. By calculating the relationship selection probability matrix corresponding to all token vectors in different graph headers, multiple relationship selection probability matrices can be obtained.
[0223] S403. Select a probability matrix and a preset probability threshold based on multiple relationships to obtain multiple binary routing mask matrices.
[0224] In this embodiment, unlike the fixed Top-K routing, the embodiment of this application adopts a Top-P dynamic routing strategy, adaptively determining the number of experts based on the cumulative confidence of the expert probability distribution. Specifically, the relationship selection probability matrix g corresponding to the h-th graph header is used...h The expert probabilities corresponding to each token vector are sorted in descending order. The minimum set of experts required for the cumulative probability to reach the preset probability threshold p is selected.
[0225]
[0226] Among them, g hl r The relation selection probability corresponding to the expert r in the l-th token vector of the h-th header is given by r, where r is the choice of relation expert, including time experts, spatial experts, and cross-temporal and spatial experts; p is a preset probability threshold. Let T be the minimum set of experts for the l-th token vector in the h-th header that satisfies a preset probability threshold. Each element of the minimum expert set matrix represents the minimum set of experts for the corresponding token vector that satisfies the preset probability threshold; T represents time experts; S represents spatial experts; and ST represents cross-temporal and spatiotemporal experts. For example, the relation selection probability g corresponding to the l-th token vector in the h-th header... hl =[0.78, 0.15, 0.07], with a preset probability threshold p of 0.9, then the minimum set of experts corresponding to the l-th token vector in the h-th header that satisfies the preset probability threshold is... Let {T, S} be the coordinates.
[0227] Based on this, the binary expert routing mask corresponding to the l-th token vector in the h-th header is obtained:
[0228]
[0229] Among them, g hl r Let r be the binary expert routing mask corresponding to the expert r of the l-th token vector in the h-th header, where r is the choice of relational expert, including time expert, spatial expert and cross-temporal expert; T is the time expert; S is the spatial expert; ST is the cross-temporal expert; This refers to the set of minimum experts that satisfy a preset probability threshold, corresponding to the l-th token vector in the h-th header. For example, the set of minimum experts that satisfy a preset probability threshold, corresponding to the l-th token vector in the h-th header. If the token vector is {T, S}, then the binary expert route mask corresponding to this token vector is {1, 1, 0}.
[0230] In the binary expert routing mask matrix corresponding to the h-th header, each element represents the binary expert routing mask of the corresponding token vector. By calculating the binary routing mask matrices corresponding to all token vectors in different headers, multiple binary routing mask matrices can be obtained.
[0231] S404. Based on multiple binary routing mask matrices, obtain multiple gated routing mask matrices.
[0232] In this embodiment, after obtaining the binary expert routing mask corresponding to the h-th header, the gated routing mask between different token vectors under the h-th header is calculated, specifically:
[0233]
[0234] in, The binary expert routing mask corresponding to the expert r of the l1-th token vector in the h-th graph header; The value of the relation mask corresponding to the expert r between token vector l1 and token vector l2 is determined; This is the gated routing mask between token vectors l1 and l2 in the h-th graph header. For example, it's the binary expert routing mask corresponding to the expert r of the l1-th token vector in the h-th graph header. Given {1, 1, 0}, the gated routing mask between token vector l1 and token vector l2 under the h-th graph header is... If the token vectors l1 and l2 under the h-th header have a temporal relationship, then , and If the value is 0, then If token vector l1 and token vector l2 under the h-th graph header have a spatial relationship, then , and If the value is 0, then If the token vector l1 and token vector l2 under the h-th graph header have a cross-temporal and spatiotemporal relationship, then , and If the value is 0, then .
[0235] After obtaining the gated routing mask between different token vectors under the h-th header, the corresponding gated routing mask matrix under the h-th header can be obtained. By calculating the gated routing mask matrices corresponding to all token vectors in different headers, multiple gated routing mask matrices can be obtained.
[0236] Through the above process, the model first learns the dynamic graph structure related to the input using feature similarity, then removes weakly correlated connections through bottom-k sparsity, and finally dynamically selects effective dependencies in the T / S / ST three-class relation space using Noisy Top-p routing. This mechanism transforms traditional fixed graph structure learning into dynamic relation combination selection, enabling the model to adaptively focus on different types of spatiotemporal dependencies according to real-time traffic conditions, thereby improving the modeling ability and interpretability in complex traffic scenarios.
[0237] This application proposes a region-aware graph expert routing mechanism. Unlike traditional MoEs that directly operate on feature mappings, this application applies an expert mechanism to the dynamic graph structure selection process. Specifically, the model divides the dynamic graph into three types of relation regions: temporal, spatial, and cross-temporal / spatial, and adaptively selects the corresponding graph experts through a gating network. Thus, each expert corresponds to a spatiotemporal relation type with clear semantics, thereby achieving interpretable relation-aware expert modeling. Simultaneously, by combining a scale-specific graph encoder and a cross-scale gating fusion mechanism, this application can adaptively select different relation experts at different time scales, achieving unified modeling of multi-scale, multi-relationship, and multi-modal traffic dynamics.
[0238] The above gating routing mechanism can selectively retain and suppress different types of global dependencies, so that graph propagation only proceeds along effective relations. This reduces redundant relations involved in the calculation and allows temporal, spatial, and cross-temporal dependencies to maintain relatively independent expressions in unified modeling, thereby improving the stability and adaptability of prediction results in complex traffic scenarios.
[0239] Based on the above embodiments, this application provides a traffic flow prediction method. In the traffic flow prediction method provided in this embodiment, step S107, obtaining multiple map header outputs based on multiple gated routing mask matrices, includes the following steps:
[0240] S501. Based on multiple gated routing mask matrices, obtain multiple dynamic graph adjacency matrices.
[0241] In this embodiment, after obtaining the gated routing mask matrix corresponding to the h-th graph header, the dynamic graph adjacency matrix corresponding to the h-th graph header is calculated, specifically:
[0242]
[0243] Among them, M moe h A is the gated routing mask matrix corresponding to the h-th graph header; knn flat To assign the A corresponding to the h-th image header T A S and A STThe resulting matrix after concatenation; I is the self-join matrix; ⊙ represents element-wise multiplication; A h Let be the dynamic graph adjacency matrix corresponding to the h-th graph header. By calculating the dynamic graph adjacency matrices corresponding to all token vectors in different graph headers, multiple dynamic graph adjacency matrices can be obtained.
[0244] After obtaining multiple dynamic graph adjacency matrices, the dynamic graph adjacency matrices are normalized along the neighbor dimension to ensure the stability of the aggregation weights.
[0245] S502. Based on multiple dynamic graph adjacency matrices, multiple graph headers are output.
[0246] In this embodiment, after obtaining the dynamic graph adjacency matrix, the present application further designs a graph filtering block for topologically guided information propagation of the spatiotemporal token vector representation. Unlike traditional graph convolution which directly relies on a fixed adjacency matrix, the graph filtering block in this embodiment uses a dynamically learned sparse relation graph as a filter, enabling the model to adaptively adjust the information aggregation path according to the current traffic state. This design not only enhances the propagation capability of key spatiotemporal dependencies but also suppresses interference from noisy edges and redundant connections.
[0247] The adjacency matrix of the dynamic graph obtained by the above method forms a variable graph structure under the control of the gating mask. Multiple graph heads then perform parallel propagation and feature extraction based on this graph structure, so that the graph propagation results can simultaneously contain multiple types of dependency information. With this method, the graph structure can be adaptively adjusted according to traffic conditions, and the graph head output can separately express different relational patterns, thereby improving the ability of subsequent fusion representation to characterize complex traffic changes.
[0248] This application embodiment uses multi-head graph convolution for information aggregation. For the nth graph filtering layer at the s-th scale, the input is... The input is normalized to obtain the normalized input. For the h-th graph header of the n-th graph filter layer, the input features are first projected onto the corresponding subspace, and then topological propagation is performed using the normalized dynamic graph:
[0249]
[0250] in, This is the input to the h-th graph header after normalization, corresponding to the n-th graph filtering layer; The learnable parameter matrix for the h-th graph header corresponding to the n-th graph filtering layer; This is the dynamic graph adjacency matrix of the h-th graph header after normalization, corresponding to the n-th graph filtering layer; This represents the output of the h-th graph header corresponding to the n-th graph filtering layer. By calculating the outputs of all token vectors corresponding to different graph headers, multiple graph header outputs can be obtained.
[0251]
[0252] in, This is the output of the first image header corresponding to the nth image filtering layer; This is the output of the second image header corresponding to the nth image filtering layer; For the nth graph filter layer, the hth layer is... g Output of each header; h g This represents the total number of image headers corresponding to the nth image filter layer. This represents the graph propagation result corresponding to the nth graph filter layer.
[0253] Based on the above embodiments, this application provides a traffic flow prediction method. In the traffic flow prediction method provided in this embodiment, step S108 includes the following steps:
[0254] S601. Based on the graph propagation results and the input for each scale, obtain the residual connection results for each scale.
[0255] In this embodiment, to alleviate the gradient decay and feature degradation problems in deep graph propagation, residual connections are introduced after graph propagation. The residual structure can retain the original information in the input features and avoid excessive smoothing of key local features during dynamic aggregation. At the same time, when unreliable connections are generated during dynamic graph propagation, the residual path can also provide a stable information channel, thereby improving the stability of model training.
[0256]
[0257] in, This represents the graph propagation result corresponding to the nth graph filtering layer; H is the input corresponding to the nth graph filter layer. (n-1) ∈R B×L×D L is the total number of token vectors, and D is the dimension of the high-dimensional vector corresponding to the token vector; This represents the residual connection result corresponding to the nth graph filter layer.
[0258] S602. Normalize the residual connection results for each scale to obtain the normalized residual connection results for each scale.
[0259] In this embodiment, the residual connection result corresponding to the nth graph filtering layer is... Normalization is performed to obtain the residual connection result of the nth graph filter layer after normalization. .
[0260] S603. Input the normalized residual connection results of each scale into the feedforward network to obtain the feedforward output of each scale.
[0261] In this embodiment, to further enhance the nonlinear expressive power in the feature dimension, the SwiGLU feedforward network is introduced after graph propagation.
[0262]
[0263] Where SiLU is a smooth nonlinear activation function; ⊙ represents element-wise multiplication; This represents the residual connection result of the nth graph filter layer after normalization. , and Let n be the learnable parameter matrix of the nth graph filter layer; This is the feedforward output of the nth graph filter layer.
[0264] Compared to conventional feed-forward networks (FFNs), the SwiGLU feed-forward network adaptively adjusts the importance of feature channels through a gated multiplication mechanism, enabling it to more effectively model nonlinear variations and heterogeneous patterns in traffic flow.
[0265] S604. Based on the residual connection results of each scale and the feedforward output of each scale, obtain the output of each scale.
[0266] In this embodiment, the calculation formula is:
[0267]
[0268] in, This represents the residual connection result corresponding to the nth graph filter layer; This is the feedforward output of the nth graph filter layer; This is the output of the nth graph filter layer.
[0269] After graph propagation, the original scale input and propagation information are preserved, and the stability and expressive power of each scale feature are enhanced through normalization and feedforward transformation. This allows traffic evolution information at different time scales to be modeled separately and maintain distinguishability. The output of each scale obtained can provide a more complete representation of local fluctuations and global correlations for subsequent fusion processes, thereby improving the accuracy and stability of traffic flow prediction results.
[0270] Through the above design, the graph filter block has three advantages. First, the dynamic graph structure allows the information propagation path to adapt to changes in the input traffic state. Second, the dual filtering mechanism of Bottom-k and Mask MoE reduces noise edges and redundant propagation, mitigating dependency confounding. Finally, residual connections and the SwiGLU feedforward network enhance deep representation capabilities, enabling the model to capture complex nonlinear traffic patterns while maintaining training stability.
[0271] Traffic flow exhibits significant multi-scale dynamic characteristics. On short-term timescales, traffic conditions are typically influenced by local congestion propagation, traffic light control, and sudden disturbances, manifesting as rapid fluctuations and local anomalies. On medium- to long-term timescales, traffic flow exhibits periodicity, trends, and regional coordinated changes. For example, morning and evening rush hours reflect daily cycle patterns, while holidays, severe weather, or traffic control may trigger trend shifts over longer periods. Therefore, single-timescale modeling methods struggle to simultaneously capture both short-term local fluctuations and long-term global evolution trends. To address this, this application employs a scale-specific graph coding hierarchy. It constructs time views at different scales through hierarchical time segmentation and configures an independent dynamic graph encoder for each scale. Within each scale, graph learning and relation-aware expert routing capture the dependency propagation patterns unique to that scale. Between scales, information exchange occurs through a cross-scale gating fusion mechanism. This design enables the model to simultaneously preserve global trends and local dynamics, explicitly characterizing topological differences across different scales.
[0272] For the first graph filter layer at the s-th scale, the input is H (s,0)The following steps are performed: S301 obtains the global original similarity matrix of the h-th graph header corresponding to the first graph filtering layer; S302 obtains the global sparse similarity matrix of the h-th graph header corresponding to the first graph filtering layer; S303 and S304 obtain the global temporal dependency matrix, global spatial dependency matrix, and global intertemporal dependency matrix of the h-th graph header corresponding to the first graph filtering layer; S401 obtains the original relation selection score matrix of the h-th graph header corresponding to the first graph filtering layer; S402 obtains the relation selection probability matrix of the h-th graph header corresponding to the first graph filtering layer; S403 obtains the binary routing mask matrix of the h-th graph header corresponding to the first graph filtering layer; S404 obtains the gated routing mask matrix of the h-th graph header corresponding to the first graph filtering layer; S501 obtains the... The dynamic graph adjacency matrix is generated. The output of the h-th graph header corresponding to the first graph filter layer is obtained via S502. The graph propagation result corresponding to the first graph filter layer is obtained by concatenating the multiple graph header outputs corresponding to the first graph filter layer. The residual connection result of the first graph filter layer is obtained via S601 based on the input of the first graph filter layer and the graph propagation result corresponding to the first graph filter layer. The residual connection result of the first graph filter layer is normalized via S602 to obtain the normalized residual connection result of the first graph filter layer. The normalized residual connection result of the first graph filter layer is input into the feedforward network via S603 to obtain the feedforward output of the first graph filter layer. The output of the first graph filter layer at the s-th scale is obtained via S604 based on the residual connection result and the feedforward output of the first graph filter layer.
[0273] After obtaining the output of the first graph filter layer at the s-th scale, the output of the first graph filter layer is used as the input of the second graph filter layer, and the above steps are repeated to obtain the output of the second graph filter layer. This process is repeated until the output of the n-th graph filter layer at the s-th scale is obtained. g The output of the graph filter layer, n g This represents the total number of filter layers in the image at the s-th scale.
[0274] To address the characteristics of traffic flow, which simultaneously includes short-term fluctuations, local disturbances, and long-term trends, this application constructs multiple time-scale views through hierarchical time segmentation and configures independent graph encoders for different scales, enabling the model to learn scale-related dynamic graph topology. Furthermore, a cross-scale gating fusion mechanism achieves adaptive information interaction between global trends and local dynamics, avoiding scale information mixing caused by simple splicing or shared encoding.
[0275] To evaluate the performance of the prediction method in this application, comparative experiments were conducted on datasets A, B, C, D, and E. Datasets A, B, C, and D were collected by sensors on highways, while dataset E originated from urban traffic flow records, with information recorded every 30 seconds. Table 1 provides a description and recording information for the datasets. For more detailed information about the datasets, please refer to Table 1, where the type indicates the prediction target of the dataset.
[0276] Table 1
[0277]
[0278] The dataset partitioning and input settings were consistent with existing benchmark studies, with all datasets divided into training, validation, and test sets in a 6:2:2 ratio. In the experiments, both the input sequence length and prediction length were set to 12 time steps. All experiments were conducted on an NVIDIA RTX 4090 using Python 3.11. The Adam optimizer was used for model training, with cosine annealing dynamically adjusting the learning rate. The initial learning rate settings for different datasets were as follows: 0.0005 for dataset B, and 0.001 for datasets A, C, and D. The batch size was uniformly set to 64, the maximum number of training epochs was set to 100, and an early stopping mechanism with a patience value of 20 was configured to prevent overfitting. The mean absolute error was used as the loss function during training.
[0279] To evaluate model performance, embodiments of this application focus on using three commonly used metrics for calculation and analysis:
[0280] 1) Mean Absolute Error (MAE):
[0281]
[0282] 2) Mean Absolute Percentage Error (MAPE):
[0283]
[0284] 3) Root Mean Square Error (RMSE):
[0285]
[0286] in, For the j-th actual value, Let be the j-th predicted value, q be the total number of predicted or actual values, MAE be the mean absolute error, MAPE be the mean absolute percentage error, and RMSE be the root mean square error.
[0287] The performance of the spatiotemporal multi-scale dynamic graph hybrid expert network model is compared with 15 benchmark models, all using their recommended parameter settings. The Historical Average (HA) benchmark model is a heuristic prediction method based on the assumption of periodic stationarity. It utilizes the inherent periodicity of traffic data, using the mean of observations at the same historical time step as the predicted value for the current moment. The Autoregressive Integrated Moving Average (ARIMA) model eliminates data non-stationarity through differencing operations and combines autoregressive and moving average terms to fit the lagged dependencies of the time series. The Vector Auto-Regression (VAR) benchmark model treats traffic data from all nodes as a unified vector, mining pairwise correlations between different nodes through linear mapping. However, VAR faces the problem of parameter explosion as the number of nodes increases. The GraphWaveNet benchmark model proposes an adaptive adjacency matrix that can automatically learn potential spatial dependencies from the data without requiring predefined graph structure knowledge. The Spatial-Temporal Synchronous Graph Convolutional Networks (STSGCN) benchmark model utilizes spatiotemporal synchronous convolutional modules to simultaneously capture local spatiotemporal correlations, effectively addressing the heterogeneity problem in spatiotemporal feature extraction. The Adaptive Graph Convolutional Recurrent Network (AGCRN) benchmark model employs node adaptive parameter learning and data adaptive graph generation. This model automatically infers dynamic dependencies between nodes during training and captures the unique patterns of specific nodes, significantly enhancing model flexibility. The Propagation Delay-aware Dynamic long-range Transformer (PDFormer) benchmark model addresses the time delay phenomenon in traffic flow propagation by designing a propagation delay-aware attention mechanism. Furthermore, this model combines short-range and long-range spatial dependency modeling, dynamically capturing global interaction features in complex urban traffic networks, representing the current state-of-the-art in spatiotemporal graph transformers. The Heterogeneity-Informed Spatiotemporal Meta-Network (HimNet) baseline model proposes a hierarchical information mining architecture to address the complex spatiotemporal dependency hierarchy in traffic data.This model explicitly captures traffic flow evolution patterns from the node level to the region level by constructing a multi-scale spatiotemporal hierarchical structure. The Spatial-Temporal Dynamic Network (STDN) benchmark model models dynamic spatial similarity through a flow gating mechanism and utilizes periodic offset attention to handle long-term periodic variations. The MFSFFE benchmark model proposes a multi-form feature enhancement module that uses sequence autocorrelation knowledge to specifically enhance the original signal, thereby obtaining more representative and richer feature representations for model training. The Decomposition Dynamic Graph Convolutional Recurrent Network (DDGCRN) benchmark model introduces a decomposition mechanism to decouple traffic flow into trend and residual terms. Based on this, the model designs a dynamic graph convolution module that can dynamically infer dependencies between nodes based on real-time data, rather than relying on a static predefined graph. The Spatio-Temporal MeetWavelets (STWave) benchmark model processes traffic signals in the frequency domain, utilizing wavelet properties to decouple complex spatio-temporal sequences into high-frequency bursts and low-frequency stable trends, capturing spatio-temporal correlations across different frequency components. The Spatiotemporal Graph Mixture of Experts (STGMoE) benchmark model introduces a sparse mixed expert mechanism into the basic time series model, reducing inference overhead by activating only a subset of expert networks while maintaining a large model capacity, providing an effective approach for conditional computation in long-series time series forecasting. The Mixture of Adaptive Graph Experts (MAGE) benchmark model proposes a lightweight linear adaptive graph learning mechanism, improving spatio-temporal prediction efficiency and performance by reducing redundant graph structure learning.
[0288] Figure 3 This illustration shows the comparison results of different models under the MAE evaluation index provided in the embodiments of this application. Figure 1 , Figure 4 This illustration shows the comparison results of different models under the MAE evaluation index provided in the embodiments of this application. Figure 2 , Figure 5 This illustration shows the comparison results of different models under the MAE evaluation index provided in the embodiments of this application. Figure 3 , Figure 6 This illustration shows the comparison results of different models under the MAE evaluation index provided in the embodiments of this application. Figure 4 . Figure 3 , Figure 4 , Figure 5 and Figure 6The x-axis represents MAE, and the y-axis represents the prediction step size. Figure 3 The experimental results are for dataset A. Figure 4 The experimental results for dataset B, Figure 5 The experimental results are for dataset C. Figure 6 The results are for dataset D.
[0289] Figure 7 This illustration shows the comparison results of different models under the MAPE evaluation index provided in the embodiments of this application. Figure 1 , Figure 8 This illustration shows the comparison results of different models under the MAPE evaluation index provided in the embodiments of this application. Figure 2 , Figure 9 This illustration shows the comparison results of different models under the MAPE evaluation index provided in the embodiments of this application. Figure 3 , Figure 10 This illustration shows the comparison results of different models under the MAPE evaluation index provided in the embodiments of this application. Figure 4 . Figure 7 , Figure 8 , Figure 9 and Figure 10 The x-axis represents MAPE, and the y-axis represents the prediction step size. Figure 7 The experimental results are for dataset A. Figure 8 The experimental results for dataset B, Figure 9 The experimental results are for dataset C. Figure 10 The results are for dataset D.
[0290] Figure 11 This illustration shows the comparison results of different models under the RMSE evaluation index provided in the embodiments of this application. Figure 1 , Figure 12 This illustration shows the comparison results of different models under the RMSE evaluation index provided in the embodiments of this application. Figure 2 , Figure 13 This illustration shows the comparison results of different models under the RMSE evaluation index provided in the embodiments of this application. Figure 3 , Figure 14 This illustration shows the comparison results of different models under the RMSE evaluation index provided in the embodiments of this application. Figure 4 . Figure 11 , Figure 12 , Figure 13 and Figure 14 The x-axis represents RMSE, and the y-axis represents the prediction step size. Figure 11 The experimental results are for dataset A. Figure 12 The experimental results for dataset B, Figure 13 The experimental results are for dataset C. Figure 14 The results are for dataset D.
[0291] To comprehensively verify the predictive performance and generalization ability of the proposed model, experiments were conducted on two types of real traffic flow prediction datasets. The first type includes five commonly used traffic flow datasets: Dataset A, Dataset B, Dataset C, Dataset D, and Dataset E, covering highway and urban traffic scenarios of different scales. The second type includes four regional traffic datasets: Regional Dataset O, Regional Dataset P, Regional Dataset Q, and Regional Dataset R, used to further verify the model's adaptability to different regional road network structures and traffic patterns. The model proposed in this application was compared with several representative methods, including traditional models, graph neural network models, spatiotemporal Transformer models, multi-scale models, and dynamic graph learning models.
[0292] Table 2 shows the performance comparison between the model provided in this application embodiment and the baseline model on five datasets. STMDGE is the model provided in this application embodiment, as shown in Table 2:
[0293] Table 2
[0294]
[0295] Table 3 compares the performance of the model provided in this application embodiment with the baseline model on four regional traffic datasets. STMDGE is the model provided in this application embodiment, as shown in Table 3.
[0296] Table 3
[0297]
[0298] The overall results show that the model proposed in this application exhibits strong predictive performance and stability in both sets of experiments. Among the 15 evaluation metrics for five datasets (A, B, C, D, and E), the model proposed in this application achieves optimal results on 13 metrics. It is on par with HimNet on the MAPE metric for dataset B, and only slightly lower than MAGE on the RMSE metric for dataset D. Among the 12 evaluation metrics for four regional datasets (O, P, Q, and R), the model proposed in this application achieves optimal results on 11 metrics, only slightly lower than PatchSTG on the RMSE metric for regional dataset R by a small margin of 0.01. Combining the results of both sets of experiments, the model proposed in this application achieves 24 optimal results and 1 tied-optimal result out of all 27 evaluation metrics, with only 2 metrics being suboptimal. This indicates that the proposed model has strong generalization ability under different scales, regional structures, and traffic dynamics.
[0299] Compared to traditional models, deep learning methods generally demonstrate significant advantages. HA, ARIMA, and VAR primarily rely on assumptions of linearity, stationarity, or fixed periodicity, making it difficult to characterize the complex nonlinear spatiotemporal dependencies in real traffic systems, thus resulting in high errors on most datasets. In contrast, graph neural network methods such as GraphWaveNet, DiffusionConvolutional Recurrent Neural Network (DCRNN), STSGCN, and AGCRN significantly improve prediction performance by introducing graph structures to model spatial dependencies between nodes, demonstrating the crucial role of topological relationship modeling in traffic flow prediction.
[0300] This application's embodiments conducted systematic experiments on nine real-world traffic datasets, including five datasets and four regional datasets. Experimental results show that STMDGE outperforms existing representative methods on most evaluation metrics, and the effectiveness of dynamic graph learning, structured relationship decoupling, dynamic expert routing, and scale-specific multi-scale encoding mechanisms is further verified through ablation experiments, efficiency analysis, and visualization analysis.
[0301] Further observation reveals that dynamic graph learning, spatiotemporal Transformers, and multi-scale methods have demonstrated more competitive performance in recent years. For example, PDFormer, HimNet, MFSFFE, DDGCRN, STWave, and MAGE have achieved low errors on multiple datasets, indicating that long-range dependency modeling, multi-scale feature extraction, and adaptive graph learning all contribute to improving traffic flow prediction performance. STWave also exhibits good predictive capabilities on regional datasets. However, most of these methods still model spatiotemporal relationships within a unified graph space or unified representation space, making it difficult to explicitly distinguish the semantic differences between temporal, spatial, and cross-spatiotemporal dependencies, and they also rarely consider changes in the dynamic graph topology at different time scales.
[0302] In contrast, the model proposed in this application achieves more fine-grained spatiotemporal dependency modeling through T / S / ST relation space decomposition, Noisy Top-p dynamic expert routing, and scale-specific multi-scale graph encoding. On dataset B, the proposed model reduces the MAE from 18.16 to 17.95 compared to MAGE, and the RMSE from 30.03 to 29.52 compared to PDFormer. On dataset C, the proposed model reduces the MAE from 19.24 to 19.09, the RMSE from 32.47 to 32.44, and the MAPE from 8.10% to 8.07% compared to DDGCRN. These results demonstrate that structured relation decoupling and dynamic graph routing mechanisms can effectively alleviate dependency confounding and noise propagation problems in unified graph modeling.
[0303] On dataset E, the model proposed in this application also achieves state-of-the-art performance, with MAE, RMSE, and MAPE reaching 8.23, 14.27, and 33.42%, respectively. This demonstrates that the prediction method of this application is not only applicable to highway sensor data but can also be generalized to urban traffic scenarios. Since urban road networks typically have more complex road connections and more pronounced local traffic disturbances, the advantages of the model proposed in this application on dataset E further validate its adaptability to complex traffic patterns.
[0304] On four regional traffic datasets—regional datasets O, P, Q, and R—the model proposed in this application also demonstrates stability advantages. Taking regional dataset O as an example, the MAE, RMSE, and MAPE of the model proposed in this application are 16.74, 27.85, and 11.19%, respectively, which are 4.12%, 5.88%, and 4.44% lower than the optimal baseline PatchSTG. On regional datasets P and Q, the model proposed in this application also achieves optimal results in all three metrics, indicating that the proposed method can adapt to different regional ranges and traffic flow distributions. On regional dataset R, the model proposed in this application achieves optimal results in MAE and MAPE, at 17.68% and 12.43%, respectively. Only the RMSE is slightly lower than PatchSTG by 0.01, indicating that the two perform similarly in terms of large error control, while the model proposed in this application still has advantages in terms of overall error and relative error control.
[0305] In summary, the results of both main experiments demonstrate the effectiveness of the model proposed in this application. Compared to existing methods, the advantages of the model proposed in this application mainly come from three aspects: First, the T / S / ST relation space decomposition can explicitly distinguish between time dependencies, spatial dependencies, and cross-temporal dependencies, alleviating the problem of heterogeneous relation confounding; second, NoisyTop-p dynamic expert routing can adaptively select relation experts according to different traffic states, enhancing the model's adaptability to complex traffic patterns; finally, scale-specific multi-scale graph encoding can learn the corresponding dynamic graph structure at different time granularities, thereby simultaneously capturing long-term trends, local fluctuations, and sudden disturbances. These designs enable the model proposed in this application to achieve stable and competitive prediction performance in various traffic prediction scenarios.
[0306] Table 4 compares the training efficiency of the model provided in this application embodiment with the baseline model. STMDGE is the model provided in this application embodiment. Here, / indicates that the baseline model cannot fully run the dataset even with the smallest batch size, as shown in Table 4.
[0307]
[0308] To further evaluate the actual training efficiency of the model on large-scale regional traffic datasets, this application compares the prediction accuracy, batch size, and training time of different models on regional datasets O, P, Q, and R. The results are shown in Table 4.
[0309] In terms of prediction performance, the model provided in this application embodiment achieves the lowest MAE on all four datasets, indicating its stable predictive advantage in different regional traffic scenarios. Compared with PatchSTG, the MAE of the model provided in this application embodiment on regional datasets O, P, Q, and R is reduced from 17.46, 19.87, 19.30, and 17.74 to 16.74, 19.64, 18.97, and 17.68, respectively, demonstrating that the method in this application embodiment can effectively improve prediction accuracy while maintaining strong expressive power.
[0310] From the perspective of training efficiency, PatchSTG has the shortest training time, indicating its lightweight structure and suitability for scenarios with high efficiency requirements. The training time of the model provided in this embodiment is higher than PatchSTG, but significantly lower than STWave. For example, on the region dataset R, STWave's training time is 3845, while the model provided in this embodiment is 2102, a reduction of approximately 45.33%; on the region dataset Q, STWave's training time is 1517, while the model provided in this embodiment is 613, a reduction of approximately 59.59%. This demonstrates that although the method in this embodiment introduces dynamic graph learning, relational expert routing, and multi-scale encoding mechanisms, it effectively controls computational overhead through Bottom-k sparsity and relation-aware routing.
[0311] Furthermore, compared to D2STGNN, the model provided in this application embodiment achieves lower MAE on both region dataset O and region dataset P, and the training time on region dataset P is reduced from 2529 to 412, demonstrating a significant efficiency improvement. In summary, the model provided in this application embodiment achieves a good balance between prediction accuracy and training efficiency: it has higher accuracy compared to lightweight models and lower training costs compared to complex dynamic graphs or multi-scale models, verifying the practicality of the dynamic sparse spatiotemporal modeling framework in this application embodiment.
[0312] Figure 15 This is a schematic diagram illustrating the impact of batch size on MAE and MAPE, provided in an embodiment of this application. Figure 16 This diagram illustrates the impact of the number of headers on MAE and MAPE, as provided in the embodiments of this application. Figure 17This is a schematic diagram illustrating the effect of the total number of filter layers on MAE and MAPE provided in an embodiment of this application. Figure 18 This diagram illustrates the impact of hidden dimensions on MAE and inference time, as provided in embodiments of this application. Figure 15 In the graph, the horizontal axis represents batch size, and the vertical axis represents MAE and MAPE. The left vertical axis represents MAE, and the right vertical axis represents MAPE. Figure 16 In the diagram, the horizontal axis represents the number of headers, and the vertical axis represents MAE and MAPE. The left vertical axis represents MAE, and the right vertical axis represents MAPE. Figure 17 In the graph, the horizontal axis represents the total number of filter layers, and the vertical axis represents MAE and MAPE. The left vertical axis represents MAE, and the right vertical axis represents MAPE. Figure 18 In the diagram, the horizontal axis represents the hidden dimension, and the vertical axis represents the MAE and inference time. The left vertical axis represents the MAE, and the right vertical axis represents the inference time, which is in milliseconds. Figure 15 , Figure 16 , Figure 17 and Figure 18 All experiments were conducted on dataset A.
[0313] To explore the role of multi-view association mining mechanisms in capturing complex patterns, this application's embodiments set different numbers of heads H in the experiments. g ∈{1,2,4,8,16}. When H g =1, because the model can only capture basic spatial topological patterns, resulting in the worst evaluation metric. With H g Increasing the number of nodes to 4 or 8 significantly enhances the model's ability to learn dynamic node correlations across multiple orthogonal implicit subspaces, while both MAE and RMSE show a marked decrease. However, when H... g When the number of heads exceeds 8, the performance improvement plateaus, while the computational complexity increases significantly. This indicates that within a certain range, the number of heads has a significant positive impact on performance, but the benefits diminish beyond a certain threshold. Therefore, for scenarios with a large number of graph nodes or high prediction accuracy requirements, it is recommended to set H... g =4.
[0314] Secondly, to examine the impact of graph filter block stacking depth on model performance, the embodiments of this application tested the total number of graph filter layers n in the model. g ∈{1,2,3,4,5,6}. When n g =1 or n g When the number of layers is 2, the model depth is relatively shallow, making it difficult to fully capture long-range spatiotemporal dependencies and complex traffic evolution patterns. As the number of layers increases to n... g When n=3, the model's prediction performance reaches its optimal level, indicating that appropriately increasing the network depth helps enhance the spatiotemporal information propagation capability. However, when n... gWhen the value is greater than 3, the performance improvement becomes less significant, and may even lead to slight degradation due to overpropagation, feature redundancy, or increased training complexity. Therefore, the embodiments of this application use n. g =3 is set as the model depth to achieve a better balance between prediction accuracy and inference efficiency.
[0315] Finally, this embodiment further analyzes the impact of the hidden dimension d on the model's representational capability, with the test range being d∈{32,64,96,128,256}. When d=32, the model's representational capacity is limited, making it difficult to fully fit complex spatiotemporal dependencies, thus resulting in relatively poor prediction performance. As d increases, the model's representational capability gradually improves, and the prediction error decreases significantly. When d=96, the model achieves a good balance between accuracy and computational cost. While further increasing the hidden dimension can improve expressive capability, it also increases the number of parameters and computational cost, and the performance improvement is not significant. Therefore, this embodiment sets the hidden dimension to d=96, and it can be appropriately adjusted according to the size and complexity of the dataset.
[0316] In summary, parameter sensitivity experiments show that the model provided in this embodiment has good stability with respect to key hyperparameters. Increasing the number of headers, model layers, and hidden dimensions within a reasonable range can help improve prediction performance, but excessively large parameter settings will lead to increased computational overhead and diminishing returns. Considering prediction accuracy, training efficiency, and model complexity, this embodiment ultimately adopts H... g =4、n g =3 and d=96 are used as the default configurations.
[0317] Figure 19 This is a schematic diagram of an electronic device provided as an embodiment of this application. The electronic device is intended for use with various electronic devices capable of performing traffic flow prediction methods, such as microcomputers, microcontrollers, and other suitable computers. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0318] like Figure 19 As shown, the electronic device includes at least one processor 801 and a memory 802. The electronic device also includes a communication component 803. The processor 801, memory 802, and communication component 803 are connected via a bus 804.
[0319] In the specific implementation process, at least one processor 801 executes computer execution instructions stored in memory 802, causing at least one processor 801 to execute the traffic flow prediction method executed on the electronic device side as described above.
[0320] In the above embodiments, it should be understood that the processor 801 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor 801 can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0321] The memory 802 may include high-speed random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.
[0322] Bus 804 can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Bus 804 can be divided into address bus, data bus, control bus, etc. For ease of illustration, the bus 804 in the accompanying drawings of this application is not limited to only one bus or one type of bus.
[0323] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the traffic flow prediction method described above.
[0324] The memory 802 is the non-transitory computer-readable storage medium provided by this invention. The non-transitory computer-readable storage medium of this invention stores computer instructions for causing a computer to execute the traffic flow prediction method provided by this invention.
[0325] In addition, this embodiment also provides a computer program product, including a computer program, which, when executed by a processor, is used to implement the traffic flow prediction method of the above embodiment.
[0326] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope.
Claims
1. A traffic flow prediction method, characterized in that, include: Historical traffic sequence data from multiple sensor nodes are acquired, and the historical traffic sequence data from multiple sensor nodes is segmented into patches to obtain multiple patch data. Multiple patch data are mapped to obtain the word vector of each patch data. Obtain the target dimension spatiotemporal vector for each of the aforementioned word vectors; Multiple patch data are segmented into multi-scale segments to obtain the input for each scale; Based on the target dimension spatiotemporal vector of each lexical vector, multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-spatiotemporal dependency matrices are obtained. Based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices, multiple gated routing mask matrices are obtained; Multiple graph header outputs are obtained based on multiple gated routing mask matrices, and the graph propagation result is obtained by splicing the multiple graph header outputs. Based on the graph propagation results and the input at each scale, the output at each scale is obtained; Based on the output of each scale, the fused output of each scale is obtained; Based on the fusion output of each scale, a multi-scale fusion output is obtained; The predicted input is obtained from the multi-scale fusion output, and the predicted traffic flow corresponding to multiple sensor nodes is obtained from the predicted input.
2. The method according to claim 1, characterized in that, The step of obtaining the target dimension spatiotemporal vector for each of the lexical vectors includes: Obtain the target dimension vector for each of the given word vectors; Obtain the sinusoidal position code for each of the target dimension vectors; Based on the target dimension vector of each lexical vector and the sine position encoding of each target dimension vector, the target dimension spatiotemporal vector of each lexical vector is obtained.
3. The method according to claim 1, characterized in that, The process of obtaining multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices based on the target dimension spatiotemporal vector of each lexical vector includes: Based on the target dimension spatiotemporal vector of each lexical vector, multiple global original similarity matrices are obtained; Based on multiple global original similarity matrices and a preset sparse mask matrix, multiple global sparse similarity matrices are obtained; Based on the sensor node index and patch index of each lexical vector, a global temporal relation binary mask matrix, a global spatial relation binary mask matrix, and a global cross-temporal and spatial relation binary mask matrix are obtained. Based on multiple global sparse similarity matrices, global temporal relation binary mask matrices, global spatial relation binary mask matrices, and global cross-temporal relation binary mask matrices, multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices are obtained.
4. The method according to claim 1, characterized in that, The process involves obtaining multiple gated routing mask matrices based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices, including: Based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices, multiple original relation selection score matrices are obtained; Based on the selection score matrix of multiple original relations, a selection probability matrix of multiple relations is obtained; Multiple binary routing mask matrices are obtained by selecting probability matrices and preset probability thresholds based on multiple relationships; Multiple gated routing mask matrices are obtained from multiple binary routing mask matrices.
5. The method according to claim 1, characterized in that, The process of obtaining multiple header outputs based on multiple gated routing mask matrices includes: Based on multiple gated routing mask matrices, multiple dynamic graph adjacency matrices are obtained; Multiple graph headers are output based on multiple dynamic graph adjacency matrices.
6. The method according to claim 1, characterized in that, The process of obtaining the output for each scale based on the graph propagation results and the input for each scale includes: Based on the graph propagation results and the input at each scale, the residual connection results at each scale are obtained; The residual connection results at each scale are normalized to obtain the normalized residual connection results at each scale. The normalized residual connection results for each scale are input into the feedforward network to obtain the feedforward output for each scale; The output for each scale is obtained based on the residual connection results and the feedforward output for each scale.
7. A traffic flow prediction device, characterized in that, include: The first data processing module is used to acquire historical traffic sequence data from multiple sensor nodes and perform patching segmentation on the historical traffic sequence data from multiple sensor nodes to obtain multiple patch data. The first mapping module is used to map multiple patch data to obtain the word vector of each patch data. The second mapping module is used to obtain the target dimension spatiotemporal vector of each of the lexical vectors; The segmentation module is used to perform multi-scale segmentation on multiple patch data to obtain the input for each scale; The dependency matrix acquisition module is used to obtain multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal dependency matrices based on the target dimension spatiotemporal vector of each lexical vector. The gated routing mask matrix acquisition module is used to obtain multiple gated routing mask matrices based on multiple global temporal dependency matrices, global spatial dependency matrices, and global cross-temporal and spatial dependency matrices. The splicing module is used to obtain multiple graph header outputs based on multiple gated routing mask matrices, and to splice the multiple graph header outputs to obtain the graph propagation result; The second data processing module is used to obtain the output of each scale based on the graph propagation results and the input of each scale; The fusion output acquisition module is used to obtain the fusion output for each scale based on the output of each scale; The multi-scale fusion output acquisition module is used to obtain the multi-scale fusion output based on the fusion output of each scale; The prediction module is used to obtain the prediction input based on the multi-scale fusion output, and to obtain the predicted traffic flow corresponding to multiple sensor nodes based on the prediction input.
8. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the traffic flow prediction method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the traffic flow prediction method as described in any one of claims 1 to 6.
10. A computer program product, characterized in that, Includes a computer program, which, when executed by a processor, is used to implement the traffic flow prediction method as described in any one of claims 1 to 6.
