Traffic flow prediction method, device, storage medium and product
By fusing multi-source spatiotemporal features and using an adaptive attention mechanism, combined with spatial lag correlation analysis, the problems of spatiotemporal heterogeneity and lag effects in traffic flow prediction are solved, enabling accurate prediction of future traffic flow and improving the accuracy and adaptability of the prediction.
Patent Information
- Application Number
- CN202610145548.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-02
- Publication Date
- 2026-05-29
AI Technical Summary
Existing traffic flow prediction methods are unable to effectively capture the spatiotemporal heterogeneity and spatial lag coupling effect of urban traffic flow, resulting in insufficient prediction accuracy and adaptability in variable scenarios.
By acquiring historical traffic flow data of the target road area and topological relationship information of related road areas, multi-source spatiotemporal feature fusion is performed. Combined with adaptive attention mechanism and spatial lag correlation analysis, time series and fused spatiotemporal features are generated to achieve accurate prediction of future traffic flow.
It improves the accuracy and scenario adaptability of traffic flow prediction, can dynamically identify and match traffic flow change patterns in different time periods such as morning and evening peak hours and holidays, explicitly quantifies the traffic flow propagation lag effect between upstream and downstream intersections, and improves the model's analytical accuracy of spatial coupling relationships.
Smart Images

