Space-time diagram comparative learning method based on big kernel attention traffic flow prediction
Through the large-nuclear attention mechanism and the comparative learning method of time and space graph, the problem of insufficient adaptability to the topological structure of dynamic road networks in the existing traffic flow prediction technology is solved, the robustness of the model and the modeling accuracy of complex traffic patterns are improved, and the dynamic changes of urban traffic are adapted to the dynamic changes.
Patent Information
- Application Number
- CN202510648010.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2045-05-19
AI Technical Summary
Existing traffic flow prediction technologies are difficult to accurately characterize the spatial and temporal dependence of urban road networks, lack adaptability to the topology of dynamic road networks, and lack a robust processing mechanism for noise and outliers in traffic flow data, making it difficult to capture large-scale spatial dependence.
The large-core attention mechanism and the spatial-temporal graph comparison learning method are adopted, and the large-core space attention module is designed through feature-level, topological-level and time interpolated data enhancement strategies, and combined with the spatial-temporal comparison learning task, the model's perception of changes in the topological structure of the dynamic road network is improved, and the ability to generalize and portray complex traffic patterns is enhanced.
It significantly improves the robustness of the model for data loss and noise, enhances the modeling ability of the topological changes of the dynamic road network, improves the modeling accuracy and generalization of the spatial and temporal dependence of complex traffic flows, and adapts to the dynamic changes of urban traffic.
Smart Images

