Traffic flow prediction method and device based on multi-level space-time and perception fusion
By employing a multi-layered spatiotemporal and perception fusion method, periodic labels and adaptive features are dynamically embedded to construct a spatiotemporal and local mutation perception attention module. This addresses the short-term fluctuations and non-stationarity issues in traffic flow prediction, achieving efficient traffic flow prediction.
Patent Information
- Application Number
- CN202511653945.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-12
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2045-11-12
AI Technical Summary
Existing traffic flow prediction models struggle to effectively capture dramatic short-term fluctuations and non-stationary local abrupt changes in real traffic data, resulting in poor prediction performance.
A multi-level spatiotemporal and perception fusion approach is adopted. By fusing periodic labels and adaptive vectors through a dynamic multi-level feature embedding module, a spatiotemporal and local mutation perception attention module is constructed. Furthermore, multi-source attention outputs are integrated through a hyperdomain interaction fusion module to form an end-to-end traffic flow prediction framework.
It enables effective modeling and prediction of spatiotemporal dependencies and local mutations in complex traffic scenarios, improving the accuracy and stability of traffic flow prediction, and is applicable to typical scenarios such as peak-hour congestion and sudden accidents.
Smart Images

Figure CN121092937B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the field of traffic flow prediction, and relates to a multi-level space-time and perception fusion traffic flow prediction method and device. BACKGROUND
[0002] Traffic flow prediction is one of the core tasks in intelligent transportation systems, and is of great significance for relieving urban congestion, improving road operation efficiency, and supporting traffic signal control and travel scheduling.
[0003] Currently, prediction models based on graph neural networks or Transformer architecture are mostly used to model the space-time dependence of traffic flow from different perspectives. Among them, the prediction model based on graph neural network captures the spatial correlation and dynamic propagation characteristics between nodes by explicitly modeling the topological structure of the traffic network. In particular, multi-scale feature extraction technology significantly enhances the adaptability of the model to complex traffic scenarios. For example, DCRNN (Diffusion Convolutional Recurrent Neural Network) captures the space-time propagation characteristics through diffusion convolution, and STGCN (Spatio-Temporal Graph Convolutional Networks) optimizes feature extraction by fusing graph convolution and time convolution. On this basis, GWNet (Graph WaveNet) dynamically describes the implicit relationship between road segments through a learnable adaptive adjacency matrix, while MTGNN (Multivariate Time Series Forecasting with Graph Neural Networks) expands the time series receptive field and improves the spatial expression ability under sparse topology by means of gating and jump convolution.
[0004] The prediction model based on the Transformer architecture utilizes the self-attention mechanism to strengthen the modeling ability of long-term trends and periodic patterns from a global perspective, for example, the STID (Spatial-Temporal Identity) model and the STAEformer (Spatial-Temporal Autoencoder Transformer) model utilize label embedding and attention mechanism to strengthen the learning of periodic patterns. At the same time, the PDFormer (Periodic Dynamics Transformer) deals with complex spatio-temporal interactions through dynamic decomposition and attention fusion, and the DTRformer (Decomposed Trend Representation Transformer) utilizes trend fusion mechanism to balance long-term and short-term changes, thereby improving the stability and accuracy of long-term prediction.
[0005] However, real traffic data often contains severe short-term fluctuations, such as sudden accidents, local anomalies, etc. As shown in the traffic flow trend of a certain highway within 24 hours, the traffic flow rapidly rises during the morning and evening peak periods, and significantly drops in the afternoon due to a sudden accident. This typical short-term mutation and non-stationary fluctuation highlights the severe changes of traffic flow in the time dimension. However, these phenomena often cannot be fully captured by existing traffic flow prediction models, resulting in poor prediction results. Figure 1
[0006] Therefore, it is urgent to develop a traffic flow prediction method that can consider dynamic spatio-temporal dependence and non-stationary local mutation in a unified framework, thereby improving overall accuracy. SUMMARY
[0007] To solve the above technical problems, the present application proposes a multi-level spatio-temporal and perception fusion traffic flow prediction method. Based on Transformer, it includes the following three core parts: dynamic multi-level feature embedding module, which fuses original flow, periodic label and adaptive vector to enhance input expression. Spatio-temporal and local mutation perception attention module, which adopts three parallel attention mechanisms to model time dependence, spatial dependence and local mutation features simultaneously. Super-domain interaction fusion module, which efficiently integrates the output results of multi-source attention through cross-attention and gating mechanism. The present application systematically considers spatio-temporal dependence, local mutation perception and multi-source feature fusion.
[0008] The specific technical solutions of the present application are as follows:
[0009] A traffic flow prediction method based on multi-level spatio-temporal and perception fusion, characterized in that it comprises the following steps:
[0010] Step 1, constructing a dynamic multi-level feature embedding module: for the input traffic flow data , fusion of periodic label and adaptive feature vector, generating high-dimensional feature representation , the periodic label includes intra-day time slice index and intra-week date index, wherein, T is the number of time steps, N is the number of nodes, C is the feature dimension before fusion, is the total embedding dimension after fusion.
[0011] Step 2, constructing a spatio-temporal and local mutation perception attention module: based on the features output by the first step , through time attention mechanism, spatial attention mechanism and local mutation perception attention mechanism, respectively extracting time-dependent features , spatial-dependent features and local mutation perception features , the dimensions of the three are .
[0012] Step 3, constructing a super-domain interaction fusion module: integrating the time-dependent features , spatial-dependent features and local mutation perception features output by the second step, generating a unified spatio-temporal feature representation .
[0013] Step 4, constructing an output layer; the fusion features output by the third step are mapped to traffic flow prediction sequences through a linear layer and a nonlinear activation function , wherein is the predicted time step, P is the predicted dimension.
[0014] Step 5, model training and prediction: using masked mean absolute error as the loss function, using gradient descent algorithm to optimize model parameters, obtaining the final prediction model and performing traffic flow prediction.
[0015] In some embodiments, step 1 comprises:
[0016] Step 1.1, generating original feature embedding through a fully connected layer , wherein , is the embedding dimension, is the fully connected operation;
[0017] Step 1.2, generating intra-week cycle embedding by learnable embedding matrix and intra-day cycle embedding ;
[0018] Step 1.3, optimizing adaptive embedding by end-to-end backpropagation where is adaptive embedding dimension;
[0019] Step 1.4, concatenating above embeddings along feature dimension to get comprehensive feature representation:
[0020] ;
[0021] where, , denotes concatenation operation along feature dimension, is total embedding dimension.
[0022] In some embodiments, step 2 comprises:
[0023] Step 2.1, extracting time-dependent features by time attention mechanism :
[0024] performing linear transformation on input features to generate query matrix , key matrix and value matrix :
[0025] ;
[0026] where, weight matrix , h is number of attention heads;
[0027] For the i th attention head, calculate time attention output:
[0028] ;
[0029] where, and respectively represent query sub-matrix, key sub-matrix and value sub-matrix assigned to the th attention head after splitting query matrix , key matrix and value matrix i along feature dimension;
[0030] concatenate and linearly map outputs of h attention heads to get time features :
[0031] ;
[0032] wherein, is the output projection matrix;
[0033] Step 2.2, extract spatial dependent features by spatial attention mechanism :
[0034] Linearly transform the input features to generate query matrix , key matrix and value matrix :
[0035] ;
[0036] wherein, the weight matrix , h is the number of attention heads;
[0037] For the i th attention head, calculate the spatial attention output:
[0038] ;
[0039] wherein, and respectively represent the query sub-matrix, key sub-matrix and value sub-matrix assigned to the th attention head after splitting the query matrix , key matrix and value matrix i along the feature dimension;
[0040] Concatenate and linearly map the outputs of h heads to obtain the spatial feature :
[0041] ;
[0042] wherein, is the output projection matrix;
[0043] Step 2.3, extract local mutation aware features by local mutation aware attention mechanism :
[0044] For the input features , define a local space-time window t at each time step n and node W ;
[0045] Calculate the mean and variance :
[0046] ;
[0047] ;
[0048] where, is the total number of elements in the window;
[0049] Trend estimation is calculated by moving average with Gaussian weighting :
[0050] ;
[0051] where, , is the Gaussian kernel hyperparameter;
[0052] The variance and trend are input into the multi-layer perception to generate an adaptive smoothing factor :
[0053] ;
[0054] Smooth the original features to obtain mutation-aware features :
[0055] ;
[0056] where, EMA is the exponential moving average function used to smooth abnormal fluctuations, and the calculation formula is:
[0057] ;
[0058] Apply a multi-head attention mechanism to , which is as follows:
[0059] Perform linear transformation on the input features to generate the query matrix , the key matrix , and the value matrix :
[0060] ;
[0061] where , h is the number of attention heads;
[0062] For the i th attention head, calculate the local mutation-aware attention output:
[0063] ;
[0064] wherein, and represent the query matrix , the key matrix and the value matrix after being cut along the feature dimension, and are assigned to the query sub-matrix, the key sub-matrix and the value sub-matrix of the i-th attention head; i
[0065] The outputs of the i heads are spliced and linearly mapped to obtain the final output of the local mutation-aware attention mechanism h :
[0066] ;
[0067] wherein, is an output projection matrix.
[0068] In some embodiments, step 3 comprises:
[0069] Step 3.1, linearly processing the time-dependent feature , the space-dependent feature and the local mutation-aware feature to generate a unified dimensional feature representation :
[0070] ;
[0071] wherein, represents the unified feature representation before fusion, which is part of the input of the subsequent interaction fusion module;
[0072] Step 3.2, using cross-attention mechanism to calculate the pairwise interaction between the time-dependent feature , the space-dependent feature and the local mutation-aware feature :
[0073] ,
[0074] ,
[0075] ,
[0076] wherein, is a linear projection matrix, represent the query matrix of the time, space and local mutation-aware feature, respectively, key matrices representing time, space and local mutation-aware features, respectively, value matrices representing time, space and local mutation-aware features, respectively;
[0077] Step 3.3, calculate cross-domain interaction features to capture deep-level association information between time, space and local mutation-aware features:
[0078] ;
[0079] ;
[0080] ;
[0081] ;
[0082] wherein, are the fusion representations of time features, space features and local mutation-aware features after cross-attention mechanism, respectively, is the unified interaction feature after splicing the three, is the number of attention heads, is the fusion weight matrix;
[0083] Step 3.4, introduce a multi-scale gating fusion mechanism to dynamically adjust the weight of feature fusion:
[0084] ;
[0085] ;
[0086] ;
[0087] wherein, GAP (·) represents a global average pooling operation for extracting global statistical information of features, is a learnable weight factor, DilatedConv (·) represents a multi-scale dilated convolution, and the dilated rate changes according to the scale;
[0088] Step 3.5, fuse the features before fusion and the multi-source interaction features to generate the final output :
[0089] ;
[0090] ;
[0091] ;
[0092] wherein, LayerNorm (·) represents a layer normalization operation.
[0093] In some embodiments, step 4 is specifically:
[0094] ;
[0095] ;
[0096] wherein, is the hidden layer feature representation, Linear (·) denotes a linear transformation, ReLU(·) is an activation function used to introduce non-linear characteristics to enhance the model's expression ability for non-linear relationships, is a weight matrix, is a bias vector.
[0097] In some embodiments, step 5 specifically includes:
[0098] The masked mean absolute error is used as the loss function:
[0099] ;
[0100] wherein, and are the predicted value and the true value, respectively, is a mask matrix;
[0101] The optimization process uses the Adam optimizer, and the hyperparameter configuration of the optimizer includes the initial learning rate and the weight decay , which balances the convergence speed and model generalization ability by adjusting the learning rate and regularization parameters. A multi-step learning rate scheduling strategy is introduced in the optimization process, and the learning rate is decayed to 0.5 times, 0.25 times and 0.1 times of the original value at the 30th, 50th and 80th epoch, respectively, which is specifically:
[0102] ;
[0103] wherein, is the learning rate of the th epoch, is the initial learning rate, denotes the floor function;
[0104] The training process is set to 150 epochs, with batch sizes of 16 (PEMS04 and PEMS08) and 1 (PEMS07), and data shuffling is enabled to reduce the risk of overfitting. The model saves checkpoints at the end of each epoch, and the optimal model parameters are selected based on the Masked MAE index of the validation set;
[0105] The maximum gradient norm is set to 1.0, gradient clipping is applied to prevent gradient explosion, and the optimal model parameters are selected based on the Masked MAE index of the verification set.
[0106] The application further provides a computer device comprising a memory, a processor and a computer program stored on the memory, wherein the processor executes the traffic flow prediction method described in any of the preceding embodiments.
[0107] The application further provides a computer readable storage medium storing a computer program, wherein the program is executed by a processor to implement the traffic flow prediction method described in any of the preceding embodiments.
[0108] The technical effects of the application are as follows:
[0109] 1. Multi-level feature embedding of traffic flow data is realized: according to the dynamic multi-level feature embedding module, the original data, periodic information and adaptive information are fused to enhance the representation capability. In complex traffic scenarios, the spatio-temporal periodicity is clearly defined from the data structure level, providing rich context information for the subsequent attention mechanism, thereby realizing multi-level feature embedding of traffic flow data.
[0110] 2. Spatio-temporal dependence and local mutation perception modeling is realized: a spatio-temporal and local mutation perception attention module is constructed to extract time, space and mutation features in parallel, avoiding information loss. In this module, three parallel multi-head attention mechanisms are used to capture time dependence, spatial dependence and local mutation features. It is suitable for typical traffic scenarios such as peak congestion and sudden accidents.
[0111] 3. Interactive fusion of multi-source features is realized: the cross-attention and gating mechanism are constructed through the super-domain interactive fusion module, which retains the individual information of each feature while absorbing the effective interaction of multi-source information.
[0112] 4. A traffic flow prediction method with integrated prediction process is realized: dynamic multi-level feature embedding, spatio-temporal and local mutation perception attention, and super-domain interactive fusion are organically integrated to form an end-to-end framework for traffic flow prediction, which can jointly model and efficiently predict spatio-temporal dependence and non-stationary mutations in complex traffic scenarios, facilitating the integration with traffic management systems. BRIEF DESCRIPTION OF DRAWINGS
[0113] Figure 1 is the traffic flow trend of a certain highway within 24 hours.
[0114] Figure 2 is the overall framework of the method of the application.
[0115] Figure 3 is the ablation experiment analysis graph of the application on the PEMS04 data set.
[0116] Figure 4 is the ablation experiment analysis figure of the present application on PEMS07 dataset.
[0117] Figure 5 is the ablation experiment analysis figure of the present application on PEMS08 dataset.
[0118] Figure 6 is the parameter analysis figure of the present application on 3 datasets about the number of encoder layers.
[0119] Figure 7 is the parameter analysis figure of the present application on 3 datasets about the number of attention heads.
[0120] Figure 8 is the parameter analysis figure of the present application on 3 datasets about the embedding dimension.
[0121] Figure 9 is the parameter analysis figure of the present application on 3 datasets about the initial learning rate.
[0122] Figure 10 is the predicted value versus true value comparison figure of the present application on PEMS04 dataset.
[0123] Figure 11 is the predicted value versus true value comparison figure of the present application on PEMS07 dataset.
[0124] Figure 12 is the predicted value versus true value comparison figure of the present application on PEMS08 dataset.
[0125] Figure 13 is the predicted value versus true value scatter analysis figure of the present application on PEMS08 dataset.
[0126] Figure 14 is the adaptive embedding visualization analysis figure of the present application. DETAILED DESCRIPTION
[0127] It should be noted that the following detailed description is exemplary in nature and is intended to serve as an illustrative description of the present application. It should be noted that all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs.
[0128] The system architecture of the present invention and the solutions in the prior art will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. It should be noted that the described embodiments are only for explanation and illustration of the present invention, and not all of the contents. Based on the embodiments provided by the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of the present invention.
[0129] Example 1:
[0130] like Figure 2 As shown, the present invention provides a technical solution:
[0131] A traffic flow prediction method based on multi-level spatiotemporal and perception fusion includes the following steps:
[0132] Step 1: Construct a Dynamic Multi-Level Embedding Module: This module embeds the input traffic flow data... By fusing periodic labels and adaptive feature vectors, a high-dimensional feature representation is generated. The periodic labels include intraday time slice indexes and intraweek date indexes, among which, T Where N is the number of time steps, N is the number of nodes, and C is the feature dimension before fusion. This represents the total embedding dimension after fusion.
[0133] Explanation of traffic flow data: The traffic network is represented as a directed graph. G = (V, E, A), in V It is a collection of sensors. E It is the set of edges between adjacent sensors on the traffic network. A It is an adjacency matrix, specifically... Corresponding to G The adjacency matrix is used to represent the connection relationship between sensors; data collection is performed to obtain sensor data in the traffic network. This data includes historical traffic flow information, which is usually recorded in the form of time series, such as recording traffic flow, speed and other information every 5 minutes.
[0134] The specific steps are as follows: [Time step...] t The location on the transportation network i Traffic flow or speed values from each sensor are expressed as follows: ,in C =1 indicates that only single-channel data is considered (e.g., only traffic or only speed), and no multi-feature fusion is performed. At the time step... t At that time, the values of all sensors on the traffic network are represented as follows:
[0135] ;
[0136] wherein, is the flow or speed value of the i th sensor at time t ; N is the total number of sensors; C =1 means each sensor only has one feature (flow or speed); is a column vector of N×1 , representing the flow or speed values of all sensors at time step t .
[0137] Given the historical traffic data as: , wherein is the sensor data vector at each time step; is the total number of time steps of historical data, X is a tensor of , containing all sensor data from time step 1 to .
[0138] For more detailed introduction of traffic flow data, please refer to the Chinese invention patent publication document with publication number CN120409841A applied by the applicant of the present application.
[0139] Traffic flow has very obvious weekly periodicity and daily periodicity, wherein, the weekly periodicity: the morning rush hour commuting flow on weekdays is usually much higher than the flow on weekends, the flow pattern on Monday may be similar to that on Friday, but is completely different from that on Sunday. The daily periodicity: there are early peak, mid-peak, evening peak, and night valley patterns every day. Therefore, the daily time slice index and the weekly date index are embedded as periodic labels into the input traffic flow data, which provides a data basis for improving the prediction accuracy of future regular flow.
[0140] The weekly and daily embedding is fixed and predefined, which is based on the known periodic rules of humans (weekdays / weekends, peak / flat). But the real world is much more complex, there are many factors that affect traffic flow that cannot be represented by simple periodic labels. For example, unknown events such as temporary traffic control, large-scale activities, sudden weather; long-term flow change trends caused by surrounding area construction, new community occupancy; deep association patterns between different areas that cannot be explicitly expressed through graph structure, etc. Therefore, the present application embeds an adaptive feature vector into the input traffic flow data, thereby further enriching the feature representation of the input data.
[0141] Step 2, constructing a spatio-temporal and local discontinuity sensing attention module (STLDSA): based on the feature degree output in the first step , time-dependent features , space-dependent features and local discontinuity sensing features are extracted through time attention mechanism, space attention mechanism and local discontinuity sensing attention mechanism respectively, and the dimensions of the three are .
[0142] Step 3, constructing a trans-dimensional interactive module (TIFM): integrating time-dependent features , space-dependent features and local discontinuity sensing features output in the second step, generating unified spatio-temporal feature representation .
[0143] Step 4, constructing an output layer; the fusion features output in the third step are mapped to traffic flow prediction sequence through linear layer and nonlinear activation function , wherein is the number of predicted time steps, P is the predicted dimension.
[0144] Step 5, model training and prediction: using masked mean absolute error as loss function, using gradient descent algorithm to optimize model parameters, obtaining final prediction model and performing traffic flow prediction.
[0145] The traffic flow prediction method of the application receives historical traffic flow data (time step x node number x feature number), and outputs prediction sequence of future time steps .
[0146] Wherein: the dynamic multi-level feature embedding module is used for fusing the original traffic, the periodic label and the adaptive vector, and in a complex traffic scene, the spatiotemporal periodicity is determined from the data structure layer, and rich context information is provided for the subsequent attention mechanism, so that multi-level feature embedding of traffic flow data is realized. The spatiotemporal and local mutation perception attention module adopts three parallel multi-head attention mechanisms, respectively captures time dependence, space dependence and local mutation features, and is suitable for typical traffic scenes such as peak congestion and sudden accidents. The super-domain interaction fusion module constructs cross-attention and gating mechanism, while retaining the individual information of each feature, and absorbing the effective interaction of multi-source information.
[0147] The application organically integrates dynamic multi-level feature embedding, spatiotemporal and local mutation perception attention, and super-domain interaction fusion, forms an end-to-end framework for traffic flow prediction, can jointly model and efficiently predict spatiotemporal dependence and non-stationary mutation in complex traffic scenes, and is convenient for docking with a traffic management system.
[0148] Embodiment 2:
[0149] On the basis of embodiment 1, step 1 comprises:
[0150] Step 1.1, generating original feature embedding through a full connection layer , wherein , is the embedding dimension, is full connection operation.
[0151] Step 1.2, generating weekly periodic embedding and daily periodic embedding through a learnable embedding matrix.
[0152] Step 1.3, optimizing adaptive embedding through end-to-end back propagation , wherein is the adaptive embedding dimension, and the purpose is to capture the implicit mode not explicitly expressed in the data.
[0153] Step 1.4, splicing the above embedding along the feature dimension to obtain comprehensive feature representation:
[0154] .
[0155] , wherein , indicates the splicing operation along the feature dimension, is the total embedding dimension.
[0156] Embodiment 3:
[0157] On the basis of embodiment 1, step 2 comprises:
[0158] Step 2.1: Extract time-dependent features using a time attention mechanism. :
[0159] For input features Perform a linear transformation to generate the query matrix. Key matrix Sum matrix :
[0160] ;
[0161] Among them, the weight matrix ,h For the number of attention heads;
[0162] For the i Each attention head calculates the time-based attention output:
[0163] ;
[0164] in, and These represent query matrices respectively. Key matrix Sum matrix After segmenting along the feature dimension, it is assigned to the first... i The query submatrix, key matrix, and value submatrix of each attention head;
[0165] Will h The outputs of each attention head are concatenated and linearly mapped to obtain the temporal features. :
[0166] ;
[0167] in, To output the projection matrix;
[0168] Step 2.2: Extract spatial dependency features using spatial attention mechanism :
[0169] For input features Perform a linear transformation to generate the query matrix. Key matrix Sum matrix :
[0170] ;
[0171] Among them, the weight matrix , h For the number of attention heads;
[0172] For thei The attention head calculates the spatial attention output:
[0173] ;
[0174] wherein, and respectively represent the query sub-matrix, the key sub-matrix and the value sub-matrix assigned to the i-th attention head after the query matrix , the key matrix and the value matrix are cut along the feature dimension; i
[0175] The outputs of the i heads are spliced and linearly mapped to obtain the spatial feature h :
[0176] ;
[0177] wherein, is the output projection matrix;
[0178] Step 2.3, extracting local mutation-aware features by local mutation-aware attention mechanism :
[0179] For the input feature , a local spatio-temporal window t is defined at each time step n and node W ;
[0180] The mean and variance of the features in the window are calculated:
[0181] ;
[0182] ;
[0183] wherein, is the total number of elements in the window;
[0184] The trend estimate is calculated by using the moving average of Gaussian weighting:
[0185] ;
[0186] wherein, , is the Gaussian kernel hyperparameter; optionally, is set to 0.1.
[0187] Input the variance and trend into the multi-layer perception to generate an adaptive smoothing factor :
[0188] ;
[0189] Smooth the original features to obtain mutation-aware features :
[0190] ;
[0191] wherein, EMA (·) is an exponential moving average function used to smooth abnormal fluctuations while retaining key change information, and the calculation formula is:
[0192] ;
[0193] Optionally, is set to 0.9.
[0194] Apply a multi-head attention mechanism to the input features, as follows:
[0195] Perform linear transformation on the input features to generate a query matrix , a key matrix and a value matrix :
[0196] ;
[0197] wherein, , h is the number of attention heads;
[0198] For the i-th attention head, calculate the local mutation-aware attention output as follows: i
[0199] ;
[0200] wherein, and respectively represent the query sub-matrix, the key sub-matrix and the value sub-matrix assigned to the i-th attention head after the query matrix , the key matrix and the value matrix are cut along the feature dimension; i
[0201] Concatenate the outputs of the h heads and linearly map them to obtain the final output of the local mutation-aware attention mechanism h :
[0202] ;
[0203] wherein, is an output projection matrix.
[0204] The time-dependent feature , the space-dependent feature and the local mutation-aware feature are three different perspectives of abstract representation extracted from the original data by the model, which respectively capture different types of key information in traffic flow. The three types of features analyze the data from different angles, and finally make a conclusion through the fusion module.
[0205] The time-dependent feature : It is biased to capture global and sequential time variation rules, and focuses on the dependence of one or more sensor nodes themselves at different time points.
[0206] The main capture modes include: long-term trend (such as the overall flow increasing year by year with the development of the city); periodicity (such as the daily morning peak and the weekly “Monday congestion”); short-term sequence dependence (such as the traffic transmission caused by the movement of the vehicle fleet after the green light turns on).
[0207] The space-dependent feature : It is biased to capture global and networked spatial correlation, and focuses on the mutual influence between different sensor nodes (spatial positions) at the same time point.
[0208] The main capture modes include: proximity effect (downstream intersection is affected by upstream intersection); functional similarity (similar land use properties in different areas lead to similar traffic patterns), etc.
[0209] The local mutation-aware feature : It captures local, short-term, non-stationary abnormal fluctuations, and is a “anomaly detector” and “smoother” for the model, which is specifically designed to handle sudden situations that do not conform to regular spatiotemporal rules.
[0210] The main capture modes include: traffic interruption caused by traffic accidents, temporary traffic control, etc.
[0211] The three types of features are finally sent to the hyper-domain interactive fusion module for deep integration, so that the three types of features communicate, confirm and supplement each other, and finally form a unified representation that grasps both global rules and local mutations, thereby making more accurate and robust predictions.
[0212] Embodiment 4:
[0213] On the basis of embodiment 1, step 3 includes:
[0214] Step 3.1, the time-dependent feature , spatial dependent features and local mutation aware features linear processing to generate unified dimensional feature representation :
[0215] ;
[0216] wherein, represents the unified feature representation before fusion, as part of the input of the subsequent interactive fusion module;
[0217] Step 3.2, calculate the two-way interaction between time dependent features, spatial dependent features and local mutation aware features using cross attention mechanism:
[0218] ,
[0219] ,
[0220] ,
[0221] wherein, is a linear projection matrix, respectively represent the query matrix of time, spatial and local mutation aware features, respectively represent the key matrix of time, spatial and local mutation aware features, respectively represent the value matrix of time, spatial and local mutation aware features;
[0222] Step 3.3, calculate cross-domain interactive features to capture deep-level association information between time, spatial and local mutation aware features:
[0223] ;
[0224] ;
[0225] ;
[0226] ;
[0227] wherein, respectively are the fusion representations of time features, spatial features and local mutation aware features after cross attention mechanism, is the unified interactive feature after splicing, is the number of attention heads, is the fusion weight matrix;
[0228] Step 3.4, introduce a multi-scale gating fusion mechanism to dynamically adjust the weight of feature fusion:
[0229] ;
[0230] ;
[0231] ;
[0232] wherein, GAP (·) represents a global average pooling operation for extracting global statistical information of the features, is a learnable weight factor, DilatedConv (·) represents a multi-scale dilated convolution, and the dilated rate changes according to the scale;
[0233] Step 3.5, fuse the pre-fusion features and multi-source interaction features to generate the final output to realize unified spatio-temporal feature representation and provide high-quality input for traffic flow prediction:
[0234] ;
[0235] ;
[0236] ;
[0237] wherein, LayerNorm (·) represents a layer normalization operation.
[0238] Embodiment 5:
[0239] On the basis of embodiment 1, step 4 is implemented based on the following formula:
[0240] ;
[0241] ;
[0242] wherein, is a hidden layer feature representation, Linear (·) represents a linear transformation, ReLU(·) is an activation function for introducing a nonlinear property to enhance the expression ability of the model for nonlinear relationships, is a weight matrix, is a bias vector.
[0243] Embodiment 6:
[0244] On the basis of embodiment 1, step 5 includes:
[0245] The masked mean absolute error is used as the loss function:
[0246] ;
[0247] wherein, and are predicted and true values respectively, is a mask matrix;
[0248] The optimization process adopts an Adam optimizer, and the hyperparameter configuration of the optimizer includes an initial learning rate and a weight decay The learning rate and the regularization parameter are adjusted to balance the convergence speed and the model generalization ability, a multi-step learning rate scheduling strategy is introduced in the optimization process, and the learning rate is decayed to 0.5 times, 0.25 times and 0.1 times of the original value at the 30th, 50th and 80th epoch, and the specific is:
[0249] ;
[0250] wherein, is the learning rate of the th epoch, is the initial learning rate, denotes the floor function;
[0251] The training process is set to 150 epochs, the batch size on the PEMS04 and PEMS08 datasets is set to 16, the batch size on the PEMS07 dataset is set to 1, and data shuffling is enabled to reduce the risk of overfitting, the model saves checkpoints at the end of each epoch, and the optimal model parameters are selected based on the Masked MAE index of the validation set.
[0252] The maximum gradient norm is set to 1.0, gradient clipping is applied to prevent gradient explosion, and the optimal model parameters are selected based on the Masked MAE index of the validation set.
[0253] Embodiment 7:
[0254] The application provides a technical scheme:
[0255] An apparatus comprising a memory and a processor, the memory storing a computer program, and the processor implementing the traffic flow prediction method of any of the preceding embodiments when executing the computer program.
[0256] Embodiment 8:
[0257] The application provides a technical scheme:
[0258] A computer-readable storage medium storing a computer program, the program being executed by a processor to implement the traffic flow prediction method of any of the preceding embodiments.
[0259] Experiment and result analysis
[0260] To verify the prediction performance of the ML-STACAF of the present application, the present application uses three public data sets, including PEMS04, PEMS07 and PEMS08 for experiments. The GPS data of the PEMS data set is from https: / / PeMS.dot.ca.gov / .
[0261] The information of the PEMS04, PEMS07 and PEMS08 data sets is shown in the following table:
[0262] Dataset Number of samples Number of nodes Time interval Sampling interval PEMS04 16992 307 2018 / 1 / 1-2018 / 2 / 28 5 minutes PEMS07 28224 883 2017 / 5 / 1-2017 / 8 / 31 5 minutes PEMS08 17856 170 2016 / 7 / 1-2016 / 8 / 31 5 minutes
[0263] Experimental setup
[0264] The data set is divided into training, validation and test sets in the ratio of 6:2:2, and the historical 12 time steps (60 minutes, 5 minute interval) traffic flow data Predict the flow of the next 12 time steps . The model uses Masked MAE as the loss function, that is:
[0265] ;
[0266] The number of Transformer encoder layers is 2 on the PEMS04 and PEMS08 data sets and 3 on the PEMS07 data set. The number of attention heads is 4, the embedding dimension is 152, the size of the local spatio-temporal window W The size of the convolution kernel is 3, the initial value of the adaptive smoothing factor is 0.5, the hidden layer dimension of the fusion module is 128, the initial learning rate is 0.001, and the weight decay is 0.0003.
[0267] The Adam optimizer (β1=0.9, β2=0.999) is used for training, the batch size is set to 16 on the PEMS04 and PEMS08 data sets, the batch size is set to 1 on the PEMS07 data set, and a total of 150 epochs. Enable data shuffling, reduce the learning rate to 0.1 times at 20 and 25 epochs, save the model every 5 epochs, and select the optimal model based on the validation set.
[0268] The experimental platform is PyTorch1.9.0, Python3.8, the hardware is Intel i5-13600KF, RTX 4070Super (12GB), 32GB memory, Ubuntu 20.04. All comparative model parameters are trained under the same data division and prediction scheme to ensure fair comparison.
[0269] Three commonly used evaluation indicators in traffic flow prediction tasks are selected to evaluate the prediction accuracy of the model.
[0270] MAE: Mean Absolute Error, which is the average of the absolute errors of all individual observations and predicted values.
[0271] RMSE: Root Mean Square Error, which is the square root of the average of the errors of all individual observations and predicted values.
[0272] MAPE: Mean Absolute Percentage Error, which is the average of the relative errors obtained by dividing the absolute error of each point by the true value.
[0273] The lower the value of the three indicators, the better the prediction performance of the model.
[0274] To comprehensively evaluate the performance of the ML-STACAF of the present application, the following 12 kinds of baseline methods are selected for comparison, covering traditional methods, graph neural network models and advanced models based on attention mechanism, as follows.
[0275] SVR: Support Vector Regression model, which models the nonlinear relationship between input features, traffic flow and spatio-temporal sequence through kernel function.
[0276] ARIMA: Autoregressive Integrated Moving Average model, which is based on the statistical characteristics of time series for prediction.
[0277] DCRNN: Diffusion Convolution Recurrent Neural Network, which combines diffusion convolution and RNN technology to model spatio-temporal features.
[0278] STGCN: Spatio-Temporal Graph Convolutional Network, which integrates spatio-temporal dependencies through graph convolution and one-dimensional time convolution.
[0279] GWNet: Graph-based Neural Network, which uses diffusion convolution and adaptive adjacency matrix to capture spatial dependencies.
[0280] STID: Spatio-Temporal Interaction Decomposition model, which captures long-term trends by decomposing time and space interactions.
[0281] GMAN: Graph Multi-Attention Network, which uses multi-head attention mechanism to dynamically learn the relationship between nodes.
[0282] DGCRN: Dynamic Graph Convolutional Recurrent Network, which optimizes spatio-temporal dependency modeling through dynamic graph structure, alleviating the limitations of fixed adjacency matrix.
[0283] STWave: Transformer-based model, which converts traffic data into wave signals, suitable for short-term prediction.
[0284] PDFormer: A prediction model based on Transformer, combining dynamic decomposition and attention mechanism to model spatio-temporal features.
[0285] STAEformer: A model combining label embedding and self-attention mechanism to enhance dynamic pattern learning ability.
[0286] DTRformer: A Transformer model for modeling multi-scale features through dynamic decomposition to predict long sequences.
[0287] To verify the effectiveness of ML-STACAF in the traffic flow prediction task, ML-STACAF and the above-mentioned baseline methods are comprehensively experimented on PEMS04, PEMS07 and PEMS08 datasets.
[0288] The detailed performance comparison of ML-STACAF and various baseline methods on the three datasets is shown in the following table:
[0289]
[0290] As can be seen from the comparison results in the table, on the three datasets, the prediction accuracy of the ML-STACAF model provided by the application is superior to that of the 12 baseline methods, which shows that the ML-STACAF model provided by the application can jointly model and efficiently predict spatio-temporal dependence and non-stationary mutations in various complex traffic scenarios, facilitating the connection with traffic management systems.
[0291] Ablation experiment:
[0292] In order to evaluate the effectiveness of different modules in ML-STACAF, ablation experiments are performed on PEMS04, PEMS07 and PEMS08 datasets, and the following four variant models are designed for comparative analysis:
[0293] (a) w / o : Remove adaptive embedding from ML-STACAF, only use time embedding and day embedding;
[0294] (b) w / o LDS: Remove local mutation-aware attention from ML-STACAF, only use parallel time attention and spatial attention;
[0295] (c) w / o TIFM: Remove super-domain interaction fusion module from ML-STACAF, only use addition for feature fusion;
[0296] (d) w / o LDS&TIFM: Remove local mutation-aware attention and super-domain interaction fusion module from ML-STACAF, only use addition to add the processing results of the spatio-temporal attention module.
[0297] In addition to the above differences, the specific settings of all variant models are consistent with ML-STACAF. The experimental results are shown in Table 1. Figures 3-5
[0298]
[0299] From the results of the ablation experiment data, it can be determined that the dynamic multi-level feature embedding module can effectively capture periodic patterns. The local mutation perception attention module accurately models the spatio-temporal dependence and local mutations. The super-domain interaction fusion module enhances feature fusion through cross-attention and gating mechanisms, which collectively improves prediction accuracy.
[0300] Hyperparameter sensitivity analysis:
[0301] To analyze the influence of hyperparameters on model performance, hyperparameter sensitivity analysis was conducted on the PEMS04, PEMS07, and PEMS08 datasets, focusing on testing the impact of the number of attention heads and embedding dimensions on prediction performance. The experimental settings were consistent with Example 1.
[0302] The number of attention heads ranged from {2, 4, 6, 8, 10}, and the embedding dimension ranged from {32, 64, 96, 128, 160}. When testing a single hyperparameter, other parameters were fixed at the optimal value (based on the MAE performance of the PEMS04 dataset).
[0303] The experimental results show that on the PEMS04 and PEMS08 datasets, when the number of attention heads is 4 or 6, the MAE and RMSE performance of the model is relatively stable, with a fluctuation amplitude of less than 1.5%; when the number of attention heads increases to 10, the performance decreases slightly, with an increase in MAE of about 2.3%, possibly due to excessive attention heads introducing redundant calculations. When the embedding dimension is between 64 and 128, the model performance is optimal, for example, on the PEMS07 dataset, when the embedding dimension is 96, the MAE reaches the lowest value, which is about 3.1% higher than when the dimension is 32, and when the dimension increases to 160, the performance decreases slightly by about 1.8%, indicating that too high an embedding dimension may lead to overfitting.
[0304] On the PEMS07 dataset, the combination of 6 attention heads and 96 embedding dimensions achieved the optimal MAE performance, which was about 2.1% higher than that of 2 or 10 heads. In addition, by analyzing the weight distribution of the time attention, spatial attention, and local mutation perception attention in the STLDSA module, it was found that when the number of attention heads was 6, the weight distribution of each attention mechanism was more balanced, effectively capturing the characteristics of peak periods and mutation points. These results show that appropriate hyperparameter settings can optimize the model's expressive power and computational efficiency, suitable for the prediction needs of complex traffic scenarios. The specific hyperparameter analysis diagram of each part is shown in Figures 6-9 .
[0305] Visualization analysis:
[0306] To further verify the modeling ability of ML-STACAF for local disturbances, the prediction results of some key nodes were visualized, as shown in Figures 10-12 . The figure shows the trend of the true value and the ML-STACAF model prediction value in a certain time period, with the horizontal axis representing the time step and the vertical axis representing the traffic flow. It can be observed that at some time points, the true flow has obvious fluctuations or sudden drops. However, ML-STACAF shows rapid response capability and minimal error, accurately capturing local mutation characteristics. This advantage mainly comes from the introduction of the time-space and local mutation perception attention module inside the model, which explicitly models the disturbance characteristics of different time steps and spatial nodes, guiding the model to focus on mutation positions and improving the perception ability of non-stationary components. At the same time, the super-domain interaction fusion mechanism further enhances the information transmission efficiency between time, space, and disturbance characteristics, avoiding the dilution of local information in the global modeling process.
[0307] To further demonstrate the accuracy and reliability of the ML-STACAF model in the traffic flow prediction task, Figure 13 the corresponding relationship between the prediction value and the true value of the ML-STACAF model on the PEMS08 dataset is presented in the form of a scatter plot, which intuitively reflects the fitting distribution characteristics of the model within the full sample range. The high concentration of data points near the diagonal line indicates that the model has strong generalization ability at different flow levels, which helps to comprehensively evaluate the overall prediction performance and stability of the model in complex traffic scenarios.
[0308] In addition, Figure 14 the visualization analysis of the adaptive embedding of the ML-STACAF model is presented. Figure 13The left plot of Fig. 1 employs the t-SNE technique to map the high-dimensional embedding of sensor nodes into a two-dimensional space, and the significant clustering structure reflects the spatial correlation patterns in the traffic network. These naturally formed clusters embody the similarity of nodes with close geographical locations in the feature space, verifying that the model effectively captures the topological structure and spatial dependence of the road network. Figure 13 The right plot of Fig. 1 demonstrates the modeling capability of the model on time series features, and the heat map reveals the correlation strength distribution between consecutive 12 time steps. It is evident that there is a high correlation between adjacent time steps, and as the time interval increases, the correlation decays regularly, which is highly consistent with the inherent temporal regularity of traffic flow evolution. Through this refined spatio-temporal embedding mechanism, the ML-STACAF achieves accurate modeling of complex spatio-temporal dependence patterns in traffic data.
Claims
1. A traffic flow prediction method based on multi-level spatiotemporal and perception fusion, characterized in that, It includes the following steps: Step 1: Construct a dynamic multi-level feature embedding module: This module embeds the input traffic flow data... By fusing periodic labels and adaptive feature vectors, a high-dimensional feature representation is generated. The periodic labels include intraday time slice indexes and intraweek date indexes, where T is the number of time steps, N is the number of nodes, and C is the feature dimension before fusion. The total embedding dimension after fusion; The adaptive feature vector is an adaptive embedding optimized through end-to-end backpropagation. ,in, For adaptive embedding dimensions; Step 2: Construct a spatiotemporal and local mutation-aware attention module: based on the features output in Step 1. Temporally dependent features are extracted through temporal attention, spatial attention, and local mutation perception attention mechanisms, respectively. Spatial dependence features and local mutation sensing features All three dimensions are ; Among them, the local mutation sensing feature Extracted through local mutation-aware attention mechanisms, including: For input features At each time step t and node n, a local spatiotemporal window W is defined; wherein, the input features The output features of step 1 ; Calculate the mean of the features within this window. and variance : ; ; in, This represents the total number of elements within the window. Trend estimation is calculated using Gaussian weighted moving average. : ; in, , The hyperparameters are Gaussian kernel parameters; The variance and trend are input into a multilayer perceptron to generate an adaptive smoothing factor. : MLP (Var, Trend); use For input features Perform smoothing: MOTHER ; Wherein, EMA(·) is the exponential moving average function, used to smooth out abnormal fluctuations, and its calculation formula is: MOTHER ; A multi-head attention mechanism is applied to the smoothed features, as follows: Perform a linear transformation on the features to generate a query matrix. Key matrix Sum matrix : ; in Let h be the linear projection matrix, and h be the number of attention heads. For the i-th attention head, calculate the local mutation-aware attention output: head softmax ; in, , and These represent query matrices respectively. Key matrix Sum matrix After segmenting along the feature dimension, the query submatrix, key matrix, and value submatrix are assigned to the i-th attention head; The outputs of h heads are concatenated and linearly mapped to obtain the local mutation-aware feature as the final output. : Concat ; in, To output the projection matrix; Step 3: Construct a hyperdomain interaction fusion module: Integrate the time-dependent features output in step 2. Spatial dependence features and local mutation sensing features Generate a unified spatiotemporal feature representation. ; Step 4: Construct the output layer; combine the fused features output in step 3. A traffic flow prediction sequence is generated by mapping linear layers and nonlinear activation functions. ,in P represents the number of time steps for prediction, and P represents the dimension of the prediction. Step 5, Model Training and Prediction: Using the mask mean absolute error as the loss function, the model parameters are optimized using the gradient descent algorithm to obtain the final prediction model and perform traffic flow prediction.
2. The traffic flow prediction method as described in claim 1, characterized in that, Step 1 specifically includes: The original feature embedding is generated through a fully connected layer. FC ,in For the embedding dimension, FC This is a fully connected operation; Generate intra-weekly periodic embeddings using a learnable embedding matrix. and intraday cycle embedding ; Optimize adaptive embedding through end-to-end backpropagation The adaptive feature vector is obtained. By concatenating the above embeddings along the feature dimension, we obtain the comprehensive feature representation: ; in, , This indicates a concatenation operation along the feature dimension. For the total embedding dimension.
3. The traffic flow prediction method as described in claim 1, characterized in that, The local mutation perception features are extracted using a local mutation perception attention mechanism. Previously, step 2 also included: Step 2.1: Extract time-dependent features using a time attention mechanism. : For input features Perform a linear transformation to generate the query matrix. Key matrix Sum matrix : ; Among them, the weight matrix h represents the number of attention heads; For the i-th attention head, calculate the temporal attention output: ; in, and These represent query matrices respectively. Key matrix Sum matrix After segmenting along the feature dimension, the query submatrix, key matrix, and value submatrix are assigned to the i-th attention head; The outputs of h attention heads are concatenated and linearly mapped to obtain the temporal features. : Concat ; in, To output the projection matrix; Step 2.2: Extract spatial dependency features using spatial attention mechanism : For input features Perform a linear transformation to generate the query matrix. Key matrix Sum matrix : ; Among them, the weight matrix Let h be the linear projection matrix, and h be the number of attention heads; For the i-th attention head, calculate the spatial attention output: softmax ; in, , and These represent query matrices respectively. Key matrix Sum matrix After segmenting along the feature dimension, the query submatrix, key matrix, and value submatrix are assigned to the i-th attention head; The outputs of h heads are concatenated and linearly mapped to obtain spatial features. : Concat ; in, This is for outputting the projection matrix.
4. The traffic flow prediction method as described in claim 1, characterized in that, Step 3 specifically includes: Step 3.1, Time-dependent features Spatial dependence features and local mutation sensing features Perform linear processing to generate feature representations of uniform dimension. : ; in, This represents the unified feature representation before fusion, serving as part of the input for subsequent interactive fusion modules; Step 3.2: Calculate time-dependent features using a cross-attention mechanism. Spatial dependence features and local mutation sensing features The two-way interaction between them: ; ; ; in, It is a linear projection matrix. These represent query matrices for time, space, and local mutation sensing features, respectively. Key matrices representing temporal, spatial, and local mutation-sensing features, respectively. Value matrices representing temporal, spatial, and local mutation sensing features, respectively; Step 3.3: Calculate cross-domain interaction features to capture deep-level correlations between temporal, spatial, and local mutation perception features: ; ; ; ; in, These are the fused representations of temporal features, spatial features, and local mutation perception features after passing through a cross-attention mechanism. The unified interactive features are the result of combining the three elements. For the number of attention heads, For the fusion weight matrix; Step 3.4: Introduce a multi-scale gating fusion mechanism to dynamically adjust the weights of feature fusion. ; ; ; Where GAP(·) represents the global average pooling operation, used to extract global statistical information of features. For learnable weight factors, DilatedConv(·) represents multi-scale dilated convolution, where the dilation rate varies with scale; Step 3.5: Fuse the features before fusion with the multi-source interaction features to generate the final output. : ; ; ; Among them, LayerNorm(·) represents the layer normalization operation.
5. The traffic flow prediction method as described in claim 1, characterized in that, Step 4 specifically involves: ; ; in, For hidden layer feature representation, Linear(·) represents a linear transformation, and ReLU(·) is the activation function used to introduce nonlinear characteristics to enhance the model's ability to express nonlinear relationships. This is the weight matrix. This is the bias vector.
6. The traffic flow prediction method as described in claim 1, characterized in that, Step 5 specifically includes: The mean absolute error of the mask is used as the loss function: ; in, and These are the predicted value and the actual value, respectively. It is a mask matrix; The optimization process uses the Adam optimizer, and the optimizer's hyperparameters include the initial learning rate. and weight decay By adjusting the learning rate and regularization parameters to balance convergence speed and model generalization ability, a multi-step learning rate scheduling strategy is introduced during the optimization process. At the 30th, 50th, and 80th epochs, the learning rate is decayed to 0.5 times, 0.25 times, and 0.1 times the original value, respectively. ; in, For the first Learning rate per epoch The initial learning rate, Indicates rounding down; The training process was set to 150 epochs, the batch size on the PEMS04 and PEMS08 datasets was set to 16, the batch size on the PEMS07 dataset was set to 1, and data shuffling was enabled to mitigate the risk of overfitting. The model saved checkpoints at the end of each epoch, and the optimal model parameters were selected based on the Masked MAE metric of the validation set. The maximum gradient norm is set to 1.0, gradient clipping is applied to prevent gradient explosion, and the optimal model parameters are selected based on the Masked MAE metric of the validation set.
7. An apparatus comprising a memory, a processor, and a computer program stored in the memory, characterized in that, When the processor executes the program, it implements the traffic flow prediction method according to any one of claims 1-6.
Citation Information
Patent Citations
Non-stationary traffic prediction method based on wave flow decomposition and time delay perception
CN120409841A
Traffic flow prediction method based on multi-model network coupling
CN118675338A
Traffic flow prediction method based on time-space synchronization embedded graph Transform model
CN120071622A