Traffic jam prediction method and device based on comparative learning and knowledge distillation
By introducing contrastive learning and self-distillation mechanisms into the traffic congestion prediction model and constructing a multi-task loss function, the problems of insufficient diversity and limited generalization ability of the STGNN model are solved, and more accurate and stable traffic congestion prediction is achieved.
Patent Information
- Application Number
- CN202610076327.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-21
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2046-01-21
AI Technical Summary
Existing traffic congestion prediction methods based on spatiotemporal graph neural networks (STGNN) suffer from insufficient model diversity, limited generalization ability, difficulty in distinguishing complex congestion patterns, and insufficient supervision signals, resulting in poor prediction performance.
By introducing a contrastive learning module and a self-distillation mechanism, a temporal feature generator is constructed through a variational autoencoder (VAE) and a contrastive learning module. Combined with a spatial topology learning module and a self-distillation mechanism, a backbone spatiotemporal graph neural network (STGNN) is used to optimize model parameters using a multi-task loss function, thereby enhancing feature diversity and robustness.
It significantly improves the accuracy of traffic congestion prediction and the generalization ability of the model, enabling it to better distinguish complex congestion patterns and improve the stability and accuracy of prediction.
Smart Images

Figure CN121542933A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of traffic congestion prediction technology, specifically relating to a traffic congestion prediction method and apparatus based on contrastive learning and knowledge distillation. Background Technology
[0002] With economic development and accelerated urbanization, various modes of transportation have become rapidly popularized, the number of motor vehicles has surged, and the pressure on urban transportation systems has become increasingly severe. Traffic congestion has become a core challenge for sustainable urban development.
[0003] Traffic congestion prediction is one of the core tasks of intelligent transportation systems. Existing methods based on spatiotemporal graph neural networks (STGNN) (ST-FiT) achieve prediction by modeling spatial adjacency relationships and temporal dependencies, but their generated models lack diversity and have limited generalization ability.
[0004] Specifically, in the model's temporal data augmentation module, traditional variational autoencoders (VAEs), due to their inherent training objectives and inference mechanisms, are prone to "pattern collapse" when generating complex spatiotemporal feature data. That is, the model only generates a few of the most common or simplest traffic patterns, ignoring the various sporadic, sudden, or complex congestion evolution patterns that exist in the real road network. This results in insufficient diversity of the generated data and fails to effectively enhance the model's generalization ability.
[0005] The backbone network of the model (i.e., the core STGNN) relies solely on the final prediction result as a supervision signal. This single "end-to-end" supervision signal is essentially a "weak supervision" that cannot provide fine-grained guidance for feature learning in the intermediate layers of the model. As a result, the model has limited ability to capture complex spatiotemporal dependencies, and it is particularly difficult to distinguish between congestion patterns that look similar but have different causes (such as accident congestion and normal peak congestion). Summary of the Invention
[0006] To address the technical problem that existing methods based on Spatiotemporal Graph Neural Networks (STGNNs) for traffic congestion prediction, which rely on modeling spatial adjacency relationships and temporal dependencies to achieve prediction, suffer from insufficient diversity in generated models and limited model generalization ability, this application proposes a traffic congestion prediction method and apparatus based on contrastive learning and knowledge distillation.
[0007] The first aspect of this application provides a traffic congestion prediction method based on contrastive learning and knowledge distillation, comprising the following steps: S1: Preprocess the original traffic dataset to obtain traffic feature time series data, wherein the traffic feature time series data includes traffic indicators and congestion levels based on traffic density. S2: Construct a traffic congestion prediction model, which includes the following steps: A time feature generator is used to enhance the time features of the traffic feature time series data. It includes a variational autoencoder and a contrastive learning module. The contrastive learning module is configured to generate positive samples by time series perturbation and use the features of different nodes or time periods as negative samples to maximize the latent space difference. The spatial topology learning module is used to perform spatial feature enhancement on data that has been enhanced with temporal features, resulting in data with enhanced spatiotemporal features. A backbone spatiotemporal graph neural network is used to output congestion level predictions based on data enhanced with spatiotemporal features. The backbone spatiotemporal graph neural network adopts a self-distillation mechanism, including a teacher model and a student model, and uses exponential moving average to update the parameters of the teacher model. S3: Construct a multi-task loss function; S4: Train the traffic congestion prediction model using the traffic feature time series data, and optimize the model parameters by minimizing the multi-task loss function; S5: Input the traffic dataset to be predicted into the trained traffic congestion prediction model, and output the predicted congestion level of each node at each sampling time point.
[0008] Furthermore, multi-task loss function The expression is:
[0009]
[0010] in, , , Here are the weighting coefficients, which are... The original supervised loss function is... Let be the distillation loss function. This is a combination of the VAE loss function and the contrastive learning loss function. The loss function for VAE is... To compare the learning loss function.
[0011] Furthermore, the preprocessing in step S1 includes: Traffic flow and average speed are extracted as traffic indicators from the original traffic dataset; if the original traffic dataset includes average occupancy, it is also extracted. Replace the zero values in the extracted traffic indicators with the average of the non-zero values; Calculate traffic density; Traffic density is normalized to the range [0, 1]. Based on the normalized traffic density, a linear mapping method is used to classify congestion levels. The extracted traffic indicators are combined with the congestion level to form the time-series data of traffic characteristics.
[0012] Furthermore, the calculation of traffic density includes: If the original traffic data does not include average occupancy, traffic density is calculated using the following formula. : ; in, For traffic flow, Average speed; If the original traffic dataset includes average occupancy, then traffic density is calculated using the following formula. :
[0013] in, , The normalized average market share These are the preset weighting coefficients.
[0014] Furthermore, normalizing the traffic density to the [0,1] range includes: Calculate the traffic density array minimum value and maximum value ; like and If they are equal, return a value equal to... An array of the same shape, where all elements are 0; Otherwise, use the following formula for linear normalization: ; in, This represents the result after normalization. For array A sample value in the dataset.
[0015] Furthermore, the congestion level is divided by a continuous congestion index, which is derived from the normalized traffic density through a linear mapping method. The congestion index classifies traffic conditions into four levels: unimpeded, slightly congested, moderately congested, and severely congested.
[0016] Furthermore, the normalized traffic density is converted into a continuous congestion index using a linear mapping method, specifically as follows: Calculate the normalized traffic density , , Third place; Traffic density value Mapped to a congestion index according to the following rules: like The congestion index is... ; like The congestion index is... ; like The congestion index is... ; like The congestion index is... .
[0017] Another aspect of the present invention provides a traffic congestion prediction device based on contrastive learning and knowledge distillation, comprising the following modules: Preprocessing module: configured to preprocess the original traffic dataset to obtain traffic feature time series data, wherein the traffic feature time series data includes traffic indicators and congestion levels based on traffic density; Model building module: Configured to build traffic congestion prediction models, including: A time feature generator is used to enhance the time features of the traffic feature time series data. It includes a variational autoencoder and a contrastive learning module. The contrastive learning module is configured to generate positive samples by time series perturbation and use the features of different nodes or time periods as negative samples to maximize the latent space difference. Spatial topology learning module: used to perform spatial feature enhancement on data that has been enhanced with temporal features, to obtain data with enhanced spatiotemporal features; The backbone spatiotemporal graph neural network is used to output congestion level prediction values based on data enhanced with spatiotemporal features. The backbone spatiotemporal graph neural network adopts a self-distillation mechanism, including a teacher model and a student model, and uses exponential moving average to update the parameters of the teacher model. And it is configured to construct a multi-task loss function, and to add a dynamic weight adjustment strategy to the multi-task loss function; Model training module: configured to train the traffic congestion prediction model using the traffic feature time series data, and optimize the model parameters by minimizing the multi-task loss function; Prediction module: It is configured to input the traffic dataset to be predicted into the trained traffic congestion prediction model and output the predicted congestion level of each node at each sampling time point.
[0018] The beneficial effects of the method described in this invention are as follows: 1. Enhanced feature diversity and robustness in synergy.
[0019] This application constructs a collaborative "generation-discrimination" internal mechanism by introducing a contrastive learning module into a variational autoencoder (VAE). The VAE is responsible for learning the basic distribution of the data to ensure generation quality, while the contrastive learning module explicitly encourages the model to discover and retain atypical temporal patterns that are easily overlooked by the VAE by maximizing the difference between positive and negative samples in the latent space. This internal collaborative mechanism effectively avoids the pattern collapse problem of the VAE in principle, resulting in augmented data that is not only diverse but also more discriminative.
[0020] 2. Enhanced model generalization and knowledge extraction capabilities.
[0021] The self-distillation mechanism introduced in this application within the Spatiotemporal Graph Neural Network (STGNN) essentially constructs a dynamically evolving "teacher-student mutual learning" system. The teacher model smooths the parameters of the student model using an exponential moving average (EMA), providing a more stable and informative "soft label" supervision signal. The soft labels contain relative relationship information between categories (congestion levels). Compared to single supervision using only "hard labels," this guides the student model to learn the decision boundaries between categories and the internal patterns of the data, thereby improving the model's generalization ability in complex traffic scenarios.
[0022] The traffic congestion prediction method and apparatus based on contrastive learning and knowledge distillation provided by this invention are applicable to traffic congestion prediction. Attached Figure Description
[0023] Figure 1 This is a flowchart illustrating the traffic congestion prediction method based on contrastive learning and knowledge distillation in an embodiment of the present invention. Figure 2 This is a schematic diagram of the traffic congestion prediction model in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of the time feature generator (including a variational autoencoder and a contrastive learning module) in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of the backbone spatiotemporal graph neural network (introducing a self-distillation mechanism) in an embodiment of the present invention. Detailed Implementation
[0024] The technical solution of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the present invention.
[0025] Example 1: like Figure 1 and Figure 2 As shown, this embodiment provides a technical solution: A traffic congestion prediction method based on contrastive learning and knowledge distillation includes the following steps: Step S1: Preprocess the original traffic dataset to obtain traffic feature time series data, which includes traffic indicators and congestion levels based on traffic density.
[0026] The raw traffic data consists of traffic indicators collected at each node (the basic observation point or sensor location in the traffic network) at each sampling time point, including at least two traffic indicators: traffic flow and average speed. It may also include an additional traffic indicator: average occupancy.
[0027] In the Spatiotemporal Graph Neural Network (STGNN) model, the entire urban road network is abstracted as a graph, which consists of nodes and edges. The nodes represent observation points or sensors, and the edges represent the connections between nodes, such as whether two sensors are on the same road, whether they are adjacent, or the association defined based on road connectivity.
[0028] Traffic flow refers to the number of vehicles passing through a node per unit of time (e.g., per hour). Average speed refers to the average speed at which vehicles travel along a road. Average occupancy refers to the proportion of time that road space is occupied. Among these, average occupancy provides a stable and direct measure of road space utilization and congestion. Using it to adjust traffic density can significantly improve the accuracy of the model's perception of real traffic conditions, thereby making more reliable predictions.
[0029] Step S2: Construct a traffic congestion prediction model, which includes the following steps: A temporal feature generator is used to enhance the temporal features of the traffic feature time-series data generated in step S1. The temporal feature generator includes a variational autoencoder (VAE) and a contrastive learning module. The contrastive learning module is configured to generate positive samples through time-series perturbation and utilize features from different nodes or time periods as negative samples to maximize latent space differences, thereby enhancing the diversity of the generated data. For example, latent space differences can be maximized based on normalized cross-entropy loss with temperature parameters (NT-Xent loss), a commonly used and classic loss function in the field of contrastive learning.
[0030] The spatial topology learning module is used to enhance the spatial features of the data after temporal feature enhancement, resulting in data with enhanced spatiotemporal features.
[0031] The backbone spatiotemporal graph neural network (STGNN) is used to output congestion level predictions based on data enhanced with spatiotemporal features. The backbone spatiotemporal graph neural network adopts a self-distillation mechanism, which includes a teacher model and a student model, and uses the exponential moving average (EMA) to update the parameters of the teacher model.
[0032] S3: Constructing a multi-task loss function Its expression is: ; ; in, , , These are the weighting coefficients. The original supervised loss function is... Let be the distillation loss function. This is a combination of the VAE loss function and the contrastive learning loss function. It is the VAE loss function. It is the contrastive learning loss function.
[0033] Optional, original supervised loss function Using the mean absolute error (MAE), the distillation loss function KL divergence is used.
[0034] Distillation loss function The difference between the student model output and the teacher model's softened labels is calculated using KL divergence, with the following formula: ; in, This refers to the temperature parameter.
[0035] Step S4: Train a traffic congestion prediction model using time-series traffic feature data, and optimize the model parameters by minimizing the multi-task loss function.
[0036] Step S5: Input the traffic dataset to be predicted into the trained traffic congestion prediction model, and output the predicted congestion level of each node at each sampling time point.
[0037] The core innovation of this embodiment lies in the construction strategy of the traffic congestion prediction model in step S2. Specifically, it is reflected in: First, an improved time feature generator is adopted.
[0038] Existing time feature generators only include variational autoencoders (VAEs). In this embodiment, the time feature generator is improved by adding a contrastive learning module. A contrastive learning loss (function) is added to the latent space to force the generated time series data to align with the real data in terms of time series patterns, thus avoiding the generation of invalid data or data that deviates from the true distribution.
[0039] Variational autoencoders (VAEs), as an existing part of temporal feature generators, are used to learn the latent distribution of traffic data and generate synthetic samples. The encoder maps the input data to the mean and variance of the latent space, and then generates latent variables through reparameterization sampling. Finally, the decoder reconstructs the samples into samples that are similar to the original input data but have a certain degree of randomness. During training, the model parameters are optimized by minimizing the reconstruction error and KL divergence, so that the generated samples retain the main features of the data while also having diversity.
[0040] Reference Figure 3 As shown, the specific construction process (including training method) of the improved temporal feature generator is as follows: Initialization Phase: Initialize the variational autoencoder (including encoder and decoder) and the contrastive learning module (including shared encoder and projector head). Ensure that the encoder of the variational autoencoder (VAE) shares the spatiotemporal graph convolutional layer parameters with the feature extraction network of the contrastive learning module.
[0041] Variational Autoencoder (VAE) pre-training phase: The VAE is trained using raw traffic data, learning the latent distribution of the data by minimizing reconstruction error and KL divergence. The trained VAE can generate synthetic samples consistent with the real data distribution, providing more diverse training data for contrastive learning.
[0042] The joint training phase specifically includes: Data generation: Variational autoencoders (VAEs) sample from the latent space to generate synthetic samples, which together with the original samples form the training set.
[0043] Data augmentation: Multiple data augmentation strategies are applied to the original samples and the samples generated by the variational autoencoder (VAE) to generate positive and negative sample pairs required for contrastive learning.
[0044] Feature extraction and contrastive learning: The enhanced samples are input into the shared encoder for feature extraction, then mapped to the contrast space through the projection head, the contrastive learning loss is calculated and the model parameters are updated.
[0045] Variational Autoencoder (VAE) Optimization: Using features extracted during contrastive learning, the VAE is further optimized by reconstructing consistency loss to generate samples that better meet the needs of contrastive learning.
[0046] Dynamic weight adjustment phase: The weights of the variational autoencoder (VAE) loss, contrastive learning loss, and reconstruction consistency loss are dynamically adjusted based on the training phase. In the early stages of training, the focus is on the VAE learning the basic distribution of the data, with weights biased towards the VAE loss. In the later stages of training, the weights of contrastive learning are increased to enhance the robustness of the feature representation, while the reconstruction consistency loss ensures the interpretability of the features.
[0047] Iterative optimization phase: Repeat the joint training process described above. The variational autoencoder (VAE) continuously generates higher-quality synthetic samples, while the contrastive learning module continuously optimizes the feature representation. The two form a mutually reinforcing closed loop. With training iterations, the model gradually learns feature representations that both conform to the data distribution and are robust to disturbances, thereby improving the accuracy and stability of traffic flow prediction.
[0048] Optionally, the contrastive learning module adopts the SimCLR architecture, including: The input time window is randomly perturbed (e.g., node dropping, noise injection) to generate positive samples.
[0049] Features from different nodes or features from non-adjacent time periods are used as negative samples.
[0050] Alternatively, in a time feature generator, a time series data is subjected to two random perturbations, resulting in two similar versions, which constitute a positive sample pair. Other samples in the same batch of training data are treated as negative samples.
[0051] Optionally, the contrastive learning module uses the NT-Xent loss function: ; in, Original features For positive sample features, For temperature parameters, For batch size, This represents the contrastive learning loss function.
[0052] The latent space contrastive loss is calculated using the NT-Xent loss function. In the latent space (Embedding vector space) obtained after feature extraction, the feature representation is optimized by calculating the similarity difference between positive and negative sample pairs.
[0053] Second, the spatial topology learning module.
[0054] The introduced spatial topology learning module uses a graph convolutional network (GCN) layer to learn the road connection relationships between nodes, obtain a spatial topology feature matrix, and concatenate it with the temporally enhanced data to obtain spatiotemporally enhanced data.
[0055] The spatial topology learning module is used for: Combine the node's time-series sliding window data with the initial adjacency matrix. As input; Using a multilayer perceptron (MLP) encoder, the time-series sliding window data of each node is converted into a hidden representation; Through another multilayer perceptron (MLP), each pair of nodes , The hidden representation is mapped to a scalar Finally, a scalar matrix is obtained. Using this matrix Parameterize the Bernoulli distribution between node pairs; By employing the Gumbel-Softmax reparameterization technique, a refined adjacency matrix is constructed by sampling from the Bernoulli distribution. To characterize the learned spatial topology, i.e. ,in For temperature parameters; To enhance the sparsity of the spatial topology, a threshold is used. right Perform the transformation, that is ,in For temperature, make Time node and The probability of generating edges between them decreases.
[0056] Finally, the module outputs a refined adjacency matrix. This matrix can be used for prediction tasks in subsequent backbone spatiotemporal graph neural networks (STGNN).
[0057] Third, the improved backbone spatiotemporal graph neural network (STGNN).
[0058] Existing STGNNs do not include a self-distillation mechanism. This embodiment improves STGNNs by introducing a self-distillation mechanism. The core backbone network is the existing part, while the improved part includes a teacher-student model structure and a multi-task loss function.
[0059] Reference Figure 4 As shown, the construction process of the improved backbone spatiotemporal graph neural network (STGNN) is as follows: 1. The model initialization phase includes the following processes: Create a dual-model structure: Initialize two identical spatiotemporal graph neural network (STGNN) models, serving as the teacher model and the student model respectively. Both have the same architecture (such as multi-layer spatiotemporal convolutional blocks and output layers), but their parameters are independent.
[0060] Parameter synchronization: In some implementations, the student model inherits the initial parameters (such as pre-trained weights) of the teacher model, accelerating convergence.
[0061] 2. The teacher model training phase includes the following processes: Data loading and preprocessing: Historical traffic flow data (such as vehicle speed and traffic volume) is acquired from the traffic sensor network; a spatiotemporal graph structure is constructed, where nodes represent sensors and edges represent road connections; the data is standardized and processed using a sliding window method to generate training samples. Specifically, in this embodiment, data with enhanced spatiotemporal features is used as training samples.
[0062] Forward propagation: The teacher model receives input data and extracts spatial and temporal features through spatiotemporal convolutional layers; the output layer generates traffic flow predictions for future time steps.
[0063] Loss calculation and parameter update: Calculate the loss between the predicted value and the true value (such as RMSE, MAE); update the teacher model parameters through backpropagation.
[0064] 3. The teacher model knowledge extraction stage specifically includes the following processes: Fix teacher parameters: After training is complete, freeze all parameters of the teacher model to ensure stable output during knowledge transfer.
[0065] Generating Soft Targets: The teacher model performs another forward propagation on the training data to generate predictions. Temperature scaling is then applied to these predictions to soften the probability distribution and expose more relative relationships between categories. The formula for generating soft targets is as follows: ; Among them, temperature The time distribution is smoother. Time degenerates into standard .
[0066] 4. The student model distillation training phase includes the following processes: Data preparation: Use the same training data as the teacher model; the student model receives the same input and generates its own predictions (hard predictions).
[0067] Multi-task loss calculation (for ease of understanding, we will not consider the case of contrastive learning loss for now): Task Loss (i.e., the original supervised loss function): the loss between the student's hard prediction and the true label (such as MSE), ensuring that the student learns the basic task; Distillation Loss: The loss between student soft predictions (generated at the same temperature T) and teacher soft labels (such as KL divergence), guiding students to learn the teacher's generalization ability; The total loss is obtained by weighting the two types of losses, as shown in the following formula: ; in, The distillation weights are typically increased as the training progresses.
[0068] In this embodiment, because the temporal feature generator adds a contrastive learning module, a contrastive learning loss (function) is introduced into the latent space. Therefore, the multi-task loss function, i.e., the total loss, is... The calculation process is as follows: ; ; in, , , These are the weighting coefficients. The original supervised loss function is... Let be the distillation loss function. This is a combination of the VAE loss function and the contrastive learning loss function. It is the VAE loss function. It is a contrastive learning loss function; Student model parameter update: Update only the parameters of the student model through backpropagation so that it fits both the real labels and the teacher's soft knowledge.
[0069] 5. The stage of dynamically adjusting distillation parameters includes the following: Temperature annealing: A higher temperature T is used in the early stages of training to soften the teacher's output distribution and encourage students to learn a wider range of knowledge; the temperature is lowered in the later stages of training to focus on the teacher's confident predictions and improve students' accuracy.
[0070] Distillation weight scheduling: In the early stages of model training, the original supervised loss weights ( The weight is set to 1.0, which dominates the learning process and encourages the student model to focus on learning the basic patterns corresponding to the original supervised loss function, ensuring mastery of fundamental tasks. Distillation loss weights ( The initial weight is set to 0.5, and the weight of the contrastive learning loss is set to 0.1 to assist the original supervised loss in training.
[0071] As training progressed, after the warm-up rounds, It begins to decay linearly. Specifically, as the number of training epochs increases, the decay rate decreases according to the formula... , The value gradually decreased from 1.0 to 0.1. During this process, the relative influence of distillation loss and contrastive learning loss gradually increased. Distillation loss softens the teacher model's output distribution and uses KL divergence to measure the difference between the student model's and teacher model's outputs, helping the student model learn complex decision-making logic. Contrastive learning loss, on the other hand, enhances the model's ability to distinguish similar samples by maximizing the similarity of positive sample pairs and minimizing the similarity of negative sample pairs. Therefore, as... As the learning curve fades, the student model can gradually absorb the advanced knowledge of the teacher model, achieving a smooth transition from basic learning to knowledge refinement.
[0072] 6. Teacher model update, specifically including the following processes: Periodic parameter inheritance: In some implementations, the parameters of the student model are copied back to the teacher model at regular training cycles.
[0073] Forming a closed-loop self-learning: The teacher model continuously evolves by absorbing the latest knowledge from students, forming an iterative improvement process.
[0074] Finally, in the inference stage, only the student model is used for prediction, and the teacher model is no longer involved. Since the student model learns both the real labels and the teacher's generalized knowledge at the same time, its performance is usually better than the model trained alone.
[0075] In this embodiment, the student model and the teacher model share the backbone network structure. The teacher model updates its parameters from the student model via EMA, using the following formula:
[0076] in, denoted as EMA decay coefficient, where EMA stands for Exponential Moving Average.
[0077] As can be seen, the traffic congestion prediction method based on contrastive learning and knowledge distillation in this embodiment addresses the shortcomings of existing ST-FiT models through the following technical solutions: Traffic density is calculated based on traffic indicators in the dataset, and congestion levels are classified based on traffic density.
[0078] A contrastive learning module is introduced into the variational autoencoder (VAE). Positive samples are generated by perturbating the time window and negative samples are generated by using features of different nodes or time periods. The latent space difference is maximized based on NT-Xent loss, thereby enhancing the diversity of generated data.
[0079] A backbone spatiotemporal graph neural network (STGNN) with a self-distillation optimization mechanism is adopted. The teacher model parameters are updated through a teacher-student model architecture and exponential moving average (EMA). The prediction accuracy is improved by combining the original loss and distillation loss. By combining comparative learning with self-distillation, the prediction accuracy is significantly improved, making it suitable for traffic congestion prediction scenarios.
[0080] In summary, the traffic congestion prediction method based on contrastive learning and knowledge distillation in this embodiment has the following advantages: 1. Enhanced feature diversity and robustness in synergy.
[0081] This application constructs a collaborative "generation-discrimination" internal mechanism by introducing a contrastive learning module into a variational autoencoder (VAE). The VAE is responsible for learning the basic distribution of the data to ensure generation quality, while the contrastive learning module explicitly encourages the model to discover and retain atypical temporal patterns that are easily overlooked by the VAE by maximizing the difference between positive and negative samples in the latent space. This internal collaborative mechanism effectively avoids the pattern collapse problem of the VAE in principle, resulting in augmented data that is not only diverse but also more discriminative.
[0082] 2. Enhanced model generalization and knowledge extraction capabilities.
[0083] The self-distillation mechanism introduced in this application within the Spatiotemporal Graph Neural Network (STGNN) essentially constructs a dynamically evolving "teacher-student mutual learning" system. The teacher model smooths the parameters of the student model using an exponential moving average (EMA), providing a more stable and informative "soft label" supervision signal. This soft label contains relative relationship information between categories (congestion levels). Compared to single supervision using only "hard labels," it guides the student model to learn the decision boundaries between categories and the internal patterns of the data, thereby improving the model's generalization ability in unseen complex traffic scenarios.
[0084] 3. The synergistic optimization effect of multi-task losses.
[0085] The multi-task loss function designed in this application is not a simple weighted sum. Through the proposed dynamic weight adjustment strategy, this loss function guides the model to optimize in stages and with emphasis during training: initially focusing on mastering the basic prediction task (high... In the middle stage, students begin to absorb generalized knowledge from the teacher model (enhancing) Later, the learning of features that are robust to perturbations is strengthened (to improve...). This orderly and dynamic optimization process ensures that the model ultimately achieves the optimal balance between accuracy, generalization, and robustness through its learning path.
[0086] In summary, through the joint optimization of contrastive learning and self-distillation, this application significantly improves the accuracy and robustness of traffic congestion prediction, making it suitable for real-time prediction scenarios in intelligent transportation systems.
[0087] Example 2: As mentioned in Example 1, the original traffic dataset includes at least two traffic indicators: traffic flow and average speed, and may also include average occupancy.
[0088] Based on Example 1, the preprocessing in step S1 includes: Traffic flow and average speed are extracted as traffic indicators from the original traffic dataset; if the original traffic dataset includes average occupancy, it is also extracted.
[0089] Replace the zero values in the extracted traffic indicators with the average of the non-zero values.
[0090] Calculate traffic density.
[0091] Traffic density is normalized to the range [0, 1].
[0092] Based on the normalized traffic density, a linear mapping method is used to classify congestion levels.
[0093] The extracted traffic indicators are combined with congestion levels to form time-series data of traffic characteristics.
[0094] Example 3: Based on Example 2, the calculation of traffic density includes: If the average occupancy rate is not included in the original traffic dataset, traffic density is calculated using the following formula: ; in, For traffic density, For traffic flow, This represents the average speed.
[0095] If the original traffic dataset includes average occupancy, then use the following steps to calculate traffic density: First, the average occupancy rate is normalized, then weighted and summed with the initial density calculated based on traffic flow and average speed to obtain the final traffic density. The specific formula is as follows: ; ; in, For traffic density, For the initial density, The normalized average market share These are the weighting coefficients.
[0096] In this embodiment, the weighting coefficient The default value is 0.7, which can be adjusted according to the actual situation.
[0097] Example 4: Based on Example 2, normalizing the traffic density to the range of [0, 1] includes: Calculate the traffic density array minimum value and maximum value .
[0098] like and If they are equal, return a value equal to... An array of elements of the same shape, all of which are 0.
[0099] Otherwise, use the following formula for linear normalization: ; in, This represents the result after normalization. For array A sample value in the dataset.
[0100] Example 5: Based on Example 2, the congestion level is a continuous congestion index converted from the normalized traffic density through a linear mapping method. The congestion index divides traffic congestion into four levels: unimpeded, slightly congested, moderately congested, and severely congested.
[0101] In this embodiment, the specific process of classifying congestion levels using the linear mapping method is as follows: Calculation of normalized traffic density , , The ternary digits divide the normalized traffic density into four intervals: [0, ... ]、( , ]、( , ]、( , 1).
[0102] The four intervals are linearly mapped to equidistant subintervals within the range [0, 1].
[0103] Let the normalized traffic density be... : like ,but Corresponding congestion index The congestion index range corresponding to the interval [0, p25] is [0, 0.25], corresponding to the first congestion level: unimpeded.
[0104] like ,but Corresponding congestion index The congestion index range corresponding to the interval (p25, p50) is (0.25, 0.5], which corresponds to the second congestion level: mild congestion.
[0105] like ,but Corresponding congestion index The congestion index range corresponding to the interval (p50, p75) is (0.5, 0.75), corresponding to the third congestion level: moderate congestion.
[0106] like ,but Corresponding congestion index The congestion index range corresponding to the interval (p75, 1) is (0.75, 1], which corresponds to the 4th congestion level: severe congestion.
[0107] Example 6: like Figure 4 As shown, this embodiment provides a technical solution: A traffic congestion prediction device based on contrastive learning and knowledge distillation includes the following modules: The preprocessing module is configured to preprocess the original traffic dataset to obtain traffic feature time series data, which includes traffic indicators and congestion levels based on traffic density. The model building module, configured to build traffic congestion prediction models, includes the following: A time feature generator is used to enhance the time features of traffic feature time series data. It includes a variational autoencoder (VAE) and a contrastive learning module. The contrastive learning module is configured to generate positive samples by time series perturbation and use features of different nodes or time periods as negative samples to maximize the latent space differences. The spatial topology learning module is used to perform spatial feature enhancement on data that has been enhanced with temporal features, so as to obtain data with enhanced spatiotemporal features. The backbone spatiotemporal graph neural network (STGNN) is used to output congestion level predictions based on data enhanced with spatiotemporal features. The STGNN adopts a self-distillation mechanism, including a teacher model and a student model, and uses exponential moving average (EMA) to update the parameters of the teacher model. and configured to construct a multi-task loss function Its expression is: ; ; in, , , These are the weighting coefficients. The original supervised loss function is... Let be the distillation loss function. This is a combination of the VAE loss function and the contrastive learning loss function. The loss function for VAE is... To learn the loss function by comparison; The model training module is configured to train a traffic congestion prediction model using time-series traffic feature data and optimize model parameters by minimizing the multi-task loss function. The prediction module is configured to input the traffic dataset to be predicted into the trained traffic congestion prediction model and output the predicted congestion level of each node at each sampling time point.
[0108] The traffic congestion prediction device in this embodiment can be used to implement any of the traffic congestion prediction methods in embodiments 1 to 5 above. Further implementation details can be found in the descriptions of the above embodiments, and will not be repeated here.
Claims
1. A traffic congestion prediction method based on contrastive learning and knowledge distillation, characterized in that, Includes the following steps: S1: Preprocess the original traffic dataset to obtain traffic feature time series data, wherein the traffic feature time series data includes traffic indicators and congestion levels based on traffic density. S2: Construct a traffic congestion prediction model, which includes the following steps: A time feature generator is used to enhance the time features of the traffic feature time series data. It includes a variational autoencoder and a contrastive learning module. The contrastive learning module is configured to generate positive samples by time series perturbation and use the features of different nodes or time periods as negative samples to maximize the latent space difference. The spatial topology learning module is used to enhance the spatial features of the data after temporal feature enhancement, resulting in data with enhanced spatiotemporal features. A backbone spatiotemporal graph neural network is used to output congestion level predictions based on data enhanced with spatiotemporal features. The backbone spatiotemporal graph neural network adopts a self-distillation mechanism, including a teacher model and a student model, and uses exponential moving average to update the parameters of the teacher model. S3: Construct a multi-task loss function; S4: Train the traffic congestion prediction model using the traffic feature time series data, and optimize the model parameters by minimizing the multi-task loss function; S5: Input the traffic dataset to be predicted into the trained traffic congestion prediction model, and output the predicted congestion level of each node at each sampling time point.
2. The traffic congestion prediction method based on contrastive learning and knowledge distillation according to claim 1, characterized in that, Multi-task loss function The expression is: ; ; in, , , Here are the weighting coefficients, which are... The original supervised loss function is... Let be the distillation loss function. This is a combination of the VAE loss function and the contrastive learning loss function. The loss function for VAE is... To compare the learning loss function.
3. The traffic congestion prediction method based on contrastive learning and knowledge distillation according to claim 2, characterized in that, The preprocessing in step S1 includes: Traffic flow and average speed are extracted as traffic indicators from the original traffic dataset; if the original traffic dataset includes average occupancy, it is also extracted. Replace the zero values in the extracted traffic indicators with the average of the non-zero values; Calculate traffic density; Traffic density is normalized to the range [0, 1]. Based on the normalized traffic density, a linear mapping method is used to classify congestion levels. The extracted traffic indicators are combined with the congestion level to form the time-series data of traffic characteristics.
4. The traffic congestion prediction method based on contrastive learning and knowledge distillation according to claim 3, characterized in that, The calculation of traffic density includes: If the original traffic data does not include average occupancy, traffic density is calculated using the following formula. : ; in, For traffic flow, Average speed; If the original traffic dataset includes average occupancy, then traffic density is calculated using the following formula. : in, , The normalized average market share These are the preset weighting coefficients.
5. The traffic congestion prediction method based on contrastive learning and knowledge distillation according to claim 4, characterized in that, The normalization of traffic density to the [0,1] range includes: Calculate the traffic density array minimum value and maximum value ; like and If they are equal, return a value equal to... An array of the same shape, where all elements are 0; Otherwise, use the following formula for linear normalization: ; in, This represents the result after normalization. For array A sample value in the dataset.
6. The traffic congestion prediction method based on contrastive learning and knowledge distillation according to claim 5, characterized in that, The congestion level is defined by a continuous congestion index, which is derived from the normalized traffic density through a linear mapping method. The congestion index classifies traffic conditions into four levels: unimpeded, slightly congested, moderately congested, and severely congested.
7. The traffic congestion prediction method based on contrastive learning and knowledge distillation according to claim 6, characterized in that, The normalized traffic density is converted into a continuous congestion index using a linear mapping method, specifically as follows: Calculate the normalized traffic density , , Third place; Traffic density value Mapped to a congestion index according to the following rules: like The congestion index is... ; like The congestion index is... ; like The congestion index is... ; like The congestion index is... .
8. A traffic congestion prediction device based on contrastive learning and knowledge distillation, characterized in that, Includes the following modules: Preprocessing module: configured to preprocess the original traffic dataset to obtain traffic feature time series data, wherein the traffic feature time series data includes traffic indicators and congestion levels based on traffic density; Model building module: Configured to build traffic congestion prediction models, including: A time feature generator is used to enhance the time features of the traffic feature time series data. It includes a variational autoencoder and a contrastive learning module. The contrastive learning module is configured to generate positive samples by time series perturbation and use the features of different nodes or time periods as negative samples to maximize the latent space difference. Spatial topology learning module: used to perform spatial feature enhancement on data that has been enhanced with temporal features, to obtain data with enhanced spatiotemporal features; The backbone spatiotemporal graph neural network is used to output congestion level prediction values based on data enhanced with spatiotemporal features. The backbone spatiotemporal graph neural network adopts a self-distillation mechanism, including a teacher model and a student model, and uses exponential moving average to update the parameters of the teacher model. And it is configured to construct a multi-task loss function, and to add a dynamic weight adjustment strategy to the multi-task loss function; Model training module: configured to train the traffic congestion prediction model using the traffic feature time series data, and optimize the model parameters by minimizing the multi-task loss function; Prediction module: It is configured to input the traffic dataset to be predicted into the trained traffic congestion prediction model and output the predicted congestion level of each node at each sampling time point.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1-7.
10. A computer-readable storage medium for storing computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the steps of the method according to any one of claims 1-7.
Citation Information
Patent Citations
Traffic jam prediction method and device
CN118486161A
Space-time diagram comparative learning method based on big kernel attention traffic flow prediction
CN120472686A
Urban traffic big data congestion prediction method based on deep learning
CN120913406A
Traffic flow prediction method and device based on multi-level space-time and perception fusion
CN121092937A
Cited By
Traffic robust knowledge distillation training prediction method and device, equipment and storage medium
CN122176928A