A spatiotemporal graph contrastive learning method based on large kernel attention traffic flow prediction
By employing a large-kernel attention and spatiotemporal graph comparative learning method, this study addresses the issues of adaptability to dynamic road network topology and noise robustness in existing traffic flow prediction technologies. It enables efficient modeling and prediction of complex traffic patterns, adapting to diverse urban traffic scenarios.
Patent Information
- Application Number
- CN202510648010.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2045-05-19
AI Technical Summary
Existing traffic flow prediction technologies struggle to accurately characterize the spatiotemporal dependencies of urban road networks, lack adaptability to dynamic road network topologies, and lack robust mechanisms for handling noise and outliers in traffic flow data. Traditional attention mechanisms have limited receptive fields, making it difficult to capture large-scale spatial dependencies.
We adopt a method based on big-kernel attention and spatiotemporal graph contrastive learning. Through feature-level, topology-level and temporal interpolation data augmentation strategies, we design a big-kernel spatial attention module. Combined with spatiotemporal contrastive learning tasks, we improve the model's ability to perceive changes in dynamic road network topology and enhance its ability to generalize and characterize complex traffic patterns.
It significantly improves the model's robustness to missing data and noise, enhances its ability to model dynamic changes in road network topology, and improves the modeling accuracy and generalization of complex traffic flow spatiotemporal dependencies, adapting to the ever-changing scenarios of urban traffic.
Smart Images