Figure CN120472686A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of traffic flow prediction in smart cities, and in particular to a spatiotemporal graph comparative learning method based on large-core attention traffic flow prediction. Background Art
[0002] With the acceleration of urbanization, urban traffic faces many challenges such as congestion and low management efficiency. Accurately predicting traffic flow in various areas of a city over a period of time is crucial to alleviating congestion and optimizing traffic control strategies.
[0003] Current traffic flow prediction technology has the following problems:
[0004] 1. Urban road networks are complex non-Euclidean geometric spaces. Traditional methods such as convolutional neural networks (CNNs) and recurrent neural networks (RNNs) have difficulty accurately capturing their spatiotemporal dependencies.
[0005] 2. Traffic flow data has strong temporal and spatial correlation and dynamics. Traffic conditions in different time periods (such as morning and evening rush hours) and between different regions have complex interactions.
[0006] 3. External factors (such as weather and traffic accidents) interfere with the system, and existing methods lack effective mechanisms to handle such dynamic changes.
[0007] 4. Actual traffic data often contains noise and missing values, which affects the accuracy of the prediction model.
[0008] With the recent development of information technology and artificial intelligence, traffic flow forecasting has become a key research area in intelligent transportation systems (ITS). Accurately predicting future traffic conditions is crucial for alleviating urban congestion, optimizing the travel experience, and enabling real-time regulation of transportation networks. Integrating reliable traffic forecasting into intelligent transportation systems is crucial for building a safe, efficient, and intelligent modern transportation system.
[0009] In recent years, graph neural networks (GNNs) and attention mechanisms have been introduced into the field of traffic flow prediction and have made some progress. However, existing methods still have the following shortcomings:
[0010] 1. Most of them assume that the road network topology is static and are difficult to adapt to dynamically changing road networks;
[0011] 2. Lack of robust processing mechanisms for noise and outliers in traffic flow data;
[0012] 3. The traditional attention mechanism has a limited receptive field and is unable to capture large-scale spatial dependencies, which affects its ability to model complex traffic patterns.
[0013] Therefore, key challenges in this field are how to design flexible prediction models for dynamic road networks, improve their robustness to noise and anomalies, and enhance their ability to capture large-scale spatiotemporal dependencies. This paper proposes a traffic flow prediction method based on large-core attention and spatiotemporal graph comparative learning. This method addresses these challenges by expanding the spatial receptive field through a large-core attention mechanism and optimizing representation capabilities through spatiotemporal comparative learning. Summary of the Invention
[0014] The purpose of the present invention is to overcome the above-mentioned defects in the prior art and provide a spatiotemporal graph comparative learning method for traffic flow prediction based on large-core attention. Specifically, the present invention improves the robustness of the model to data missing and noise through data augmentation strategies at the feature level, topology level and time interpolation; enhances the model's perception of changes in dynamic road network topology by designing a large-core spatial attention module; and improves the generalization and characterization capabilities of complex traffic patterns by introducing spatiotemporal comparative learning tasks and self-supervisory signals.
[0015] 1. Data augmentation strategies significantly improve the model's ability to adapt to missing and abnormal conditions in real-world traffic data;
[0016] 2. The large-core attention mechanism significantly enhances the model's ability to model dynamic road network topology changes;
[0017] 3. The spatiotemporal comparative learning task effectively improves the generalization of the model and the accuracy of modeling the spatiotemporal dependencies of complex traffic flows.
[0018] To achieve the above objectives, the present invention provides a spatiotemporal graph contrastive learning method for traffic flow prediction based on large-core attention, which includes the following steps:
[0019] Step S1: Organize the collected traffic flow data into a time series format and construct a road network spatiotemporal graph;
[0020] Step S2: Perform feature-level, topology-level, and time-interpolation data enhancement on the traffic flow data to generate an enhanced feature matrix as input for subsequent steps;
[0021] Step S3: Encode the road network spatiotemporal graph, adopt a large-core attention mechanism, extract spatiotemporal features through large-scale convolution and adaptive feature fusion, and enhance spatial dependency and temporal consistency;
[0022] Step S4: Based on the spatiotemporal representation after encoding in step S3, design contrastive learning tasks in both time and space dimensions to enhance representation learning;
[0023] Step S5: Input the spatiotemporal representation after the encoder contrast learning task into the decoder;
[0024] Step S6: The decoder uses a multi-layer perceptron structure to restore the features to traffic prediction values for multiple future time steps through a fully connected layer;
[0025] Step S8: Return to step S1 and continue training.
[0026] Preferably, in step S1, the road network spatiotemporal graph is G = (V, E, A, X), which is used to depict the topological structure and temporal characteristics of the urban road network. The construction process is as follows:
[0027] Sub-step S11: Node set V: Each node in the graph represents a monitoring unit, and the node’s feature is the traffic flow sequence of the monitoring unit at different time steps;
[0028] Sub-step S12: edge set E: Each edge in the graph represents the spatial association between two monitoring units, which can be constructed based on the road topology or the Euclidean distance between nodes;
[0029] Sub-step S13: Adjacency matrix A∈R N×N :R represents a set of real numbers, and the matrix describes the adjacency relationship between nodes. The urban space is divided into N=ixj in longitude and latitude, A ij =1 indicates that there is an edge connection between node i and node j, otherwise A ij =0;
[0030] Among them, traffic flow data X∈R T×N×2 , R T×N×2 Represents a spatiotemporal tensor containing the inflow and outflow of vehicles in N regions over the past T time steps.
[0031] Preferably, in step S2, the process of performing feature-level, topology-level, and time-interpolation data enhancement on the traffic flow data and forming an enhanced feature matrix includes the following sub-steps:
[0032] Sub-step S21: Feature-level data enhancement randomly masks traffic information of different granularities to simulate data loss caused by accidents, equipment failures, or power outages in practice. The following is the masking mechanism:
[0033]
[0034] Among them, E ij ∈R TxNx2 , E ij is a random mask with a value between 0 and 1, ε is an adjustable value, t represents the current time step, and T represents the length of the historical time window. is the original input feature matrix, is the feature-level data enhancement matrix;
[0035] Sub-step S22: Topological data enhancement introduces random topological changes by perturbing the adjacency matrix A of the graph, which includes the following two perturbation methods:
[0036] (1) Local spatial enhancement: Randomly perturb the predefined adjacency matrix A, corresponding to the formula:
[0037] M l =A⊙M t ∈R N*N
[0038] Among them, M t is the initialization matrix, M l is the local augmented matrix, ⊙ is the Hadamard product;
[0039] (2) Global spatial enhancement: self-learn a perturbation matrix and superimpose it on the original adjacency matrix, corresponding to the formula:
[0040] M g =A⊕M t ∈R N*N
[0041] Among them, M t is the initialization matrix, M g For all augmented matrices, add the matrix elements together;
[0042] Sub-step S23: Shift the data along the time axis to utilize the intermediate state between two consecutive time steps, and perform weighted averaging between the two consecutive time steps to ensure interpolation accuracy. The formula is as follows:
[0043] P (t-S):t =αX (t-S):t +(1-α)X (t-S+1):(t+1)
[0044] Among them, α is a hyperparameter adjustment between 0 and 1, (tS):t represents the time range from tS to t, (t-S+1):(t+1) represents the time range from t-S+1 to t+1, P (t-S):t Represents the new time series data generated by interpolation, X (t-S):t Represents the original time series data, X (t-S):(t+1) Represents time series data shifted backward one time step.
[0045] As a preferred embodiment, in step S3, the original feature matrix is defined as X ij , the local enhancement matrix is M l , the global enhancement matrix is M g , the step S3 specifically includes the following sub-steps:
[0046] Sub-step S31: Following the message passing and aggregation process, the spatial dependencies between nodes are encoded and the potential features are extracted from the traffic network. The local graph convolution formula can be defined as:
[0047]
[0048] in, and are the outputs of the l-1th graph convolutional layer of the local branch and the global branch respectively, and the outputs serve as the input of the lth graph convolutional layer; is the initial input, i.e., the traffic flow data after feature enhancement processing in step S2; and are the local and global adjacency matrices normalized by the degree matrix, respectively; where, is the degree matrix, which is a diagonal matrix where each diagonal element represents the degree of the corresponding node; Θ is the learnable weight parameter matrix shared by the two branches; T represents the time step, N is the number of monitoring points, and F represents the dimension of the feature vector of each node;
[0049] Sub-step S32: mining temporal dependencies and integrating them with spatial information, 1×kt standard convolution on the obtained spatial representation H l and H g Encoding;
[0050]
[0051] Among them, [1,K t ] represents the size of the convolution kernel, K t is the size of the temporal convolution kernel, and Respectively represent the local and global feature representations after time convolution processing; tanh represents the tangent function; σ represents the sigmoid function; ⊙ represents element-level multiplication; and Respectively represent the local and global feature representations after activation function processing;
[0052] Sub-step S33: In order to better obtain spatial information, obtain spatial information through the large-core spatial attention module;
[0053] Among them, the spatial receptive field is expanded by 5x5 and 7x7 depthwise separable convolutions respectively, and then the features of different scales are adaptively integrated through the attention mechanism;
[0054] In this way, the spatiotemporal feature information is obtained in the space-time-space structure. The mathematical formula is as follows:
[0055]
[0056] Among them, H l Hg represents the spatiotemporal feature representation of the local enhancement branch after LFA processing, and Hg represents the spatiotemporal feature representation of the global enhancement branch after LFA processing. LFA is a module that adaptively fuses features through multi-scale convolution and attention mechanism using a large-core attention mechanism. T is the time step, N is the number of nodes, and F is the feature dimension.
[0057] Preferably, in step S4, step S4 includes the following sub-steps:
[0058] Step S41: Contrastive learning tasks in two dimensions, time and space, are as follows:
[0059] Contrastive learning task in the temporal dimension:
[0060] First, the local and global representations are concatenated along the feature dimension to generate a cascade representation At each time step, the corresponding sample serves as an anchor point;
[0061] Then, the samples that are most similar and least similar to the anchor point are selected from other time steps as positive and negative pairs, where the yellow points with indicating arrows are The most similar flow pattern is shown and is selected as the positive direction. In comparison, the blue point with the indicating arrow The most obvious flow pattern is shown and is designated as the negative pair. The formulas for the positive and negative pairs are expressed as:
[0062]
[0063] in, It is represented as the positive sample corresponding to time step t, which represents the traffic pattern most similar to the current time step; It is represented as the negative sample corresponding to time step t, which represents the traffic pattern that is most dissimilar to the current time step; and Respectively, they represent searching for the index i that makes the expression take the minimum or maximum value in the time step range from 1 to T; Indicates the sum of all N regions; Is an indicator function, which takes 1 when i≠t to ensure that the current time step will not be selected; (H t,n -H i,n ) 2 represents the square of the Euclidean distance between time step t and time step i in region n; represents the feature dimension after concatenation, where 2F is the sum of local and global features;
[0064] Contrastive learning task in spatial dimension:
[0065] Spatial contrastive learning processes local road segment representation and global road network representation based on the attention mechanism, and narrows the distribution of similar samples by maximizing the mutual information of positive sample pairs. The formula is as follows:
[0066]
[0067] Among them, L tl is the temporal contrastive learning loss, τ is the temperature parameter, sim(.) represents the cosine similarity function, and N is the batch size;
[0068] Sub-step S42: Temporal contrastive learning obtains positive and negative sample pairs through hard sampling at each time step, and learns the consistency features of the time series by optimizing the similarity difference between the positive and negative pairs. The formula is as follows:
[0069]
[0070] Among them, L sl is the temporal contrastive learning loss, and denote the local and global representations of the i-th sample, respectively, τ is the temperature parameter, sim(,.,) represents the cosine similarity function, N is the batch size, and λ represents the (0, 1) indicator function.
[0071] Preferably, between steps S6 and S8, step S7 is also included: constructing a knowledge distillation and incremental learning framework, steps S1-S6 form a spatiotemporal graph comparative learning model based on large-core attention traffic flow prediction, and step S7 is used to achieve continuous optimization of the model.
[0072] Preferably, step S7 includes sub-step S71: designing a knowledge distillation mechanism to extract key knowledge from a complex teacher model and transfer it to a lightweight student model:
[0073] L distill =α*L pred +(1-α)*τ 2 *KL(σ(z t / τ),σ(z s / τ))
[0074] Among them, z t and z s are the output feature vectors of the teacher model and the student model respectively, τ is the temperature parameter, KL(,.,) represents the KL divergence, which is used to measure the difference between the probability distribution of the output of the teacher model and the student model, σ represents the softmax function, which converts the feature vector into a probability distribution, α is the weight parameter for balancing the prediction loss and the distillation loss, L pred is the loss function of the prediction task, usually the mean square error or mean absolute error, Ldistill It is the total loss function of knowledge distillation, using mean square error or mean absolute error.
[0075] Preferably, step S7 further includes sub-step S72: designing an incremental learning strategy so that the spatiotemporal graph comparative learning model can continuously integrate new traffic patterns without forgetting the learned knowledge:
[0076] (1) Memory replay: Maintain a historical traffic pattern sample library M and use it in a mixed way when learning new patterns
[0077] L memory =L new +λ*L replay (M)
[0078] (2) Model adaptation: Design regularization terms to prevent drastic changes in key parameters
[0079] L adapt =L memory +γ*||θ new -θ old || 2
[0080] Among them, L new is the training loss for new data, θ new and θ old Represent the new and old parameters of the model respectively, L replay (M) is the replay loss of the data in the historical sample library M, λ is the weight parameter for balancing the learning of new and old knowledge, and L replay (M) is the replay loss of the data in the historical sample library M, ||θ new -θ old || is the L2 norm, which is used to limit the amplitude of parameter changes, and γ is the regularization strength parameter.
[0081] Preferably, step S7 further includes sub-step S73: constructing an online evaluation and update mechanism to dynamically adjust the model structure and parameters based on the performance of the spatiotemporal graph comparison learning model on real-time traffic data:
[0082]
[0083] Among them D t is the new data batch at time t, η is the adaptive learning rate, is the gradient of the loss function with respect to the parameters, guiding the direction and magnitude of parameter updates, θ t and θ (t-1) represent the model parameters at time t and time t-1 respectively.
[0084] Compared with the prior art, the present invention has the following beneficial effects:
[0085] 1. The present invention uses three data enhancement strategies: feature level, topology level, and time interpolation, which effectively improves the robustness and generalization ability of the model of the present invention for incomplete traffic data.
[0086] Furthermore, the present invention comprehensively considers various data missing situations in actual traffic scenarios, such as missing flow values, missing regions, and missing continuous time steps caused by accidents, equipment failures, power outages, etc., and performs data enhancement by randomly masking flow information of different granularities, so that the model can better handle incomplete data in the real world.
[0087] 2. Through a large-core spatial attention module, multi-scale convolution and attention aggregation mechanisms significantly enhance the model's ability to capture and model local-global spatial dependencies. This attention module employs a dual-branch structure, utilizing depthwise separable convolutions of two different scales, 5x5 and 7x7, to expand the receptive field. The attention mechanism then adaptively fuses spatial features at different scales, enabling a more comprehensive extraction of the multi-scale spatial correlations inherent in urban road networks. Compared to existing methods, this invention simultaneously considers key information from both local road segments and the global road network, significantly improving the accuracy of spatial modeling.
[0088] 3. The present invention designs comparative learning tasks in both time and space dimensions, which, with the assistance of unsupervised signals, promotes the model of the present invention to learn more general and discriminative spatiotemporal representations of traffic flows.
[0089] Furthermore, the present invention introduces a contrastive task in the spatial dimension, maximizing the mutual information between local and global positive samples to reduce the distance between similar regions in latent space. In the temporal dimension, hard sampling is used to construct positive and negative sample pairs, optimizing the consistency and difference between similar and different traffic trends. The addition of spatiotemporal contrastive learning alleviates the problem of sparse supervision signals in traffic flow prediction and improves the model's generalization performance.
[0090] 4. The present invention constructs an end-to-end trainable joint learning framework, which simultaneously optimizes supervised prediction tasks and self-supervised comparison tasks based on encoder sharing, and can take into account both accuracy and generalization.
[0091] Furthermore, the present invention utilizes a space-time-space encoder architecture to fully extract local and global spatiotemporal features, while the decoder employs a simple and effective multi-layer perceptron structure to restore future traffic flow. This joint training process not only improves the accuracy of the primary task but also leverages self-supervisory signals from the comparison task to enhance the model's robustness, enabling it to better cope with complex and changing real-world traffic scenarios.
[0092] 5. This invention introduces knowledge distillation and incremental learning mechanisms to achieve continuous optimization and lightweight deployment of the model.
[0093] Furthermore, the present invention uses knowledge distillation technology to transfer key knowledge extracted from a fully trained complex teacher model to a student model with lower computing resource requirements, which greatly reduces the computational complexity and storage requirements of the model while maintaining prediction accuracy, making it more suitable for deployment on edge devices. Through the memory replay and model adaptation mechanism in the incremental learning strategy, the model can continuously integrate emerging traffic patterns and laws without forgetting the learned knowledge. The online evaluation and update mechanism gives the entire system adaptive capabilities, and can dynamically adjust the internal structure and parameters according to the characteristics of real-time traffic data to maintain continuous optimization of prediction performance. The combination of these technologies not only improves the terminal deployability of the model, but also enables it to adapt to new characteristics and changing trends of urban traffic over time, providing stable and reliable technical support for long-term intelligent transportation systems.
[0094] 6. In summary, the embodiments of the present invention propose a spatiotemporal graph comparative learning method for traffic flow prediction based on large-core attention, which effectively solves the problems of data missing and insufficient noise processing mechanisms in the existing technology through feature-level and topology-level adaptive data enhancement; improves the model's perception and modeling capabilities of dynamic road network structure changes through the large-core attention mechanism; introduces spatiotemporal comparative learning tasks and combines them with self-supervisory signals, significantly enhancing the model's generalization to complex traffic patterns and improving the discriminability of traffic flow spatiotemporal feature representations. At the same time, the present invention further adopts an end-to-end joint training framework, which effectively reduces computational complexity and storage requirements through the knowledge distillation mechanism while improving the model's prediction accuracy, thereby achieving efficient deployment of the model on edge devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0095] 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0096] Figure 1 This is a flow diagram of a spatiotemporal graph comparative learning method based on large-core attention traffic flow prediction provided by an embodiment of the present invention;
[0097] Figure 2 This is an architecture diagram of a spatiotemporal graph contrastive learning method for large-core attention traffic flow prediction provided by an embodiment of the present invention;
[0098] Figure 3 This is a schematic diagram of the process principle of large-core attention provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0099] The following will clearly and completely describe the technical solution in this embodiment of the present invention in conjunction with the drawings in this embodiment of the present invention. Obviously, the embodiment described is only one embodiment of the present invention, not all embodiments of the present invention. Based on this embodiment of the present invention, all other embodiments of the present invention obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.
[0100] See also Figures 1 to 3 , an embodiment of the present invention provides a spatiotemporal graph contrastive learning method based on large-core attention traffic flow prediction, comprising the following steps:
[0101] Step S1: Organize the collected traffic flow data into a time series format and construct a road network spatiotemporal graph;
[0102] In step S1, the road network spatiotemporal graph is G = (V, E, A, X), which is used to describe the topological structure and temporal characteristics of the urban road network. The construction process is as follows:
[0103] Sub-step S11: Node set V: Each node in the graph represents a monitoring unit, and the node’s feature is the traffic flow sequence of the monitoring unit at different time steps;
[0104] Sub-step S12: edge set E: Each edge in the graph represents the spatial association between two monitoring units, which can be constructed based on the road topology or the Euclidean distance between nodes;
[0105] Sub-step S13: Adjacency matrix A∈R N×N :R represents a set of real numbers, and the matrix describes the adjacency relationship between nodes. The urban space is divided into N=ixj in longitude and latitude, A ij =1 indicates that there is an edge connection between node i and node j, otherwise A ij =0;
[0106] Among them, traffic flow data X∈R T×N×2 , R T×N×2 represents a spatiotemporal tensor containing the inflow and outflow traffic flows of N regions in the past T time steps;
[0107] Step S2: Perform feature-level, topology-level, and time-interpolation data enhancement on the traffic flow data to generate an enhanced feature matrix as input for subsequent steps to improve the robustness of the model of the present invention to incomplete data;
[0108] In step S2, the process of performing feature-level, topology-level, and time-interpolation data enhancement on the traffic flow data and forming an enhanced feature matrix as input for subsequent steps includes the following sub-steps:
[0109] Sub-step S21: Feature-level data enhancement: By randomly masking traffic information of different granularities, we simulate data loss caused by accidents, equipment failures, or power outages in practice. The following is the masking mechanism:
[0110]
[0111] Among them, E ij ∈R TxNx2 , E ij is a random mask with a value between 0 and 1, ε is an adjustable value, t represents the current time step (current moment), and T represents the length of the historical time window. is the original input feature matrix, is the feature-level data enhancement matrix;
[0112] Advantages of processing in sub-step S21: The random masking method improves the robustness of the model to missing data, enabling the model to maintain good prediction performance even in the face of inevitable missing data in the real world;
[0113] Sub-step S22: Topological data enhancement: introducing random topological changes by perturbing the adjacency matrix A of the graph, which includes the following two perturbation methods:
[0114] (1) Local spatial enhancement: Randomly perturb the predefined adjacency matrix A, corresponding to the formula:
[0115] M l =A⊙M t ∈R N*N
[0116] Among them, M t is the initialization matrix, M l is the local augmented matrix, ⊙ is the Hadamard product;
[0117] (2) Global spatial enhancement: self-learn a perturbation matrix and superimpose it on the original adjacency matrix, corresponding to the formula:
[0118] M g =A⊕M t ∈R N*N
[0119] Among them, M t is the initialization matrix, M g For all augmented matrices, add the matrix elements together;
[0120] Advantages of processing in sub-step S22: By randomly perturbing the topological structure, the model's adaptability to road network changes is enhanced, enabling the model to capture traffic patterns under different spatial relationships, thereby improving the modeling capability of dynamic traffic networks;
[0121] Sub-step S23: Shift the data along the time axis to utilize the intermediate state between two consecutive time steps, perform weighted averaging between two consecutive time steps, effectively improve the time granularity and smoothness of the data, and ensure the interpolation accuracy. The formula is as follows:
[0122] P (t-S):t =αX (t-S):t +(1-α)X (t-S+1):(t+1)
[0123] Among them, α is a hyperparameter adjustment between 0 and 1, (tS):t represents the time range from tS to t, (t-S+1):(t+1) represents the time range from t-S+1 to t+1, P (t-S):t Represents the new time series data generated by interpolation, X (t-S):t Represents the original time series data, X (t-S):(t+1) Represents time series data shifted backward by one time step;
[0124] Advantages of processing in sub-step S23: It enhances the continuity and smoothness of data through time interpolation, enabling the model to learn more fine-grained feature changes in the time dimension, thereby improving sensitivity to time series changes and prediction accuracy;
[0125] In summary, the advantages of step S2 are: it utilizes three data augmentation strategies: feature-level, topology-level, and time interpolation, effectively improving the robustness and generalization ability of the model for incomplete traffic data. Furthermore, step S2 comprehensively considers various data missing conditions in actual traffic scenarios, such as missing flow values, missing regions, and missing consecutive time steps caused by accidents, equipment failures, and power outages. By randomly masking traffic information of different granularities for data augmentation, the model is better able to handle incomplete data in the real world.
[0126] Step S3: Encode the road network spatiotemporal graph, adopt a large-core attention mechanism, extract spatiotemporal features through large-scale convolution and adaptive feature fusion, and enhance spatial dependency and temporal consistency;
[0127] In step S3, the original feature matrix is defined as X ij , the local enhancement matrix is M l , the global enhancement matrix is M g , the step S3 specifically includes the following sub-steps:
[0128] Sub-step S31: Following the message passing and aggregation process, the spatial dependencies between nodes are encoded and the potential features are extracted from the traffic network. The local graph convolution formula can be defined as:
[0129]
[0130] in, and are the outputs of the l-1th graph convolutional layer of the local branch and the global branch, respectively, which serve as the input of the lth graph convolutional layer; is the initial input, that is, the traffic flow data after feature enhancement processing in step S2; and are the local and global adjacency matrices normalized by the degree matrix, respectively; where, is the degree matrix, which is a diagonal matrix where each diagonal element represents the degree of the corresponding node (i.e., the number of edges connecting the node); Θ is the learnable weight parameter matrix shared by the two branches; T represents the time step, N is the number of monitoring points, and F represents the dimension of the feature vector of each node;
[0131] Sub-step S32: mining temporal dependencies and integrating them with spatial information, 1×kt standard convolution on the obtained spatial representation H l and H g Encoding;
[0132]
[0133] Among them, [1,K t ] represents the size of the convolution kernel, K t is the size of the temporal convolution kernel, and Respectively represent the local and global feature representations after time convolution processing; tanh represents the tangent function; σ represents the sigmoid function; ⊙ represents element-level multiplication; and Respectively represent the local and global feature representations after activation function processing;
[0134] Sub-step S33: In order to better obtain spatial information, we have a large-core spatial attention module to obtain spatial information;
[0135] Among them, the spatial receptive field is expanded by 5x5 and 7x7 depthwise separable convolutions respectively, and then the features of different scales are adaptively integrated through the attention mechanism;
[0136] In this way, the spatiotemporal feature information is obtained in the space-time-space structure. The mathematical formula is as follows:
[0137]
[0138] Among them, H lHg represents the spatiotemporal feature representation of the local enhancement branch after LFA processing, and Hg represents the spatiotemporal feature representation of the global enhancement branch after LFA processing. LFA is a module that adaptively fuses features through multi-scale convolution (such as 5x5 and 7x7) and attention mechanism of large-core attention mechanism. T is the time step, N is the number of nodes, and F is the feature dimension.
[0139] The processing advantage of step S3 is that it can fully capture the spatiotemporal dependencies of traffic flows through a multi-layer space-time-space architecture. At the same time, the large-core attention mechanism expands the spatial receptive field, enabling the model to perceive spatial correlations in a larger range, improving the ability to model long-distance traffic impacts, and ultimately enhancing the ability to express complex urban traffic networks.
[0140] Step S4: Based on the spatiotemporal representation after encoding in step S3, design contrastive learning tasks in both time and space dimensions to enhance representation learning;
[0141] Wherein, in step S4, step S4 includes the following sub-steps:
[0142] Step S41: Contrastive learning tasks in two dimensions, time and space, are as follows:
[0143] Contrastive learning task in the temporal dimension:
[0144] First, the local and global representations are concatenated along the feature dimension to generate a cascade representation At each time step, the corresponding sample serves as an anchor point;
[0145] Then, we select the most similar and least similar samples to the anchor point from other time steps as positive and negative pairs, where the yellow points with indicating arrows are The most similar flow pattern is shown and is selected as the positive direction. In comparison, the blue point with the indicating arrow The most obvious flow pattern is shown and is designated as the negative pair. The formulas for the positive and negative pairs are expressed as:
[0146]
[0147] in, It is represented as the positive sample corresponding to time step t, which represents the traffic pattern most similar to the current time step; It is represented as the negative sample corresponding to time step t, which represents the traffic pattern that is most dissimilar to the current time step; and Respectively, they represent searching for the index i that makes the expression take the minimum or maximum value in the time step range from 1 to T; Indicates the sum of all N regions; Is an indicator function, which takes 1 when i≠t to ensure that the current time step will not be selected; (H t,n -H i,n ) 2 represents the square of the Euclidean distance between time step t and time step i in region n; represents the feature dimension after concatenation, where 2F is the sum of local and global features;
[0148] Among them, the local branch is represented by H l Mapped to a 64-dimensional latent space as the cluster assignment target of the clustering task, this is used as the self-supervisory signal to represent the global branch H g Perform clustering to align the local-global semantic space by minimizing the cross entropy loss;
[0149] Contrastive learning task in spatial dimension:
[0150] Spatial contrastive learning processes local road segment representation and global road network representation based on the attention mechanism, and narrows the distribution of similar samples by maximizing the mutual information of positive sample pairs. The formula is as follows:
[0151]
[0152] Among them, L tl is the temporal contrastive learning loss, τ is the temperature parameter, sim(.) represents the cosine similarity function, and N is the batch size;
[0153] Sub-step S42: Temporal contrastive learning obtains positive and negative sample pairs through hard sampling at each time step, and learns the consistency features of the time series by optimizing the similarity difference between the positive and negative pairs. The formula is as follows:
[0154]
[0155] Among them, L sl is the temporal contrastive learning loss, and denote the local and global representations of the i-th sample, respectively, τ is the temperature parameter, sim(,.,) represents the cosine similarity function, N is the batch size, and λ represents the (0, 1) indicator function.
[0156] The processing advantage of step S4 is that through the contrastive learning tasks in both time and space dimensions, the model can learn more robust and discriminative representations. Contrastive learning in the time dimension helps capture the periodicity and trend characteristics in time series data, while contrastive learning in the space dimension enhances the ability to model spatial correlations between regions. This two-dimensional contrastive learning strategy significantly improves the model's ability to recognize and predict complex spatiotemporal patterns.
[0157] Step S5: Input the spatiotemporal representation after the encoder contrast learning task into the decoder;
[0158] Step S6: The decoder uses a multi-layer perceptron structure to restore the features to traffic prediction values for multiple future time steps through a fully connected layer;
[0159] The spatiotemporal representation output by the encoder in the last step is input into an MLP decoder containing two fully connected layers, which outputs the predicted inflow and outflow traffic flow of each grid in the next 30 minutes.
[0160] The above steps S1-S6 form a spatiotemporal graph contrastive learning model based on large-core attention traffic flow prediction;
[0161] The model is trained end-to-end on 4 months of data in the training set, and the prediction accuracy is evaluated on the test set;
[0162] This model utilizes an end-to-end trainable joint learning framework to simultaneously optimize supervised prediction tasks and self-supervised comparison tasks based on encoder sharing, achieving a balanced balance of accuracy and generalization. Furthermore, the invention employs a spatial-temporal-spatial encoder architecture to fully extract local-global spatiotemporal features, while the decoder employs a simple and effective multi-layer perceptron structure to restore future traffic flow. While improving the accuracy of the primary task, the joint training process leverages the self-supervisory signal from the comparison task to enhance the model's robustness, enabling it to better cope with complex and changing real-world traffic scenarios.
[0163] Step S7: Constructing a knowledge distillation and incremental learning framework. Step S7 is used to achieve continuous optimization of the spatiotemporal graph contrastive learning model based on large-core attention traffic flow prediction.
[0164] Wherein, step S7 includes the following sub-steps:
[0165] Sub-step S71: Design a knowledge distillation mechanism to extract key knowledge from the complex teacher model and transfer it to the lightweight student model:
[0166] L distill =α*L pred +(1-α)*τ 2 *KL(σ(z t / τ),σ(z s / τ))
[0167] Among them, z t and z sare the output feature vectors of the teacher model and the student model respectively, τ is the temperature parameter, KL(,.,) represents the KL divergence, which is used to measure the difference between the probability distribution of the output of the teacher model and the student model, σ represents the softmax function, which converts the feature vector into a probability distribution, α is the weight parameter for balancing the prediction loss and the distillation loss, L pred is the loss function of the prediction task, usually the mean square error or mean absolute error, L distill is the total loss function of knowledge distillation, using mean square error (MSE) or mean absolute error (MAE);
[0168] The technical principle of sub-step S71 is to compress and transfer the "knowledge" of the trained complex teacher model (i.e., the spatiotemporal graph contrastive learning model based on large-core attention traffic flow prediction constructed in steps S1-S6, which has high prediction performance but consumes a lot of computing resources) into a student model with fewer parameters through knowledge distillation technology;
[0169] The output feature vectors of the teacher model are softened (adjusted by the temperature parameter τ) to produce richer probability distribution information, not just the final prediction result. The student model achieves performance close to that of the teacher model with fewer computational resources by minimizing the KL divergence between its own output and the probability distribution of the teacher model's output, while also optimizing the loss of the underlying prediction task.
[0170] Sub-step S72: Design an incremental learning strategy so that the spatiotemporal graph comparative learning model can continuously integrate new traffic patterns without forgetting the learned knowledge:
[0171] (1) Memory replay: Maintain a historical traffic pattern sample library M and use it in a mixed way when learning new patterns
[0172] L memory =L new +λ*L replay (M)
[0173] (2) Model adaptation: Design regularization terms to prevent drastic changes in key parameters
[0174] L adapt =L memory +γ*||θ new -θ old || 2
[0175] Among them, L new is the training loss for new data, θ new and θ old Represent the new and old parameters of the model respectively, L replay (M) is the replay loss of the data in the historical sample library M, λ is the weight parameter for balancing the learning of new and old knowledge, and Lreplay (M) is the replay loss of the data in the historical sample library M, ||θ new -θ old || is the L2 norm, which is used to limit the amplitude of parameter changes, and γ is the regularization strength parameter;
[0176] Sub-step S73: Construct an online evaluation and update mechanism to dynamically adjust the model structure and parameters based on the performance of the spatiotemporal graph comparison learning model on real-time traffic data:
[0177]
[0178] Among them D t is the new data batch at time t, η is the adaptive learning rate, is the gradient of the loss function with respect to the parameters, guiding the direction and magnitude of parameter updates, θ t and θ (t-1) represent the model parameters at time t and time t-1 respectively.
[0179] In summary, the processing advantage of step S7 is that it achieves continuous optimization and lightweight deployment of the model through knowledge distillation and incremental learning mechanisms. Furthermore, the present invention uses knowledge distillation technology to migrate the key knowledge extracted from the fully trained complex teacher model to the student model with lower computing resource requirements, while maintaining the prediction accuracy. The computational complexity and storage requirements of the model are greatly reduced, making it more suitable for deployment on edge devices. Through the memory replay and model adaptation mechanism in the incremental learning strategy, the model can continuously integrate emerging traffic patterns and laws without forgetting the learned knowledge. The online evaluation and update mechanism makes the entire system adaptive and can dynamically adjust the internal structure and parameters according to the characteristics of real-time traffic data to maintain continuous optimization of prediction performance. The combination of these technologies not only improves the terminal deployability of the model, but also enables it to adapt to the new characteristics and changing trends of urban traffic over time, providing stable and reliable technical support for the long-term operation of intelligent transportation systems.
[0180] Step S8: Return to step S1 and continue training.
[0181] In summary, the embodiments of the present invention propose a spatiotemporal graph comparative learning method for traffic flow prediction based on large-core attention, which effectively improves the robustness of the model to incomplete traffic data through feature-level and topology-level adaptive data augmentation strategies; through the large-core attention mechanism, the model's perception and modeling capabilities of dynamic road network topological structure changes are significantly enhanced; by designing spatiotemporal comparative learning tasks, the model's generalization and expression capabilities for complex spatiotemporal dependencies of traffic flows are further improved. In addition, through an end-to-end joint training framework, the model is able to take into account both prediction accuracy and generalization; using the knowledge distillation mechanism, the knowledge of the complex teacher model is efficiently transferred to the lightweight student model, which significantly reduces the computing and storage requirements while maintaining accuracy, and realizes the efficient deployment of the model on edge devices.
[0182] Practical applications represented by the Smart Dongguan Traffic Brain show that the technical solution proposed in this invention can significantly improve the accuracy and real-time performance of traffic flow predictions at key intersections and road networks in the city, providing critical data support for control measures such as alleviating traffic congestion, optimizing signal timing, and reasonably guiding and directing traffic.
[0183] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A spatiotemporal graph contrastive learning method for traffic flow prediction based on large kernel attention, characterized by: It includes the following steps: Step S1: Organize the collected traffic flow data into a time series format and construct a road network spatiotemporal graph; Step S2: Perform feature-level, topology-level, and time-interpolation data enhancement on the traffic flow data to generate an enhanced feature matrix as input for subsequent steps; Step S3: Encode the road network spatiotemporal graph, adopt a large-core attention mechanism, extract spatiotemporal features through large-scale convolution and adaptive feature fusion, and enhance spatial dependency and temporal consistency; Step S4: Based on the spatiotemporal representation after encoding in step S3, design contrastive learning tasks in both time and space dimensions to enhance representation learning; Step S5: Input the spatiotemporal representation after the encoder contrast learning task into the decoder; Step S6: The decoder uses a multi-layer perceptron structure to restore the features to traffic prediction values for multiple future time steps through a fully connected layer; Step S8: Return to step S1 and continue training.
2. The spatiotemporal graph contrastive learning method based on large-core attention traffic flow prediction according to claim 1 is characterized in that: In step S1, the road network spatiotemporal graph is G = (V, E, A, X), which is used to describe the topological structure and temporal characteristics of the urban road network. The construction process is as follows: Sub-step S11: Node set V: Each node in the graph represents a monitoring unit, and the node’s feature is the traffic flow sequence of the monitoring unit at different time steps; Sub-step S12: edge set E: Each edge in the graph represents the spatial association between two monitoring units, which can be constructed based on the road topology or the Euclidean distance between nodes; Sub-step S13: Adjacency matrix A∈R N×N :R represents a set of real numbers, and the matrix describes the adjacency relationship between nodes. The urban space is divided into N=ixj in longitude and latitude, A ij =1 indicates that there is an edge connection between node i and node j, otherwise A ij =0; Among them, traffic flow data X∈R T×N×2 , R T×N×2 Represents a spatiotemporal tensor containing the inflow and outflow of vehicles in N regions over the past T time steps.
3. The spatiotemporal graph contrastive learning method for traffic flow prediction based on large-core attention according to claim 2 is characterized in that: In step S2, the process of performing feature-level, topology-level, and time-interpolation data enhancement on the traffic flow data and forming an enhanced feature matrix includes the following sub-steps: Sub-step S21: Feature-level data enhancement randomly masks traffic information of different granularities to simulate data loss caused by accidents, equipment failures, or power outages in practice. The following is the masking mechanism: Among them, E ij ∈R TxNx2 , E ij is a random mask with a value between 0 and 1, ε is an adjustable value, t represents the current time step, and T represents the length of the historical time window. is the original input feature matrix, is the feature-level data enhancement matrix; Sub-step S22: Topological data enhancement introduces random topological changes by perturbing the adjacency matrix A of the graph, which includes the following two perturbation methods: (1) Local spatial enhancement: Randomly perturb the predefined adjacency matrix A, corresponding to the formula: M l =A⊙M t ∈R N*N Among them, M t is the initialization matrix, M l is the local augmented matrix, ⊙ is the Hadamard product; (2) Global spatial enhancement: self-learn a perturbation matrix and superimpose it on the original adjacency matrix, corresponding to the formula: Among them, M t is the initialization matrix, M g are all augmented matrices, Adding matrix elements; Sub-step S23: Shift the data along the time axis to utilize the intermediate state between two consecutive time steps, and perform weighted averaging between the two consecutive time steps to ensure interpolation accuracy. The formula is as follows: P (t-S):t =αX (t-S):t +(1-a)X (t-S+1):(t+1) Among them, α is a hyperparameter adjustment between 0 and 1, (tS):t represents the time range from tS to t, (t-S+1):(t+1) represents the time range from t-S+1 to t+1, P (t-S):t Represents the new time series data generated by interpolation, X (t-S):t Represents the original time series data, X (t-S):(t+1) Represents time series data shifted backward one time step.
4. A spatiotemporal graph contrastive learning method based on large-core attention traffic flow prediction according to claim 1 or 3, wherein: In step S3, the original feature matrix is defined as X ij , the local enhancement matrix is M l , the global enhancement matrix is M g , the step S3 specifically includes the following sub-steps: Sub-step S31: Following the message passing and aggregation process, the spatial dependencies between nodes are encoded and the potential features are extracted from the traffic network. The local graph convolution formula can be defined as: in, and are the outputs of the l-1th graph convolutional layer of the local branch and the global branch respectively, and the outputs serve as the input of the lth graph convolutional layer; is the initial input, i.e., the traffic flow data after feature enhancement processing in step S2; and are the local and global adjacency matrices normalized by the degree matrix, respectively; where, is the degree matrix, which is a diagonal matrix where each diagonal element represents the degree of the corresponding node; Θ is the learnable weight parameter matrix shared by the two branches; T represents the time step, N is the number of monitoring points, and F represents the dimension of the feature vector of each node; Sub-step S32: mining temporal dependencies and integrating them with spatial information, 1×kt standard convolution on the obtained spatial representation H l and H g Encoding; Among them, [1,K t ] represents the size of the convolution kernel, K t is the size of the temporal convolution kernel, and Respectively represent the local and global feature representations after time convolution processing; tanh represents the tangent function; σ represents the sigmoid function; ⊙ represents element-level multiplication; and Respectively represent the local and global feature representations after activation function processing; Sub-step S33: In order to better obtain spatial information, obtain spatial information through the large-core spatial attention module; The spatial receptive field is expanded by 5x5 and 7x7 depthwise separable convolutions, and then the features of different scales are adaptively integrated through the attention mechanism. In this way, the spatiotemporal feature information is obtained in the space-time-space structure. The mathematical formula is as follows: Among them, H l Hg represents the spatiotemporal feature representation of the local enhancement branch after LFA processing, and Hg represents the spatiotemporal feature representation of the global enhancement branch after LFA processing. LFA is a module that adaptively fuses features through multi-scale convolution and attention mechanism using a large-core attention mechanism. T is the time step, N is the number of nodes, and F is the feature dimension.
5. The spatiotemporal graph contrastive learning method for traffic flow prediction based on large-core attention according to claim 4 is characterized in that: In step S4, step S4 includes the following sub-steps: Step S41: Contrastive learning tasks in two dimensions, time and space, are as follows: Contrastive learning task in the temporal dimension: First, the local and global representations are concatenated along the feature dimension to generate a concatenated representation H = At each time step, the corresponding sample serves as an anchor point; Then, the samples that are most similar and least similar to the anchor point are selected from other time steps as positive and negative pairs, where the yellow points with indicating arrows are The most similar flow pattern is shown and is selected as the positive direction. In comparison, the blue point with the indicating arrow The most obvious flow pattern is shown and is designated as the negative pair. The formulas for the positive and negative pairs are expressed as: in, It is represented as the positive sample corresponding to time step t, which represents the traffic pattern most similar to the current time step; It is represented as the negative sample corresponding to time step t, which represents the traffic pattern that is most dissimilar to the current time step; and Respectively, they represent searching for the index i that makes the expression take the minimum or maximum value in the time step range from 1 to T; Indicates the sum of all N regions; Is an indicator function, which takes 1 when i≠t to ensure that the current time step will not be selected; (H t,n -H i,n ) 2 represents the square of the Euclidean distance between time step t and time step i in region n; R N×2F represents the feature dimension after concatenation, where 2F is the sum of local and global features; Contrastive learning task in spatial dimension: Spatial contrastive learning processes local road segment representation and global road network representation based on the attention mechanism, and narrows the distribution of similar samples by maximizing the mutual information of positive sample pairs. The formula is as follows: Among them, L tl is the temporal contrastive learning loss, τ is the temperature parameter, sim(.) represents the cosine similarity function, and N is the batch size; Sub-step S42: Temporal contrastive learning obtains positive and negative sample pairs through hard sampling at each time step, and learns the consistency features of the time series by optimizing the similarity difference between the positive and negative pairs. The formula is as follows: Among them, L sl is the temporal contrastive learning loss, and denote the local and global representations of the i-th sample, respectively, τ is the temperature parameter, sim(,.,) represents the cosine similarity function, N is the batch size, and λ represents the (0, 1) indicator function.
6. The spatiotemporal graph contrastive learning method for traffic flow prediction based on large-core attention according to claim 1 is characterized in that: Between steps S6 and S8, step S7 is also included: constructing a knowledge distillation and incremental learning framework. Steps S1-S6 form a spatiotemporal graph comparative learning model based on large-core attention traffic flow prediction. Step S7 is used to achieve continuous optimization of the model.
7. The spatiotemporal graph contrastive learning method for traffic flow prediction based on large-core attention according to claim 6 is characterized in that: Step S7 includes sub-step S71: designing a knowledge distillation mechanism to extract key knowledge from the complex teacher model and transfer it to the lightweight student model: L distill =α*L pred +(1-a)*t 2 *KL(σ(z t / τ),σ(z s / t)) Among them, z t and z s are the output feature vectors of the teacher model and the student model respectively, τ is the temperature parameter, KL(,.,) represents the KL divergence, which is used to measure the difference between the probability distribution of the output of the teacher model and the student model, σ represents the softmax function, which converts the feature vector into a probability distribution, α is the weight parameter for balancing the prediction loss and the distillation loss, L pred is the loss function of the prediction task, usually the mean square error or mean absolute error, L distill It is the total loss function of knowledge distillation, using mean square error or mean absolute error.
8. The spatiotemporal graph contrastive learning method for traffic flow prediction based on large-core attention according to claim 7 is characterized in that: Step S7 also includes sub-step S72: designing an incremental learning strategy so that the spatiotemporal graph comparative learning model can continuously integrate new traffic patterns without forgetting the learned knowledge: (1) Memory replay: Maintain a historical traffic pattern sample library M and use it in a mixed way when learning new patterns L memory =L new +λ*L replay (M) (2) Model adaptation: Design regularization terms to prevent drastic changes in key parameters L adapt =L memory +γ*||θ new -θ old || 2 Among them, L new is the training loss for new data, θ new and θ old Represent the new and old parameters of the model respectively, L replay (M) is the replay loss of the data in the historical sample library M, λ is the weight parameter for balancing the learning of new and old knowledge, and L replay (M) is the replay loss of the data in the historical sample library M, ||θ new -θ old || is the L2 norm, which is used to limit the amplitude of parameter changes, and γ is the regularization strength parameter.
9. The spatiotemporal graph contrastive learning method for traffic flow prediction based on large-core attention according to claim 8 is characterized in that: Step S7 also includes sub-step S73: constructing an online evaluation and update mechanism to dynamically adjust the model structure and parameters based on the performance of the spatiotemporal graph comparison learning model on real-time traffic data: Among them D t is the new data batch at time t, η is the adaptive learning rate, is the gradient of the loss function with respect to the parameters, guiding the direction and magnitude of parameter updates, θ t and θ (t-1) represent the model parameters at time t and time t-1 respectively.
Citation Information
Patent Citations
Traffic flow prediction method based on improved space-time Transform
CN115273464A
Traffic flow prediction method based on adaptive graph attention neural network
CN115762147A
Method and device for predicting traffic flow by combining rainfall capacity and space-time diagram convolution model
CN118247953A
Traffic flow prediction method based on time-varying fusion graph convolutional network
CN118262517A
Urban traffic flow prediction method based on road network spatial heterogeneity
CN118675325A
Cited By
Method and system for predicting urban park visitor flow based on optimized CNN-LSTM model
CN121168766A
Traffic prediction method based on distillation big language model
CN121305878A
Traffic jam prediction method and device based on comparative learning and knowledge distillation
CN121542933A
A traffic congestion prediction method and device based on contrast learning and knowledge distillation
CN121542933B