Neural network traffic flow prediction method based on multi-scale space-time diagram, electronic equipment and computer readable medium
By constructing a dynamic adaptive graph through a multi-scale spatiotemporal graph neural network, the problem of dynamic spatiotemporal correlation modeling of traffic flow data is solved, and the accuracy of traffic flow prediction is improved.
Patent Information
- Application Number
- CN202510886848.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-10-03
AI Technical Summary
Traffic flow data has both temporal and spatial attributes. Existing technologies make it difficult to effectively model its dynamic spatiotemporal correlations, resulting in insufficient accuracy in traffic flow predictions.
A multi-scale spatiotemporal graph neural network is adopted to dynamically learn the temporal and spatial dependencies of traffic flows by extracting multi-scale temporal dependencies and constructing a dynamic adaptive graph. It is combined with a dual-path parallel gated temporal convolutional network and a multi-scale gated temporal unit.
It improves the dynamic spatiotemporal correlation modeling capabilities of traffic flow prediction, comprehensively extracts the temporal correlation and spatial dependence of traffic flow, and improves prediction accuracy.
Smart Images

Figure CN120748191A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of intelligent transportation technology, and specifically relates to a traffic flow prediction method based on a multi-scale spatiotemporal graph neural network, an electronic device, and a computer-readable medium. Background Art
[0002] Accurate traffic flow predictions are crucial for effective traffic guidance and control decisions. Today, traffic equipment (cameras, sensors, etc.) deployed along roads continuously collects large amounts of traffic flow data. However, unlike traditional time series or image data, traffic flow data exhibits both temporal and spatial attributes, and these attributes are interdependent. Consequently, traffic flow prediction remains extremely challenging.
[0003] Traffic flow data exhibits non-Euclidean properties, where spatial interdependence between nodes depends not only on physical distance but is also intrinsically linked to road network topology and traffic flow patterns. In road networks, traffic flow propagation primarily occurs through geographically proximal, physically adjacent nodes, which establish fundamental neighborhood dependencies determined by their geographic location. Functionally similar nodes can exhibit consistent evolutionary patterns through complex interdependence even when they are spatially disconnected or geographically distant. Summary of the Invention
[0004] In order to solve the problems existing in the above-mentioned prior art, the present invention provides a traffic flow prediction method based on a multi-scale spatiotemporal graph neural network, an electronic device and a computer-readable medium. By extracting multi-scale time dependencies and constructing a dynamic adaptive graph to model spatial dependencies, the modeling capability of dynamic spatiotemporal correlations in traffic prediction is improved.
[0005] The specific technical solution adopted in the present invention is:
[0006] A traffic flow prediction method based on a multi-scale spatiotemporal graph neural network includes the following steps:
[0007] S1. Obtain traffic flow data sequences from traffic equipment, clean and standardize the data, and divide it into training, validation, and test datasets.
[0008] S2. Construct a traffic flow prediction model, which includes an input and preprocessing module, a spatiotemporal mining module, and an output and prediction module;
[0009] S21. The input and preprocessing module is provided with a data node embedding layer for dimensionality conversion of the training dataset;
[0010] S22. The spatiotemporal mining module includes a temporal representation module and a spatial representation module;
[0011] The temporal representation module is equipped with a dual-parallel gated temporal convolutional network and a multi-scale gated temporal unit. This dual-parallel structure extracts the multi-scale temporal dependencies of traffic flows in the converted training dataset and obtains the output of the temporal representation learning process.
[0012] The spatial representation module generates a dynamic graph of node dynamic traffic patterns using input data and a road network graph. The output of the temporal representation learning process is fed into the spatial representation module to obtain a predicted representation of traffic flow data that captures spatiotemporal dependencies.
[0013] S23. In the output and prediction module, the traffic flow data prediction representation after capturing the spatiotemporal dependency is converted into a traffic flow data prediction value and output to obtain a traffic flow prediction value;
[0014] S3. Train the model multiple times based on the training dataset and modify the parameters to obtain a traffic flow prediction model; select and evaluate the trained traffic flow prediction model based on the validation dataset, and perform traffic flow prediction based on the test dataset and the trained traffic flow prediction model.
[0015] The training method of the traffic flow prediction model in step S2 is:
[0016] Step A: Perform an iterative training on the traffic flow prediction model;
[0017] Step B: Repeat step A until the specified number of iterations is reached, and the traffic flow prediction model training is completed.
[0018] The specific steps of the one-time iterative training are as follows:
[0019] Step (1), dimensionality conversion: In the input and preprocessing module, the training data in the training dataset is input into the data node embedding layer for dimensionality conversion to obtain the converted traffic flow data sequence; at the same time, the learnable embedding representations E1 and E2 are initialized for subsequent dynamic graph construction;
[0020] Assume that the training data of one of the iteration batches is The converted traffic flow data sequence obtained
[0021] Among them, C is the initial feature dimension, such as traffic flow information; N represents the number of nodes; T represents the time length; D represents the number of dimensions after conversion;
[0022] Step (2), temporal representation learning process: the transformed traffic flow data sequence is sent as input to the spatiotemporal temporal representation module to learn the dynamic temporal representation of the traffic flow conditions, extract multi-scale temporal dependencies including long-term and short-term temporal dependencies, and obtain the output of the temporal representation learning process;
[0023] Step (21) uses a gated temporal convolutional network to capture the global temporal representation. Specifically, the dilated causal convolution is integrated into the temporal convolution layer, different convolution kernel sizes are set in the temporal convolution layer, temporal features of different scales are extracted, and then the rate of information flow at each time step is controlled by a gating mechanism. The process can be expressed as:
[0024]
[0025] Where ⊙ represents the Hadamard product, f c (·,θ c ) and f g (·,θ g ) represents filtered convolution and gated convolution, tanh() represents the hyperbolic tangent activation function, and σ() represents the sigmoid activation function;
[0026] Step (22) uses multi-scale gated time units to capture local time features, i.e., short-term time representation, specifically:
[0027]
[0028] where Γ1, Γ2, and Γ3 are parameter matrices of dimensions 1×S1, 1×S2, and 1×S3, respectively; FC(·) represents a fully connected operation, which is used to map the concatenated features to the desired output dimensions, thereby resizing the features after concatenation; τ Represents the process of gated convolution;
[0029] In temporal representation learning, the outputs of multi-scale gated temporal units and gated temporal convolutions are adaptively fused using a dynamic gating mechanism; the entire temporal representation learning process is expressed as:
[0030]
[0031] Among them, α is the adaptive gating parameter, which is dynamically calculated at each time step;
[0032] Step (3), constructing a dynamic spatiotemporal graph: the output of the temporal representation learning process is fed as input to the spatial representation module to learn the spatial correlation hidden in the traffic pattern and construct a dynamic spatiotemporal graph;
[0033] Step (4), the constructed dynamic spatiotemporal graph is obtained by learning the graph neural network to obtain the traffic flow data prediction representation after capturing the spatiotemporal dependency; wherein the dynamic spatiotemporal graph includes the fusion generation of the static adaptive graph and the dynamic graph;
[0034] Step (5), in the output and prediction module, the traffic flow data prediction representation after capturing the spatiotemporal dependency is converted into a traffic flow data prediction value and output. The conversion method is as follows:
[0035]
[0036] FC(·) represents the fully connected operation, and ReLU is the activation function;
[0037] Step (6), parameter adjustment: Calculate the prediction loss value and adjust the network parameters in the traffic flow prediction model based on the loss of all samples in the batch.
[0038] The static adaptive graph in step (4) is specifically: exploring the global features that remain unchanged in the graph structure through node embedding; this enables the model to autonomously reveal the hidden space dependencies between nodes; specifically, by using two trainable node embedding matrices E1 and E2∈R(N,K), where K represents the dimension of the hidden space and N is the number of nodes; these matrices are randomly initialized and trained to approximate the hidden space relationships between nodes;
[0039]
[0040] The ReLU function is used to maintain matrix sparsity by setting the values below the element-wise threshold defined by ∈ to zero;
[0041] The softmax function is used to normalize the matrix;
[0042] Diag(Λ) represents the adaptive diagonal matrix, which enhances the adaptability of the matrix nodes and dynamically generates diagonal weights;
[0043] The learned implicit spatial relations are embedded into a predefined matrix; this integration supplements the information from the predefined structure by incorporating the learned latent spatial dependencies; therefore, the adaptive static matrix can be defined as follows:
[0044] A s =A pre +A emb
[0045] Apre represents a predefined structure matrix, which can be derived by methods such as Gaussian kernel function;
[0046] Aemb represents a learnable embedding matrix that captures the hidden relationships between nodes;
[0047] The dynamic graph module in step (4) specifically comprises: using Wasserstein distance metric to measure the distance or dissimilarity of traffic flow distribution at different nodes;
[0048]
[0049] where ξ1 and ξ2 follow distributions P and Q, respectively, Γ represents all possible joint distributions of γ(ξ1, ξ2); ||·|| represents the norm, and ||ξ1-ξ2|| represents the cost of moving a unit mass from distribution P to distribution Q; P and Q are defined as the prior path flow distribution and the estimated path flow distribution, respectively; therefore, ξ1 and ξ2 represent the possible values of the prior and estimated path flow, respectively; based on this foundation, the 1-Wasserstein distance is used to quantify the difference between the estimated path flow distribution and the prior path flow distribution;
[0050] A DRD =1-d DRD
[0051] ADRD represents the degree of correlation between recorded points. For each node in the road network, the first k elements with the largest value in the i-th row are retained, and the remaining entries are set to 0. This process forms a dynamic similarity graph, denoted as A. d ;
[0052] A gated fusion module is used to dynamically generate weight values and adaptively fuse static and dynamic components, as shown in the following equation
[0053] F=σ(f(stack(A s ,A a )))
[0054] A h =F☉A s +(1-F)☉A d
[0055] Where F is the gating matrix obtained by multi-layer convolution, σ represents the normalization function, and the sigmoid function is used. The weak connections between nodes are eliminated by applying the threshold and ReLU function, thereby maintaining the sparsity of Aadp.
[0056] A adp =Norm(ReLU(A h -ε))
[0057] Obtain the optimal graph structure Aadp through adaptive graph structure learning components;
[0058] The form of the graph convolution layer is defined as:
[0059]
[0060] where g* represents the graph with optimized structure Aadp; θg (l) Represents the trainable parameters of the lth layer; * represents the graph convolution operation.
[0061] Before training the traffic flow prediction model, the training data set is first divided into batches according to the batch size M, with a total number of batches B; then, each batch of data is iteratively trained in turn, that is, steps (2)-(6) are repeated in step A until all the data of batch B in the training data set participate in the traffic flow prediction model training, and the traffic flow prediction model training is completed.
[0062] An electronic device includes a processor and a memory, wherein the memory is used to store executable instructions of the processor, and the processor executes the executable instructions to enable the electronic device to implement the traffic flow prediction method based on a multi-scale spatiotemporal graph neural network.
[0063] A computer-readable medium stores a computer program, which, when executed by a processor, implements the traffic flow prediction method based on a multi-scale spatiotemporal graph neural network.
[0064] The beneficial effects of the present invention are:
[0065] 1. By extracting multi-scale temporal dependencies and constructing dynamic adaptive graphs to model spatial dependencies, the modeling capability of dynamic spatiotemporal correlations in traffic forecasting is improved.
[0066] 2. This invention is based on a dual-stream framework, where one stream performs multi-scale gated temporal unit convolution, while the other stream applies gated temporal convolution to comprehensively extract the temporal correlation of traffic flow data. A dynamic gate fusion module autonomously learns and synthesizes multi-scale temporal features to extract global and local temporal correlations in traffic flow data.
[0067] 3. The present invention utilizes a data-driven strategy to develop a dynamic graph construction module, combined with a graph structure learning method that incorporates multiple factors. This allows for dynamic graph structure learning from historical data, fully accounting for the unique traffic flow patterns of each node. The dynamic similarity graph is combined with an adaptive static graph to generate a dynamic spatiotemporal graph that not only considers the potential relationships between nodes, but also the dynamic traffic patterns and the spatial correlation of each node. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1 A schematic diagram of the time representation learning process of the present invention;
[0069] Figure 2 A flowchart for constructing a static adaptive graph;
[0070] Figure 3 A comparison diagram of the prediction model of the present invention; DETAILED DESCRIPTION
[0071] The present invention will be further described below with reference to the accompanying drawings and specific embodiments:
[0072] Specific embodiment 1, as Figure 1 and Figure 2 As shown, the present invention discloses a traffic flow prediction method based on a multi-scale spatiotemporal graph neural network, including the following technical contents;
[0073] 1. Data Acquisition and Processing
[0074] Traffic flow data sequences obtained from traffic equipment, such as cameras and sensors. The acquired traffic flow data sequences are cleaned and standardized, and then divided into training data sets, validation data sets, and test data sets;
[0075] Given a historical traffic flow signal sequence of the past T time steps
[0076] Predict traffic flow data for the next T′ time steps
[0077] Data cleaning includes: first filling in the missing traffic flow data by linear interpolation method, then aggregating the filled traffic flow data into 5-minute time intervals, and deleting values that are obviously beyond the reasonable range.
[0078] Standardization includes: using the Z-score normalization method to normalize the traffic flow data series; the normalization formula is as follows:
[0079]
[0080] Among them, X t represents the value of the normalized traffic flow data sequence at time step t, is the value of the traffic flow data sequence at time step t, μ is the mean value of the traffic flow data sequence, and σ is the standard deviation of the traffic flow data sequence.
[0081] The training dataset and test dataset are divided by a sliding window mechanism. Specifically, according to the artificially set time window size T, the normalized traffic flow data is divided using a fixed-length sliding step to obtain the training dataset and test dataset.
[0082] 2. Build a traffic flow prediction model;
[0083] The traffic flow prediction model uses a dual-path structure to fully extract time representation, uses a dynamic spatiotemporal graph to capture the unique traffic pattern characteristics of each node, and uses a training dataset to train the constructed traffic flow prediction model;
[0084] Based on the trained traffic flow prediction model, traffic flow prediction is performed on the test dataset.
[0085] As a further technical solution, the traffic flow prediction model includes an input and preprocessing module, a spatiotemporal mining module, and an output and prediction module;
[0086] in,
[0087] (1) The input and preprocessing module is equipped with a data node embedding layer for data dimension conversion;
[0088] (2) The spatiotemporal mining module includes a time representation module and a dynamic graph construction module;
[0089] The temporal representation module is provided with a dual-path parallel dual-stream framework structure of a gated temporal convolutional network and a multi-scale gated temporal unit, which is used to extract long-term and short-term temporal dependencies;
[0090] The dynamic graph construction module uses a data-driven strategy to generate a dynamic spatiotemporal graph that includes the dynamic traffic patterns of each node. This module considers both static and dynamic perspectives to learn a more comprehensive graph structure. The adaptive static graph module operates from a macro perspective, capturing a more comprehensive representation of static graph information. Meanwhile, the dynamic graph module is generated through data-driven (Wasserstein metric distance). Combining static local graphs and dynamic similarity graphs can more completely represent spatial dependencies, overcoming the limitations of single-graph approaches.
[0091] (3) Output and prediction module, which is used to convert the traffic flow data prediction representation after capturing the spatiotemporal dependencies into traffic data prediction values.
[0092] The traffic flow prediction model constructed is trained using the training dataset, which includes the following steps:
[0093] Step A: Perform an iterative training on the traffic flow prediction model. The specific steps are as follows:
[0094] Step (1), dimensionality conversion: In the input and preprocessing module, the training data in the training dataset is input into the data node embedding layer for dimensionality conversion to obtain the converted traffic flow data sequence; at the same time, the learnable embedding representations E1 and E2 are initialized for subsequent dynamic graph construction;
[0095] Assume that one of the batches of training data is The converted traffic flow data sequence obtained
[0096] Where C is the initial feature dimension, such as traffic flow information. N represents the number of nodes, T represents the time length, and D represents the number of dimensions after conversion.
[0097] Step (2), time representation learning process: The transformed traffic flow data sequence is sent as input to the spatiotemporal time representation module, and a dual-path parallel structure of gated time convolutional network and multi-scale gated time unit is used to learn the dynamic time representation of traffic flow conditions, extract long-term and short-term time dependencies, and obtain the output of the time representation learning process, such as Figure 1 As shown;
[0098] In step (2), a gated temporal convolutional network is used to capture the global temporal representation, i.e., the long-term temporal representation. Specifically, the dilated causal convolution is integrated into the temporal convolution layer, four convolution kernel sizes k∈{2,3,6,7} are set in the temporal convolution layer to extract temporal features of different scales, and then the rate of information flow at each time step is controlled by the gating mechanism. The process can be expressed as:
[0099]
[0100] Where ⊙ represents the Hadamard product, f c (·,θ c ) and f g (·,θ g ) represents filtered convolution and gated convolution, tanh() represents the hyperbolic tangent activation function, and σ() represents the sigmoid activation function;
[0101] In step (2), a multi-scale gated time unit is used to capture local temporal features, specifically:
[0102]
[0103] where Γ1, Γ2, and Γ3 are parameter matrices of dimensions 1×S1, 1×S2, and 1×S3, respectively. FC(·) represents a fully connected operation that maps the concatenated features to the desired output dimensions, thereby resizing the features after concatenation.
[0104] The multi-scale gated temporal unit is able to capture short- to medium-term temporal patterns through its multi-receptive field design. At the same time, the gated temporal convolution expands the receptive field through dilated convolution, making it possible to capture longer-term dependencies. By integrating these two mechanisms, TDL achieves comprehensive extraction of temporal features at different time scales from traffic data. In temporal representation learning, the outputs of the multi-scale gated temporal unit and the gated temporal convolution are adaptively fused using a dynamic gating mechanism. The entire temporal representation learning process is expressed as:
[0105]
[0106] Here, α is an adaptive gating parameter, dynamically calculated at each time step. It is used to regulate the fusion of temporal representations, specifically controlling the relative influence of short- to medium-term patterns and long-range dependencies on the final output Hout(r)∈RN×M×Cr. By adaptively fusing the outputs of two branches, which themselves employ internal gating mechanisms, temporal representation learning effectively prioritizes and preserves the most critical temporal information across different time scales.
[0107] Step (3), constructing a dynamic spatiotemporal graph: the output of the temporal representation learning process is fed as input to the dynamic graph construction module to learn the spatial correlation hidden in the traffic pattern and construct a dynamic spatiotemporal graph;
[0108] Step (4), such as Figure 2 As shown in the figure, the constructed dynamic spatiotemporal graph is used to obtain traffic flow data prediction representation after capturing spatiotemporal dependencies through the learning of graph neural networks;
[0109] Static Adaptive Graph: Exploring global features that remain unchanged in the graph structure through node embeddings. This allows the model to autonomously reveal latent spatial dependencies between nodes. Specifically, this is achieved by using two trainable node embedding matrices E1 and E2∈R(N,K), where K represents the dimension of the latent space and N is the number of nodes. These matrices are randomly initialized and trained to approximate the latent spatial relationships between nodes.
[0110]
[0111] The ReLU function is used to maintain matrix sparsity by setting values below a defined element-wise threshold to zero. The softmax function is used to normalize the matrix. In addition, Diag(Λ) represents an adaptive diagonal matrix, which enhances the adaptability of the matrix nodes and dynamically generates diagonal weights.
[0112] The learned implicit spatial relations are embedded into the predefined matrix. This integration supplements the information from the predefined structure by combining the learned latent spatial dependencies. Therefore, the adaptive static matrix can be defined as follows:
[0113] A s =A pre +A emb
[0114] Apre represents a predefined structure matrix that can be derived by methods such as the Gaussian kernel function. Aemb represents a learnable embedding matrix used to capture the hidden relationships between nodes.
[0115] Dynamic Adaptive Graph: The Wasserstein distance metric is used to measure the distance or dissimilarity of traffic flow distribution at different nodes.
[0116]
[0117] where ξ1 and ξ2 follow distributions P and Q, respectively, and Γ represents the possible joint distribution of γ(ξ1, ξ2). ||·|| represents the norm, and ||ξ1-ξ2∥ represents the cost of moving a unit of mass from distribution P to distribution Q. In our approach, P and Q are defined as the prior path flow distribution and the estimated path flow distribution, respectively. Therefore, ξ1 and ξ2 represent the possible values of the prior and estimated path flow, respectively. Based on this foundation, the 1-Wasserstein distance is used to quantify the difference between the estimated path flow distribution and the prior path flow distribution.
[0118] A DRD =1-d DRD
[0119] ADRD represents the degree of correlation between recorded points. To ensure the specified sparsity is achieved, we process the correlation matrix (derived from the ADRD values). For each node in the road network, we retain the top k elements with the largest values in the i-th row and set the remaining entries to 0. This process forms a dynamic similarity graph, denoted as Ad.
[0120] A gated fusion module is used to dynamically generate weight values and adaptively fuse static and dynamic components, as shown in the following equation
[0121] F=σ(f(stack(A s ,A d )))
[0122] A h =F☉A s +(1-F)☉A d
[0123] Where F is the gating matrix obtained through multiple layers of convolution, σ represents the normalization function, in this case, we use the sigmoid function. We eliminate weak connections between nodes by applying the threshold and ReLU function, thereby maintaining the sparsity of Aadp.
[0124] A adp =Norm(ReLU(A h -ε))
[0125] Through the adaptive graph structure learning component, we obtain the optimal graph structure Aadp.
[0126] The form of the graph convolution layer is defined as:
[0127]
[0128] where g* represents the graph Aadp with optimized structure. θg(l) represents the trainable parameters of layer l. * represents the graph convolution operation.
[0129] Step (5), in the output and prediction module, converting the traffic flow data prediction representation after capturing the spatiotemporal dependency into a traffic flow data prediction value and outputting it;
[0130]
[0131] Step (6), parameter adjustment: Calculate the prediction loss value and adjust the network parameters in the traffic flow prediction model based on the loss of all samples in the batch.
[0132] Step B: Repeat step A until the specified number of iterations is reached, and the traffic flow prediction model is trained.
[0133] As a further technical solution, before training the traffic flow prediction model, the training dataset is first divided into batches of size M, with a total number of batches of B;
[0134] Then, each batch of data is iteratively trained in turn. Step A: The traffic flow prediction model is iteratively trained. Steps (2)-(6) are repeated until all batches of data in the training set participate in the traffic flow prediction model training.
[0135] As a specific example of this application, METR-LA was used as experimental data. METR-LA is a large-scale dataset collected from 1,500 traffic loop detectors on the Los Angeles County highway network. This dataset includes speed, road capacity, and occupancy data, covering approximately 3,420 miles.
[0136] The present invention is compared with other typical traffic flow prediction methods (VAR, STGCN, GWN), among which,
[0137] VAR: Vector Autoregression Model
[0138] STGCN: Spatiotemporal Graph Neural Network Model
[0139] Graph WaveNet
[0140] PGCN: Progressive Graph Neural Networks
[0141] The results are shown in Table 1.
[0142] Table 1 Comparison of indicators of different algorithms
[0143]
[0144] It can be seen from the table that on the METR-LA dataset, the proposed method has improved compared with the suboptimal method in terms of MAE, RMSE and MAPE indicators. Figure 3 As shown, the competitiveness and effectiveness of the method of the present invention are verified.
[0145] Specific embodiment 2, based on specific embodiment 1, performs data cleaning and standardization on the traffic flow data sequence containing direction attributes extracted by traffic equipment, wherein the direction attributes are artificially defined upward (entering the city) and downward (exiting the city) directions. According to the upward and downward directions, the training data set, the verification data set and the test data set are respectively delineated. When annotating the data, the data are annotated according to the local traffic flow tidal time period, and the time is divided into off-peak period and peak period according to whether it is the traffic flow peak period. That is, the data set is divided again by the tidal time and direction attributes in the data input stage, and the traffic flow fluctuation amplitude in each re-divided data set is weakened, which can significantly reduce the prediction error of the traffic flow prediction model.
Claims
1. A traffic flow prediction method based on a multi-scale spatiotemporal graph neural network, characterized by: The following steps are included: S1. Obtain traffic flow data sequences from traffic equipment, clean and standardize the data, and divide it into training, validation, and test datasets. S2. Construct a traffic flow prediction model, which includes an input and preprocessing module, a spatiotemporal mining module, and an output and prediction module; S21. The input and preprocessing module is provided with a data node embedding layer for dimensionality conversion of the training dataset; S22. The spatiotemporal mining module includes a temporal representation module and a spatial representation module; The temporal representation module is equipped with a dual-parallel gated temporal convolutional network and a multi-scale gated temporal unit. This dual-parallel structure extracts the multi-scale temporal dependencies of traffic flows in the converted training dataset and obtains the output of the temporal representation learning process. The spatial representation module generates a dynamic graph of node dynamic traffic patterns using input data and a road network graph. The output of the temporal representation learning process is fed into the spatial representation module to obtain a predicted representation of traffic flow data that captures spatiotemporal dependencies. S23. In the output and prediction module, the traffic flow data prediction representation after capturing the spatiotemporal dependency is converted into a traffic flow data prediction value and output to obtain a traffic flow prediction value; S3. Train the model multiple times based on the training dataset and modify the parameters to obtain a traffic flow prediction model; select and evaluate the trained traffic flow prediction model based on the validation dataset, and perform traffic flow prediction based on the test dataset and the trained traffic flow prediction model.
2. The method according to claim 1, wherein: The training method of the traffic flow prediction model in step S2 is: Step A: Perform an iterative training on the traffic flow prediction model; Step B: Repeat step A until the specified number of iterations is reached, and the traffic flow prediction model training is completed.
3. The method according to claim 2, wherein: The specific steps of the one-time iterative training are as follows: Step (1), dimensionality conversion: In the input and preprocessing module, the training data in the training dataset is input into the data node embedding layer for dimensionality conversion to obtain the converted traffic flow data sequence; at the same time, the learnable embedding representations E1 and E2 are initialized for subsequent dynamic graph construction; Assume that the training data of one of the iteration batches is The converted traffic flow data sequence obtained Among them, C is the initial feature dimension, such as traffic flow information; N represents the number of nodes; T represents the time length; D represents the number of dimensions after conversion; Step (2), temporal representation learning process: the transformed traffic flow data sequence is sent as input to the spatiotemporal temporal representation module to learn the dynamic temporal representation of the traffic flow conditions, extract multi-scale temporal dependencies including long-term and short-term temporal dependencies, and obtain the output of the temporal representation learning process; Step (21) uses a gated temporal convolutional network to capture the global temporal representation. Specifically, the dilated causal convolution is integrated into the temporal convolution layer, different convolution kernel sizes are set in the temporal convolution layer, temporal features of different scales are extracted, and then the rate of information flow at each time step is controlled by a gating mechanism. The process can be expressed as: Where ⊙ represents the Hadamard product, f c (·,θ c ) and f g (·,θ g ) represents filtered convolution and gated convolution, tanh() represents the hyperbolic tangent activation function, and σ() represents the sigmoid activation function; Step (22) uses multi-scale gated time units to capture local time features, i.e., short-term time representation, specifically: where Γ1, Γ2, and Γ3 are parameter matrices of dimensions 1×S1, 1×S2, and 1×S3, respectively; FC(·) represents a fully connected operation, which is used to map the concatenated features to the desired output dimensions, thereby resizing the features after concatenation; τ Represents the process of gated convolution; In temporal representation learning, the outputs of multi-scale gated temporal units and gated temporal convolutions are adaptively fused using a dynamic gating mechanism; the entire temporal representation learning process is expressed as: Among them, α is the adaptive gating parameter, which is dynamically calculated at each time step; Step (3), constructing a dynamic spatiotemporal graph: the output of the temporal representation learning process is fed as input to the spatial representation module to learn the spatial correlation hidden in the traffic pattern and construct a dynamic spatiotemporal graph; Step (4), the constructed dynamic spatiotemporal graph is obtained by learning the graph neural network to obtain the traffic flow data prediction representation after capturing the spatiotemporal dependency; wherein the dynamic spatiotemporal graph includes the fusion generation of the static adaptive graph and the dynamic graph; Step (5), in the output and prediction module, the traffic flow data prediction representation after capturing the spatiotemporal dependency is converted into a traffic flow data prediction value and output. The conversion method is as follows: FC(·) represents the fully connected operation, and ReLU is the activation function; Step (6), parameter adjustment: Calculate the prediction loss value and adjust the network parameters in the traffic flow prediction model based on the loss of all samples in the batch.
4. The method according to claim 3, wherein: The static adaptive graph in step (4) is specifically: exploring the global features that remain unchanged in the graph structure through node embedding; this enables the model to autonomously reveal the hidden space dependencies between nodes; specifically, by using two trainable node embedding matrices E1 and E2∈R(N,K), where K represents the dimension of the hidden space and N is the number of nodes; these matrices are randomly initialized and trained to approximate the hidden space relationships between nodes; The ReLU function is used to maintain matrix sparsity by setting the values below the element-wise threshold defined by ∈ to zero; The softmax function is used to normalize the matrix; Diag(Λ) represents the adaptive diagonal matrix, which enhances the adaptability of the matrix nodes and dynamically generates diagonal weights; The learned implicit spatial relations are embedded into a predefined matrix; this integration supplements the information from the predefined structure by incorporating the learned latent spatial dependencies; therefore, the adaptive static matrix can be defined as follows: A s =A pre +A emb Apre represents a predefined structure matrix, which can be derived by methods such as Gaussian kernel function; Aemb represents a learnable embedding matrix that captures the hidden relationships between nodes.
5. The method according to claim 3, wherein: The dynamic graph module in step (4) specifically comprises: using Wasserstein distance metric to measure the distance or dissimilarity of traffic flow distribution at different nodes; where ξ1 and ξ2 follow distributions P and Q, respectively, Γ represents all possible joint distributions of γ(ξ1, ξ2); ||·|| represents the norm, and ||ξ1-ξ2|| represents the cost of moving a unit mass from distribution P to distribution Q; P and Q are defined as the prior path flow distribution and the estimated path flow distribution, respectively; therefore, ξ1 and ξ2 represent the possible values of the prior and estimated path flow, respectively; based on this foundation, the 1-Wasserstein distance is used to quantify the difference between the estimated path flow distribution and the prior path flow distribution; A DRD =1-d DRD ADRD represents the degree of correlation between recorded points. For each node in the road network, the first k elements with the largest value in the i-th row are retained, and the remaining entries are set to 0. This process forms a dynamic similarity graph, denoted as A. d ; A gated fusion module is used to dynamically generate weight values and adaptively fuse static and dynamic components, as shown in the following equation F=σ(f(stack(A s ,A d ))) A h =F☉A s +(1-F)☉A d Where F is the gating matrix obtained by multi-layer convolution, σ represents the normalization function, and the sigmoid function is used. The weak connections between nodes are eliminated by applying the threshold and ReLU function, thereby maintaining the sparsity of Aadp. A adp =Norm(ReLU(A h -ε)) Obtain the optimal graph structure Aadp through adaptive graph structure learning components; The form of the graph convolution layer is defined as: where g* represents the graph with optimized structure Aadp; θg (l) Represents the trainable parameters of the lth layer; * represents the graph convolution operation.
6. The method according to claim 3, wherein: Before training the traffic flow prediction model, the training data set is first divided into batches according to the batch size M, with a total number of batches B; then, each batch of data is iteratively trained in turn, that is, steps (2)-(6) are repeated in step A until all the data of batch B in the training data set participate in the traffic flow prediction model training, and the traffic flow prediction model training is completed.
7. An electronic device, characterized in that: It includes a processor and a memory, wherein the memory is used to store executable instructions of the processor, and the processor executes the executable instructions to enable the electronic device to implement the traffic flow prediction method based on a multi-scale spatiotemporal graph neural network as described in any one of claims 1 to 6.
8. A computer-readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the traffic flow prediction method based on a multi-scale spatiotemporal graph neural network described in any one of claims 1 to 6 is implemented.