Traffic network flow prediction method and system based on pre-training space-time diagram neural network model
By using the pre-trained spatiotemporal graph neural network model PSTM, the problems of long-term context capture and computational burden in existing models are solved, and efficient traffic flow prediction is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HENAN UNIVERSITY
- Filing Date
- 2026-01-29
- Publication Date
- 2026-05-05
AI Technical Summary
Existing graph neural network models struggle to capture long-term contextual information, incur significant computational burden when processing long-sequence data, and fail to adequately consider the spatiotemporal correlation of traffic data, leading to inaccurate traffic flow predictions.
A pre-trained spatiotemporal graph neural network model PSTM is adopted. Temporal and spatial features are extracted during the pre-training stage. The automatic masking coding strategy and frequency domain transformation are used to reduce the computational burden. In the fine-tuning stage, long-term and short-term features are fused for prediction.
It improves the accuracy and efficiency of traffic flow prediction, significantly reduces training time and parameter complexity, and achieves accurate short-term traffic flow prediction.
Smart Images

Figure CN121982891A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of traffic data mining technology, and in particular to a method and system for predicting traffic network flow based on a pre-trained spatiotemporal graph neural network model. Background Technology
[0002] Complex transportation networks collect massive amounts of traffic flow data with spatiotemporal labels using numerous sensors. Utilizing this traffic spatiotemporal data for traffic flow prediction is a core task of intelligent transportation, playing a crucial role in various applications such as road network planning, traffic management, and travel navigation. Numerous research and application results have already emerged. Accurate traffic flow prediction helps managers regulate the transportation system, optimize traffic resource allocation, alleviate road congestion, support route recommendations, and predict travel times.
[0003] Traffic forecasting in complex traffic networks is influenced by numerous factors and suffers from poor forecast stability. It requires not only modeling the non-stationary temporal traffic data of each traffic node but also considering the spatial dependencies and interaction mechanisms among multiple nodes. By analyzing the inherent spatiotemporal characteristics of historical traffic flow, we can identify existing periodic trends and understand the non-static interaction mechanisms that shape traffic flow patterns, leading to more accurate predictions of future traffic flow.
[0004] There are three main problems with existing traffic prediction methods: (1) Existing graph neural network models cannot capture long-term contextual information, and it is unreliable to model traffic dependencies using only short-term data. For example, when examining data within a short window, the time series are observed to be completely different within the short-term time window. However, from the perspective of long-term time windows, they have similar trends. Therefore, existing graph neural network models are difficult to accurately predict different future trends based on limited historical data. (2) Modeling long-term data will bring huge computational burden. Although long-term time series are beneficial to reduce the noise caused by short-term fluctuations, inputting such long-term time series into STGNN or Transformer models will lead to significant computational overhead. Although some pre-trained models can handle long-term data, the use of masking strategies and multi-layer Transformers to learn features and reconstruct sequences during the pre-training stage will exacerbate performance problems, especially when dealing with complex networks. (3) Traffic data not only contains temporal information, but also spatial correlations between observation nodes, which is an aspect that most existing pre-trained models have not yet fully addressed. Summary of the Invention
[0005] This invention addresses the traffic flow prediction problem in complex traffic networks. It proposes a method and system for traffic network flow prediction based on a pre-trained spatial-temporal masked graph neural network (PSTM) model. Specifically, a PSTM model is designed to model the temporal and spatial correlations of historical traffic node data. The proposed model achieves accurate short-term (2-hour) traffic flow prediction, with prediction accuracy superior to existing traffic flow prediction models based on methods such as GNNs.
[0006] In a first aspect, the present invention provides a traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model, comprising: a pre-training stage and a fine-tuning stage;
[0007] Obtain the historical traffic flow sequence for T time steps prior to time t. The historical traffic flow sequence Segmented into long-term spatiotemporal sequences and short-term spatiotemporal sequences ;
[0008] The pre-training phase includes: first processing the original long-term spatiotemporal sequence... The input is fed to the encoder, and the encoder's output is then fed to the decoder to obtain the reconstructed sequence. The reconstruction loss is calculated based on a preset loss function, and the encoder and decoder are optimized based on the reconstruction loss.
[0009] In the encoder, a block embedding layer is first used to embed the sequence. Divided into A non-overlapping subsequence is used to obtain the block embedding. Then, a positional encoding layer is used to positionally encode all subsequences to obtain positional embedding features. Next, the location embedding features are... Perform random masking to obtain the masked fragment-level representation. and unmasked fragment-level representation Finally, the unmasked fragments are represented. The input is fed into the L-layer spatiotemporal transformation encoder to obtain the latent output representation. In the decoder, the Fast Fourier Transform is used to represent all potential outputs. The signal is converted to the frequency domain and reconstructed using linear interpolation in the frequency domain to obtain the reconstructed sequence. ;
[0010] The fine-tuning phase includes: freezing the encoder parameters obtained in the pre-training phase; and adjusting the long-term spatiotemporal sequence. The input is fed into the encoder to obtain long-term feature representations. The short-term spatiotemporal sequence The input is fed into a spatiotemporal graph neural network to obtain short-term feature representations. The long-term features are represented using a multilayer perceptron. and the short-term feature representation The fusion is performed, and the fusion result is passed through a linear layer to obtain the result at time t. The system calculates a future traffic flow sequence with a time step; it also calculates the prediction loss between the predicted future traffic flow sequence and the actual future traffic flow sequence, and optimizes the spatiotemporal graph neural network accordingly. .
[0011] This invention aims to effectively extract temporal patterns from large amounts of historical time-series data, generating context-rich fragment-level features to enable models to capture long-term temporal pattern characteristics. During pre-training, a masked autoencoding strategy is employed, allowing the model to capture long-term historical data features spanning several weeks and produce representations that accurately reflect complex temporal patterns. In the decoding phase, frequency domain transformation effectively preserves the frequency characteristics of a given lookback window. This method not only ensures semantic consistency between the lookback window and the prediction range but also significantly reduces training time and parameter complexity. Masked autoencoding is combined with attention mechanisms and graph convolution techniques to dynamically capture node similarity features. Notably, PSTM is designed as a flexible framework that can be seamlessly integrated with various STGNN architectures, significantly reducing parameter counting and training time while improving overall performance.
[0012] Furthermore, the position encoding layer employs learnable position embeddings for position encoding; wherein the position encoding formula for the i-th node is:
[0013]
[0014] in, This represents the result of the i-th node after position encoding. Let represent the learnable parameters corresponding to the p-th time slice. This represents the time slice of the i-th node. , This represents the feature dimension after position encoding.
[0015] Furthermore, the location embedding features Random masking includes:
[0016] Set the mask ratio Masked fragment-level representation ; Unmasked fragment-level representation ; .
[0017] Furthermore, the aforementioned representation of unmasked fragments... The input is fed into the L-layer spatiotemporal transformation encoder to obtain the latent output representation. ,include:
[0018] set up and express The i-th node in the middle is at the 1st position Time step and the Given the representation at time step, the process of temporal attention encoding for the i-th node is as follows:
[0019]
[0020]
[0021] in, Indicates the first The node of the first Time step for the first Temporal attention weights for time steps It is a bivariate function used to measure pairwise correlation. This indicates the performance of feature space transformation. Represents a non-linear activation function. This represents the natural exponential function. It is a bivariate function used to measure pairwise correlation;
[0022] By integrating the temporal attention encoding results of all nodes, we obtain the temporal attention mechanism representation of all nodes. ;based on The latent output representation is obtained by following the learning process described below. :
[0023]
[0024] in, Represents the temporal attention mechanism for all nodes, with parameters For learnable weights, Let d be the d-th order neighborhood of graph G, where d is the expansion rate. Let m represent the m-th convolutional kernel, and M represent the number of convolutional kernels.
[0025] Furthermore, the long-term features are represented using a multilayer perceptron. and the short-term feature representation The integration process specifically includes:
[0026]
[0027] in, This represents a multilayer perceptron. The prediction head uses a spatiotemporal graph neural network. This indicates the fusion result.
[0028] Secondly, the present invention provides a traffic network flow prediction system based on a pre-trained spatiotemporal graph neural network model, comprising:
[0029] The data acquisition module is used to obtain historical traffic flow sequences for T time steps prior to time t. The historical traffic flow sequence Segmented into long-term spatiotemporal sequences and short-term spatiotemporal sequences ;
[0030] The pre-training module is used to perform the pre-training phase, which includes first processing the original long-term spatiotemporal sequences. The input is fed to the encoder, and the encoder's output is then fed to the decoder to obtain the reconstructed sequence. The reconstruction loss is calculated based on a preset loss function, and the encoder and decoder are optimized based on the reconstruction loss.
[0031] In the encoder, a block embedding layer is first used to embed the sequence. Divided into A non-overlapping subsequence is used to obtain the block embedding. Then, a positional encoding layer is used to positionally encode all subsequences to obtain positional embedding features. Next, the location embedding features are... Perform random masking to obtain the masked fragment-level representation. and unmasked fragment-level representation Finally, the unmasked fragments are represented. The input is fed into the L-layer spatiotemporal transformation encoder to obtain the latent output representation. In the decoder, the Fast Fourier Transform is used to represent all potential outputs. The signal is converted to the frequency domain and reconstructed using linear interpolation in the frequency domain to obtain the reconstructed sequence. ;
[0032] The fine-tuning module is used to perform the fine-tuning phase, including freezing the encoder parameters obtained in the pre-training phase; and adjusting the long-term spatiotemporal sequence. The input is fed into the encoder to obtain long-term feature representations. The short-term spatiotemporal sequence The input is fed into a spatiotemporal graph neural network to obtain short-term feature representations. The long-term features are represented using a multilayer perceptron. and the short-term feature representation The fusion is performed, and the fusion result is passed through a linear layer to obtain the result at time t. The system calculates a future traffic flow sequence with a time step; it also calculates the prediction loss between the predicted future traffic flow sequence and the actual future traffic flow sequence, and optimizes the spatiotemporal graph neural network accordingly. .
[0033] Thirdly, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method as described in the first aspect.
[0034] Fourthly, the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in the first aspect.
[0035] The beneficial effects of this invention are as follows:
[0036] This invention focuses on traffic flow prediction in transportation networks, using massive amounts of historical traffic flow data as its research object. The prediction process is divided into two stages: pre-training and fine-tuning. In the pre-training stage, long sequences are allowed as input, enabling the model to perform data masking during the encoder stage, capturing temporal features from a wide range of historical sequences. The decoder extracts and reconstructs frequency domain features, emphasizing the periodicity of long sequences. This biphase method utilizes frequency domain linear interpolation for reconstruction, significantly reducing training time and parameter overhead. In the fine-tuning stage, the model introduces a long-short-term feature fusion mechanism, fusing pre-trained long-term features with short-term features learned by the downstream traffic flow prediction model. This improves the accuracy and efficiency of long-term prediction tasks, demonstrating the model's adaptability to various traffic prediction scenarios. This invention achieves high prediction accuracy, outperforming existing graph neural network-based traffic flow prediction models. Attached Figure Description
[0037] Figure 1 A block diagram illustrating the principle of a traffic network flow prediction model PSTM based on a pre-trained spatiotemporal graph neural network model provided in this embodiment of the invention;
[0038] Figure 2 This is a schematic diagram of the structure of a traffic network flow prediction system based on a pre-trained spatiotemporal graph neural network model provided in an embodiment of the present invention;
[0039] Figure 3 This is a structural block diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0040] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of the embodiments of this invention will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0041] In this invention, the traffic network is defined as an undirected graph G=(V,E,A); where V is the set of sensor nodes; sensor nodes are generally located at intersections or junctions; this invention defines the traffic network as including N nodes in total. E is the set of edges, representing the connectivity between nodes, i.e., the paths between the locations of the sensor nodes. A represents the adjacency matrix of the relationships between nodes, where 1 indicates that two nodes are adjacent, and 0 indicates that two nodes are not adjacent.
[0042] In this invention, each sensor node in the traffic network G is configured to detect F measurements (such as speed, traffic flow, etc.) at the same sampling frequency; that is, each node generates a feature vector of length F at each time point. Therefore, the traffic information of the traffic network G at time t... It can be represented as: , This represents the feature vector of length F generated by the Nth sensor node at time t; at this point, the input data for traffic flow prediction is transformed into a historical sequence. :
[0043]
[0044] Where T represents the time step;
[0045] Therefore, the traffic flow prediction problem to be solved by this invention is transformed into a problem of predicting the future T time steps using historical traffic sequences; this problem can be expressed by the following formula:
[0046]
[0047] Where f represents the neural network model, and the prediction result is expressed as... .
[0048] Based on the above definition, such as Figure 1 As shown, this invention proposes a traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model, including a pre-training stage and a fine-tuning stage;
[0049] Obtain the historical traffic flow sequence with T time steps prior to time t, and segment the historical traffic flow sequence into a long-term spatiotemporal sequence. and short-term spatiotemporal sequences ;
[0050] Correspondingly, the pre-training stage includes: first processing the original long-term spatiotemporal sequence... (For example, traffic information within 7 or 14 days) is input into the encoder, and the encoder's output is then input into the decoder to obtain the reconstructed long-term spatiotemporal sequence. The reconstruction loss is calculated based on a preset loss function, and the encoder and decoder are optimized based on the reconstruction loss.
[0051] Specifically, the present invention aims to effectively extract time patterns from a large amount of historical time series data and generate fragment-level features rich in contextual information, so that the model can capture long-term time pattern features.
[0052] The data processing procedure of the encoder is as follows:
[0053] Step A: First, use a block embedding layer to embed the sequence Divided into The block embedding is obtained by dividing the non-overlapping subsequences (a subsequence is also called a time slice). To capture the dependencies between different subsequences and highlight the temporal order of each subsequence, a positional encoding layer is then used to encode the positions of all subsequences, i.e., adding order information to each subsequence to obtain positional embedding features. ;
[0054] Specifically, assuming , Represents a sequence The length (usually set to) ), Indicates the number of sensor nodes. The feature dimension is represented by C, which can include speed, average speed, and flow rate, in which case the feature dimension C=3; the length of a subsequence is set to L, satisfying... Ideally It can be Divisible by. , This represents the dimension of the feature mapping to the latent space. .
[0055] This step will involve time series. Segmenting the data into smaller pieces offers several advantages: First, compared to using a single data point, segmenting the time series provides a more explicit semantic representation. Second, this strategy benefits downstream tasks, as subsequent STGNN models can directly utilize these patches as input. Finally, it significantly reduces the sequence length input to the encoder, thereby improving the encoder's efficiency during the pre-training phase.
[0056] As one possible implementation, taking the i-th node as an example, the position bit encoding layer uses learnable position embedding for position encoding, as shown in the formula:
[0057]
[0058] Among them, it means Let represent the learnable parameters corresponding to the p-th time slice. This represents the result of position encoding of the i-th node, block embedding. A time slice containing all nodes, where i represents the i-th node. This represents the time slice of the i-th node. .
[0059] Learnable positional embeddings are crucial for learning the periodic features of time series because they are fully customizable and less affected by noise in the input data.
[0060] Step B: To enable the model to better learn long-term features, embed features at the location. Perform random masking to obtain the masked fragment-level representation. and unmasked fragment-level representation ;
[0061] Specifically, by using a masking algorithm to randomly mask sensor data, the sequence length of the input spatiotemporal conversion encoder is significantly reduced, making the spatiotemporal conversion encoder more effective in the pre-training stage, especially when a high masking ratio is applied. , ; , , For concealment ratio.
[0062] Step C: Represent the unmasked fragments at the fragment level The data is input to an L-layer spatiotemporal transformation encoder (spatiotemporal Transformer) to simultaneously capture the complex and long-term spatiotemporal dependencies inherent in traffic data, yielding a potential output representation. ;
[0063] Specifically, the temporal attention mechanism in the spatiotemporal Transformer can extract the correlation between vectors in each coding layer, thus facilitating the simultaneous computation of temporal dependencies between N sensor nodes. The temporal attention mechanism for all nodes is represented as follows: , The temporal attention encoding result of the i-th node is represented as , F represents the feature dimension after processing by the time attention mechanism.
[0064] Among them, let and express The i-th node in the middle is at the 1st position Time step and the The representation at time step, the time attention mechanism of the i-th node can be represented as:
[0065]
[0066]
[0067] in, Indicates the first The node of the first Time step for the first Temporal attention weights for time steps. It is a bivariate function used to measure pairwise correlation. This indicates the performance of feature space transformation. Represents a non-linear activation function. This represents the natural exponential function. It is a bivariate function used to measure pairwise correlation.
[0068] Simultaneously, this invention also designs a single-layer graph attention network (GAT) with spatial attention, utilizing extended convolutional kernels to propagate node features over long distances. This method enhances the model's capabilities while mitigating overfitting and oversmoothing issues, resulting in a feature output representation as follows: , This represents the output feature dimension obtained after GAT calculation. The calculation formula is as follows:
[0069]
[0070] in, Represents the temporal attention mechanism for all nodes, with parameters For learnable weights, Let d be the d-th order neighborhood of graph G, where d is the expansion rate. Let m represent the m-th convolutional kernel, and M represent the number of convolutional kernels.
[0071] The data processing procedure of the decoder is as follows:
[0072] Step D: Represent all potential outputs using Fast Fourier Transform (FFT). The signal is converted to the frequency domain and reconstructed using linear interpolation in the frequency domain to obtain the reconstructed long-term spatiotemporal sequence. ;
[0073] Specifically, As input, the discrete-time signal is first transformed from the time domain to the complex frequency domain using the Fast Fourier Transform (FFT) method. This transformation will... Each real-valued input is compressed into A complex sequence provides a more compact and efficient representation of the underlying patterns in time series data.
[0074] Next, a low-pass filter (LPF) is applied to process the transformed frequency domain signal. The main goal of the LPF is to compress the model size while preserving essential information. The LPF achieves this by discarding frequency components above a specified cutoff frequency (COF), resulting in a more concise frequency domain representation. The LPF retains relevant information in the time series while discarding components beyond the model's learning capacity. This ensures that a significant portion of the meaningful content of the original time series is preserved. Furthermore, the high-frequency components filtered out by the low-pass filter typically include noise that is irrelevant to effective time series modeling itself.
[0075] Finally, the original sequence is recovered by interpolating the frequency representation of the corresponding non-masked segments, and then the interpolated frequency data is mapped back to the time domain.
[0076] The above design enables the model to capture amplitude and phase components from the frequency domain perspective, where the amplitude of the frequency component represents its intensity or strength in the original time-domain signal. Furthermore, by transforming the data to the frequency domain, key information can be preserved while reducing the size of the model parameters, thereby accelerating training time. The resulting reconstructed sequence is represented as follows:
[0077]
[0078] in, For a fully reconstructed time series representation, and These represent the Fast Fourier Transform and the Inverse Real Fast Fourier Transform, respectively. This indicates the weights used in the linear interpolation process. Padding is a zero-padding operation designed to ensure dimensionality consistency after interpolation and maintain the integrity of the transformed data.
[0079] Finally, the original sequence and reconstructed sequence We compare loss functions to train the model and verify the periodic patterns in the data.
[0080] As one possible implementation method, the loss function is defined as follows in this embodiment of the invention:
[0081]
[0082] Where L represents the length of a single subsequence, and N represents the number of nodes. Indicates the number of subsequences. This represents the learnable parameters.
[0083] The reconstruction accuracy is trained using the loss function described above, enabling the model to better learn long-term trend features. At the same time, combining the frequency domain can better capture the periodic features in the time series.
[0084] In this embodiment of the invention, a masked autoencoding strategy is employed during pre-training, enabling the model to capture long-term historical data features spanning several weeks and generate representations that accurately reflect complex temporal patterns. During the decoding phase, frequency domain transformation effectively preserves the frequency characteristics of a given lookback window. This method not only ensures semantic consistency between the lookback window and the prediction range but also significantly reduces training time and parameter complexity.
[0085] The fine-tuning phase includes:
[0086] Step E: Freeze the encoder parameters obtained during the pre-training phase; freeze the long-term spatiotemporal sequence. The input is fed into the encoder to obtain long-term feature representations. Graph learning is performed based on the long-term feature representation to obtain a discrete sparse graph; the short-term spatiotemporal sequence is input into a spatiotemporal graph neural network to obtain a short-term feature representation. ;in, Dimensions representing short-term characteristics.
[0087] Specifically, in the fine-tuning phase, the input consists of two parts of data: a long-term spatiotemporal sequence. and short-term spatiotemporal sequences The objective of this invention is to enhance STGNN using parameter representations from the pre-trained encoder stage. First, the training parameters obtained after the pre-training stage of the long-term spatiotemporal sequence are frozen. In the fine-tuning stage, only encoding operations are performed, resulting in the encoded long-term feature representation. .
[0088] In graph structure learning modules, many spatiotemporal graph neural networks rely on predefined graphs to represent the relationships between nodes. However, in many cases, predefined graphs cannot fully capture the true dependencies between nodes. Therefore, this invention will... Let be the feature set of the time series of node i, where Indicates a connection. for A portion of it. Then, the semantic relationship graph is calculated. It reflects the dependencies between nodes. The sparsity of the learning graph can be controlled by setting hyperparameters. The trained matrix ,in This represents the correlation between node i and node j.
[0089] The specific training steps are as follows:
[0090]
[0091]
[0092]
[0093] in, Let i be the original time series of node i. The sum of the global and local features of node i is represented by a convolutional network. The first dimension represents the positive probability, and the second dimension represents the negative probability. It is a random vector sampled from the Gumbel(0,1) distribution. This refers to the temperature parameter of the SoftMax function.
[0094] Step F: Represent the long-term features using a multilayer perceptron (MLP). and the short-term feature representation The fusion is performed, and the fusion result is passed through a linear layer to obtain the result at time t. Future traffic flow sequence at a time step ; Indicate the output dimension; assume the actual future traffic flow sequence is ;Calculate the prediction loss between two future sequences, as the training task for the fine-tuning phase. Among these, In this embodiment, .
[0095] Specifically, the modulated short-term features are connected to the long-term features through a regression layer, and then projected into a D-dimensional space through an additional MLP layer, thus representing the long-term features. Short-term feature representation Perform the fusion. Fusion result. Represented as:
[0096]
[0097] MLP stands for Multilayer Perceptron. This represents the prediction head; in this embodiment, a spatiotemporal graph neural network is used.
[0098] Finally, the fusion result is passed through a linear layer to obtain the prediction result, which is represented as:
[0099]
[0100] This invention aims to predict traffic in complex traffic networks, using massive historical traffic flow data as its research object. It employs a pre-trained spatiotemporal graph neural network model to extract long-term and short-term spatiotemporal features of traffic nodes. This significantly reduces training time while providing a framework compatible with most traffic prediction models, enhancing their prediction accuracy. Empirical studies on the PEMS03 and PEMS04 traffic datasets demonstrate that the proposed spatiotemporal graph network model PSTM for traffic flow prediction exhibits high accuracy, outperforming similar models in multiple metrics such as MAE, RMSE, and MAPE, achieving state-of-the-art (SOTA) results. Data descriptions for PEMS03 and PEMS04 are shown in Table 1, and detailed experimental results are shown in Table 2.
[0101] Table 1. Data Description for PEMS03 and PEMS04
[0102]
[0103] Table 2 Experimental Results
[0104]
[0105] Based on the same inventive concept, such as Figure 2 As shown, this embodiment of the invention provides a traffic network flow prediction system based on a pre-trained spatiotemporal graph neural network model, including: a data acquisition module, a pre-training module, and a fine-tuning module.
[0106] The data acquisition module is used to acquire historical traffic flow sequences with T time steps prior to time t, and to segment the historical traffic flow sequences into long-term spatiotemporal sequences. and short-term spatiotemporal sequences ;
[0107] The pre-training module is used to perform the pre-training phase, which includes first processing the original long-term spatiotemporal sequences. The input is fed to the encoder, and the encoder's output is then fed to the decoder to obtain the reconstructed long-term spatiotemporal sequence. The reconstruction loss is calculated based on a preset loss function, and the encoder and decoder are optimized based on the reconstruction loss.
[0108] In the encoder, a block embedding layer is first used to embed the sequence. Divided into A non-overlapping subsequence is used to obtain the block embedding. Then, a positional encoding layer is used to positionally encode all subsequences to obtain positional embedding features. Next, the location embedding features are... Perform random masking to obtain the masked fragment-level representation. and unmasked fragment-level representation Finally, the unmasked fragments are represented. The input is fed into the L-layer spatiotemporal transformation encoder to obtain the latent output representation. In the decoder, the Fast Fourier Transform is used to represent all potential outputs. The signal is converted to the frequency domain and reconstructed using linear interpolation in the frequency domain to obtain the reconstructed long-term spatiotemporal sequence. ;
[0109] The fine-tuning module is used to perform the fine-tuning phase, including freezing the encoder parameters obtained in the pre-training phase; and adjusting the long-term spatiotemporal sequence. The input is fed into the encoder to obtain long-term feature representations. Graph learning is performed based on the long-term feature representation to obtain a discrete sparse graph; the short-term spatiotemporal sequence is then processed. The input is fed into a spatiotemporal graph neural network to obtain short-term feature representations. The long-term features are represented using a multilayer perceptron. and the short-term feature representation The fusion is performed, and the fusion result is passed through a linear layer to obtain the result at time t. The system calculates the prediction loss between the predicted future traffic flow sequence and the actual future traffic flow sequence, and optimizes the spatiotemporal graph neural network.
[0110] It should be noted that the prediction system provided in this embodiment of the invention is for implementing the above method, and its specific functions can be referred to the above method embodiments, which will not be repeated here.
[0111] Figure 3 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 3As shown, the electronic device may include: a processor 301, a communication interface 302, a memory 303, and a communication bus 304. The processor 301, communication interface 302, and memory 303 communicate with each other via the communication bus 304. The processor 301 can call logical instructions in the memory 303 to execute an adaptive dynamic receptive field infrared target detection method for multi-view scenarios of unmanned aerial vehicles (UAVs). This method includes: constructing a detection network, including: acquiring historical traffic flow sequences with T time steps prior to time t, and segmenting the historical traffic flow sequences into long-term spatiotemporal sequences. and short-term spatiotemporal sequences The pre-training phase includes: first processing the original long-term spatiotemporal sequences... The input is fed to the encoder, and the encoder's output is then fed to the decoder to obtain the reconstructed long-term spatiotemporal sequence. The reconstruction loss is calculated based on a preset loss function, and the encoder and decoder are optimized based on the reconstruction loss; wherein, in the encoder, a block embedding layer is first used to reconstruct the sequence. Divided into A non-overlapping subsequence is used to obtain the block embedding. Then, a positional encoding layer is used to positionally encode all subsequences to obtain positional embedding features. Next, the location embedding features are... Perform random masking to obtain the masked fragment-level representation. and unmasked fragment-level representation Finally, the unmasked fragments are represented. The input is fed into the L-layer spatiotemporal transformation encoder to obtain the latent output representation. In the decoder, the Fast Fourier Transform is used to represent all potential outputs. The signal is converted to the frequency domain and reconstructed using linear interpolation in the frequency domain to obtain the reconstructed long-term spatiotemporal sequence. The fine-tuning stage includes: freezing the encoder parameters obtained in the pre-training stage; and adjusting the long-term spatiotemporal sequence. The input is fed into the encoder to obtain long-term feature representations. Graph learning is performed based on the long-term feature representation to obtain a discrete sparse graph; the short-term spatiotemporal sequence is then processed. The input is fed into a spatiotemporal graph neural network to obtain short-term feature representations. The long-term features are represented using a multilayer perceptron. and the short-term feature representation The fusion is performed, and the fusion result is passed through a linear layer to obtain the result at time t. The system calculates the prediction loss between the predicted future traffic flow sequence and the actual future traffic flow sequence, and optimizes the spatiotemporal graph neural network.
[0112] Furthermore, when the logical instructions in the aforementioned memory 303 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0113] This invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer can execute a traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model provided in the above-described method embodiments.
[0114] This invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements a traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model provided in the above-described method embodiments.
[0115] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0116] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model, characterized in that, include: Pre-training phase and fine-tuning phase; Obtain the historical traffic flow sequence for T time steps prior to time t. The historical traffic flow sequence Segmented into long-term spatiotemporal sequences and short-term spatiotemporal sequences ; The pre-training phase includes: first processing the original long-term spatiotemporal sequence... The input is fed to the encoder, and the encoder's output is then fed to the decoder to obtain the reconstructed sequence. The reconstruction loss is calculated based on a preset loss function, and the encoder and decoder are optimized based on the reconstruction loss. In the encoder, a block embedding layer is first used to embed the sequence. Divided into A non-overlapping subsequence is used to obtain the block embedding. Then, a positional encoding layer is used to positionally encode all subsequences to obtain positional embedding features. Next, the location embedding features are... Perform random masking to obtain the masked fragment-level representation. and unmasked fragment-level representation Finally, the unmasked fragments are represented. The input is fed into the L-layer spatiotemporal transformation encoder to obtain the latent output representation. In the decoder, the Fast Fourier Transform is used to represent all potential outputs. The signal is converted to the frequency domain and reconstructed using linear interpolation in the frequency domain to obtain the reconstructed sequence. ; The fine-tuning phase includes: freezing the encoder parameters obtained in the pre-training phase; and adjusting the long-term spatiotemporal sequence. The input is fed into the encoder to obtain long-term feature representations. The short-term spatiotemporal sequence The input is fed into a spatiotemporal graph neural network to obtain short-term feature representations. The long-term features are represented using a multilayer perceptron. and the short-term feature representation The fusion is performed, and the fusion result is passed through a linear layer to obtain the result at time t. The system calculates a future traffic flow sequence with a time step; it also calculates the prediction loss between the predicted future traffic flow sequence and the actual future traffic flow sequence, and optimizes the spatiotemporal graph neural network accordingly. .
2. The traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model according to claim 1, characterized in that, The position encoding layer uses learnable position embeddings for position encoding; wherein, the position encoding formula for the i-th node is: in, This represents the result of the i-th node after position encoding. Let represent the learnable parameters corresponding to the p-th time slice. This represents the time slice of the i-th node. , This represents the feature dimension after position encoding.
3. The traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model according to claim 1, characterized in that, For the location embedding features Random masking includes: Set the mask ratio Masked fragment-level representation ; Unmasked fragment-level representation ; .
4. The traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model according to claim 1, characterized in that, The aforementioned representation of unmasked fragments The input is fed into the L-layer spatiotemporal transformation encoder to obtain the latent output representation. ,include: set up and express The i-th node in the middle is at the 1st position Time step and the Given the representation at time step, the process of temporal attention encoding for the i-th node is as follows: in, Indicates the first The node of the first Time step for the first Temporal attention weights for time steps It is a bivariate function used to measure pairwise correlation. This indicates the performance of feature space transformation. Represents a non-linear activation function. This represents the natural exponential function. It is a bivariate function used to measure pairwise correlation; By integrating the temporal attention encoding results of all nodes, we obtain the temporal attention mechanism representation of all nodes. ;based on The latent output representation is obtained by following the learning process described below. : in, Represents the temporal attention mechanism for all nodes, with parameters For learnable weights, Let d be the d-th order neighborhood of graph G, where d is the expansion rate. Let m represent the m-th convolutional kernel, and M represent the number of convolutional kernels.
5. The traffic network flow prediction method based on a pre-trained spatiotemporal graph neural network model according to claim 1, characterized in that, Representing the long-term features using a multilayer perceptron and the short-term feature representation The integration process specifically includes: in, This represents a multilayer perceptron. The prediction head uses a spatiotemporal graph neural network. This indicates the fusion result.
6. A traffic network flow prediction system based on a pre-trained spatiotemporal graph neural network model, characterized in that, include: The data acquisition module is used to obtain historical traffic flow sequences for T time steps prior to time t. The historical traffic flow sequence Segmented into long-term spatiotemporal sequences and short-term spatiotemporal sequences ; The pre-training module is used to perform the pre-training phase, which includes first processing the original long-term spatiotemporal sequences. The input is fed to the encoder, and the encoder's output is then fed to the decoder to obtain the reconstructed sequence. The reconstruction loss is calculated based on a preset loss function, and the encoder and decoder are optimized based on the reconstruction loss. In the encoder, a block embedding layer is first used to embed the sequence. Divided into A non-overlapping subsequence is used to obtain the block embedding. Then, a positional encoding layer is used to positionally encode all subsequences to obtain positional embedding features. Next, the location embedding features are... Perform random masking to obtain the masked fragment-level representation. and unmasked fragment-level representation Finally, the unmasked fragments are represented. The input is fed into the L-layer spatiotemporal transformation encoder to obtain the latent output representation. In the decoder, the Fast Fourier Transform is used to represent all potential outputs. The signal is converted to the frequency domain and reconstructed using linear interpolation in the frequency domain to obtain the reconstructed sequence. ; The fine-tuning module is used to perform the fine-tuning phase, including freezing the encoder parameters obtained in the pre-training phase; and adjusting the long-term spatiotemporal sequence. The input is fed into the encoder to obtain long-term feature representations. The short-term spatiotemporal sequence The input is fed into a spatiotemporal graph neural network to obtain short-term feature representations. The long-term features are represented using a multilayer perceptron. and the short-term feature representation The fusion is performed, and the fusion result is passed through a linear layer to obtain the result at time t. The system calculates a future traffic flow sequence with a time step; it also calculates the prediction loss between the predicted future traffic flow sequence and the actual future traffic flow sequence, and optimizes the spatiotemporal graph neural network accordingly. .
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 5.