Figure CN120472686B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of traffic flow prediction technology for smart cities, and in particular to a spatiotemporal graph comparison learning method for traffic flow prediction based on big-core attention. Background Technology
[0002] With the acceleration of urbanization, urban traffic faces numerous challenges such as congestion and low management efficiency. Accurately predicting traffic flow in various urban areas over a future period is crucial for alleviating congestion and optimizing traffic control strategies.
[0003] Current traffic flow prediction technologies have the following problems:
[0004] 1. Urban road networks are complex non-Euclidean geometric spaces, and traditional methods such as convolutional neural networks (CNN) and recurrent neural networks (RNN) are difficult to accurately characterize their spatiotemporal dependencies;
[0005] 2. Traffic flow data exhibits strong spatiotemporal correlation and dynamism. Traffic conditions at different times (such as morning and evening rush hours) and in different areas are subject to complex mutual influences.
[0006] 3. External factors (such as weather and traffic accidents) cause a lot of interference, 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 prediction models.
[0008] In recent years, with the development of information technology and artificial intelligence, traffic flow prediction has become one of the key research areas in Intelligent Transportation Systems (ITS). Accurately predicting future traffic conditions is crucial for alleviating urban traffic congestion, optimizing travel experiences, and enabling real-time control of transportation networks. Integrating reliable traffic prediction into intelligent transportation systems is essential 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, achieving some progress. However, existing methods still have the following shortcomings:
[0010] 1. Most of them assume that the road network topology is static, which makes it difficult to adapt to dynamically changing road networks;
[0011] 2. Lacks robust handling mechanisms for noise and outliers in traffic flow data;
[0012] 3. Traditional attention mechanisms have limited receptive fields, making it difficult to capture large-scale spatial dependencies and affecting the ability to model complex traffic patterns.
[0013] Therefore, how to design flexible prediction models for dynamic road networks, improve the model's robustness to noise and anomalies, and enhance its ability to characterize large-scale spatiotemporal dependencies are key issues that urgently need to be addressed in this field. This invention proposes a traffic flow prediction method based on big-kernel attention and spatiotemporal graph contrastive learning. By expanding the spatial receptive field through the big-kernel attention mechanism and optimizing representation capabilities through spatiotemporal contrastive learning, the aforementioned problems are solved. Summary of the Invention
[0014] The purpose of this invention is to overcome the above-mentioned defects in the prior art and provide a spatiotemporal graph contrastive learning method for traffic flow prediction based on large kernel attention. Specifically, this invention improves the robustness of the model to data missing and noise through feature-level, topology-level and temporal interpolation data augmentation strategies; enhances the model's ability to perceive dynamic road network topology changes by designing a large kernel spatial attention module; and improves the generalization and characterization of complex traffic patterns by introducing spatiotemporal contrastive learning tasks and self-supervised signals.
[0015] 1. Data augmentation strategies significantly improve the model's ability to adapt to missing and anomaly situations in real-world traffic data;
[0016] 2. The large kernel attention mechanism significantly enhances the model's ability to model dynamic changes in road network topology;
[0017] 3. Spatiotemporal contrastive learning tasks effectively improve the generalization of models and the modeling accuracy of complex traffic flow spatiotemporal dependencies.
[0018] To achieve the above objectives, this invention provides a spatiotemporal graph contrastive learning method for traffic flow prediction based on large kernel attention, which includes the following steps:
[0019] Step S1: Organize the collected traffic flow data into a time series format to construct a road network spatiotemporal map;
[0020] Step S2: Perform feature-level, topology-level, and time-interpolated data augmentation on the traffic flow data to generate an augmented feature matrix as input for subsequent steps;
[0021] Step S3: Encode the spatiotemporal map of the road network, and use a large kernel attention mechanism to extract spatiotemporal features through large-scale convolution and adaptive feature fusion to enhance spatial dependence and temporal consistency;
[0022] Step S4: Based on the spatiotemporal representation after encoding in step S3, design contrastive learning tasks for 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 adopts a multilayer perceptron structure, and uses a fully connected layer to restore the features into traffic prediction values for multiple future time steps;
[0025] Step S8: Return to step S1 and continue training.
[0026] Preferably, in step S1, the spatiotemporal diagram of the road network is G = (V, E, A, X), which is used to characterize the topological structure and temporal characteristics of the urban road network. Its construction process is as follows:
[0027] Sub-step S11: Node set V: Each node in the graph represents a monitoring unit, and the characteristic of a node is the traffic flow sequence of that monitoring unit at different time steps;
[0028] Sub-step S12: Edge set E: Each edge in the graph represents the spatial relationship 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 the set of real numbers, and the matrix describes the adjacency relationships between nodes. The urban space is divided into N = ixj in terms of latitude and longitude, and A... ij =1 indicates that there is an edge connecting node i and node j; otherwise, A ij =0;
[0030] Wherein, traffic flow data X∈R T×N×2 R T×N×2 This represents a spatiotemporal tensor containing the inflow and outflow traffic volumes of N regions over the past T time steps.
[0031] Preferably, in step S2, the process of performing feature-level, topology-level, and time-interpolated data enhancement on the traffic flow data to form an enhanced feature matrix includes the following sub-steps:
[0032] Sub-step S21: Feature-level data augmentation simulates data loss caused by accidents, equipment failures, or power outages in real-world scenarios by randomly masking traffic information at different granularities. The masking mechanism is as follows:
[0033]
[0034] Among them, E ij ∈R TxNx2 E ij ε is a random mask with a value between 0 and 1, t represents the current time step, and T represents the length of the historical time window. The original input feature matrix, For feature-level data augmentation matrix;
[0035] Sub-step S22: Topology-level data augmentation introduces random topology changes through the adjacency matrix A of the perturbation graph, including the following two perturbation methods:
[0036] (1) Local space 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 To initialize the matrix, M l For a locally augmented matrix, ⊙ is the Hadamard product;
[0039] (2) Global Space Augmentation: A perturbation matrix is self-learned and superimposed on the original adjacency matrix, corresponding to the formula:
[0040] M g =A⊕M t ∈R N*N
[0041] Among them, M t To initialize the matrix, M g For all augmented matrices, add the matrix elements;
[0042] Sub-step S23: Move the data along the time axis to utilize the intermediate state between two consecutive time steps, and perform a weighted average between the two consecutive time steps to ensure interpolation accuracy, as shown in the following formula:
[0043] P (t-S):t =αX (t-S):t +(1-α)X (t-S+1):(t+1)
[0044] Where α is a hyperparameter adjusted from 0 to 1, (tS): t represents the time range from time tS to time t, (t-S+1): (t+1) represents the time range from time t-S+1 to time t+1, and P (t-S):t X represents the new time series data generated through interpolation. (t-S):t X represents the original time series data. (t-S):(t+1) This represents time series data shifted backward by one time step.
[0045] Preferably, 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 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 latent features are extracted from the traffic network. The local graph convolution formula can be defined as:
[0047]
[0048] in, and These are the outputs of the (l-1)th graph convolutional layer for the local branch and the global branch, respectively, and this output is used as the input of the l-th graph convolutional layer. This is the initial input, i.e., the traffic flow data after feature enhancement processing in step S2; and These are the local and global adjacency matrices after degree matrix normalization; 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: Mine temporal dependencies and integrate them with spatial information, using a 1×kt standard convolution to obtain the spatial representation H. l and H g Encode;
[0050]
[0051] Among them, [1,K t ] represents the size of the convolution kernel, K t The size of the temporal convolution kernel. and represents the local and global feature representations after temporal convolution, respectively; tanh represents the tangent function; σ represents the sigmoid function; ⊙ represents element-wise multiplication; and These represent the local and global feature representations after processing by the activation function, respectively.
[0052] Sub-step S33: In order to better acquire spatial information, spatial information is acquired through the spatial attention module of the large kernel;
[0053] Specifically, the spatial receptive field is expanded by using 5x5 and 7x7 depthwise separable convolutions, respectively, and then features of different scales are adaptively fused through an attention mechanism.
[0054] This allows us to obtain spatiotemporal feature information using a space-time-space structure, as shown in the following mathematical formula:
[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 of big kernel attention mechanism that adaptively fuses features through multi-scale convolution and attention mechanism. T is the time step, N is the number of nodes, and F is the feature dimension.
[0057] Preferably, step S4 includes the following sub-steps:
[0058] Step S41: Includes contrastive learning tasks in both time and space dimensions, as follows:
[0059] Comparative learning task over time:
[0060] First, the local and global representations are concatenated along the feature dimension to generate a cascaded representation. At each time step, the corresponding sample serves as the anchor point;
[0061] Subsequently, from other time steps, the samples most similar to and least similar to the anchor point were selected as positive and negative pairs, respectively. The yellow dots marked with indicator arrows... The most similar flow pattern was selected as the front view, in contrast to the blue dot with the indicator arrow. The most obvious manifold pattern is shown, designated as the negative pair. The formulas for the positive and negative pairs are expressed as follows:
[0062]
[0063] in, It is represented as a positive sample corresponding to time step t, and represents the traffic pattern most similar to the current time step; Represented as a negative sample corresponding to time step t, representing the traffic pattern least similar to the current time step; and These represent the indices i that find the minimum or maximum value of the expression within the time step range from 1 to T, respectively. This represents summing over all N regions; It is an indicator function that takes the value 1 when i ≠ t, ensuring that the current time step is not selected; (H t,n -H i,n ) 2 This represents the square of the Euclidean distance between time step t and time step i in region n; This represents the feature dimension after concatenation, where 2F is the sum of local and global features;
[0064] Spatial dimension contrastive learning task:
[0065] Spatial contrastive learning processes local road segment representations and global road network representations based on attention mechanisms, and narrows the distribution of similar samples by maximizing the mutual information of positive sample pairs; its formula is as follows:
[0066]
[0067] Among them, L tl It is the time-contrast 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 temporal consistency features by optimizing the similarity difference between positive and negative pairs. The formula is as follows:
[0069]
[0070] Among them, L sl It is a comparison of learning loss over time. and Let represent 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 index function of (0, 1).
[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 contrastive learning model based on big-kernel 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 the complex teacher model and transfer it to the lightweight student model.
[0073] L distill =α*L pred +(1-α)*τ 2 *KL(σ(z t / τ),σ(z s / τ))
[0074] Among them, z t and z s These are the output feature vectors of the teacher model and the student model, respectively. τ is the temperature parameter, KL(,.,) represents the KL divergence, used to measure the difference between the output probability distributions of the teacher and student models, σ represents the softmax function, which transforms the feature vectors into a probability distribution, and α is the weighting parameter balancing the prediction loss and distillation loss. pred It is the loss function for the prediction task, usually the mean squared error or the mean absolute error, Ldistill It is the total loss function of knowledge distillation, using mean squared error or mean absolute error.
[0075] Preferably, step S7 further includes sub-step S72: designing an incremental learning strategy so that the spatiotemporal graph contrastive learning model can continuously integrate new traffic patterns without forgetting the already learned knowledge.
[0076] (1) Memory Replay: Maintain a historical traffic pattern sample library M, and use it in combination 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 The training loss for new data, θ new and θ old L represents the new and old parameters of the model, respectively. replay (M) is the replay loss of data in the historical sample database M, λ is the weighting parameter that balances 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, used to limit the range of parameter variation, 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 learning model on real-time traffic data in a spatiotemporal comparison.
[0082]
[0083] Where D t Let t be the new data batch at time t, and η be the adaptive learning rate. It is the gradient of the loss function with respect to the parameters, guiding the direction and magnitude of parameter updates, θ. t and θ (t-1) These represent the model parameters at time t and time t-1, respectively.
[0084] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0085] 1. This invention employs three data augmentation strategies: feature-level, topology-level, and time interpolation, which effectively improves the robustness and generalization ability of the model to incomplete traffic data.
[0086] Furthermore, this invention comprehensively considers various data loss 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. It enhances data by randomly masking flow information at different granularities, enabling the model to better handle incomplete data in the real world.
[0087] 2. By employing a large-kernel spatial attention module, and utilizing multi-scale convolution and attention aggregation mechanisms, the model's ability to capture and model local-global spatial dependencies is significantly enhanced. This attention module adopts a dual-branch structure, expanding the receptive field using depthwise separable convolutions at two different scales (5x5 and 7x7), and then adaptively fusing spatial features at different scales through an attention mechanism. This allows for a more comprehensive extraction of multi-scale spatial correlations inherent in the urban road network. Compared to existing methods, this invention can simultaneously consider key information from both local road segments and the global road network, significantly improving the accuracy of spatial modeling.
[0088] 3. This invention designs a comparative learning task in both time and space dimensions. With the assistance of unsupervised signals, it helps the model of this invention learn a more general and discriminative spatiotemporal representation of traffic flow.
[0089] Furthermore, this invention introduces a contrastive task in the spatial dimension, maximizing the mutual information between local and global positive samples to shorten the distance between similar regions in the latent space; in the temporal dimension, it constructs positive and negative sample pairs through hard sampling to optimize the consistency / difference of similar / different traffic trends. The addition of spatiotemporal contrastive learning alleviates the problem of sparse supervision signals in traffic flow prediction and improves the generalization performance of the model.
[0090] 4. This invention constructs an end-to-end trainable joint learning framework that simultaneously optimizes supervised prediction and self-supervised comparison tasks based on encoder sharing, thus balancing accuracy and generalization.
[0091] Furthermore, this invention employs a space-time-space encoder architecture to fully extract local and global spatiotemporal features, while the decoder uses a simple and effective multilayer perceptron structure to reconstruct future traffic flow. The joint training process improves the accuracy of the main task while enhancing the model's robustness by utilizing self-supervised signals from comparative tasks, enabling it to better cope with complex and ever-changing real-world traffic scenarios.
[0092] 5. This invention introduces knowledge distillation and incremental learning mechanisms to achieve continuous model optimization and lightweight deployment.
[0093] Furthermore, this invention utilizes knowledge distillation technology to transfer key knowledge extracted from a well-trained, complex teacher model to a student model with lower computational resource requirements. This significantly reduces the model's computational complexity and storage needs while maintaining prediction accuracy, making it more suitable for deployment on edge devices. Through memory replay and model adaptation mechanisms in the incremental learning strategy, the model can continuously integrate newly emerging traffic patterns and rules without forgetting previously learned knowledge. The online evaluation and update mechanism enables the entire system to be adaptive, dynamically adjusting its internal structure and parameters based on the characteristics of real-time traffic data to maintain continuous optimization of prediction performance. The combination of these technologies not only improves the model's terminal deployability but also enables it to adapt to new characteristics and changing trends in urban traffic over time, providing stable and reliable technical support for long-term intelligent transportation systems.
[0094] 6. In summary, the embodiments of this invention propose a spatiotemporal graph contrastive learning method for traffic flow prediction based on large kernel attention. It effectively addresses the problems of insufficient data loss and noise processing mechanisms in existing technologies through feature-level and topology-level adaptive data augmentation. The large kernel attention mechanism enhances the model's ability to perceive and model dynamic road network structure changes. The introduction of a spatiotemporal contrastive learning task combined with self-supervised signals significantly enhances the model's generalization ability to complex traffic patterns and improves the discriminative power of traffic flow spatiotemporal feature representations. Furthermore, this invention employs an end-to-end joint training framework, which, while improving model prediction accuracy, effectively reduces computational complexity and storage requirements through a knowledge distillation mechanism, enabling efficient deployment of the model on edge devices. Attached Figure Description
[0095] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0096] Figure 1 This is a flowchart illustrating the principle of a spatiotemporal graph contrastive learning method for traffic flow prediction based on big-kernel attention, provided by an embodiment of the present invention.
[0097] Figure 2 This is an architecture diagram of a spatiotemporal graph contrastive learning method for traffic flow prediction based on big-kernel attention, provided by an embodiment of the present invention.
[0098] Figure 3 This is a flowchart illustrating the principle of large-core attention provided in an embodiment of the present invention. Detailed Implementation
[0099] The technical solution of this embodiment of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiment is one embodiment of the present invention, and not all embodiments thereof. Based on this embodiment of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0100] Please see Figures 1 to 3 The present invention provides a spatiotemporal graph contrastive learning method for traffic flow prediction based on big-kernel attention, comprising the following steps:
[0101] Step S1: Organize the collected traffic flow data into a time series format to construct a road network spatiotemporal map;
[0102] In step S1, the spatiotemporal diagram of the road network is G = (V, E, A, X), which is used to characterize the topological structure and temporal characteristics of the urban road network. Its construction process is as follows:
[0103] Sub-step S11: Node set V: Each node in the graph represents a monitoring unit, and the characteristic of a node is the traffic flow sequence of that monitoring unit at different time steps;
[0104] Sub-step S12: Edge set E: Each edge in the graph represents the spatial relationship 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 the set of real numbers, and the matrix describes the adjacency relationships between nodes. The urban space is divided into N = ixj in terms of latitude and longitude, and A... ij =1 indicates that there is an edge connecting node i and node j; otherwise, A ij =0;
[0106] Wherein, traffic flow data X∈R T×N×2 R T×N×2 This represents a spatiotemporal tensor containing the inflow and outflow traffic volumes of N regions over the past T time steps.
[0107] Step S2: Perform feature-level, topology-level, and time-interpolated data augmentation on the traffic flow data to generate an augmented feature matrix as input for subsequent steps, thereby improving the robustness of the model to incomplete data.
[0108] In step S2, the process of performing feature-level, topology-level, and time-interpolated data enhancement on 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 augmentation: By randomly masking traffic information at different granularities, the system simulates data loss caused by accidents, equipment failures, or power outages in real-world scenarios. The masking mechanism is as follows:
[0110]
[0111] Among them, E ij ∈R TxNx2 E ij ε is a random mask with a value between 0 and 1, t is an adjustable value, t represents the current time step (current moment), and T represents the length of the historical time window. The original input feature matrix, For feature-level data augmentation matrix;
[0112] Advantages of sub-step S21: By using random masking, the robustness of the model to missing data is improved, enabling the model to maintain good predictive performance when faced with the unavoidable missing data situation in the real world.
[0113] Sub-step S22: Topology-level data augmentation: By perturbing the adjacency matrix A of the graph, random topology changes are introduced, including the following two perturbation methods:
[0114] (1) Local space 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 To initialize the matrix, M l For a locally augmented matrix, ⊙ is the Hadamard product;
[0117] (2) Global Space Augmentation: A perturbation matrix is self-learned and superimposed on the original adjacency matrix, corresponding to the formula:
[0118] M g =A⊕M t ∈R N*N
[0119] Among them, M t To initialize the matrix, M g For all augmented matrices, add the matrix elements;
[0120] Advantages of sub-step S22: By randomly perturbing the topology, 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 ability of dynamic traffic networks.
[0121] Sub-step S23: Move the data along the time axis to utilize the intermediate state between two consecutive time steps, and perform a weighted average between the two consecutive time steps to effectively improve the temporal granularity and smoothness of the data, thereby ensuring interpolation accuracy. The formula is as follows:
[0122] P (t-S):t =αX (t-S):t +(1-α)X (t-S+1):(t+1)
[0123] Where α is a hyperparameter adjusted from 0 to 1, (tS): t represents the time range from time tS to time t, (t-S+1): (t+1) represents the time range from time t-S+1 to time t+1, and P (t-S):t X represents the new time series data generated through interpolation. (t-S):t X represents the original time series data. (t-S):(t+1) This represents time series data shifted backward by one time step.
[0124] The advantages of sub-step S23 are: by enhancing the continuity and smoothness of the data through time interpolation, the model can learn more fine-grained feature changes in the time dimension, thereby improving the sensitivity to time series changes and the accuracy of prediction.
[0125] In summary, the advantages of step S2 are as follows: it employs three data augmentation strategies—feature-level, topology-level, and time interpolation—effectively improving the robustness and generalization ability of the model to incomplete traffic data. Furthermore, step S2 comprehensively considers various data loss scenarios in actual traffic situations, such as missing flow values, missing regions, and missing continuous time steps caused by accidents, equipment failures, power outages, etc., and performs data augmentation by randomly masking flow information at different granularities, enabling the model to better handle incomplete data in the real world.
[0126] Step S3: Encode the spatiotemporal map of the road network, and use a large kernel attention mechanism to extract spatiotemporal features through large-scale convolution and adaptive feature fusion to enhance spatial dependence 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 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 latent features are extracted from the traffic network. The local graph convolution formula can be defined as:
[0129]
[0130] in, and These are the outputs of the (l-1)th graph convolutional layer for the local branch and the global branch, respectively, and this output serves as the input to the l-th graph convolutional layer; the initial input is the traffic flow data processed by feature enhancement in step S2. and These are the local and global adjacency matrices after degree matrix normalization; where, Θ is a degree matrix, a diagonal matrix, where each diagonal element represents the degree of the corresponding node (i.e., the number of edges connected to the node); Θ is a 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: Mine temporal dependencies and integrate them with spatial information, using a 1×kt standard convolution to obtain the spatial representation H. l and H g Encode;
[0132]
[0133] Among them, [1,K t ] represents the size of the convolution kernel, K t The size of the temporal convolution kernel. and represents the local and global feature representations after temporal convolution, respectively; tanh represents the tangent function; σ represents the sigmoid function; ⊙ represents element-wise multiplication; and These represent the local and global feature representations after processing by the activation function, respectively.
[0134] Sub-step S33: In order to better acquire spatial information, we have a large-core spatial attention module to acquire spatial information;
[0135] Specifically, the spatial receptive field is expanded by using 5x5 and 7x7 depthwise separable convolutions, respectively, and then features of different scales are adaptively fused through an attention mechanism.
[0136] This allows us to obtain spatiotemporal feature information using a space-time-space structure, as shown in the following mathematical formula:
[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 (e.g., 5x5 and 7x7) and attention mechanism by the large kernel attention mechanism. T is the time step, N is the number of nodes, and F is the feature dimension.
[0139] The advantage of step S3 is that it achieves a comprehensive capture of the spatiotemporal dependence of traffic flow through a multi-layered architecture of space-time-space. At the same time, the big kernel attention mechanism expands the spatial receptive field, enabling the model to perceive a wider range of spatial relationships, improving the modeling ability for the impact of long-distance traffic, 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 for both time and space dimensions to enhance representation learning;
[0141] Specifically, step S4 includes the following sub-steps:
[0142] Step S41: Includes contrastive learning tasks in both time and space dimensions, as follows:
[0143] Comparative learning task over time:
[0144] First, the local and global representations are concatenated along the feature dimension to generate a cascaded representation. At each time step, the corresponding sample serves as the anchor point;
[0145] Subsequently, we selected the samples most similar to and least similar to the anchor point from other time steps as positive and negative pairs, respectively, where the yellow dots with indicator arrows are... The most similar flow pattern was selected as the front view, in contrast to the blue dot with the indicator arrow. The most obvious manifold pattern is shown, designated as the negative pair. The formulas for the positive and negative pairs are expressed as follows:
[0146]
[0147] in, It is represented as a positive sample corresponding to time step t, and represents the traffic pattern most similar to the current time step; Represented as a negative sample corresponding to time step t, representing the traffic pattern least similar to the current time step; and These represent the indices i that find the minimum or maximum value of the expression within the time step range from 1 to T, respectively. This represents summing over all N regions; It is an indicator function that takes the value 1 when i ≠ t, ensuring that the current time step is not selected; (H t,n -H i,n ) 2 This represents the square of the Euclidean distance between time step t and time step i in region n; This 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 for the clustering task, and used as a self-supervised signal for the global branch representation H. g Clustering is performed to align the local-global semantic space by minimizing the cross-entropy loss;
[0149] Spatial dimension contrastive learning task:
[0150] Spatial contrastive learning processes local road segment representations and global road network representations based on attention mechanisms, and narrows the distribution of similar samples by maximizing the mutual information of positive sample pairs; its formula is as follows:
[0151]
[0152] Among them, L tl It is the time-contrast 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 temporal consistency features by optimizing the similarity difference between positive and negative pairs. The formula is as follows:
[0154]
[0155] Among them, L sl It is a comparison of learning loss over time. and Let represent 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 index function of (0, 1).
[0156] The advantage of step S4 is that by comparing and learning tasks in both time and space dimensions, the model can learn more robust and discriminative representations. Comparative learning in the time dimension helps to capture the periodic and trend features in time series data, while comparative learning in the spatial dimension enhances the ability to model spatial correlations between regions. This dual-dimensional comparative learning strategy significantly improves the model's ability to identify 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 adopts a multilayer perceptron structure, and uses a fully connected layer to restore the features into traffic prediction values for multiple future time steps;
[0159] The spatiotemporal representation output from 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 for each grid in the next 30 minutes.
[0160] The above steps S1-S6 form a spatiotemporal graph contrastive learning model based on big-kernel attention traffic flow prediction;
[0161] The model was trained end-to-end on four months of data in the training set and its prediction accuracy was evaluated on the test set.
[0162] This model employs an end-to-end trainable joint learning framework, simultaneously optimizing supervised prediction and self-supervised contrastive tasks based on encoder sharing, achieving a balance between accuracy and generalization. Furthermore, this invention utilizes a space-time-space encoder architecture to fully extract local and global spatiotemporal features, while the decoder employs a simple and effective multilayer perceptron structure to reconstruct future traffic flow. The joint training process improves the accuracy of the main task while leveraging the self-supervised signals from the contrastive task to enhance the model's robustness, enabling it to better cope with complex and ever-changing real-world traffic scenarios.
[0163] Step S7: Construct a knowledge distillation and incremental learning framework. Step S7 is used to achieve continuous optimization of this spatiotemporal graph contrastive learning model based on big-kernel attention traffic flow prediction.
[0164] 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 sThese are the output feature vectors of the teacher model and the student model, respectively. τ is the temperature parameter, KL(,.,) represents the KL divergence, used to measure the difference between the output probability distributions of the teacher and student models, σ represents the softmax function, which transforms the feature vectors into a probability distribution, and α is the weighting parameter balancing the prediction loss and distillation loss. pred It is the loss function for the prediction task, usually the mean squared error or the mean absolute error, L distill It is the total loss function of knowledge distillation, using mean squared error (MSE) or mean absolute error (MAE);
[0168] The technical principle of sub-step S71 is: through knowledge distillation, the "knowledge" of the trained complex teacher model (i.e. the spatiotemporal graph contrastive learning model based on big-kernel attention traffic flow prediction constructed by steps S1-S6, which has high prediction performance but consumes a lot of computational resources) is compressed and transferred to the student model with fewer parameters.
[0169] The teacher model's output feature vector is softened (adjusted by the temperature parameter τ) to generate richer probability distribution information, not just the final prediction result. The student model achieves performance close to that of the teacher model with less computational resources by minimizing the KL divergence between its own output and the teacher model's output probability distribution, while optimizing the loss of the basic prediction task.
[0170] Sub-step S72: Design an incremental learning strategy to enable the spatiotemporal graph contrastive learning model to continuously integrate new traffic patterns without forgetting previously learned knowledge:
[0171] (1) Memory Replay: Maintain a historical traffic pattern sample library M, and use it in combination 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 The training loss for new data, θ new and θ old L represents the new and old parameters of the model, respectively. replay (M) is the replay loss of data in the historical sample database M, λ is the weighting parameter that balances 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, used to limit the range of parameter variation, 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 spatiotemporal graph comparison of the learning model's performance on real-time traffic data.
[0177]
[0178] Where D t Let t be the new data batch at time t, and η be the adaptive learning rate. It is the gradient of the loss function with respect to the parameters, guiding the direction and magnitude of parameter updates, θ. t and θ (t-1) These represent the model parameters at time t and time t-1, respectively.
[0179] In summary, the advantages of step S7 lie in achieving continuous model optimization and lightweight deployment through knowledge distillation and incremental learning mechanisms. Furthermore, this invention uses knowledge distillation technology to transfer key knowledge extracted from a well-trained, complex teacher model to a student model with lower computational resource requirements. While maintaining prediction accuracy, this significantly reduces the model's computational complexity and storage requirements, making it more suitable for deployment on edge devices. Through memory replay and model adaptation mechanisms in the incremental learning strategy, the model can continuously integrate newly emerging traffic patterns and rules without forgetting learned knowledge. The online evaluation and update mechanism enables the entire system to have adaptive capabilities, dynamically adjusting its 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 model's terminal deployability 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 long-term intelligent transportation systems.
[0180] Step S8: Return to step S1 and continue training.
[0181] In summary, the embodiments of this invention propose a spatiotemporal graph contrastive learning method for traffic flow prediction based on big-kernel attention. Through feature-level and topology-level adaptive data augmentation strategies, the robustness of the model to incomplete traffic data is effectively improved. The big-kernel attention mechanism significantly enhances the model's ability to perceive and model dynamic road network topology changes. By designing a spatiotemporal contrastive learning task, the model's generalization and representation capabilities for complex spatiotemporal dependencies in traffic flow are further improved. Furthermore, through an end-to-end joint training framework, the model can simultaneously achieve both prediction accuracy and generalization. Utilizing a knowledge distillation mechanism, knowledge from a complex teacher model is efficiently transferred to a lightweight student model, significantly reducing computational and storage requirements while maintaining accuracy, enabling efficient deployment of the model on edge devices.
[0182] Practical applications, exemplified by the Smart Dongguan Traffic Brain, demonstrate that the technical solution proposed in this invention can significantly improve the accuracy and real-time performance of traffic flow prediction at key urban intersections and within the road network, providing crucial data support for traffic control measures such as alleviating traffic congestion, optimizing signal timing, and rationally guiding and diverting traffic.
[0183] The above are merely 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 within the protection scope of the present invention.
Claims
1. A spatiotemporal graph contrastive learning method for traffic flow prediction based on large kernel attention, characterized in that, It includes the following steps: Step S1: Organize the collected traffic flow data into a time series format to construct a road network spatiotemporal map; Step S2: Perform feature-level, topology-level, and time-interpolated data augmentation on the traffic flow data to generate an augmented feature matrix as input for subsequent steps; Step S3: Encode the spatiotemporal map of the road network, and use a large kernel attention mechanism to extract spatiotemporal features through large-scale convolution and adaptive feature fusion to enhance spatial dependence and temporal consistency; Step S4: Based on the spatiotemporal representation after encoding in step S3, design contrastive learning tasks for 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 adopts a multilayer perceptron structure, and uses a fully connected layer to restore the features into traffic prediction values for multiple future time steps; Step S8: Return to step S1 and continue training; In step S1, the road network spatiotemporal diagram is as follows: It is used to characterize the topological structure and temporal features of urban road networks, and its construction process is as follows: Sub-step S11: Node set Each node in the diagram represents a monitoring unit, and the characteristic of a node is the traffic flow sequence of that monitoring unit at different time steps. Sub-step S12: Edge set Each edge in the diagram represents the spatial relationship between two monitoring units, constructed based on the road topology or the Euclidean distance between nodes; Sub-step S13: Adjacency matrix : Representing the set of real numbers, the matrix describes the adjacency relationships between nodes, where the urban space is divided into latitude and longitude. , =1 indicates a node and nodes There is an edge connecting them; otherwise... =0; Among them, traffic flow data , The spatiotemporal tensor representing the inflow and outflow of traffic; In step S2, the process of performing feature-level, topology-level, and time-interpolated data augmentation on traffic flow data to form an augmented feature matrix includes the following sub-steps: Sub-step S21: Feature-level data augmentation simulates data loss caused by accidents, equipment failures, or power outages in real-world scenarios by randomly masking traffic information at different granularities. The masking mechanism is as follows: ; in, , It is a random mask with a value in the range of 0 to 1. It is an adjustable value, where t represents the current time step and T represents the length of the historical time window. The original input feature matrix, For feature-level data augmentation matrix; Sub-step S22: Topology-level data augmentation introduces random topology changes through the adjacency matrix A of the perturbation graph, including the following two perturbation methods: (1) Local space enhancement: Randomly perturb the predefined adjacency matrix A, corresponding to the formula: ; in, To initialize the matrix, For local enhancement matrix, It is the product of Hadama; (2) Global Space Augmentation: A perturbation matrix is self-learned and superimposed on the original adjacency matrix, corresponding to the formula: ; in, To initialize the matrix, For the entire enhancement matrix, Add the matrix elements; Sub-step S23: Move the data along the time axis to utilize the intermediate state between two consecutive time steps, and perform a weighted average between the two consecutive time steps to ensure interpolation accuracy, as shown in the following formula: ; in, It involves adjusting the hyperparameters from 0 to 1. This represents new time series data generated through interpolation. Represents the original time series data. This represents time series data shifted backward by one time step. Between steps S6 and S8, there is also step S7: constructing a knowledge distillation and incremental learning framework. Steps S1-S6 form a spatiotemporal graph contrastive learning model based on big-kernel attention traffic flow prediction. Step S7 is used to achieve continuous optimization of the model.
2. The spatiotemporal graph contrastive learning method for traffic flow prediction based on large kernel attention as described in claim 1, wherein, In step S3, the original feature matrix is defined as follows: The local enhancement matrix is The global enhancement matrix is 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 latent features are extracted from the traffic network. The local graph convolution formula is defined as: ; ; in, and These are the local branch and the global branch, respectively. The output of the graph convolutional layer, which serves as the first graph convolutional layer... The input to a graph convolutional layer; This is the initial input, i.e., the traffic flow data after feature enhancement processing in step S2; and These are the local and global adjacency matrices after degree matrix normalization; where, It is a degree matrix, a diagonal matrix, where each diagonal element represents the degree of the corresponding node; It is a learnable weight parameter matrix shared by both branches; This represents the dimension of the feature vector of each node; Sub-step S32: Mining time dependencies and integrating them with spatial information. Standard convolution pairs obtain spatial representations and Encode; ; ; ; ; in, Indicates the size of the convolution kernel. The size of the temporal convolution kernel. and These represent the local and global feature representations after temporal convolution, respectively. Represents the tangent function; Represents the sigmoid function; and These represent the local and global feature representations after processing by the activation function, respectively. Sub-step S33: In order to better acquire spatial information, spatial information is acquired through the spatial attention module of the large kernel; Among them, respectively through and Depth-separable convolutions expand the spatial receptive field, and then features at different scales are adaptively fused through an attention mechanism; This allows us to obtain spatiotemporal feature information using a space-time-space structure, as shown in the mathematical formula below: ; ; in, 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 of the large kernel attention mechanism that adaptively fuses features through multi-scale convolution and attention mechanism.
3. The spatiotemporal graph comparison learning method for traffic flow prediction based on large kernel attention as described in claim 1, 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. ; in, and These are the output feature vectors of the teacher model and the student model, respectively. It's a temperature parameter. Divergence is used to measure the difference between the output probability distributions of the teacher model and the student model. express The function transforms a feature vector into a probability distribution. It is a weighting parameter that balances the prediction loss and the distillation loss. It is the loss function for the prediction task, using mean squared error or mean absolute error. It is the total loss function of knowledge distillation, using mean squared error or mean absolute error.
4. The spatiotemporal graph comparison learning method for traffic flow prediction based on large kernel attention as described in claim 3, characterized in that, Step S7 also includes sub-step S72: designing an incremental learning strategy to enable the spatiotemporal graph contrastive learning model to continuously integrate new traffic patterns without forgetting previously learned knowledge. (1) Memory Replay: Maintain a historical traffic pattern sample library M, and use it in combination when learning new patterns. ; (2) Model adaptation: Design regularization terms to prevent drastic changes in key parameters. ; in, It is the training loss on new data. and These represent the new and old parameters of the model, respectively. It is the playback loss of data in the historical sample library M. It is a weighting parameter that balances the learning of new and old knowledge. It is the playback loss of data in the historical sample library M. It is the L2 norm, used to limit the range of parameter variation, and γ is the regularization strength parameter.
Citation Information
Patent Citations
Method and device for predicting traffic flow by combining rainfall capacity and space-time diagram convolution model
CN118247953A
Deep learning traffic flow prediction method based on meteorological information fusion
CN119181256A