Figure CN122116654A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to traffic flow prediction methods, devices, storage media, and products. Background Technology
[0002] In urban transportation systems, accurate short-term traffic flow forecasting is crucial for traffic guidance, congestion control, and route planning. However, urban traffic flow exhibits complex spatiotemporal heterogeneity and coupling characteristics, significantly increasing the difficulty of forecasting. In the temporal dimension, traffic patterns show regular and dramatic changes: weekday morning rush hour (7:00-9:00) is dominated by concentrated commuter traffic, with drastic fluctuations; evening rush hour (17:00-19:00) sees traffic flowing in the opposite direction and is sensitive to sudden events, easily leading to congestion spreading; long holidays (such as Spring Festival and National Day) exhibit tidal peaks of "outbound travel before the holiday and return travel after the holiday," lasting for a long time; short holidays (such as weekends) show localized surges in traffic around commercial areas and scenic spots. In the spatial dimension, there is a strong correlation and lag effect between upstream and downstream traffic on the road network. For example, congestion at an upstream intersection usually leads to a 30%-50% decrease in traffic at a downstream intersection 10-15 minutes later. This dynamic characteristic of tight spatiotemporal coupling makes it difficult for traditional prediction methods to capture its inherent laws simultaneously and accurately, resulting in insufficient prediction accuracy and adaptability in variable scenarios. Summary of the Invention
[0003] To address the problem that existing prediction methods struggle to effectively capture the complex spatiotemporal heterogeneity of traffic flow (such as the differences in patterns during morning and evening rush hours and holidays) and spatial lag coupling effects, resulting in limited accuracy and insufficient adaptability in dynamic real-world scenarios, this paper presents a traffic flow prediction method, device, storage medium, and product designed to achieve adaptive temporal patterns and accurate quantification of spatial correlations.
[0004] This application provides a traffic flow prediction method, including:
[0005] Obtain historical traffic flow data and corresponding time context information of the target road area, as well as historical traffic flow data of at least one associated road area and topological relationship information between the associated road area and the target road area;
[0006] The acquired historical traffic flow data, temporal context information, and topological relationship information are fused and processed to generate a unified spatiotemporal feature representation;
[0007] Based on the spatiotemporal feature representation, and based on the temporal context information therein, an adaptive attention mechanism is performed on the historical traffic flow data of the target road area to generate temporal features;
[0008] Based on the topological relationship information, spatial lag correlation analysis is performed on the historical traffic flow data of the associated road area and the temporal characteristics to generate fused spatiotemporal features;
[0009] Based on the fused spatiotemporal features, the future traffic flow of the target road area is predicted.
[0010] Optionally, the step of fusing the acquired historical traffic flow data, temporal context information, and topological relationship information to generate a unified spatiotemporal feature representation includes:
[0011] Feature extraction is performed on the historical traffic flow data of the target road area to obtain time features;
[0012] Map the time context information into a time context vector;
[0013] Feature extraction is performed on the historical traffic flow data of the associated road area, and the data is processed in conjunction with the topological relationship information to obtain spatial association features;
[0014] The temporal features, the temporal context vector, and the spatial association features are fused and encoded to generate the spatiotemporal feature representation.
[0015] Optionally, based on the spatiotemporal feature representation and the temporal context information therein, an adaptive attention mechanism is performed on the historical traffic flow data of the target road area to generate temporal features, including:
[0016] Based on the spatiotemporal feature representation, determine the time category to which the current prediction time belongs;
[0017] Based on the determined time category, an attention weight distribution that matches the time category is adaptively generated;
[0018] Based on the attention weight distribution, attention calculation is performed on the historical traffic flow data of the target road area to generate the temporal features.
[0019] Optionally, the time categories include at least: morning peak hours, evening peak hours, long holidays, short holidays, and off-peak hours;
[0020] The step of adaptively generating an attention weight distribution that matches the determined time category includes:
[0021] If the time category is morning rush hour or evening rush hour, then the data from the more recent time step in the historical traffic flow data is assigned a higher cumulative attention weight;
[0022] If the time category is a long holiday, then higher cumulative attention weights are assigned to data from further time steps in the historical traffic flow data.
[0023] Optionally, the step of performing spatial lag correlation analysis on the historical traffic flow data of the associated road area and the temporal features based on the topological relationship information to generate fused spatiotemporal features includes:
[0024] Based on the distance information in the topological relationship information, determine the weight of the time-lag impact of the historical traffic flow data of the associated road area on the target road area;
[0025] The characteristics of the historical traffic flow data of the associated road area are weighted using the aforementioned lag effect weighting.
[0026] The weighted features are fused with the temporal features and attention is calculated to generate the fused spatiotemporal features.
[0027] Optionally, determining the temporal lag impact weight of the historical traffic flow data of the associated road area on the target road area based on the distance information in the topological relationship information includes:
[0028] The distance information is input into a distance attenuation function to calculate a spatial influence coefficient;
[0029] Based on the spatial influence coefficient, corresponding weights are assigned to the traffic flow data of the associated road area at different historical times. The larger the spatial influence coefficient, the higher the weight is assigned to the traffic flow data at more recent times.
[0030] Optionally, the prediction model used in the traffic flow prediction method is obtained by training by minimizing a loss function;
[0031] The loss function assigns different weights to training samples belonging to different temporal contexts during calculation.
[0032] This application also provides an electronic device comprising: one or more processors; and a memory storing computer program instructions, which, when executed, cause the processor to perform the steps of the method described above.
[0033] This application also provides a computer-readable storage medium having a computer program / instructions stored thereon, which, when executed by a processor, implement the steps of the above-described method.
[0034] This application also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described method.
[0035] The beneficial effects of the above technical solution are as follows:
[0036] In this technical solution, the traffic flow prediction method of this application effectively improves the accuracy and scenario adaptability of traffic flow prediction by fusing multi-source spatiotemporal information and constructing an adaptive processing mechanism. Multi-source information fusion provides the model with a complete feature representation that includes temporal patterns and spatial correlations, overcoming the limitations of a single data source. The adaptive attention mechanism based on temporal context can dynamically identify and fit traffic flow change patterns in different time periods such as morning and evening peak hours and holidays, thereby enhancing the model's ability to capture temporal heterogeneity. Combined with spatial lag correlation analysis of topological relationships, the lag effect and influence intensity of traffic flow propagation between upstream and downstream intersections are explicitly quantified, improving the model's analytical accuracy of spatial coupling relationships. Through the above collaborative processing, a more accurate and reliable prediction of future traffic flow is achieved. Attached Figure Description
[0037] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0038] Figure 1 This is a flowchart of one embodiment of the traffic flow prediction method described in this application;
[0039] Figure 2 A flowchart illustrating a method for generating a unified spatiotemporal feature representation for this application;
[0040] Figure 3 A flowchart of a method for generating timing features for this application;
[0041] Figure 4 A flowchart illustrating a method for generating fused spatiotemporal features according to an embodiment of this application;
[0042] Figure 5 A schematic diagram of the structure of an electronic device for performing a traffic flow prediction method provided in an embodiment of this application. Detailed Implementation
[0043] The advantages of this application are further illustrated below with reference to the accompanying drawings and specific embodiments.
[0044] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0045] The terminology used in this disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The singular forms “a,” “the,” and “the” as used in this disclosure and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0046] It should be understood that although the terms first, second, third, etc., may be used in this disclosure to describe various information, such information should not be limited to these terms. These terms are used only to distinguish information of the same type from one another. For example, without departing from the scope of this disclosure, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0047] In the description of this application, it should be understood that the numerical labels before the steps do not indicate the order of the steps, but are only used to facilitate the description of this application and to distinguish each step, and therefore should not be construed as a limitation of this application.
[0048] The following terms are used in this document.
[0049] Transformer is a deep learning model architecture used in fields such as NLP and CV, with self-attention mechanism at its core, including encoder and decoder, and combining embedding and positional encoding.
[0050] LSTM: A recurrent neural network with gating mechanism that can capture long-term dependencies in sequences and is used for NLP, time series prediction, etc.
[0051] Multi-Head Attention: Multi-head attention is a core component of the Transformer architecture. By executing the self-attention mechanism multiple times in parallel, the model learns relational information from different dimensions simultaneously. Finally, the results are concatenated and linearly transformed, thereby enhancing the ability to capture complex relationships and improving model performance.
[0052] AdamW: An optimization algorithm that combines Adam's adaptive learning rate and weight decay to improve training stability and performance.
[0053] See Figure 1 As shown, this application provides a traffic flow prediction method comprising the following steps:
[0054] S1. Obtain historical traffic flow data and corresponding time context information of the target road area, as well as historical traffic flow data of at least one associated road area and topological relationship information between the associated road area and the target road area;
[0055] In the specific implementation process, in step S1, multi-source information is first obtained, including the historical traffic flow data of the target intersection itself and its corresponding time context information, as well as the historical traffic flow data of at least one related intersection (such as the direct upstream intersection) and the topological relationship information between the two intersections.
[0056] Data Acquisition and Preprocessing: Historical traffic flow and speed data are collected by roadside sensors at 5-minute intervals; topological relationship information (such as upstream and downstream connections and actual spacing) is extracted from a Geographic Information System (GIS). Raw data undergoes preprocessing, with outliers initially screened using the "3σ criterion" and removed through manual verification; missing values are filled using an innovative "spatiotemporal fusion interpolation method." This method integrates the spatial influence of upstream intersections, the temporal continuity of the current intersection, and historical patterns. The calculation formula is: Filled value = Upstream intersection traffic flow at time T-1 × α + Current intersection traffic flow at time T-2 × β + Historical concurrent traffic flow × γ, where the weighting coefficients α, β, and γ are determined through historical data fitting and satisfy α + β + γ = 1; the time to be predicted is T, and time T-1 is a historical time point traced back, for example, when T is 8:00, time T-1 is 7:55.
[0057] Time type labeling: To characterize the temporal heterogeneity of traffic, each data point is labeled as one of five time types based on the calendar and holiday database: weekday morning peak (7:00-9:00), weekday evening peak (17:00-19:00), long holidays (holiday ≥ 3 days, including 1 day before and 1 day after the holiday), short holidays (holiday 1-2 days), and off-peak period.
[0058] Sample Construction: Finally, the input samples for the prediction model contain two feature groups: 1) Time feature group, which consists of the time type label of the time to be predicted T and the traffic flow sequence of the target intersection at 6 historical times from T-1 to T-6; 2) Spatial feature group, which consists of the traffic flow sequence of the associated intersection at times from T-1 to T-3 and the actual distance d between the two intersections.
[0059] S2. The acquired historical traffic flow data, temporal context information, and topological relationship information are fused to generate a unified spatiotemporal feature representation;
[0060] S3. Based on the spatiotemporal feature representation, and based on the temporal context information therein, an adaptive attention mechanism is performed on the historical traffic flow data of the target road area to generate temporal features;
[0061] S4. Based on the topological relationship information, perform spatial lag correlation analysis on the historical traffic flow data of the associated road area and the temporal characteristics to generate fused spatiotemporal characteristics;
[0062] S5. Based on the fused spatiotemporal characteristics, predict the future traffic flow of the target road area.
[0063] In this embodiment, the traffic flow prediction method effectively improves the accuracy and scenario adaptability of traffic flow prediction by fusing multi-source spatiotemporal information and constructing an adaptive processing mechanism. Multi-source information fusion provides the model with a complete feature representation that includes temporal patterns and spatial correlations, overcoming the limitations of a single data source. The adaptive attention mechanism based on temporal context can dynamically identify and fit traffic flow change patterns during different time periods such as morning and evening peak hours and holidays, thereby enhancing the model's ability to capture temporal heterogeneity. Combined with spatial lag correlation analysis of topological relationships, the lag effect and influence intensity of traffic propagation between upstream and downstream intersections are explicitly quantified, improving the model's analytical accuracy of spatial coupling relationships. Through the above collaborative processing, a more accurate and reliable prediction of future traffic flow is achieved.
[0064] In a preferred embodiment, see Figure 2 Step S2 shown may include the following steps:
[0065] S21. Extract features from the historical traffic flow data of the target road area to obtain time features;
[0066] S22. Map the time context information into a time context vector;
[0067] S23. Extract features from the historical traffic flow data of the associated road area and process it in conjunction with the topological relationship information to obtain spatial association features;
[0068] S24. The temporal features, the temporal context vector, and the spatial association features are fused and encoded to generate the spatiotemporal feature representation.
[0069] In step S2, spatiotemporal feature fusion is performed to encode multi-source heterogeneous data into a unified representation that can be efficiently understood by deep learning models. This process is implemented through a structured embedding layer, which specifically includes three core sub-steps: temporal feature embedding, spatial feature embedding, and the final joint embedding.
[0070] First, in the temporal feature embedding stage, the system processes two types of information in parallel. In step S21, the traffic flow sequence of the target road area (i.e., the intersection to be predicted or the target intersection) within a historical time window (e.g., from time T-1 to T-6) is input into a one-dimensional convolutional layer to capture its short-term local fluctuation patterns and output temporal features. In step S22, the temporal context information representing macroscopic traffic patterns (such as category labels like "morning rush hour" and "long holidays") is mapped into a dense temporal context vector through a fully connected layer.
[0071] Secondly, in the spatial feature embedding stage, the system simultaneously processes spatial dimension correlation information. In step S23, the traffic flow sequences of upstream associated intersections specified in the topological relationship at nearby times (e.g., from T-1 to T-3) are also input into a one-dimensional convolutional layer to extract their variation features. Simultaneously, key topological relationship information—such as the actual distance d between two intersections—is mapped to a spatial influence coefficient using the "distance-influence coefficient function" f(d) = 0.9 - 0.0008 × d (d is in meters; when d > 1000m, f(d) = 0.1). This coefficient is multiplied element-wise with the extracted upstream traffic flow features to explicitly model the distance attenuation effect. The result is then transformed by a fully connected layer to form spatial fusion features (or spatial correlation features).
[0072] Finally, in the joint embedding stage, the extracted temporal features and temporal context vectors are concatenated in step S24, and layer normalization is used to unify the scale and stabilize the distribution, ultimately obtaining deeply fused temporal fusion features. The obtained temporal fusion features and spatial fusion features are aligned according to their corresponding time steps. To explicitly inject the sequential information into the model, the aligned joint feature matrix is added to the sinusoidal positional encoding. Through this series of operations, multi-dimensional information from historical traffic flow at the target intersection, macro-temporal patterns, upstream intersection traffic flow, and road network topology is integrated into a structured spatiotemporal embedding sequence containing rich spatiotemporal semantics—the final unified spatiotemporal feature representation—laying the foundation for subsequent complex adaptive attention calculations.
[0073] In this embodiment, a structured embedding layer is introduced to deeply fuse and unify the spatiotemporal information from multiple heterogeneous sources, laying a solid foundation for subsequent accurate prediction. Specifically, temporal feature embedding processes historical traffic sequences and macroscopic time labels in parallel, using one-dimensional convolution to capture local fluctuations while mapping category information into dense vectors. This allows the model to perceive both microscopic changes and macroscopic patterns, enhancing the expressive power of temporal features. Spatial feature embedding innovatively quantifies topological distance into an influence coefficient using a physically meaningful decay function and multiplies it with upstream traffic features. This explicitly and quantitatively models the effect of spatial correlation decay with distance, improving the physical interpretability and accuracy of spatial features. The final joint embedding generates a structured spatiotemporal embedding sequence through feature concatenation, normalization, and combination with location encoding. This representation not only unifies the scale and distribution of multi-source data but also preserves the temporal sequence and correlation logic, overcoming feature conflicts or information loss caused by simple concatenation in traditional methods. It provides high-quality, highly consistent input for subsequent efficient and accurate spatiotemporal attention calculations in the model.
[0074] In a preferred embodiment, see Figure 3 Step S3 shown may include the following steps:
[0075] S31. Determine the time category to which the current prediction time belongs based on the spatiotemporal feature representation;
[0076] The time categories include at least: morning peak hours, evening peak hours, long holidays, short holidays, and off-peak hours.
[0077] The core of the adaptive attention mechanism in step S3 lies in dynamically adjusting the focus of attention on historical data based on macroscopic time patterns. This mechanism is based on the spatiotemporal feature representation (i.e., the time-series embedded sequence) generated in step S2, and generates accurate time-series features through a progressive process of "scene recognition - weight adaptation - feature extraction." In step S31, the spatiotemporal feature representation is input into a dedicated classification sub-network, which outputs the probability distribution of the current predicted time belonging to a predefined category. These time categories include, but are not limited to, morning rush hour, evening rush hour, long holidays, short holidays, and off-peak hours. This step enables the automatic identification of the current traffic scene pattern from the data.
[0078] S32. Based on the determined time category, adaptively generate an attention weight distribution that matches the time category;
[0079] S33. Based on the attention weight distribution, perform attention calculation on the historical traffic flow data of the target road area to generate the temporal features.
[0080] Further, step S32, based on the determined time category, adaptively generates an attention weight distribution that matches the time category, which may include:
[0081] If the time category is morning rush hour or evening rush hour, then the data from the more recent time step in the historical traffic flow data is assigned a higher cumulative attention weight;
[0082] If the time category is a long holiday, then higher cumulative attention weights are assigned to data from further time steps in the historical traffic flow data.
[0083] In step S32, an attention weight distribution is adaptively generated based on the identified time category probability. This adapts to the inherent patterns of traffic changes in different scenarios: for example, for scenarios where traffic exhibits "short-term sharp fluctuations," such as morning and evening peak hours, the system allocates a higher proportion of cumulative attention weight (e.g., about 70%) to the most recent few time steps in historical data (e.g., the most recent 3 steps, i.e., 15 minutes), while allocating the remaining weight (e.g., 30%) to earlier historical data; conversely, for scenarios where traffic changes are slow and historical patterns are more reliable, such as long holidays, a higher attention weight (e.g., 60%) is allocated to relatively more distant historical time steps to capture long-term trends.
[0084] In step S33, the spatiotemporal feature representation is combined with a weight matrix dynamically generated based on the scene, and then input into the multi-head attention module for calculation. This process enables the model to selectively integrate historical information based on the identified time scene, and finally output temporal features (i.e., temporal attention features) that reflect the specific changing patterns of the current time period.
[0085] In this embodiment, by introducing an adaptive attention mechanism that "first identifies the scene, then adapts the weights," the limitations of traditional methods in treating different time patterns "equally" are effectively addressed, thereby achieving accurate modeling of traffic flow temporal heterogeneity. Step S3, scene identification based on the classification subnetwork, enables the model to automatically determine whether the current time belongs to a specific category such as morning peak, evening peak, or long holiday, providing an accurate basis for subsequent differentiated processing. The dynamic weight allocation strategy, matched to the scene, adaptively adjusts the model's attention to recent and long-term historical data based on the inherent patterns of different traffic flow categories (such as the short-term drastic changes during peak hours and the historical trend continuity of long holidays), focusing attention on the information most relevant to the current scene. Finally, attention calculation based on dynamic weights generates temporal features that deeply reflect the specific change patterns of the current time period. This mechanism enables the model to no longer statically and equally process historical data, but to dynamically perceive and adapt to different traffic scenarios, thereby significantly improving the accuracy, robustness, and generalization ability of the prediction model in variable real-world environments.
[0086] In a preferred embodiment, see Figure 4 Step S4 shown may include the following steps:
[0087] S41. Based on the distance information in the topological relationship information, determine the weight of the time-lag effect of the historical traffic flow data of the associated road area on the target road area;
[0088] Further, step S41, which involves determining the temporal lag impact weight of the historical traffic flow data of the associated road area on the target road area based on the distance information in the topological relationship information, may include:
[0089] The distance information is input into a distance decay function to calculate a spatial influence coefficient. Based on the spatial influence coefficient, corresponding weights are assigned to the traffic flow data of the associated road area at different historical times. The larger the spatial influence coefficient, the higher the weight is assigned to the traffic flow data at more recent times.
[0090] In this embodiment, the distance decay function is configured such that when the distance is not greater than a preset threshold, the spatial influence coefficient decreases linearly with increasing distance; when the distance is greater than the preset threshold, the spatial influence coefficient is a fixed constant.
[0091] S42. The historical traffic flow data of the associated road area is weighted using the aforementioned lag effect weight;
[0092] S43. The weighted features are fused with the temporal features and attention is calculated to generate the fused spatiotemporal features.
[0093] In this embodiment, step S4 aims to quantitatively model the lagging effect of the upstream intersection and deeply fuse this spatial correlation information with the temporal features obtained in step S3. The core of this spatial lag correlation analysis lies in explicitly quantifying the attenuation and delay effects when the upstream traffic state is transmitted to the downstream target intersection based on the distance information in the road network topology, specifically including three links: weight determination, weighted fusion, and attention calculation.
[0094] In step S41, the lagging effect weights of each time step of the upstream historical traffic data are determined according to the key parameter in the topological relationship information - the intersection spacing d. This process is achieved through a preset distance attenuation function: when the distance is not greater than a preset threshold (such as 500 meters), the spatial influence coefficient decreases linearly with the increase of the distance; when the distance exceeds this threshold (such as 1000 meters), the influence coefficient converges to a fixed constant value (such as 0.1) to simulate the physical law that the influence attenuates to a stable state with the increase of the distance. Based on the calculated spatial influence coefficient, the system further assigns specific weights to the traffic data of different historical moments at the upstream intersection. The principle is that the larger the spatial influence coefficient (i.e., the closer the distance), the higher the weight assigned to the traffic data of the closer moment. For example, in a specific implementation, when d ≤ 500 meters, the weights assigned to the moments T - 1, T - 2, and T - 3 are 0.8, 0.15, and 0.05; when 500 meters < d ≤ 1000 meters, the weights are adjusted to 0.6, 0.3, and 0.1; when d > 1000 meters, the weights are 0.4, 0.3, and 0.3.
[0095] In step S42, the spatial lag weights (such as dimension [3, 64], where 3 represents the number of upstream time steps) are used to perform element-wise weighted processing on the traffic features (i.e., spatial fusion features) of the upstream intersection, so as to amplify the key impacts in the near term and at close range and weaken the secondary impacts in the long term and at long range.
[0096] In step S43, the weighted upstream spatial features are concatenated with the temporal features (i.e., temporal attention features) from step S3 and input into another multi-head attention module (Multi-Head Attention). Based on this, the module calculates the complex spatial dependence relationship between the "upstream intersection - target intersection", and finally outputs a fused spatio-temporal feature (i.e., spatio-temporal joint feature) that simultaneously contains an adaptive time law and a quantified spatial lag correlation.
[0097] In this embodiment, by introducing an explicit spatial lag correlation quantification model, the shortcomings of traditional methods that simply use upstream data and ignore physical attenuation laws in spatial dimension modeling are effectively overcome. Based on the weight generation mechanism of the distance attenuation function, the intersection spacing is quantified into an influence coefficient that decreases with increasing distance, and further refined into precise weight allocation for upstream traffic flow at different historical moments. This embeds the prior knowledge of traffic flow propagation that "the closer the distance, the greater and more immediate the impact" into the model. The weighted processing of spatial features amplifies the role of the recent state of key neighboring intersections, while the attention fusion with adaptive temporal features achieves deep coupling of spatiotemporal information. Ultimately, the prediction model can not only perceive the existence of spatial correlations, but also accurately quantify their strength and lag, significantly improving the ability to capture and predict complex spatial phenomena such as upstream and downstream congestion transmission, and enhancing the spatial accuracy and physical interpretability of the prediction results.
[0098] In a preferred embodiment, step S5, predicting the future traffic flow of the target road area based on the fused spatiotemporal features, may include:
[0099] The process of predicting future traffic flow based on fused spatiotemporal features is implemented through a prediction output layer. This layer is mainly responsible for decoding high-level feature representations into specific traffic flow prediction values. Its processing flow includes three core steps: feature compression, nonlinear transformation, and final prediction.
[0100] First, the prediction model inputs the spatiotemporal joint features (a feature representation in the form of a multidimensional sequence) calculated through the aforementioned steps into the feature compression module. This module uses global average pooling to aggregate the features along the time step dimension, compressing them into a dense feature vector of fixed length, thus laying the foundation for subsequent fully connected layer processing.
[0101] Subsequently, the feature vector is fed into a feedforward neural network for deep nonlinear transformation. This network typically contains two fully connected layers, with the intermediate hidden layer having a dimension of 256. During the computation, the ReLU activation function is used to introduce nonlinearity to enhance the model's ability to fit complex mapping relationships, thereby better extracting patterns strongly correlated with traffic from the fused features.
[0102] Finally, in the traffic flow prediction stage, the nonlinearly transformed feature vector is mapped through a linear output layer to obtain the standardized traffic flow prediction value of the target intersection at time T. To obtain a prediction result with actual physical meaning, this standardized value needs to undergo inverse standardization, that is, using the statistics recorded in the data preprocessing stage (such as minimum and maximum values) to convert it back to the actual traffic flow value in "vehicles per minute". At this point, the model completes a closed loop from multi-source spatiotemporal data input to the final traffic flow prediction output.
[0103] In a preferred embodiment, the prediction model used in the traffic flow prediction method is obtained by training by minimizing a loss function;
[0104] The loss function assigns different weights to training samples belonging to different temporal contexts during calculation.
[0105] In this embodiment, the loss function is the weighted average absolute percentage error (WMAPE), and the different time context information includes morning peak hours, evening peak hours, long holidays, short holidays, and off-peak hours, wherein the weights of the samples during morning peak hours and evening peak hours are greater than the weights of the samples during off-peak hours.
[0106] In this embodiment, the prediction model training and optimization process is as follows:
[0107] Dataset partitioning: The constructed samples are divided into training set, validation set and test set in a 7:2:1 ratio to ensure that the proportion of samples of each time feature is consistent (the morning rush hour samples account for 22% of all three sets and the long holiday samples account for 18% of all three sets) to avoid data distribution bias.
[0108] Loss function: The weighted average absolute percentage error (WMAPE) is used as the loss function, with higher weights assigned to samples in key time periods.
[0109]
[0110] in, Sample weights (morning peak, evening peak) =1.6; long holidays, short holidays =1.3; Off-peak period =1.0), This represents the actual traffic volume. For predicting traffic flow, N is the number of samples.
[0111] Training strategy: 1) Optimizer: AdamW optimizer is used with an initial learning rate of 0.001 and a weight decay coefficient of 0.01 (to suppress overfitting); 2) Early stopping mechanism: when the validation set WMAPE does not decrease or increases for 5 consecutive epochs (periods / rounds), training is stopped and the optimal model is saved; 3) Hyperparameter tuning: the number of Multi-Head Attention heads (4 / 8 / 12) and the dimension of the Feed Forward hidden layer (128 / 256 / 512) are optimized by grid search, and the hyperparameter combination with the smallest validation set WMAPE is selected.
[0112] In this embodiment, by introducing a scenario-weighted training strategy and system optimization process, the practicality and robustness of the prediction model are significantly improved. A weighted loss function is used to impose higher penalties on prediction errors during critical periods such as morning and evening rush hours, forcing the model to prioritize learning and optimizing prediction performance under these complex scenarios, thereby directly improving the prediction accuracy during peak hours, which is crucial for traffic management. A balanced dataset partitioning strategy ensures that the model has equal access to various time patterns during the learning process, avoiding model bias caused by uneven data distribution and enhancing the model's generalization ability. The training strategy, combining the AdamW optimizer, early stopping mechanism, and hyperparameter tuning, effectively suppresses overfitting, ensures training stability, and adaptively searches for the optimal configuration of the model structure. These measures work together to ensure that the final trained model not only performs better overall but, more importantly, provides more reliable and accurate prediction outputs in the critical, highly volatile scenarios most relevant to real traffic systems.
[0113] The traffic prediction and result evaluation process of this application mainly includes two stages: real-time prediction and comprehensive verification, which aims to test the application performance and generalization ability of the model in real-world scenarios.
[0114] In the real-time prediction phase, all input data required for the predicted time T is acquired, including: the time type label for time T, the historical traffic flow sequence of the target intersection from time T-1 to T-6, the historical traffic flow sequence of the upstream related intersection from time T-1 to T-3, and the distance between the two intersections. The input data is cleaned and validated in real-time according to the aforementioned preprocessing rules (such as outlier checks based on the 3σ criterion and manual verification) to ensure data quality. The processed, standardized data is then input into the trained spatiotemporal adaptive Transformer model for inference. The model directly outputs the predicted actual traffic flow value of the target intersection at time T, completing the end-to-end computation from multi-source data to the prediction result.
[0115] In the results evaluation phase, a comprehensive performance evaluation was conducted using multi-dimensional indicators and comparative experiments. First, Mean Absolute Percentage Error (MAPE), Root Mean Square Error (RMSE), and Prediction Response Time were selected as core evaluation indicators to measure the relative accuracy of the prediction, the level of absolute error, and the real-time performance of the system, respectively. Second, comparative verification was performed, comparing the proposed spatiotemporal adaptive Transformer model with traditional Transformer and LSTM models on the same test set. Particular emphasis was placed on comparing various indicators across different time periods (such as morning rush hour, evening rush hour, and holidays) to demonstrate the predictive advantages of this application under various time characteristics. Finally, special scenario verification was implemented, focusing on simulating extreme event scenarios such as a 50% drop or a 40% increase in traffic flow at the upstream intersection at time T-1. By analyzing the model's prediction response and error changes in such scenarios, its ability to capture spatial lag correlation mechanisms and its robustness were specifically evaluated, thereby comprehensively verifying the effectiveness of the model design.
[0116] This application's traffic flow prediction method employs a spatiotemporal collaborative differentiated modeling mechanism. Addressing the heterogeneity of the time dimension, it constructs a time-feature adaptive attention architecture. By introducing a "time type classification sub-network" to identify scenarios, it dynamically generates attention weights adapted to different traffic flow patterns (e.g., focusing on the near term for drastic fluctuations during morning rush hour, and emphasizing the long term for slow changes during long holidays). This overcomes the limitations of traditional Transformers, which use globally uniform attention weights and cannot accurately adapt to differentiated time characteristics such as morning and evening rush hours and long and short holidays. Addressing the lag in the spatial dimension, it proposes a spatial lag correlation quantity. By dynamically generating spatial weights (e.g., based on distance decay functions) in conjunction with intersection spacing, it quantifies the strength and lag of the upstream traffic flow's impact on the downstream. This allows the model to respond promptly to downstream predictions when upstream intersection traffic is abnormal, effectively capturing the physical correlation between "upstream" and "downstream," and solving the problem of LSTM or traditional Transformers simply using upstream traffic data while ignoring distance and lag effects. The synergy of these two approaches improves the accuracy and robustness of traffic flow prediction in complex spatiotemporal scenarios.
[0117] The steps of the various methods described above are only for clarity. In practice, they can be combined into one step or some steps can be split into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent. Adding insignificant modifications or introducing insignificant designs to the algorithm or process, but without changing the core design of the algorithm and process, are also within the scope of protection of this patent.
[0118] Furthermore, some embodiments of this application also provide an electronic device. The electronic device can be various forms of digital computer, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, etc. The electronic device can also be various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices.
[0119] The electronic device includes: one or more processors; and a memory storing computer program instructions that, when executed, cause the processor to perform the steps of the methods provided in any one or more of the above embodiments. Figure 5 An exemplary structural diagram of the electronic device is disclosed. For example... Figure 5 As shown, the electronic device includes one or more processors 1101, a memory 1102, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components are interconnected via different buses and can be mounted on a common motherboard or otherwise as required. The processors can process instructions executed within the electronic device, including instructions stored in or on memory to display graphical information of a GUI on an external input / output device (such as a display device coupled to the interface). In some other embodiments, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple electronic devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). The components, their connections and relationships, and their functions shown herein are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.
[0120] The electronic device may further include an input device 1103 and an output device 1104. The processor 1101, memory 1102, input device 1103, and output device 1104 may be connected via a bus or other means. Figure 5 Taking the example of a connection between China and Israel via a bus.
[0121] Input device 1103 can receive input numerical or character information, and generate key signal inputs related to user settings and function control of the electronic device, such as a touch screen, keypad, mouse, trackpad, touchpad, joystick, one or more mouse buttons, trackball, joystick, etc. Output device 1104 may include a display device, auxiliary lighting device (e.g., LED), and haptic feedback device (e.g., vibration motor). The display device may include, but is not limited to, a liquid crystal display (LCD), a light-emitting diode (LED) display, and a plasma display. In some embodiments, the display device may be a touch screen.
[0122] To provide interaction with the user, the electronic device can be a computer. The computer has: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0123] In this embodiment, a computer-readable storage medium stores a computer program / instructions, which, when executed by a processor, implement the steps of the methods provided in any one or more of the above embodiments. This computer-readable storage medium may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into that device. The aforementioned computer-readable storage medium carries one or more computer-readable instructions.
[0124] The memory 1102 can serve as a non-transitory computer-readable storage medium, used to store non-transitory software programs, non-transitory computer-executable programs, and modules. The processor 1101 executes various functional applications and data processing of the server by running the non-transitory software programs, instructions, and modules stored in the memory 1102, thereby implementing the program instructions / modules corresponding to the methods provided in any one or more of the embodiments described above in this application.
[0125] The memory 1102 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the electronic device. Furthermore, the memory 1102 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory 1102 may optionally include memory remotely located relative to the processor 1101, and these remote memories can be connected to the electronic device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0126] It should be noted that the computer-readable storage medium described in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0127] Computer-readable storage media include permanent and non-permanent, removable and non-removable media, which can store information by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, read-only optical disc (CD-ROM), digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.
[0128] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0129] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. For example, it can be implemented using an application-specific integrated circuit (ASIC), a general-purpose computer, or any other similar hardware device. In some embodiments, the software program of this application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of this application (including related data structures) can be stored in a computer-readable recording medium, such as RAM memory, magnetic or optical drives, floppy disks, or similar devices. Furthermore, some steps or functions of this application can be implemented in hardware, for example, as circuitry that works with a processor to perform the various steps or functions.
[0130] The computer program product provided in this application includes one or more computer programs / instructions. When executed by a processor, these computer programs / instructions generate, in whole or in part, the processes or functions described in this application. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0131] The flowcharts or block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of devices, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-specific system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0132] The scope of this application is defined by the appended claims rather than the foregoing description, and is therefore intended to encompass all variations falling within the meaning and scope of equivalents of the claims. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in a device claim may also be implemented by a single unit or device in software or hardware. Terms such as "first," "second," etc., are used only for distinguishing descriptions and do not indicate any particular order, nor should they be construed as indicating or implying relative importance.
[0133] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily made by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims, and the above embodiments should be regarded as exemplary and non-limiting.
Claims
1. A traffic flow prediction method, characterized in that, include: Obtain historical traffic flow data and corresponding time context information of the target road area, as well as historical traffic flow data of at least one associated road area and topological relationship information between the associated road area and the target road area; The acquired historical traffic flow data, temporal context information, and topological relationship information are fused and processed to generate a unified spatiotemporal feature representation; Based on the spatiotemporal feature representation, and based on the temporal context information therein, an adaptive attention mechanism is performed on the historical traffic flow data of the target road area to generate temporal features; Based on the topological relationship information, spatial lag correlation analysis is performed on the historical traffic flow data of the associated road area and the temporal characteristics to generate fused spatiotemporal features; Based on the fused spatiotemporal features, the future traffic flow of the target road area is predicted.
2. The traffic flow prediction method according to claim 1, characterized in that, The process of fusing the acquired historical traffic flow data, temporal context information, and topological relationship information to generate a unified spatiotemporal feature representation includes: Feature extraction is performed on the historical traffic flow data of the target road area to obtain time features; Map the time context information into a time context vector; Feature extraction is performed on the historical traffic flow data of the associated road area, and the data is processed in conjunction with the topological relationship information to obtain spatial association features; The temporal features, the temporal context vector, and the spatial association features are fused and encoded to generate the spatiotemporal feature representation.
3. The traffic flow prediction method according to claim 1, characterized in that, Based on the spatiotemporal feature representation and the temporal context information therein, an adaptive attention mechanism is performed on the historical traffic flow data of the target road area to generate temporal features, including: Based on the spatiotemporal feature representation, determine the time category to which the current prediction time belongs; Based on the determined time category, an attention weight distribution that matches the time category is adaptively generated; Based on the attention weight distribution, attention calculation is performed on the historical traffic flow data of the target road area to generate the temporal features.
4. The traffic flow prediction method according to claim 3, characterized in that, The time categories include at least: morning peak hours, evening peak hours, long holidays, short holidays, and off-peak hours; The step of adaptively generating an attention weight distribution that matches the determined time category includes: If the time category is morning rush hour or evening rush hour, then the data from the more recent time step in the historical traffic flow data is assigned a higher cumulative attention weight; If the time category is a long holiday, then higher cumulative attention weights are assigned to data from further time steps in the historical traffic flow data.
5. The traffic flow prediction method according to claim 1, characterized in that, Based on the topological relationship information, the historical traffic flow data of the associated road area is subjected to spatial lag correlation analysis with the temporal characteristics to generate fused spatiotemporal features, including: Based on the distance information in the topological relationship information, determine the weight of the time-lag impact of the historical traffic flow data of the associated road area on the target road area; The characteristics of the historical traffic flow data of the associated road area are weighted using the aforementioned lag effect weighting. The weighted features are fused with the temporal features and attention is calculated to generate the fused spatiotemporal features.
6. The traffic flow prediction method according to claim 5, characterized in that, The step of determining the temporal lag impact weight of historical traffic flow data of the associated road area on the target road area based on distance information in the topological relationship information includes: The distance information is input into a distance attenuation function to calculate a spatial influence coefficient; Based on the spatial influence coefficient, corresponding weights are assigned to the traffic flow data of the associated road area at different historical times. The larger the spatial influence coefficient, the higher the weight is assigned to the traffic flow data at more recent times.
7. The traffic flow prediction method according to claim 1, characterized in that, The prediction model used in the traffic flow prediction method is obtained by minimizing a loss function. The loss function assigns different weights to training samples belonging to different temporal contexts during calculation.
8. An electronic device, characterized in that, The electronic device includes: One or more processors; and A memory storing computer program instructions, which, when executed, cause the processor to perform the steps of the method as described in any one of claims 1 to 7.
9. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 7.
10. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 7.
