Traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism
By using multi-source learning fusion and multi-scale attention mechanisms, network weights are dynamically generated. Hierarchical sampling and residual fusion are employed to capture multi-granular temporal patterns and time-varying spatial correlations of traffic flow. This solves the problems of insufficient information fusion and modeling in existing methods and achieves high-precision traffic flow prediction.
Patent Information
- Application Number
- CN202511821356.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-05
- Publication Date
- 2026-02-24
AI Technical Summary
Existing traffic flow prediction methods struggle to effectively integrate multi-source heterogeneous information, cannot adaptively capture the dynamic impact of nonlinear external factors, lack multi-scale time pattern modeling capabilities, and static graph structures cannot reflect time-varying spatial relationships in traffic networks.
We employ a multi-source learning fusion method to dynamically generate exclusive network weights. By combining hierarchical sampling and cross-scale residual fusion, we capture multi-granular temporal patterns and time-varying spatial correlations of traffic flow through a multi-scale attention mechanism and model the traffic network using a dynamic graph structure.
It significantly improves the accuracy and robustness of traffic flow forecasting, can adapt to complex traffic environments, and has excellent forecasting performance, reducing RMSE by 26.77% and MAE by 14.11%.
Smart Images

Figure CN121564973A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism, which can be applied to scenarios such as congestion relief and signal timing optimization in intelligent urban traffic management, and belongs to the field of traffic flow prediction technology. Background Technology
[0002] The intelligent management of urban transportation systems urgently requires accurate traffic flow prediction, which can provide a scientific basis for key decisions such as congestion mitigation and signal timing optimization. However, traffic flow prediction faces three core challenges: First, the transportation system is an open system, and its evolution pattern is affected by the nonlinear modulation of multi-source heterogeneous information such as weather and holidays, requiring the achievement of context-aware adaptive feature fusion; second, traffic data exhibits complex composite dynamics in the time dimension, including short-term random disturbances and long-term periodic trends, requiring models to have the ability to represent hierarchical patterns at multiple granularities; finally, the functional dependencies between road network nodes evolve in real time with traffic conditions, necessitating the breaking through the limitations of static physical topology to achieve dynamic capture of time-varying spatial correlations.
[0003] Existing traffic flow prediction methods, from traditional statistical models to the rapidly developing deep learning models in recent years, have made significant progress in capturing spatiotemporal dependencies, but most have failed to systematically address the three major challenges mentioned above. For example, while CNN-RNN-based architectures can handle spatiotemporal features separately, their fusion of external factors is relatively rudimentary and they struggle to construct multi-scale temporal patterns hierarchically. GNN-based methods, although enhancing spatial modeling, mostly employ static graph structures that cannot adaptively capture dynamically changing spatial relationships and lack deep fusion mechanisms for multi-source external information and multi-scale temporal dynamics.
[0004] Traditional models often use simple feature concatenation to integrate external factors such as weather and time. This static strategy cannot capture the dynamic and nonlinear impact of external factors on traffic flow. This invention employs a multi-source learning fusion method to dynamically parameterize external conditions into dedicated network weights, thereby achieving adaptive nonlinear transformation of traffic flow and more accurately reflecting the differentiated effects of external factors.
[0005] Traditional models typically model on a single time scale or separate long-term and short-term trends, making it difficult to capture the complex multi-scale periodicity and dynamic interactions of traffic data. This invention achieves hierarchical modeling of multi-granularity temporal patterns through hierarchical sampling and cross-scale residual fusion. Simultaneously, a delayed projection mechanism is introduced into time attention, broadening the perceptual field by stitching together historical information, thereby effectively capturing long-term and short-term temporal dependencies.
[0006] Most models rely on predefined static adjacency matrices to describe spatial relationships, which cannot reflect the functional connections between nodes in the traffic network that change in real time with traffic conditions.
[0007] Existing traffic flow prediction methods, utilizing traditional statistical models and deep learning models such as CNN-RNN and GNN, have made some progress in capturing spatiotemporal features, but all have significant shortcomings: CNN-RNN architectures have a rudimentary way of fusing external factors and lack multi-scale temporal modeling capabilities; while GNN methods enhance spatial modeling, their graph structures are static and they fail to achieve dynamic and deep fusion of multi-source information and multi-scale temporal data. These deficiencies limit the prediction accuracy and robustness of existing models in real-world, complex traffic environments, making it difficult to meet practical application needs. Therefore, a novel traffic flow prediction method that can synergistically address the above three core problems is urgently needed. Summary of the Invention
[0008] To overcome the limitations of existing traffic prediction methods in terms of staticity when fusing heterogeneous information and in capturing multi-scale temporal patterns, this invention provides a traffic flow prediction method based on multi-source fusion and multi-scale attention mechanisms. It designs a dynamic-static graph learning strategy, which effectively captures time-varying functional spatial relationships by fusing a predefined physical topology graph with a data-driven adaptive graph structure. Through adaptive perception of the external environment and deep modeling of spatiotemporal dependencies, it aims to significantly improve the accuracy, robustness, and generalization ability of the prediction model.
[0009] The traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism includes the following steps:
[0010] Step 1: Data Input: Receive long time-series data containing traffic flow data from multiple spatial nodes, time feature data, meteorological feature data, and holiday feature data; the long time-series data is continuous time-series data within a preset time span, and each time step data contains multi-dimensional features of the corresponding time.
[0011] Step 2: Multi-source learning fusion: Construct dedicated self-learners for time feature data, meteorological feature data, and holiday feature data, respectively. The self-learners are multilayer perceptrons. Process the corresponding external feature data through their respective learners to dynamically generate dedicated weight matrices and bias vectors. Use the weight matrices and bias vectors to adaptively transform the core traffic flow data, thereby generating semantically enhanced representations that deeply embed heterogeneous contextual information.
[0012] Step 3: Multi-dimensional hybrid modeling: Input the semantically enhanced representation into the multi-dimensional hybrid module, and perform multi-scale sampling decomposition through a set of one-dimensional average pooling layers with kernel sizes of 2¹, 2², and 2³ to generate multiple subsequences with different time resolutions, forming a multi-scale feature pyramid; starting from the coarsest scale, adopt a coarse-to-fine residual enhancement strategy to integrate long-cycle trend information into short-cycle fluctuations layer by layer, and output enhanced features that fuse multi-scale time patterns;
[0013] Step 4: Deep Spatiotemporal Dependency Learning: Input the enhanced features into a deep network that alternately stacks temporally delayed self-attention modules and spatial self-attention modules;
[0014] Time-delayed self-attention module: captures the evolution patterns and long-range dependencies of each node in the time dimension, and enhances the utilization of historical information through a delay mechanism.
[0015] Spatial Self-Attention Module: Captures the dynamic spatial correlations between different nodes at the same time. This module integrates a data-driven adaptive graph builder with a predefined physical adjacency graph to accurately model time-varying spatial relationships.
[0016] Step 5: Predict the output: Map and reshape the final features output by the deep network through the output projection layer to obtain traffic flow predictions for multiple future time steps.
[0017] The process also includes step six: model training: the long-term time-series data from step one is divided into training, validation, and test sets in a 6:2:2 ratio, and traffic flow and meteorological features are processed using Z-Score normalization; the model is trained using the Masked MAE loss function, Adam optimizer, and MultiStepLR scheduler, combined with gradient pruning and early stop strategies, to obtain the optimal prediction model.
[0018] Step two specifically includes:
[0019] For traffic flow data Separately with time feature data and weather data The process of integration and self-learning is as follows:
[0020] S2.1: Parameter generation: First, external data is mapped to a set of weights W and biases b by using a self-learner composed of multilayer perceptrons, where the internal structure of the self-learner is as shown in formulas (1) and (2).
[0021]
[0022]
[0023] in, These are all learnable parameters in the meta-learner; MLP stands for Multilayer Perceptron.
[0024] S2.2: Feature fusion: The generated parameters are used to perform linear transformation and nonlinear activation on the traffic flow data to obtain the fused features, as shown in formula (3);
[0025]
[0026]
[0027] in ;
[0028] S2.3: Final Integration: After fusing the above features, the respective fused features are obtained. , Then, these features are concatenated with the original traffic flow data and finally integrated through a fully connected network to obtain the comprehensive feature representation Y of that time step, as shown in formula (4).
[0029] Step three specifically includes:
[0030] For the enhanced feature X after multi-source fusion, its hierarchical multi-scale modeling process is as follows:
[0031] S3.1: Multi-scale downsampling decomposition:
[0032] Using a set of different kernel sizes One-dimensional average pooling layer Perform multi-scale decomposition to generate K+1 subsequences with different time resolutions. This constitutes a multi-scale pyramid, specifically defined as shown in formula (5):
[0033]
[0034] in: Indicates the feature dimension index. This represents the time step index after downsampling. Let s be the sequence length corresponding to scale s. This is the original time step; Let be the downsampling factor for the s-th level, when hour ,at this time Preserve the original temporal resolution; Corresponding to the coarsest granularity time mode, the time resolution gradually becomes finer as s increases.
[0035] S3.2: Layered feature fusion from coarse to fine:
[0036] From the coarsest scale Initially, high-level semantic information is fused layer by layer to a finer scale using residual connections, initialized as follows:
[0037] Subsequently, for each scale Perform the following iterative fusion operation, as shown in formula (6):
[0038]
[0039] in, tensor Flattened into a vector , , For learnable weight matrix, For bias terms, ,in The cumulative distribution function of the standard normal distribution. Reshape the output vector back Dimensions, for matching ;
[0040] S3.3: Final Output:
[0041] After S top-down fusions, the finest feature representation is the final output of the hierarchical multi-scale temporal modeling module, as shown in formulas (7) and (8):
[0042]
[0043]
[0044] The output feature Z of formula (7) is deeply fused from the data at each time point. The model incorporates complex dynamic patterns spanning multiple time granularities, enhancing its ability to model complex temporal dependencies. tensor Flattened out, it becomes a vector.
[0045] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0046] This invention integrates a multi-source learning fusion module and a multi-scale delayed spatiotemporal graph convolutional attention module. The former, as a pre-feature enhancement unit, adaptively encodes multi-source external contextual information into traffic flow data through a self-learning mechanism, constructing context-aware enhanced feature representations for subsequent modules. Based on this, the multi-scale delayed spatiotemporal graph convolutional attention module can perform deep spatiotemporal dependency modeling in a high-quality feature space, thereby significantly improving the model's ability to represent complex traffic dynamics and its prediction accuracy.
[0047] Improved accuracy of dynamic fusion: Abandoning the traditional static fusion method, the system dynamically generates fusion parameters through a multi-source learning fusion module, achieving adaptive nonlinear fusion of external factors and traffic flow data, effectively capturing the dynamic influence of factors such as weather and time, and significantly enhancing context awareness.
[0048] Comprehensive multi-scale time modeling: Through a hierarchical strategy of "decomposition-fusion", a multi-scale feature pyramid is constructed and residual enhancement is achieved from coarse to fine. At the same time, the receptive field is broadened by combining a time delay mechanism to comprehensively capture the composite time pattern of short-cycle disturbances, medium-cycle regularities and long-cycle trends.
[0049] Precise spatial association modeling: By integrating self-learning graphs and predefined physical graphs, it breaks through the limitations of static topology and accurately captures the functional dependencies between road network nodes that change in real time with traffic conditions. Moreover, the asymmetric adjacency matrix is more in line with the unidirectional characteristics of actual traffic flow propagation.
[0050] Excellent predictive performance: Experimental results show that the RMSE of the model in this invention reaches 26.77% and the MAE reaches 14.11%. Compared with existing CNN-RNN, GNN and other models, the prediction accuracy and robustness are significantly improved, the generalization ability is stronger, and it can adapt to complex and ever-changing traffic environments. Attached Figure Description
[0051] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0052] Figure 1 This is a flowchart of the traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism of the present invention.
[0053] Figure 2 This is a network framework diagram of the traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism of the present invention.
[0054] Figure 3 This is a graph convolutional network diagram of the traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism of the present invention.
[0055] Figure 4 This is the Mix-hop propagation layer of the graph convolutional network in the traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism of this invention. Detailed Implementation
[0056] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0057] Reference Figure 1 and Figure 4 A traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism includes the following steps:
[0058] Step 1: Data Input: Receive long time-series data containing traffic flow data from multiple spatial nodes, time feature data, meteorological feature data, and holiday feature data; the long time-series data is continuous time-series data within a preset time span, and each time step data contains multi-dimensional features of the corresponding time.
[0059] Obtain traffic flow datasets, such as vehicle datasets or bicycle datasets. Each data point in the dataset includes the entry time, entry area ID, exit time, and exit area ID.
[0060] Obtain a spatial dataset of the detected traffic data. Each record in the dataset contains the region ID number, the distance between each monitoring point, the regional distribution, and the adjacency matrix of the physical connection relationships between regions.
[0061] Obtain a weather dataset, which includes temperature, precipitation, and weather conditions, such as sunny, heavy rain, light rain, heavy snow, and light snow.
[0062] Step 2: Multi-source learning fusion: Construct dedicated self-learners for time feature data, meteorological feature data, and holiday feature data, respectively. The self-learners are multilayer perceptrons. Process the corresponding external feature data through their respective learners to dynamically generate dedicated weight matrices and bias vectors. Use the weight matrices and bias vectors to adaptively transform the core traffic flow data, thereby generating semantically enhanced representations that are deeply embedded with heterogeneous contextual information.
[0063] To effectively integrate data from different sources and with different properties (such as traffic flow, weather, and time), this patent proposes a multi-source learning-based fusion module. This module can dynamically generate fusion parameters based on external features (such as weather and time) and adaptively adjust traffic flow features. Specifically, external features such as weather and time are not directly integrated with traffic features, but are input into a self-learner to generate model parameters, which then modulate the traffic features. This alleviates the semantic gap between different data sources and significantly reduces the reliance on prior expert knowledge in the feature fusion process.
[0064] Specifically, regarding traffic data Separately with time data and weather data The process of integration and self-learning is as follows:
[0065] S2.1: Parameter generation: First, external data is mapped to a set of weights W and biases b by using a self-learner composed of multilayer perceptrons (MLP), where the internals of the self-learner are as shown in formulas (1) and (2).
[0066]
[0067]
[0068] in, These are all learnable parameters in the meta-learner; MLP stands for Multilayer Perceptron.
[0069] The core function of the self-learner is not to directly extract features from the data, but to learn a high-order mapping from external contextual information to a specific task function space. The "self-learning" of this module is reflected in its ability to autonomously generate the most suitable fusion strategy, i.e., function parameters, based on different external conditions.
[0070] S2.2: Feature fusion: The generated parameters are used to perform linear transformation and nonlinear activation on the traffic data to obtain the fused features, as shown in formula (3).
[0071]
[0072]
[0073] in .
[0074] S2.3: Final Integration: After fusing the above features, the respective fused features are obtained. , These features are then concatenated with the original traffic data and finally integrated through a fully connected network to obtain the comprehensive feature representation Y for that time step, as shown in formula (4).
[0075] Unlike traditional methods that directly multiply, add, or concatenate external features with traffic data features, this proposed fusion strategy explores a different direction. Considering the semantic gap between external and traffic data, external features are not directly integrated with traffic data. Instead, they first drive a self-learner whose output modulates the parameters of the traffic data. Therefore, the fusion strength is not fixed or predefined, but learned from the self-learner.
[0076] Step 3: Multi-dimensional Hybrid Modeling: Input the semantically enhanced representation into the multi-dimensional hybrid module, through a set of kernel sizes... The one-dimensional average pooling layer is used for multi-scale downsampling decomposition to generate multiple subsequences with different time resolutions, forming a multi-scale feature pyramid. Starting from the coarsest scale, a residual enhancement strategy from coarse to fine is adopted to integrate long-term trend information into short-term fluctuations layer by layer, and output the enhanced features that fuse multi-scale time patterns.
[0077] To effectively capture the multiple patterns at different time granularities (such as long-term trends, medium-term regularities, and short-term fluctuations) coexisting in traffic flow data, this invention proposes a hierarchical modeling method based on a multi-dimensional hybrid module. This module decomposes the time series into a multi-resolution feature pyramid through downsampling, and then employs an iterative enhancement strategy from coarse to fine, injecting macro-pattern information into the fine features layer by layer in a residual manner.
[0078] Specifically, for feature X after multi-source fusion, its hierarchical multi-scale modeling process is as follows:
[0079] S3.1: Multi-scale downsampling decomposition:
[0080] Using a set of different kernel sizes One-dimensional average pooling layer Perform multi-scale decomposition to generate K+1 subsequences with different time resolutions. This constitutes a multi-scale pyramid, specifically defined as shown in formula (5):
[0081]
[0082] in: Indicates the feature dimension index. This represents the time step index after downsampling. Let s be the sequence length corresponding to scale s. This is the original time step; Let be the downsampling factor for the s-th level, when hour ,at this time Preserve the original temporal resolution; Corresponding to the coarsest granularity time mode, the time resolution gradually becomes finer as s increases.
[0083] S3.2: Layered feature fusion from coarse to fine:
[0084] From the coarsest scale Initially, high-level semantic information is fused layer by layer to a finer scale using residual connections. Initialization is as follows:
[0085] Subsequently, for each scale Perform the following iterative fusion operation, as shown in formula (6):
[0086]
[0087] in, tensor Flattened into a vector , , For learnable weight matrix, For bias terms, ,in The cumulative distribution function of the standard normal distribution. Reshape the output vector back Dimensions, for matching .
[0088] S3.3: Final Output:
[0089] After S top-down fusions, the feature representation at the finest scale (i.e., the original temporal resolution) is the final output of the hierarchical multi-scale temporal modeling module, as shown in formulas (7) and (8):
[0090]
[0091]
[0092] The output feature Z of formula (7) is deeply fused from the data at each time point. The composite dynamic pattern spanning multiple time granularities from (coarsest period) to T (original sequence length) significantly enhances the model's ability to model complex temporal dependencies. tensor Flattened out, it becomes a vector.
[0093] Step 4: Deep Spatiotemporal Dependency Learning: Input the enhanced features into a deep network that alternately stacks temporally delayed self-attention modules and spatial self-attention modules;
[0094] Time-delayed self-attention module: captures the evolution patterns and long-range dependencies of each node in the time dimension, and enhances the utilization of historical information through a delay mechanism.
[0095] Spatial Self-Attention Module: Captures the dynamic spatial correlations between different nodes at the same time. This module integrates a data-driven adaptive graph builder with a predefined physical adjacency graph to accurately model time-varying spatial relationships.
[0096] Time series data typically exhibit significant temporal dependencies and periodicity, with the current state often significantly influenced by historical states. To effectively model these dynamic dependencies, this study designs a self-attention temporal encoder module based on a time delay mechanism. The core design motivation of this mechanism is to explicitly characterize the causal influence of historical time steps on the current time step. In many typical time series tasks (such as traffic flow prediction and stock price prediction), the current state is highly correlated with the states of multiple historical time steps. By introducing an adjustable delay window, the model achieves a deep fusion of historical and current features, thereby more systematically representing the long-term dependency structure in time series and significantly improving prediction performance.
[0097] S4.1: Construction and splicing of multi-granularity historical time series sequences
[0098] The goal of this step is to construct a temporal memory representation for each time step that includes information from multiple historical moments. Specifically, for the input temporal feature tensor... (Where B is the batch size, T is the time step, N is the number of nodes, and D is the feature dimension), the delay step size parameter d=4 is set, and a delay sequence set containing the current time and the previous 4 historical time steps is generated through a time dimension shift operation. The shift operation is defined by formula (9):
[0099]
[0100] in For time step indices, zero-padded time steps with insufficient delay steps at the beginning of the sequence are padded using a zero-padded strategy. Then, all delayed sequences are concatenated along the feature dimension as shown in formula (10):
[0101]
[0102] in This indicates a feature dimension concatenation operation. This represents a sequence with a lag of i steps. This splicing operation provides rich multi-scale temporal context information for subsequent nonlinear fusion networks.
[0103] S4.2: Adaptive Delayed Projection Network Processing
[0104] This step uses a learnable nonlinear projection network to compress the stitched high-dimensional delayed features back to the original feature space dimension. This projection network employs a two-layer fully connected neural network structure, as shown in Equation (11):
[0105]
[0106] in , These are the parameters for the first layer (extended layer). ,
[0107] For the second layer parameters (compression layer). To correct the activation function of the linear unit, a nonlinear transformation capability is introduced. The key role of this projection process is that, through end-to-end training, the network can adaptively learn how to extract the most relevant temporal patterns from multiple historical moments and fuse them into a compact temporal memory representation. Unlike manually designed time decay weights, the parameters of this projection network are optimized entirely by data, enabling dynamic adjustment of the importance of different historical moments according to specific task requirements.
[0108] S4.3: Asymmetric Query - Key-Value Attention Calculation
[0109] This step is the core innovation of the delayed attention mechanism, employing an asymmetric structural design that differs from traditional self-attention. Specifically, the query vector Q and key vector K are both generated from the original input sequence X through a linear transformation, while the value vector... The delayed projection features generated by S4.2 It is obtained through linear transformation. The complete attention calculation formula is shown in formula (12):
[0110]
[0111] in The projection matrix is learnable. The dimension of the attention head is determined first by performing a dot product operation between the query vector and the key vector, followed by a scaling factor. Normalization, then through Function to calculate attention weight matrix ,in ,in Its softmax output vector The elements of this matrix Represents time t relative to time t The degree of attention is determined. Finally, the weight matrix is used to perform weighted aggregation of the delay value vector. The technical effect of this asymmetric design is that when the model assigns attention weights to time t, the actual aggregation is not based on the time t. isolated features It is not just a collection of moments. and its first four historical moments Enhanced representation Therefore, even though the sequence length is only 12 time steps, the model's temporal receptive field is actually extended to 16 time steps through the delay mechanism, which significantly enhances its ability to capture long-term dependencies.
[0112] S4.4: Residual Connectivity, Layer Normalization, and Feedforward Network Enhancement
[0113] This step ensures the stability of deep network training through residual connections and layer normalization techniques, and further enhances feature representation capabilities through feedforward neural networks.
[0114] S4.5: Multi-layer Cascade and Deep Temporal Feature Extraction
[0115] In practical applications, this invention cascades the time-delayed attention layers constructed in steps one through four into three layers, forming a deep temporal feature extraction network. Each layer's delayed attention module further refines the modeling of temporal dependencies based on the features of the previous layer. The first layer primarily captures the basic temporal patterns of the original input (such as short-term fluctuations), the second layer extracts more abstract temporal relationships (such as periodic trends), and the third layer focuses on task-related high-level semantic features (such as anomaly pattern recognition). The layers are tightly coupled through residual connections, ensuring that detailed information from lower levels is passed to the top layer. This hierarchical approach enables the model to construct a hierarchical representation from low-level temporal patterns to high-level semantic concepts, significantly improving the modeling depth and prediction accuracy for complex temporal dependencies.
[0116] Step 5: Predict the output: Map and reshape the final features output by the deep network through the output projection layer to obtain traffic flow predictions for multiple future time steps.
[0117] This step extracts spatial features from traffic flow data through a spatial attention module. Its core employs a graph neural network architecture that integrates self-learning graphs, graph fusion, and graph convolutional components to extract graph structure information and executes a standard attention mechanism. Specifically, the self-learning graph module calculates node feature similarity and generates an asymmetric adjacency matrix to capture unidirectional dependencies, the graph fusion module integrates the adjacency matrix with prior knowledge to enhance graph representation capabilities, and the graph convolutional module utilizes a two-layer mix-hop structure to process node influence propagation and fuse information, thereby significantly improving model efficiency and generalization performance.
[0118] S5.1: Self-learning graph module
[0119] The core design goal of the graph learning module is to dynamically construct an adjacency matrix representing the dependency structure between nodes through temporal data analysis. In temporal data, changes in node state exhibit significant propagation characteristics, meaning that a change in the state of a single node can trigger direct or indirect effects on other nodes. This dependency relationship can be effectively captured and modeled by the graph learning module. Specifically, the module generates an asymmetric adjacency matrix representing unidirectional dependency relationships through node feature similarity calculation, as shown in equations (13) to (15). Asymmetry represents the unidirectional dependency characteristics of the influence between nodes, meaning that the influence strength from node i to node j is significantly different from the influence strength from node j to node i, thus more accurately capturing complex asymmetric dependency relationships in real-world scenarios. This design not only significantly improves the modeling accuracy of temporal dynamic characteristics but also provides high-fidelity graph structure information for subsequent graph convolution operations.
[0120]
[0121]
[0122]
[0123]
[0124]
[0125] in, , For the initialized node embedding vector, , For learnable model parameters, where Equation (15) is used to calculate the asymmetric information of the adjacency matrix. Equations (17) and (18) further sparsify the matrix, where... It is uniformly distributed random noise. This represents element-wise multiplication, achieved by retaining the top-k nearest neighbors of each node (as determined by...). (Function implementation), ultimately generating the adjacency matrix. This significantly reduces the number of non-zero elements in the matrix. This sparsity design not only effectively reduces the computational complexity of subsequent graph convolutional networks but also avoids interference from redundant information, thereby improving the computational efficiency of the model.
[0126] S5.2: Graph Fusion Module
[0127] The core design goal of the graph fusion module is to adaptively fuse the adjacency matrix dynamically generated by the self-learning graph module with the predefined adjacency matrix after standardization of the dataset, so as to construct an optimized graph structure representation. By integrating dynamic graph topological information and domain prior knowledge, this module significantly improves the graph representation capability and realizes the collaborative modeling of potential data dependencies and structured domain knowledge. Its calculation formula is shown in equation (19).
[0128]
[0129] in, For self-learning graph matrix; For a predefined matrix; is the activation function. Mix-hop graph convolution module.
[0130] S5.3: Graph Convolution Module
[0131] The graph convolution method proposed in this module uses two mix-hop propagation layers. The overall structure of graph convolution is as follows: Figure 3 As shown, the two graph convolutions process each other's information separately; one processes the influence of node i on node j, and the other processes the influence of node j on node i. After processing, the two information are fused by addition. The figure shows the specific structure of the Mix-hop propagation layer. The specific calculation process of the propagation layer is shown in equation (20).
[0132]
[0133]
[0134] Among them, formula (20) ( ) indicates the first The output of layer graph convolution; This is the input for the propagation layer. Indicates the first The output of the layer graph convolution, for the first layer ; The number of layers used to represent the graph convolution, i.e., the propagation depth (the aggregation range of node features), is used to control the number of hops in the Mix-hop propagation layer; It is the probability transition matrix for information propagation, which defines how each traffic node aggregates information from its neighboring nodes (including physically connected neighbors and semantically related neighbors) during graph convolution. In formula (21), E represents the identity matrix. It comes from formula (19).
[0135] Step Six: Model Training: Divide the long-term time-series data from Step One into training, validation, and test sets in a 6:2:2 ratio. Use Z-Score standardization to process traffic flow and meteorological features. Use the Masked MAE loss function, Adam optimizer, and MultiStepLR scheduler, combined with gradient pruning and early stop strategies, to train the model and obtain the optimal prediction model.
[0136] Example:
[0137] This embodiment utilizes a taxi traffic data set from a city in China for traffic flow prediction. The dataset covers the city area, dividing the urban space into a 16×16 grid structure, forming 256 spatial nodes, each representing a 2km×2km area. Data collection spanned from 2013 to 2016, with a collection frequency of 30 minutes per data point, totaling 22,459 time steps.
[0138] The dataset contains 8-dimensional feature information:
[0139] Traffic flow characteristics (2-dimensional): inflow and outflow
[0140] Time features (2-dimensional): Time of day code (range 0-1) and Day of week code (range 0-6)
[0141] Meteorological characteristics (3D): temperature, wind speed, and weather type; Holiday characteristics (1D):
[0142] Time series datasets are represented as Where T is the total number of time steps (T=22459), N is the number of spatial nodes (N=256), and C is the feature dimension (C=8). Spatial information associated with the dataset is described as a graph G=(V, E, A), where V is the set of nodes (V=256), E is the set of edges (E=1280, including four-neighbor connections within a grid), and A is the adjacency matrix composed of V and E. The adjacency matrix adopts a grid topology, where each node is connected to its four neighboring nodes (up, down, left, and right), and includes self-connections.
[0143] The model needs to be iterated on the training and validation sets to find the optimal model, and then the optimal model is used on the test set.
[0144] Complete the prediction task. The prediction results on the test set represent the predictive ability of the model, where lower root mean square error (RMSE) and mean absolute error (MAE) indicate better performance.
[0145] The dataset was divided into training, validation, and test sets in a 6:2:2 ratio. The time slice size was set to 12, and the batch size to 32. Traffic flow and meteorological features were standardized using Z-Score. ,in The mean of the training set. This represents the standard deviation of the training set. Meteorological features (temperature and wind speed) are also standardized in the same way.
[0146] External data is transformed into dynamic weights and biases through three parallel meta-learners for weather, time, and holidays. These are then fused with traffic data for computation and finally integrated into a 32-dimensional fusion feature through a fully connected layer.
[0147] The 8-dimensional input is concatenated into a 160-dimensional feature representation through linear projection (24-dimensional), time period embedding (18-dimensional), weekday embedding (18-dimensional), and adaptive embedding (100-dimensional). A B×N×N dynamic graph structure is generated in parallel using a spatiotemporal attention layer.
[0148] The time series is decomposed into three scales of 12 steps, 6 steps, and 3 steps by average pooling. Residual fusion is performed layer by layer from coarse to fine using MLP to achieve multi-scale temporal feature aggregation.
[0149] A three-layer attention network with alternating temporal and spatial layers is adopted. The temporal layer uses delayed projection and multi-head attention to capture temporal dependencies, while the spatial layer combines predefined graphs and dynamic graphs to perform bidirectional graph convolution to aggregate neighbor information.
[0150] Firstly, a time-delayed self-attention layer is used. The temporal correlation matrix is calculated and weighted, and then refined by fusing spatial information in a spatial self-attention layer. Temporal features and dynamic graphs are input into a graph convolutional layer, where an adaptive adjacency matrix and a predefined adjacency matrix are fused. Spatial encoding is then performed through a depth-2 hybrid propagation on both forward and reverse graphs.
[0151] The features (B,12,256,160) are reshaped into (B,256,1920) and then mapped to 12 output time steps through a hybrid projection layer Linear(1920,12), and then reshaped into (B,12,256,1) to complete the prediction.
[0152] Using the Masked MAE loss function, Adam optimizer (learning rate 0.0001), and MultiStepLR scheduler, with gradient clipping of 5.0 and early stopping policy for 10 rounds, a prediction accuracy of RMSE=26.77% and MAE=14.11% was achieved on this dataset.
[0153] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings, but the present invention is not limited to the described embodiments. For those skilled in the art, various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principles and spirit of the present invention, and these variations still fall within the protection scope of the present invention.
Claims
1. A traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism, characterized in that: Includes the following steps: Step 1: Data Input: Receive long time-series data containing traffic flow data from multiple spatial nodes, time feature data, meteorological feature data, and holiday feature data; the long time-series data is continuous time-series data within a preset time span, and each time step data contains multi-dimensional features of the corresponding time. Step 2: Multi-source learning fusion: Construct dedicated self-learners for time feature data, meteorological feature data, and holiday feature data, respectively. The self-learners are multilayer perceptrons. Process the corresponding external feature data through their respective learners to dynamically generate dedicated weight matrices and bias vectors. Use the weight matrices and bias vectors to adaptively transform the core traffic flow data, thereby generating semantically enhanced representations that are deeply embedded with heterogeneous contextual information. Step 3: Multi-dimensional hybrid modeling: Input the semantically enhanced representation into the multi-dimensional hybrid module, and perform multi-scale downsampling decomposition through a set of one-dimensional average pooling layers with kernel sizes of 2¹, 2², and 2³ to generate multiple subsequences with different time resolutions, forming a multi-scale feature pyramid; Starting from the coarsest scale, a residual enhancement strategy is adopted from coarse to fine to gradually integrate long-term trend information into short-term fluctuations, and output enhanced features that integrate multi-scale time patterns. Step 4: Deep Spatiotemporal Dependency Learning: Input the enhanced features into a deep network that alternately stacks temporally delayed self-attention modules and spatial self-attention modules; Step 5: Predict the output: Map and reshape the final features output by the deep network through the output projection layer to obtain traffic flow predictions for multiple future time steps.
2. The traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism according to claim 1, characterized in that: It also includes step six: model training: the long time series data in step one is divided into training set, validation set and test set in a ratio of 6:2:2, and traffic flow features and meteorological features are processed by Z-Score normalization; The optimal prediction model is obtained by training the model using the Masked MAE loss function, Adam optimizer, and MultiStepLR scheduler, combined with gradient pruning and early stopping strategies.
3. The traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism according to claim 1, characterized in that: Step two specifically includes: For traffic flow data Separately with time feature data and weather data The process of integration and self-learning is as follows: S2.1: Parameter generation: First, external data is mapped into a set of weights W and biases b by using a self-learner composed of multilayer perceptrons, where the internal structure of the self-learner is as shown in formulas (1) and (2). , , in, These are the learnable parameters in the meta-learner; MLP stands for Multilayer Perceptron. S2.2: Feature fusion: The generated parameters are used to perform linear transformation and nonlinear activation on the traffic flow data to obtain the fused features, as shown in formula (3); , , in , S2.3: Final Integration: After fusing the above features, the respective fused features are obtained. , Then, these features are concatenated with the original traffic flow data and finally integrated through a fully connected network to obtain the comprehensive feature representation Y of that time step, as shown in formula (4).
4. The traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism according to claim 1, characterized in that: Step three specifically includes: For the enhanced feature X after multi-source fusion, its hierarchical multi-scale modeling process is as follows: S3.1: Multi-scale downsampling decomposition: Using a set of different kernel sizes One-dimensional average pooling layer Perform multi-scale decomposition to generate K+1 subsequences with different time resolutions. This constitutes a multi-scale pyramid, specifically defined as shown in formula (5): , in: Indicates the feature dimension index. This represents the time step index after downsampling. Let s be the sequence length corresponding to scale s. This is the original time step; Let be the downsampling factor for the s-th level, when hour , Preserve the original temporal resolution; Corresponding to the coarsest granularity time pattern, the time resolution gradually becomes finer as s increases; S3.2: Layered feature fusion from coarse to fine: From the coarsest scale Initially, high-level semantic information is fused layer by layer to a finer scale using residual connections, initialized as follows: ; Subsequently, for each scale Perform the following iterative fusion operation, as shown in formula (6): , in, tensor Flattened into a vector , , For learnable weight matrix, For bias terms, ,in The cumulative distribution function of the standard normal distribution. Reshape the output vector back Dimensions for matching ; S3.3: Final Output: After S top-down fusions, the finest-scale feature representation is the final output of the hierarchical multi-scale temporal modeling module, as shown in formulas (7) and (8): , , The output feature Z of formula (7) is deeply fused at each time point from... The composite dynamic pattern spanning multiple time granularities up to T. tensor Flattened out, it becomes a vector.
5. The traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism according to claim 1, characterized in that: In step four, the time-delayed self-attention module captures the evolution patterns and long-range dependencies of each node in the time dimension and enhances the utilization of historical information through a delay mechanism. To capture the dynamic spatial correlation between different nodes at the same time, the spatial self-attention module integrates a data-driven adaptive graph builder with a predefined physical adjacency graph to accurately model time-varying spatial relationships.
6. The traffic flow prediction method based on multi-source fusion and multi-scale attention mechanism according to claim 5, characterized in that: Step four specifically includes: S4.1: Construction and splicing of multi-granularity historical time series sequences: For the input temporal feature tensor B is the batch size, T is the time step, N is the number of nodes, and D is the feature dimension. The delay step parameter d=4 is set. A delay sequence set containing the current time and the previous 4 historical time steps is generated through the time dimension shift operation. The shift operation is defined by formula (9): , in For time step indices, for time steps at the beginning of the sequence that are less than the delay step size, a zero-padded strategy is used to fill in the gaps. Then, all delayed sequences are concatenated along the feature dimension as shown in formula (10): , in This indicates a feature dimension concatenation operation. Represents a sequence that lags by i steps; S4.2: Adaptive Delayed Projection Network Processing: The stitched high-dimensional delayed features are compressed back to the original feature space dimension by a learnable nonlinear projection network. The projection network adopts a two-layer fully connected neural network structure, as shown in Equation (11): , in , These are the parameters for the first layer (extended layer). , These are the parameters for the second compression layer. To correct the activation function of the linear unit, a nonlinear transformation capability is introduced; S4.3: Asymmetric Query - Key-Value Attention Calculation: Employing an asymmetric structural design distinct from traditional self-attention, both the query vector Q and the key vector K are generated from the original input sequence X through a linear transformation, while the value vector... The delayed projection features generated by S4.2 The complete attention calculation formula, obtained through linear transformation, is shown in formula (12): , in For a learnable projection matrix, To determine the dimension of the attention head, we first perform a dot product operation between the query vector and the key vector, and then apply a scaling factor. Normalization, then through Function to calculate attention weight matrix ,in ,in Its softmax output vector Matrix elements Represents time t relative to time t The model assigns attention weights to time t, and then uses the weight matrix to perform weighted aggregation of the delay value vector. When the model assigns attention weights to time t, the actual aggregation is not based on the time t. isolated features It is not a moment of fusion. and its first four historical moments Enhanced representation Even if the sequence length is only 12 time steps, the model's temporal receptive field is actually extended to 16 time steps through the delay mechanism, enhancing its ability to capture long-term dependencies. S4.4: Residual connectivity, layer normalization, and feedforward network enhancement: The stability of deep network training is ensured by residual connections and layer normalization techniques, and the feature representation capability is further enhanced by feedforward neural networks. S4.5: Multi-layer cascading and deep temporal feature extraction: The time-delayed attention layers constructed in steps one through four are cascaded into three layers to form a deep temporal feature extraction network. Each layer's delayed attention module can further refine the modeling of temporal dependencies based on the features of the previous layer. The first layer mainly captures the basic temporal patterns of the original input, the second layer extracts more abstract temporal relationships based on this, and the third layer focuses on task-related high-level semantic features. The layers are tightly coupled through residual connections to ensure that the detailed information at the lower level can be passed to the upper level. The hierarchical processing method enables the model to construct a hierarchical representation from low-level temporal patterns to high-level semantic concepts, improving the modeling depth and prediction accuracy of complex temporal dependencies.