A traffic flow prediction method based on multi-scale lead-lag relationship modeling
By constructing a multi-scale lead-lag relationship model, using dynamic time warping and spectral clustering algorithms to build a spatial graph, and combining multi-scale feature extraction and graph convolution technology, the traffic flow prediction problem at different time steps and spatial scales is solved, and the prediction accuracy is improved.
Patent Information
- Application Number
- CN202411537183.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2044-10-31
AI Technical Summary
Existing traffic flow forecasting methods fail to effectively model the lead-lag relationship between different time steps and at different spatial scales, resulting in insufficient prediction accuracy.
A multi-scale lead-lag relationship model is constructed, and a spatial graph is constructed through the dynamic time warping algorithm and spectral clustering algorithm. Multi-scale feature extraction, lead-lag masking and graph convolution technology are combined to learn and fuse multi-scale lead-lag features, and prediction is performed considering the dynamic attenuation effect.
It improves the accuracy and reliability of traffic flow forecasts and can better serve the construction of intelligent transportation systems and smart cities.
Smart Images

Figure CN119399954B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of intelligent transportation systems, and in particular relates to a traffic flow prediction method based on multi-scale lead-lag relationship modeling. Background Art
[0002] Traffic flow prediction plays a crucial role in intelligent transportation systems and is a core technology for smart city development. Accurate traffic flow predictions can effectively dispatch transportation resources, alleviate traffic congestion, and provide reliable advice for citizens' daily travel. Consequently, traffic flow prediction has become a research hotspot in both academia and industry.
[0003] Due to the complex temporal and spatial relationships within traffic flow sequences, accurately predicting traffic flow presents significant challenges. Over the past few decades, traffic flow prediction methods have evolved from statistical methods to deep learning-based methods. Due to their powerful representational capabilities, deep learning methods have become the mainstream approach for traffic flow prediction. These methods can be divided into two categories based on whether they consider the traffic flow of other sensors when predicting the traffic flow of each vehicle flow sensor. The first category typically uses models such as recurrent neural networks (RNNs), convolutional neural networks (CNNs), attention networks (ATNs), and multi-layer perceptrons (MLPs). These methods predict traffic flow by modeling the temporal relationships between each sensor at different time steps. The second category, typically based on models such as ANNs, MLPs, and graph neural networks (GNNs), predicts traffic flow by modeling the spatial relationships between traffic flows from each sensor. However, most existing methods focus solely on the relationships between sensor traffic flows at different time steps, or the relationships between traffic flows from each sensor within the same time step, while ignoring the lead-lag relationships between traffic flows from each sensor at different time steps.
[0004] In traffic flow forecasting, lead-lag relationships manifest themselves in multiple ways. For example, when a traffic accident occurs in a certain area, traffic sensors at the accident site will quickly record a drop in traffic flow, while sensors farther away from the accident site may only begin to reflect traffic changes after several minutes. Therefore, modeling lead-lag relationships is crucial for analyzing and understanding the dynamic changes in traffic flow across the entire road network. Currently, a small number of methods exist specifically for modeling lead-lag relationships. For example, the Dynamic Time Warping (DTW) algorithm or the cross-correlation function are used to calculate the similarity of two different series at different time delays. If the similarity is high at a certain time delay, it can be assumed that a lead-lag relationship exists between the two series. However, these methods only focus on lead-lag relationships at a single spatial scale and ignore lead-lag relationships at different spatial scales.
[0005] Therefore, it is necessary to provide a traffic flow prediction method that can comprehensively consider the lead-lag relationship at different spatial scales to improve the accuracy and reliability of traffic flow prediction, and thus better serve the construction of intelligent transportation systems and smart cities. Summary of the Invention
[0006] In view of the above, the purpose of this invention is to provide a traffic flow prediction method based on multi-scale lead-lag relationship modeling. This method utilizes the temporal similarity between traffic flow sequences to construct different spatial scales. At each scale, by combining predefined rules with a learnable graph structure, a multi-scale lead-lag graph is introduced. Furthermore, the dynamically decaying lead-lag effect is considered to effectively model and utilize the lead-lag relationship between features, thereby further improving the accuracy of traffic flow prediction. In the context of smart cities, this invention has broad application prospects in areas such as traffic resource scheduling, road network planning, and travel route recommendation.
[0007] To achieve the above-mentioned purpose, the present invention provides the following technical solutions:
[0008] An embodiment of the present invention provides a traffic flow prediction method based on multi-scale lead-lag relationship modeling, comprising the following steps:
[0009] Calculate the similarity between the original traffic flow sequences and the similarity between the normalized traffic flow sequences to construct the original spatial graph, and then construct spatial graphs at different spatial scales and allocation matrices at different spatial scales based on the original spatial graph;
[0010] A traffic flow prediction model is constructed, which includes a multi-scale feature extraction module, a multi-scale lead-lag mask construction module, a multi-scale lead-lag graph learning module, a multi-scale lead-lag graph convolution module, and a prediction module. In the multi-scale feature extraction module, multi-scale features are extracted from the selected standardized traffic flow sequence.
[0011] In the multi-scale lead-lag mask construction module, a multi-scale lead-lag mask is constructed based on the distribution matrix and spatial graph at different spatial scales based on the mutual correlation coefficient and Granger causality test;
[0012] In the multi-scale lead-lag map learning module, the multi-scale lead-lag mask learning is combined to obtain the multi-scale lead-lag map;
[0013] In the multi-scale lead-lag graph convolution module, an attenuated multi-scale lead-lag graph is constructed based on the multi-scale features and graph convolution is performed on it to obtain multi-scale lead-lag features. Graph convolution is performed on spatial graphs at different spatial scales to obtain multi-scale spatial features. The multi-scale lead-lag features and multi-scale spatial features are fused to obtain updated multi-scale features.
[0014] In the prediction module, predictions are made at each scale based on the updated multi-scale features, and the multi-scale prediction results are integrated to obtain the final traffic flow prediction result;
[0015] All standardized traffic flow sequences are used to train the traffic flow prediction model, and the trained traffic flow prediction model is used to predict traffic flow.
[0016] Preferably, the calculating the similarity between the original traffic flow sequences and the similarity between the normalized traffic flow sequences to construct the original spatial graph includes:
[0017] Using the dynamic time warping algorithm, calculate all original traffic flow sequences X raw The similarity between the two and the traffic flow sequence after standardization The similarity between them is calculated based on the first threshold ∈ 1 and the second threshold ∈ 2 The first spatial graph D is constructed respectively 1 and the second spatial graph D 2 , the calculation formula is as follows:
[0018]
[0019] Among them, DTW(·) is the dynamic time warping algorithm;
[0020] D 1 and D 2 Take the intersection and get the original space graph D.
[0021] Preferably, constructing the spatial graphs at different spatial scales and the allocation matrices at different spatial scales based on the original spatial graph includes:
[0022] The spectral clustering algorithm is used to hierarchically group the original spatial graph D. The calculation formula is as follows:
[0023] S s =SpectralClustering(N s ,D s-1 )
[0024] Among them, SpectralClustering(·) is the spectral clustering algorithm, N s is the number of groups corresponding to scale s, D s-1 is the spatial graph corresponding to scale s-1, is the distribution matrix corresponding to scale s, indicating the distribution of the sequence of scale s-1 to the group of scale s, and finally obtaining the distribution matrix S at different spatial scales 1 ,S 2 ,…,S S , where S is the total number of spatial scales;
[0025] Spatial graph D at scale s s It is calculated based on the spatial graph of scale s-1 and the allocation matrix corresponding to scale s. The calculation formula is as follows:
[0026] D s =(S s ) T D s-1 S s
[0027] in, The edges in the graph represent the spatial relationship between groups under scale s. When s = 0, D 0 =D, which is the original spatial map, and finally the spatial maps D, D at different spatial scales are obtained. 1 ,…,D S .
[0028] Preferably, the step of extracting multi-scale features from the selected normalized traffic flow sequence in the multi-scale feature extraction module includes:
[0029] For scale s, the corresponding traffic flow sequence X s , the calculation formula is as follows:
[0030]
[0031] in, Is of shape 1×N s-1 The one-hot vector of X, when s=0, 0 That is, the original normalized traffic flow sequence, and finally the multi-to-multi-scale traffic flow sequence is extracted;
[0032] The obtained multi-scale traffic flow sequence is feature coded, where for scale s, the segment length is p s , divide each sequence into P s Duan, P s =T / p s , T is the time window size. For each small sequence, the features extracted by the linear layer are calculated as follows:
[0033]
[0034] Among them, MLP(·) is a multi-layer perceptron, is the segmented sequence under scale s, is the extracted feature, d is the feature dimension, and finally multi-scale features at all spatial scales are obtained.
[0035] Preferably, the multi-scale lead-lag mask construction module constructs a multi-scale lead-lag mask based on the distribution matrix and the spatial graph at different spatial scales based on the mutual correlation coefficient and Granger causality detection, including:
[0036] For any sequence at scale s+1, according to the distribution matrix S at scale s, s , filter out the subsequences under scale s that belong to any sequence under scale s+1, and for these subsequences, according to the spatial graph D under scale s s , screen out adjacent subsequence pairs, calculate their mutual correlation coefficient, if the mutual correlation coefficient is greater than the threshold, then perform Granger causality test on the subsequence pairs, calculate the F-test coefficient of the subsequence pairs, if the F-test coefficient is greater than the threshold, it is considered that there is a lead-lag relationship between the subsequence pairs, which is used to construct a multi-scale lead-lag mask and record the corresponding lag time step.
[0037] Preferably, the multi-scale lead-lag map learning module is combined with multi-scale lead-lag mask learning to obtain the multi-scale lead-lag map, comprising:
[0038] For scale s, first, the learnable sequence embedding representation is randomly initialized and temporal embedding representation where N s is the number of sequences under scale s, P s is the number of segments of each sequence, d e is the number of dimensions of the embedding representation; secondly, the degree of the spatial graph at the corresponding scale, the out-degree and in-degree of the leading-lag mask are calculated, and the center embedding representation is learned based on these three The calculation formula is as follows:
[0039]
[0040] in, Represents the sequence n in the spatial graph D under scale s s The degree of and Indicates the sequence n under the leading and lagging mask M at scale s s The out-degree and in-degree of is the central embedding representation of sequence n;
[0041] Use the sequence embedding representation of all sequences at scale s Temporal Embedding Representation and center embedding representation For graph learning, the calculation formula is as follows:
[0042]
[0043] G s =softmax(relu(E s (E s ) T ))
[0044] in, represents addition with propagation mechanism, relu(·) is ReLU activation function, softmax(·) is Softmax function, is the node embedding representation of fusion at scale s, the superscript T is transposed, is the fully connected graph learned at scale s;
[0045] Three sparsification rules are used to s Perform sparse processing in sequence, retain only the leading and lagging relationships with spatial relationships between sequences, and convert G s Set it to upper triangle form, and then retain the K edges with the largest edge weights in the graph to obtain the sparse graph
[0046] According to the leading lag mask M s , build a connection graph G s′ with C s Combined, we get the final lead-lag graph, calculated as follows:
[0047] A s =G s′ +wC s
[0048] in, is the lead-lag map at scale s, w is the learnable weight, and finally the multi-scale lead-lag maps at different spatial scales are learned.
[0049] Preferably, the step of constructing an attenuated multi-scale lead-lag graph according to the multi-scale features in the multi-scale lead-lag graph convolution module and performing graph convolution on the attenuated multi-scale lead-lag graph to obtain the multi-scale lead-lag features includes:
[0050] Based on the calculated multi-scale features, the attention mechanism is used to dynamically adjust the weights of the edges in the lead-lag graph. For scale s, the calculation formula is as follows:
[0051] Q s =Linear1(H s ), K s =Linear2(H s )
[0052]
[0053] Among them, Q s is the query in the attention mechanism, Linear1(·) is to find Q s The corresponding linear layer, K s is the key value in the attention mechanism, Linear2(·) is to find K s The corresponding linear layer, d is the dimension of the feature vector, the superscript T is the transpose, A s′ A dynamic lead-lag diagram considering multi-scale features;
[0054] According to the lag time interval, the dynamic lead-lag graph is further adjusted using the decay function. The calculation formula is as follows:
[0055] Λ s =1-β s exp(γ s Δt)
[0056] α s =A s′ ⊙Λ s
[0057] Among them, Δt is the time interval between the historical time step and the current time step, β s and γ s is the parameter of the decay function, is the attenuation coefficient calculated based on the attenuation function and time interval, α s This is the dynamic lead-lag diagram after considering the attenuation effect;
[0058] In α s Graph convolution is performed on the graph, and the calculation formula is as follows:
[0059]
[0060] in, is the updated lead-lag feature under scale s, is the identity matrix, It is a multi-layer perceptron, and finally performs graph convolution based on the multi-scale lead-lag graph to obtain the multi-scale lead-lag features.
[0061] Preferably, performing graph convolution on spatial graphs at different spatial scales to obtain multi-scale spatial features includes:
[0062] At scale s, in the spatial graph D s Graph convolution is performed on the graph, and the calculation formula is as follows:
[0063]
[0064] in, is the updated spatial feature at scale s, is the identity matrix, It is a multi-layer perceptron, and finally multi-scale spatial features are obtained by performing graph convolution on spatial graphs at different spatial scales.
[0065] Preferably, fusing the multi-scale lead-lag feature and the multi-scale spatial feature to obtain the updated multi-scale feature includes:
[0066] The multi-scale leading and lagging features and the multi-scale spatial features are integrated. For scale s, the calculation formula is as follows:
[0067]
[0068] in, is the fusion feature of the output scale s, λ1 and λ2 are learnable weights, is the fusion feature at scale s output by the previous network, i.e., the residual, and finally the updated multi-scale features at all spatial scales are obtained.
[0069] Preferably, the prediction module performs prediction at each scale based on the updated multi-scale features, and fuses the multi-scale prediction results to obtain the final traffic flow prediction result, including:
[0070] For scale s, It is fed into a predictor composed of multiple layers of MLP and the calculation formula is as follows:
[0071]
[0072] Among them, Predictor(·) is the predictor, N under scale s s The prediction results of the H-step sequence are integrated with the prediction values of each scale to obtain the final prediction result. The calculation formula is as follows:
[0073]
[0074] Among them, S s is the distribution matrix under scale s, l is the index of the number of cumulative multiplications, and the superscript T is the transpose. is the predicted value of the traffic flow sequence obtained at the original scale, is the final prediction result.
[0075] This invention combines predefined rules with graph learning techniques to model directed and sparse multi-scale lead-lag relationships in traffic flow sequences, taking into account the dynamically attenuated lead-lag effect and effectively utilizing the multi-scale lead-lag relationship. Compared with existing technologies, this invention has at least the following advantages:
[0076] (1) This paper designs a multi-scale lead-lag graph learning module. It combines predefined multi-scale lead-lag masks based on cross-correlation and Granger causality to learn lead-lag graphs at various scales. The learned graphs are then sparsified to model directed and sparse lead-lag relationships between features.
[0077] (2) The present invention designs a multi-scale lead-lag graph convolution module, combines the attention mechanism and the attenuation function, considers the lead-lag effect of dynamic attenuation, performs graph convolution on the multi-scale lead-lag graph, and updates the multi-scale features. BRIEF DESCRIPTION OF THE DRAWINGS
[0078] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0079] Figure 1 This is an overall flow chart of a traffic flow prediction method based on multi-scale lead-lag relationship modeling provided by an embodiment of the present invention;
[0080] Figure 2 This is an overall framework diagram of a traffic flow prediction method based on multi-scale lead-lag relationship modeling provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0081] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and do not limit the scope of protection of the present invention.
[0082] The inventive concept of the present invention is as follows: to address the problem of how to model the lead-lag relationship at multiple spatial scales in traffic flow sequences in the prior art, an embodiment of the present invention provides a traffic flow prediction method based on multi-scale lead-lag relationship modeling. First, the traffic flow sequence is preprocessed and samples are divided using a sliding window method based on chronological order to construct a data set. Second, a multi-scale feature extraction module is introduced to extract features from the traffic flow sequence at each spatial scale. Then, a multi-scale lead-lag mask construction module is introduced to predefine the lead-lag relationship between features at each scale based on the cross-correlation and Granger causality between multi-scale features. Next, a multi-scale lead-lag graph learning module is introduced to learn the lead-lag graph at each scale in combination with the multi-scale lead-lag mask to model the directed and sparse lead-lag relationship between features. Then, a multi-scale lead-lag graph convolution module is introduced to perform graph convolution on the multi-scale lead-lag graph, considering the dynamically attenuated lead-lag effect, and update the multi-scale features. Finally, the updated multi-scale features are used to make predictions at each scale, and the multi-scale prediction results are fused to obtain the final traffic flow prediction result.
[0083] Figure 1 This is an overall flow chart of a traffic flow prediction method based on multi-scale lead-lag relationship modeling provided by an embodiment of the present invention. Figure 2 This is a general framework diagram of a traffic flow prediction method based on multi-scale lead-lag relationship modeling provided by an embodiment of the present invention. Figure 1 and Figure 2 As shown, the embodiment provides a traffic flow prediction method based on multi-scale lead-lag relationship modeling, comprising the following steps:
[0084] Step 1: Process the given raw traffic flow sequence to eliminate outliers and missing values. Standardize the cleaned data. Based on the time sequence, use the sliding window method to divide the standardized data into samples to construct a dataset.
[0085] Remove outliers (such as values outside the normal range) from the given original traffic flow sequence, and use linear interpolation to interpolate missing values. Perform z-score normalization on the cleaned data, and the calculation formula is as follows:
[0086]
[0087] Among them, X i,raw is the original traffic flow sequence of the i-th item, μ i,raw is the average value in the original traffic flow sequence of the i-th item, σ i,raw is the variance of the original traffic flow sequence of the i-th item, X i is the traffic flow sequence after standardization of the i-th item.
[0088] Based on the time sequence, the time window size T is set manually according to experience, and the standardized data is divided into samples using a fixed-length sliding step to construct a data set.
[0089] Step 2: Calculate the similarity between the traffic flow sequences collected by all traffic flow sensors in the dataset. Represent traffic flow sensors as nodes and similarity values as edges to construct the original spatial graph D.
[0090] Using the DTW algorithm, the similarity between the original traffic flow sequences in the dataset and the similarity between the standardized traffic flow sequences are calculated. According to the corresponding threshold, the DTW similarity greater than the threshold is set to 1, and the DTW similarity less than the threshold is set to 0. The calculation formula is as follows:
[0091]
[0092] Among them, X raw and are the original traffic flow sequence and the standardized traffic flow sequence respectively. ∈ 1 and ∈ 2 is the corresponding threshold, and D 1 and D 2 Take the intersection and get the final original space graph D.
[0093] Step 3: Use the spectral clustering algorithm to perform hierarchical clustering on the original spatial graph D to obtain spatial graphs D, D at different spatial scales. 1 ,…,D S and the corresponding allocation matrix S 1 ,S 2 ,…,S S .
[0094] The spectral clustering algorithm is used to hierarchically group the original spatial graph D. The calculation formula is as follows:
[0095] S s =SpectralClustering(N s ,D s-1 ), (3)
[0096] Among them, SpectralClustering(·) is the spectral clustering algorithm, N s is the number of groups corresponding to scale s, D s-1 is the spatial graph corresponding to scale s-1, is the distribution matrix corresponding to scale s, indicating the distribution of the sequence of scale s-1 to the group of scale s, and finally obtaining the distribution matrix S at different spatial scales 1 ,S 2 ,…,S S, where S is the total number of spatial scales.
[0097] Spatial graph D at scale s s It is calculated based on the spatial graph of scale s-1 and the allocation matrix corresponding to scale s. The calculation formula is as follows:
[0098] D s =(S s ) T D s-1 S s , (4)
[0099] in, The edges in the graph represent the spatial relationship between groups under scale s. When s = 0, D 0 =D, which is the original spatial map, and finally the spatial maps D, D at different spatial scales are obtained. 1 ,…,D S .
[0100] Step 4: Divide the dataset into batches according to a fixed batch size, with a total batch size of B.
[0101] The data set is divided into batches based on the batch size M set by experience. The total number of batches is B. The calculation formula is as follows:
[0102]
[0103] Among them, N Samples is the total number of samples in the dataset.
[0104] Step 5: Randomly select a batch of training samples from the data set, where each sample contains the traffic flow sequence of N traffic flow sensors on the traffic network for T time steps.
[0105] Step 6: Using the traffic flow sequence X and the distribution matrix S at the original spatial scale 1 ,S 2 ,…,S S , calculate the multi-scale traffic flow sequence X 1 ,X 2 ,…,X S , and perform feature encoding on the multi-scale traffic flow sequence to obtain multi-scale features.
[0106] For scale s, the corresponding traffic flow sequence X s , the calculation formula is as follows:
[0107]
[0108] in, Is of shape 1×N s-1The one-hot vector of X, when s=0, 0 This is the original traffic flow sequence.
[0109] For the obtained multi-scale traffic flow sequence, feature encoding is performed. Specifically, for each scale, the traffic flow sequence is segmented according to different segment lengths. For scale s, the segment length is p s , each sequence can be divided into P s Duan, P s =T / p s For each small sequence, the features extracted by the linear layer are calculated as follows:
[0110]
[0111] Among them, MLP(·) is a multi-layer perceptron, is the segmented sequence under scale s, is the extracted feature, d is the feature dimension, and finally multi-scale features at all spatial scales are obtained.
[0112] Step 7: For any sequence at scale s+1, according to the distribution matrix S s , filter out the subsequences belonging to the sequence under scale s. For these subsequences, according to the spatial graph D s , filter out adjacent subsequence pairs and calculate their mutual correlation coefficient. If the mutual correlation coefficient is greater than a threshold, Granger causality test is performed on the subsequence pair. If the F-test coefficient is greater than the threshold, it is considered that a lead-lag relationship exists between the subsequence pairs. This is used to construct a multi-scale lead-lag mask and record the corresponding lag time step.
[0113] Assume that under scale s, the lead-lag relationship only exists between pairs of sequences that belong to the same sequence at scale s+1 and have a spatial relationship with each other. For a sequence at scale s+1, according to the distribution matrix S s , filter out all subsequences belonging to the sequence under scale s. Then according to the spatial graph D s , and further screen out adjacent subsequence pairs from these subsequences.
[0114] For the selected subsequence pairs, calculate their mutual correlation coefficients at different lag time steps. Here, the lag time step value belongs to {0, p s ,2p s ,…,T}, that is, the values are taken as integer multiples of the segment length. If the calculated mutual correlation coefficient is greater than the threshold, Granger causality test is further performed on the subsequence pair at that lag time step, and the F-test coefficient is calculated. If the F-test coefficient is greater than the threshold, it is considered that a lead-lag relationship exists between the subsequence pairs.
[0115] After traversing all subsequence pairs at scale s, the leading and lagging masks at scale s can be constructed Specifically, if the sequence i has a leading-lagging relationship with respect to the sequence j at the lag time step τ under the scale s, then If there is no lead-lag relationship, it is recorded as 0.
[0116] In step 8, randomly initialize the learnable sequence embedding and temporal embedding representations for each scale. Calculate the spatial graph degree, the out-degree, and in-degree of the lead-lag mask at the corresponding scale, and use these to learn the center embedding. The sequence embedding, temporal embedding, and center embedding are fed into the lead-lag graph learning module and combined with the multi-scale lead-lag mask to learn a directed and sparse multi-scale lead-lag graph.
[0117] For scale s, first, the learnable sequence embedding representation is randomly initialized and temporal embedding representation where N s is the number of sequences under scale s, P s is the number of segments of each sequence, d e is the number of dimensions of the embedding representation. Secondly, the degree of the spatial graph at the corresponding scale, the out-degree and in-degree of the leading-lag mask are calculated, and the center embedding representation is learned based on these three. The calculation formula is as follows:
[0118]
[0119] in, Represents the sequence n in the spatial graph D under scale s s The degree of and Indicates the sequence n under the leading and lagging mask M at scale s s The out-degree and in-degree of .
[0120] is the central embedding representation of sequence n.
[0121] use and For graph learning, the calculation formula is as follows:
[0122]
[0123] G s =softmax(relu(Es(Es) T )), (9)
[0124] in, represents addition with propagation mechanism, relu(·) is ReLU activation function, softmax(·) is Softmax function, is the fused node embedding representation, the superscript T is transposed, is the fully connected graph for learning.
[0125] Three sparsification rules are used to s The sparse processing is performed in sequence. First, only the lead-lag relationship with spatial relationship between sequences is retained. Second, since the lead-lag relationship means that the past segment of a sequence will affect the future segment of another sequence, G s Set it to upper triangular form. Furthermore, retain the K edges with the largest weights in the graph, and get the sparse graph
[0126] According to the leading lag mask M s , build a connection graph like If is 1, is a diagonal matrix τ steps above the main diagonal.
[0127] G s′ with C s Combined, we get the final lead-lag graph, calculated as follows:
[0128] A s =G s′ +wC s , (10)
[0129] in, is the lead-lag map at scale s, w is the learnable weight, and finally the multi-scale lead-lag maps at different spatial scales are learned.
[0130] In step 9, the attention mechanism is used to dynamically adjust the edge weights in the lead-lag graph based on the multi-scale features. An exponential decay function is used to calculate the decay effect based on the lag time interval, further adjusting the edge weights in the lead-lag graph. Graph convolution is performed on the adjusted lead-lag graph to update the multi-scale lead-lag features.
[0131] According to the multi-scale feature H calculated in formula (7) s , the attention mechanism is used to dynamically adjust the weights of the edges in the leading-lagging graph. The calculation formula is as follows:
[0132]
[0133] Among them, Q s is the query in the attention mechanism, Linear1(·) is to find Q s The corresponding linear layer, K sis the key value in the attention mechanism, Linear2(·) is to find K s The corresponding linear layer, d is the dimension of the feature vector, the superscript T is the transpose, A s′ A dynamic lead-lag graph considering multi-scale features.
[0134] Next, the dynamic lead-lag graph is further adjusted using the decay function according to the lag time interval. The calculation formula is as follows:
[0135] Λ s =1-β s exp(γ s Δt),
[0136] α s =A s′ ⊙Λ s , (12)
[0137] Among them, Δt is the time interval between the historical time step and the current time step, and is the time interval between the historical time step and the current time step according to the leading lag mask M. s Calculated, β s and γ s is the parameter of the decay function, is the attenuation coefficient calculated based on the attenuation function and time interval. s This is the dynamic lead-lag diagram after considering the attenuation effect. s Graph convolution is performed on the graph, and the calculation formula is as follows:
[0138]
[0139] in, represents the updated leading-lag feature at scale s, represents the identity matrix, represents MLP.
[0140] Step 10, in the multi-scale space graph D,D 1 ,…,D S Graph convolution is performed on the multi-scale spatial features to obtain multi-scale spatial features, and the multi-scale leading and lagging features are fused with the multi-scale spatial features to obtain updated multi-scale features.
[0141] At scale s, in the spatial graph D s Graph convolution is performed on the graph, and the calculation formula is as follows:
[0142]
[0143] in, represents the updated spatial features at scale s, represents the identity matrix, Represents MLP, and finally multi-scale spatial features are obtained by performing graph convolution on spatial graphs at different spatial scales.
[0144] The updated leading and lagging features are fused with the spatial features, and the calculation formula is as follows:
[0145]
[0146] in, is the fusion feature of the output scale s, λ1 and λ2 are learnable weights, is the fusion feature at scale s output by the previous network, i.e., the residual, and finally the updated multi-scale features at all spatial scales are obtained.
[0147] In step 11, the updated multi-scale features are input into the prediction module, predictions are performed at each scale, and the multi-scale prediction results are integrated to obtain the final traffic flow prediction result.
[0148] For scale s, It is fed into a predictor consisting of two layers of MLP and the calculation formula is as follows:
[0149]
[0150] Among them, Predictor(·) is the predictor, N under scale s s The prediction results of the H-step sequence are obtained by fusing the prediction values of each scale to obtain the final prediction result. The calculation formula is as follows:
[0151]
[0152] Among them, S s is the distribution matrix calculated in step 3, l is the index of the number of times of multiplication, and the superscript T is the transpose. is the predicted value of the traffic flow sequence obtained at the original scale, is the final prediction result.
[0153] Step 12: Calculate the error between the true observation value and the model prediction value of all samples in a batch to obtain the training loss
[0154] Using mean absolute error as training loss The calculation formula is as follows:
[0155]
[0156] Among them, M is the total number of samples and m is the sample index.
[0157] Step 13, based on the training loss Adjust the network parameters in the entire model.
[0158] Based on the training loss obtained in step 12 Update the network parameters θ in the entire model, and the calculation formula is as follows:
[0159]
[0160] Among them, η is an artificially set learning rate.
[0161] Step 14: Repeat steps 5-13 until all batches in the dataset participate in model training.
[0162] Step 15: Repeat steps 5-14 until the specified number of iterations is reached.
[0163] Step 16: Input the traffic flow sequence to be predicted into the trained model to obtain the prediction result.
[0164] The specific implementation methods described above provide a detailed description of the technical solutions and beneficial effects of the present invention. It should be understood that the above is only the most preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A traffic flow prediction method based on multi-scale lead-lag relationship modeling, characterized in that: The following steps are involved: Calculate the similarity between the original traffic flow sequences and the similarity between the normalized traffic flow sequences to construct the original spatial graph, and then construct spatial graphs at different spatial scales and allocation matrices at different spatial scales based on the original spatial graph; A traffic flow prediction model is constructed, which includes a multi-scale feature extraction module, a multi-scale lead-lag mask construction module, a multi-scale lead-lag graph learning module, a multi-scale lead-lag graph convolution module, and a prediction module. In the multi-scale feature extraction module, multi-scale features are extracted from the selected standardized traffic flow sequence. In the multi-scale lead-lag mask construction module, a multi-scale lead-lag mask is constructed based on the distribution matrix and spatial graph at different spatial scales based on the mutual correlation coefficient and Granger causality test; In the multi-scale lead-lag map learning module, the multi-scale lead-lag mask learning is combined to obtain the multi-scale lead-lag map; In the multi-scale lead-lag graph convolution module, an attenuated multi-scale lead-lag graph is constructed based on the multi-scale features and graph convolution is performed on it to obtain multi-scale lead-lag features. Graph convolution is performed on spatial graphs at different spatial scales to obtain multi-scale spatial features. The multi-scale lead-lag features and multi-scale spatial features are fused to obtain updated multi-scale features. In the prediction module, predictions are made at each scale based on the updated multi-scale features, and the multi-scale prediction results are integrated to obtain the final traffic flow prediction result; All standardized traffic flow sequences are used to train the traffic flow prediction model, and the trained traffic flow prediction model is used to predict traffic flow.
2. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 1 is characterized in that: The calculating the similarity between the original traffic flow sequences and the similarity between the normalized traffic flow sequences to construct the original spatial graph includes: Using the dynamic time warping algorithm, calculate all original traffic flow sequences X raw The similarity between the two and the traffic flow sequence after standardization The similarity between them is based on the first threshold set# 1 and the second threshold ∈ 2 The first spatial graph D is constructed respectively 1 and the second spatial graph D 2 , the calculation formula is as follows: Among them, DTW(·) is the dynamic time warping algorithm; D 1 and D 2 Take the intersection and get the original space graph D.
3. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 1 is characterized in that: The step of constructing spatial graphs at different spatial scales and allocation matrices at different spatial scales based on the original spatial graph includes: The spectral clustering algorithm is used to hierarchically group the original spatial graph D. The calculation formula is as follows: S s =SpectralClustering(N s ,D s-1 ) Among them, SpectralClustering(·) is the spectral clustering algorithm, N s is the number of groups corresponding to scale s, D s-1 is the spatial graph corresponding to scale s-1, is the distribution matrix corresponding to scale s, indicating the distribution of the sequence of scale s-1 to the group of scale s, and finally obtaining the distribution matrix S at different spatial scales 1 ,S 2 ,…,S S , where S is the total number of spatial scales; Spatial graph D at scale s s It is calculated based on the spatial graph of scale s-1 and the allocation matrix corresponding to scale s. The calculation formula is as follows: D s =(S s ) T D s-1 S s in, The edges in the graph represent the spatial relationship between groups under scale s. When s = 0, D 0 =D, which is the original spatial map, and finally the spatial maps D, D at different spatial scales are obtained. 1 ,…,D S .
4. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 3 is characterized in that: The multi-scale feature extraction module extracts multi-scale features from the selected standardized traffic flow sequence, including: For scale s, the corresponding traffic flow sequence X s , the calculation formula is as follows: in, Is of shape 1×N s-1 The one-hot vector of X, when s=0, 0 That is, the original normalized traffic flow sequence, and finally the multi-to-multi-scale traffic flow sequence is extracted; The obtained multi-scale traffic flow sequence is feature coded, where for scale s, the segment length is p s , divide each sequence into P s Duan, P s =T / p s , T is the time window size. For each small sequence, the features extracted by the linear layer are calculated as follows: Among them, MLP(·) is a multi-layer perceptron, is the segmented sequence under scale s, is the extracted feature, d is the feature dimension, and finally multi-scale features at all spatial scales are obtained.
5. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 1 is characterized in that: The multi-scale lead-lag mask construction module constructs a multi-scale lead-lag mask based on the distribution matrix and the spatial graph at different spatial scales based on the mutual correlation coefficient and Granger causality detection, including: For any sequence at scale s+1, according to the distribution matrix S at scale s, s , filter out the subsequences under scale s that belong to any sequence under scale s+1, and for these subsequences, according to the spatial graph D under scale s s , screen out adjacent subsequence pairs, calculate their mutual correlation coefficient, if the mutual correlation coefficient is greater than the threshold, then perform Granger causality test on the subsequence pairs, calculate the F-test coefficient of the subsequence pairs, if the F-test coefficient is greater than the threshold, it is considered that there is a lead-lag relationship between the subsequence pairs, which is used to construct a multi-scale lead-lag mask and record the corresponding lag time step.
6. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 4 is characterized in that: The multi-scale lead-lag map learning module is combined with multi-scale lead-lag mask learning to obtain a multi-scale lead-lag map, including: For scale s, first, the learnable sequence embedding representation is randomly initialized and temporal embedding representation where N s is the number of sequences under scale s, P s is the number of segments of each sequence, d e is the number of dimensions of the embedding representation; secondly, the degree of the spatial graph at the corresponding scale, the out-degree and in-degree of the leading-lag mask are calculated, and the center embedding representation is learned based on these three The calculation formula is as follows: in, Represents the sequence n in the spatial graph D under scale s s The degree of and Indicates the sequence n under the leading and lagging mask M at scale s s The out-degree and in-degree of is the central embedding representation of sequence n; Use the sequence embedding representation of all sequences at scale s Temporal Embedding Representation and center embedding representation For graph learning, the calculation formula is as follows: G s =softmax(clock(E s (AND s ) T )) in, represents addition with propagation mechanism, relu(·) is ReLU activation function, softmax(·) is Softmax function, is the node embedding representation of fusion at scale s, the superscript T is transposed, is the fully connected graph learned at scale s; Three sparsification rules are used to s Perform sparse processing in sequence, retain only the leading and lagging relationships with spatial relationships between sequences, and convert G s Set it to upper triangle form, and then retain the K edges with the largest edge weights in the graph to obtain the sparse graph According to the leading lag mask M s , build a connection graph G s′ with C s Combined, we get the final lead-lag graph, calculated as follows: A s =G s′ +wC s in, is the lead-lag map at scale s, w is the learnable weight, and finally the multi-scale lead-lag maps at different spatial scales are learned.
7. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 6 is characterized in that: The multi-scale lead-lag graph convolution module constructs an attenuated multi-scale lead-lag graph according to the multi-scale features and performs graph convolution on the graph to obtain the multi-scale lead-lag features, including: Based on the calculated multi-scale features, the attention mechanism is used to dynamically adjust the weights of the edges in the lead-lag graph. For scale s, the calculation formula is as follows: Q s =Linear1(H s ),K s =Linear2(H s ) Among them, Q s is the query in the attention mechanism, Linear1(·) is to find Q s The corresponding linear layer, K s is the key value in the attention mechanism, Linear2(·) is to find K s The corresponding linear layer, d is the dimension of the feature vector, the superscript T is the transpose, A s′ A dynamic lead-lag diagram considering multi-scale features; According to the lag time interval, the dynamic lead-lag graph is further adjusted using the decay function. The calculation formula is as follows: L s =1-β s exp(γ s Δt) α s =A s′ ⊙ s Among them, Δt is the time interval between the historical time step and the current time step, β s and γ s is the parameter of the decay function, is the attenuation coefficient calculated based on the attenuation function and time interval, α s This is the dynamic lead-lag diagram after considering the attenuation effect; In α s Graph convolution is performed on the graph, and the calculation formula is as follows: in, is the updated lead-lag feature under scale s, is the identity matrix, It is a multi-layer perceptron, and finally performs graph convolution based on the multi-scale lead-lag graph to obtain the multi-scale lead-lag features.
8. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 7 is characterized in that: The multi-scale spatial features obtained by performing graph convolution on spatial graphs at different spatial scales include: At scale s, in the spatial graph D s Graph convolution is performed on the graph, and the calculation formula is as follows: in, is the updated spatial feature at scale s, is the identity matrix, It is a multi-layer perceptron, and finally multi-scale spatial features are obtained by performing graph convolution on spatial graphs at different spatial scales.
9. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 8 is characterized in that: The updated multi-scale features are obtained by fusing the multi-scale leading and lagging features with the multi-scale spatial features, including: The multi-scale leading and lagging features and the multi-scale spatial features are integrated. For scale s, the calculation formula is as follows: in, is the fusion feature of the output scale s, λ1 and λ2 are learnable weights, is the fusion feature at scale s output by the previous network, i.e., the residual, and finally the updated multi-scale features at all spatial scales are obtained.
10. The traffic flow prediction method based on multi-scale lead-lag relationship modeling according to claim 9 is characterized in that: The prediction module performs predictions at each scale based on the updated multi-scale features, and fuses the multi-scale prediction results to obtain the final traffic flow prediction result, including: For scale s, It is fed into a predictor composed of multiple layers of MLP and the calculation formula is as follows: Among them, Predictor(·) is the predictor, N under scale s s The prediction results of the H-step sequence are integrated with the prediction values of each scale to obtain the final prediction result. The calculation formula is as follows: Among them, S s is the distribution matrix under scale s, l is the index of the number of cumulative multiplications, and the superscript T is the transpose. is the predicted value of the traffic flow sequence obtained at the original scale, is the final prediction result.
Citation Information
Patent Citations
Traffic flow prediction method based on multi-scale spatial feature mining
CN116070778A
Urban area passenger flow volume prediction method based on big data
CN116542391A