A traffic flow prediction method based on a graph neural network and related equipment
Patent Information
- Application Number
- CN202611354916.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-03
- Publication Date
- 2026-10-13
AI Technical Summary
[0003]本申请实施例提供了一种基于图神经网络的交通流量预测方法及相关设备,可以解决交通流量预测的准确性低的问题
在本申请的实施例中,通过获取目标区域中多个交通节点的交通流量数据,然后基于所有交通流量数据,生成交通流量嵌入向量,并向交通流量嵌入向量中添加位置编码和掩码,得到掩码向量,再根据所有交通节点构建交通邻接矩阵,并根据交通邻接矩阵,利用图神经网络对掩码向量进行空间增强,得到空间增强特征,然后对空间增强特征进行时间增强,得到时间增强特征,并对时间增强特征进行优化,得到最终增强特征,最后基于最终增强特征对目标区域进行交通流量预测,得到目标区域的交通流量预测结果。其中,通过构建交通节点的交通邻接矩阵,能够对交通节点的空间相关程度和依赖演化信息进行挖掘,基于交通邻接矩阵和掩码向量提取特征,实现在时间和空间两方面的信息捕捉,对经过空间和时间增强后的特征进行进一步的优化,能够进一步提高对交通流量演化的感知能力和演化规律学习,提升最终增强特征的信息精度,利用精度高的最终增强特征进行交通流量预测,能够有效提高交通流量预测的准确性。
Smart Images

Figure CN122906881A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of traffic flow prediction technology, and in particular to a traffic flow prediction method and related equipment based on graph neural networks. Background Technology
[0002] Spatiotemporal data refers to information that simultaneously contains spatial and temporal dimensions. It is used to characterize the evolution of various phenomena in different geographical locations over time and is widely applied in the field of intelligent transportation. However, due to the complex coupling relationship between spatial dependence and temporal evolution in spatiotemporal data, achieving high-precision spatiotemporal prediction (such as traffic flow prediction) remains a highly challenging task. On the one hand, spatiotemporal heterogeneity is difficult to model effectively. In spatiotemporal data, the correlation between different spatial locations is not fixed but evolves dynamically over time. However, most existing methods use predefined static graph structures (such as adjacency matrices constructed based on distance thresholds or Pearson correlation coefficients) to describe spatial relationships, which cannot capture the dynamic evolution characteristics of spatial dependence structures, resulting in a significant decrease in prediction accuracy when facing changes in spatiotemporal distribution. Furthermore, long-range temporal dependencies are not adequately captured. Spatiotemporal data simultaneously contains two multi-scale features: short-term local fluctuations and long-term global trends. Taking traffic flow as an example, there are both short-term fluctuations at morning and evening peak hours on an hourly basis and long-term periodic patterns on a daily or weekly basis. Current mainstream methods typically use short historical time windows as input for end-to-end training. This short-sighted input strategy limits the model's ability to perceive long-term dependencies, making it difficult for the model to learn periodic patterns spanning days or even weeks. The predictive performance of existing models is significantly limited, especially when the target of prediction is affected by long-term external factors. Using spatiotemporal data in these ways to predict traffic flow results in low accuracy. Summary of the Invention
[0003] This application provides a traffic flow prediction method and related equipment based on graph neural networks, which can solve the problem of low accuracy in traffic flow prediction.
[0004] In a first aspect, embodiments of this application provide a traffic flow prediction method based on graph neural networks, the traffic flow prediction method comprising: Acquire traffic flow data for multiple traffic nodes in the target area; the traffic flow data includes traffic flow values for each traffic node at multiple historical time points; Based on all traffic flow data, a traffic flow embedding vector is generated, and a location code and a mask are added to the traffic flow embedding vector to obtain a mask vector. All historical moments are divided into multiple historical time blocks. A traffic adjacency matrix is generated for each historical time block based on the traffic flow values of all traffic nodes in each historical time block. Based on all traffic adjacency matrices, a graph neural network is used to spatially augment the mask vector to obtain spatial augmentation features. The elements in the traffic adjacency matrix are used to describe the correlation between the corresponding two traffic nodes. The correlation is either a topological adjacency relationship or a state association relationship. The encoder is used to perform temporal augmentation on the spatial augmentation features to obtain temporal augmentation features, and the encoder is trained based on the temporal augmentation features; The long-term historical traffic flow data of the target area is encoded using the trained encoder to obtain a long-term contextual representation. Short-term dynamic features are extracted from the short-term historical traffic flow data of the target area. The long-term contextual representation and the short-term dynamic features are fused, and traffic flow is predicted based on the fusion result to obtain the traffic flow prediction result of the target area.
[0005] Optionally, based on all traffic flow data, a traffic flow embedding vector is generated, including: All traffic flow data are represented as a third-order tensor, and an initial embedding sequence is extracted from the third-order tensor using a sliding window of a preset size; The initial embedding sequence is convolved to obtain the traffic flow embedding vector.
[0006] Optionally, location encoding and a mask are added to the traffic flow embedding vector to obtain a mask vector, including: Add location encoding to the traffic flow embedding vector to obtain the location embedding vector; A time block mask and a node region mask are generated, and a mask vector is calculated based on the time block mask, the node region mask and the location embedding vector; the time block mask is used to mask continuous time blocks, and the node region mask is used to mask traffic nodes that meet the preset spatial correlation conditions.
[0007] Optionally, a traffic adjacency matrix for each historical time block is generated based on the traffic flow values of all traffic nodes in each historical time block, including: Through the formula: ; Constructing a traffic adjacency matrix ; in, Indicates the first Each historical time segment The total number of historical time blocks. and The first The first and second learnable embedding matrices of all traffic nodes generated based on traffic flow values for each historical time block. For the embedded dimension.
[0008] Optionally, based on all traffic adjacency matrices, a graph neural network is used to spatially augment the mask vector to obtain spatially augmented features, including: The node feature update formula for each layer in the graph neural network is constructed based on all traffic adjacency matrices. The mask vector is input into the graph neural network for processing to obtain spatially enhanced features.
[0009] Optionally, the spatial augmentation features are temporally augmented using an encoder to obtain temporally augmented features, including: Reshape the spatial augmentation features into reshaped features that conform to the encoder input format; The reshaped features are input into the encoder for processing to obtain temporally enhanced features.
[0010] Optionally, the encoder can be trained based on temporal augmentation features, including: The temporal enhancement features are reconstructed using a decoder to obtain a reconstructed vector; A reconstruction loss function is constructed based on the reconstructed vector, the traffic flow embedding vector, and the mask location index set; the reconstruction loss function is used to describe the difference between the reconstructed vector at the mask location and the corresponding traffic flow embedding vector; The traffic flow embedding vector is applied with a first composite mask and a second composite mask to obtain a first mask vector and a second mask vector; the first composite mask and the second composite mask have the same mask ratio but different mask positions; The first mask vector and the second mask vector are respectively input into the graph neural network and the encoder to obtain the first time-enhanced feature and the second time-enhanced feature, and a consistency loss function is constructed based on the first time-enhanced feature and the second time-enhanced feature; The graph neural network and the encoder are jointly trained based on the reconstruction loss function and the consistency loss function.
[0011] Optionally, the loss function is: ; in, This represents the reconstruction loss function value. Represents the set of mask position indices. This indicates the total number of elements in the position index set. Represents the position in the traffic flow embedding vector The element at that location, Represents the position in the reconstructed vector The element at that location.
[0012] The reconstruction loss function is: ; in, This represents the reconstruction loss function value. Represents the set of mask position indices. This indicates the total number of elements in the position index set. Represents the position in the traffic flow embedding vector The element at that location, Represents the position in the reconstructed vector Elements at the location; The consistency loss function is: ; in, This represents the value of the consistency loss function. This represents the set of indexes of positions in both the first and second composite masks that are not masked. The total number of elements in the set. and These represent the first and second time-enhanced features at different locations. The representation vector at that location, express The square of the distance.
[0013] Secondly, embodiments of this application provide a traffic flow prediction device based on a graph neural network, comprising: The acquisition module is used to acquire traffic flow data from multiple traffic nodes in the target area; the traffic flow data includes the traffic flow values of the traffic nodes at multiple historical times. The masking module is used to generate a traffic flow embedding vector based on all traffic flow data, and add location encoding and mask to the traffic flow embedding vector to obtain a mask vector; The spatial augmentation module is used to divide all historical moments into multiple historical time blocks. Based on the traffic flow values of all traffic nodes in each historical time block, it generates a traffic adjacency matrix for each historical time block. Based on all traffic adjacency matrices, it uses a graph neural network to perform spatial augmentation on the mask vector to obtain spatial augmentation features. The elements in the traffic adjacency matrix are used to describe the correlation between the corresponding two traffic nodes. The correlation is either a topological adjacency relationship or a state association relationship. The temporal augmentation module is used to perform temporal augmentation on the spatial augmentation features using the encoder, to obtain temporally augmented features, and to train the encoder based on the temporally augmented features; The prediction module is used to encode the long-term historical traffic flow data of the target area using the trained encoder to obtain a long-term contextual representation, and to extract features from the short-term historical traffic flow data of the target area to obtain short-term dynamic features. The long-term contextual representation and the short-term dynamic features are fused, and traffic flow is predicted based on the fusion result to obtain the traffic flow prediction result of the target area.
[0014] Thirdly, embodiments of this application provide a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described traffic flow prediction method based on a graph neural network.
[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described traffic flow prediction method based on a graph neural network.
[0016] The above-mentioned solution in this application has the following beneficial effects: In the embodiments of this application, traffic flow data of multiple traffic nodes in the target area is acquired. Then, based on all traffic flow data, a traffic flow embedding vector is generated, and a location code and mask are added to the traffic flow embedding vector to obtain a mask vector. A traffic adjacency matrix is then constructed based on all traffic nodes. Based on the traffic adjacency matrix, a graph neural network is used to spatially augment the mask vector to obtain spatially augmented features. Then, temporal augmentation is performed on the spatially augmented features to obtain temporally augmented features. The temporally augmented features are then optimized to obtain the final augmented features. Finally, traffic flow prediction for the target area is performed based on the final augmented features to obtain the traffic flow prediction result for the target area. Specifically, by constructing a traffic adjacency matrix of traffic nodes, the spatial correlation and dependency evolution information of traffic nodes can be mined. Features are extracted based on the traffic adjacency matrix and mask vector, achieving information capture in both time and space. Further optimization of the features after spatial and temporal augmentation can further improve the perception ability and learning of traffic flow evolution patterns, improving the information accuracy of the final augmented features. Using the high-accuracy final augmented features for traffic flow prediction can effectively improve the accuracy of traffic flow prediction.
[0017] Furthermore, traffic flow data from multiple historical moments is used to train features and predict traffic flow in the target area, avoiding insufficient evolutionary perception caused by using short-term data, effectively learning long-term evolution, and ensuring the reliability and accuracy of traffic flow prediction.
[0018] Other beneficial effects of this application will be described in detail in the following detailed description section. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A flowchart illustrating a traffic flow prediction method based on a graph neural network, provided in an embodiment of this application; Figure 2 A schematic diagram of the structure of a traffic flow prediction device based on a graph neural network provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. Detailed Implementation
[0021] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0022] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0023] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0024] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0025] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0026] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0027] To address the issue of low accuracy in existing traffic flow prediction methods, this application provides a traffic flow prediction method based on graph neural networks. This method acquires traffic flow data from multiple traffic nodes in a target area, generates a traffic flow embedding vector based on all traffic flow data, adds location encoding and a mask to the embedding vector to obtain a mask vector, constructs a traffic adjacency matrix based on all traffic nodes, and uses a graph neural network to spatially augment the mask vector based on the adjacency matrix to obtain spatial augmented features. Then, temporal augmentation is applied to the spatial augmented features to obtain temporal augmented features, which are then optimized to obtain the final augmented features. Finally, traffic flow prediction for the target area is performed based on the final augmented features to obtain the traffic flow prediction result for the target area. By constructing a traffic adjacency matrix for traffic nodes, the spatial correlation and dependency evolution information of traffic nodes can be mined. Based on the traffic adjacency matrix and mask vector, features are extracted to achieve information capture in both time and space. Further optimization of the features after spatial and temporal enhancement can further improve the perception of traffic flow evolution and the learning of evolutionary patterns, thereby improving the information accuracy of the final enhanced features. Using the high-accuracy final enhanced features for traffic flow prediction can effectively improve the accuracy of traffic flow prediction.
[0028] Furthermore, traffic flow data from multiple historical moments is used to train features and predict traffic flow in the target area, avoiding insufficient evolutionary perception caused by using short-term data, effectively learning long-term evolution, and ensuring the reliability and accuracy of traffic flow prediction.
[0029] The following is an exemplary description of the traffic flow prediction method based on graph neural networks provided in this application.
[0030] like Figure 1 As shown, the traffic flow prediction method based on graph neural networks provided in this application includes the following steps: Step 11: Obtain traffic flow data for multiple traffic nodes in the target area.
[0031] The target area mentioned above is the area where traffic flow prediction is required, such as a certain urban area. The traffic flow data mentioned above includes traffic flow values (such as vehicle flow values) of traffic nodes at multiple historical times. Traffic nodes are traffic points such as intersections and road junctions, and historical times are times before the current time.
[0032] In some embodiments of this application, traffic flow data of traffic nodes can be acquired through devices such as sensors.
[0033] Step 12: Based on all traffic flow data, generate a traffic flow embedding vector, and add location encoding and mask to the traffic flow embedding vector to obtain a mask vector.
[0034] In some embodiments of this application, the steps of generating a traffic flow embedding vector based on all traffic flow data and adding location encoding and a mask to the traffic flow embedding vector to obtain a mask vector include: The first step is to represent all traffic flow data as a third-order tensor and extract the initial embedding sequence from the third-order tensor using a sliding window of a preset size.
[0035] For example, the traffic flow values from all traffic flow data are arranged into a third-order tensor. ,in Represents the total number of traffic nodes. The length of a time sequence representing the entire historical moment. This represents the feature dimension (i.e., the traffic flow value dimension) recorded by each node at each time step, using a length of [missing information]. The sliding window from the original tensor Extracting the initial embedding sequence ,in It is the number of channels after embedding. It is the number of blocks. It is the standard input length of the model used in downstream tasks to predict traffic flow (such as a fully connected layer). It is usually set to 72. The value is typically set to 12. For example, the N, T, and F of the original tensor X are 358, 26208, and 1, respectively. Starting from the first time step of T, the window size is 72*12. The window slides from front to back, and continuous segments of time of 72*12 steps are extracted in the time dimension T to obtain the initial embedding sequence X'. Each X' is N, K, and C, which is 358 and 864, respectively.
[0036] The second step is to perform a convolution operation on the initial embedding sequence to obtain the traffic flow embedding vector.
[0037] For example, this can be achieved using a convolution kernel with a size of Step size is The two-dimensional convolution operation divides the initial embedding sequence into blocks along the time dimension to obtain the traffic flow embedding vector. This convolution operation will be continuous Each time step is mapped to an embedding vector, thus making the length of the vector equal to the number of embedding vectors. The sequence is compressed into Each block.
[0038] The third step is to add location encoding to the traffic flow embedding vector to obtain the location embedding vector.
[0039] For example, the expression is: ,in For position embedding vectors, For position encoding, The multiple elements within it correspond one-to-one with multiple traffic nodes, used to describe the absolute location of the traffic nodes in the target area, and are obtained through presets.
[0040] The fourth step is to generate a time block mask and a node region mask, and then calculate the mask vector based on the time block mask, the node region mask, and the position embedding vector.
[0041] The time block mask is used to mask continuous time blocks, and the node region mask is used to mask traffic nodes that meet the preset spatial correlation conditions.
[0042] The specific process of generating the temporal block mask is as follows: First, in the temporal block dimension... Random selection starting position ,in , To preset the mask ratio, The number of time blocks for continuous occlusion. For each starting position. index range All time blocks within the specified time are marked as to be occluded. To avoid overlapping occlusion intervals, there should be at least a certain interval between each starting position. Each block. Therefore, the temporal block mask tensor. Defined as: when The time block index where it is located When it belongs to any of the shielding regions, ,otherwise This mask applies to all nodes. and channels They share the same occlusion mode.
[0043] The specific process for generating the node region mask is as follows: First, based on the traffic adjacency matrix... Calculate the spatial correlation degree of each node. For each node... Its spatial correlation degree is defined as This is the sum of the spatial association strengths between the node and all other nodes. Then, all nodes are sorted from highest to lowest spatial association strength, and the top nodes are selected. Each node is considered a "set of highly correlated nodes". ,in Preset mask ratio. Node region mask tensor. Defined as: when node hour, (That is, the node is occluded in all time blocks and channels), otherwise .
[0044] The temporal block mask and the node region mask are combined to obtain the final composite mask tensor. The masking process can be represented as the Hadamard product: .in For the mask vector, For position embedding vectors, This represents the element-wise Hadamard product. At that time, for... The element at the correct position is preserved; when When this happens, the element at the corresponding position is masked.
[0045] Step 13: Divide all historical moments into multiple historical time blocks, generate a traffic adjacency matrix for each historical time block based on the traffic flow values of all traffic nodes in each historical time block, and use a graph neural network to spatially augment the mask vector based on all traffic adjacency matrices to obtain spatially augmented features.
[0046] The elements in the traffic adjacency matrix described above describe the relationships between two corresponding traffic nodes. These relationships can be either topological adjacency or state association. Multiple elements in the traffic adjacency matrix correspond one-to-one with multiple pairs of traffic nodes.
[0047] In some embodiments of this application, the steps of dividing all historical moments into multiple historical time blocks, generating a traffic adjacency matrix for each historical time block based on the traffic flow values of all traffic nodes in each historical time block, and using a graph neural network to spatially augment the mask vector based on all traffic adjacency matrices to obtain spatially augmented features include: The first step is to divide all historical moments into multiple historical time blocks.
[0048] For example, all historical moments are divided according to a preset time length, and each historical time block includes multiple historical moments.
[0049] The second step is to generate a traffic adjacency matrix for each historical time block based on the traffic flow values of all traffic nodes in each historical time block.
[0050] Specifically, through the formula: ; Constructing a traffic adjacency matrix .
[0051] in, Indicates the first Each historical time segment The total number of historical time blocks. and The first The first and second learnable embedding matrices of all traffic nodes generated based on traffic flow values for each historical time block. For the embedded dimension.
[0052] For example, the elements in the first and second adjacency matrices correspond to the representation vectors of nodes in the two sets of potential spaces, respectively, and are multiplied by matrix multiplication. The potential association strength between any two nodes can be calculated, thus obtaining the correlation matrix between nodes. Negative correlations are then filtered out using the ReLU activation function. Finally, an adaptive adjacency matrix is obtained through SoftMax normalization.
[0053] Because the spatial dependency structure of the traffic network has temporal continuity, the traffic state between adjacent historical time blocks will not change abruptly. Therefore, the dynamic traffic adjacency matrix under adjacent time blocks should also maintain a certain smoothness and continuity, rather than changing completely independently. To this end, a temporal smoothing constraint is introduced to impose a limit on the magnitude of change of the dynamic traffic adjacency matrix between adjacent historical time blocks. For the ... The first historical time block and the first Each historical time block has a dynamic traffic adjacency matrix as follows: and Calculate the difference between the two as a measure of smoothing loss for that adjacent time block pair: ; in, Denotes the square of the Frobenius norm. This represents the total number of historical time blocks.
[0054] The third step is to construct the node feature update formula for each layer in the graph neural network based on all traffic adjacency matrices.
[0055] For example, the node feature update formula is: ,in, This is the input node feature matrix. In the first layer of the graph neural network, this input is the adjacency matrix of all traffic nodes. It is an identity matrix, used to preserve the characteristics of the nodes themselves. , It is a learnable scalar parameter used to adjust the strength of self-connections. It is a multilayer perceptron responsible for performing nonlinear transformations on the aggregated features. It is its output dimension. Each layer can have independent learnable parameters. .
[0056] The fourth step is to input the mask vector into the graph neural network for computation to obtain spatial augmentation features.
[0057] For example, the mask vector is input into a graph neural network. Each layer in the graph neural network updates the input features according to the node feature update formula. The input features of the first layer are the mask vectors, and the output features of the last layer are the spatial augmentation features. .
[0058] Step 14: Use the encoder to perform temporal augmentation on the spatial augmentation features to obtain temporal augmentation features, and train the graph neural network and encoder based on the temporal augmentation features.
[0059] In some embodiments of this application, the steps of using an encoder to perform temporal augmentation on spatial augmentation features to obtain temporally augmented features, and then training the graph neural network and the encoder based on the temporally augmented features include: The first step is to reshape the spatial augmentation features into reshaped features that conform to the encoder input format.
[0060] For example, at each time step The features of each node are concatenated to form a sequence input. At this point, the length of the sequence equals the number of blocks. The vector dimension at each position is .
[0061] The second step is to input the reshaped features into the encoder for processing to obtain the temporally enhanced features.
[0062] For example, the encoder described above can be a Transformer encoder, which inputs the reshaped features into the encoder for computation and outputs temporally enhanced features.
[0063] The core of the Transformer encoder is multi-head self-attention. For the input sequence The The first layer calculates the query, key, and value matrix: .in, It is a learnable projection matrix. This is the dimension of each attention head. The attention score is calculated as follows: Multi-head attention executes the above computational process in parallel. Then, the results are stitched together and projected back to the original dimensions. .in .
[0064] Each Transformer layer contains a multi-head attention sublayer and a feedforward network (FFN) sublayer, followed by residual connections and layer normalization: ; The FFN consists of two linear transformations and a GELU activation function. .go through After the Transformer encoder layer, the final temporal augmentation features are obtained. This feature implies long-term temporal dependencies.
[0065] The third step is to use the decoder to reconstruct the temporal enhancement features and obtain the reconstructed vector.
[0066] For example, the decoder can be a Transformer decoder, which takes the temporal augmentation features as input and processes them to obtain the reconstructed vector. The expression is: ,in, To reconstruct the vector, This indicates the decoder.
[0067] The fourth step is to construct a reconstruction loss function based on the reconstruction vector, the traffic flow embedding vector, and the mask location index set.
[0068] The reconstruction loss function is used to describe the difference between the reconstructed vector at the mask location and the corresponding traffic flow embedding vector.
[0069] The reconstruction loss function is: ; in, This represents the reconstruction loss function value. Represents the set of mask position indices. This indicates the total number of elements in the position index set. Represents the position in the traffic flow embedding vector The element at that location, Represents the position in the reconstructed vector The element at that location.
[0070] Fifth step: Apply the first composite mask and the second composite mask to the traffic flow embedding vector to obtain the first mask vector and the second mask vector.
[0071] The first composite mask and the second composite mask mentioned above have the same mask ratio but different mask positions.
[0072] Specifically, embedding vectors at the same position Apply the first composite mask respectively Second composite mask The first mask vector is obtained. Second mask vector The first composite mask and the second composite mask have the same mask ratio (both are r), but the mask positions are different.
[0073] The sixth step involves inputting the first mask vector and the second mask vector into the graph neural network and the encoder, respectively, to obtain the first time-enhanced features and the second time-enhanced features, and then constructing a consistency loss function based on the first time-enhanced features and the second time-enhanced features.
[0074] The first mask vector and the second mask vector are input into the graph neural network and the encoder, respectively, to obtain the first-time enhanced features. Second time enhancement features .
[0075] For the first time enhancement feature Extract the representation vector corresponding to the unmasked position. For the second time-enhanced features Extract the representation vector corresponding to the same unmasked position. It should be noted that "the same unmasked position" here refers to a position that is not masked in either the first composite mask or the second composite mask.
[0076] Specifically, the consistency loss function is: ; in, This represents the value of the consistency loss function. This represents the set of indexes of positions in both the first and second composite masks that are not masked. The total number of elements in the set. and These represent the first and second time-enhanced features at different locations. The representation vector at that location, express The square of the distance.
[0077] This consistency loss function constrains the representation of different masked views of the same data to remain consistent at the unmasked locations, forcing the encoder to learn a robust spatiotemporal representation that is invariant to the masking pattern, thereby enhancing the model's generalization ability and pre-training performance.
[0078] Step 7: Jointly train the graph neural network and the encoder according to the reconstruction loss function and the consistency loss function.
[0079] For example, the backpropagation algorithm and Adam optimizer can be used to iteratively optimize the learnable parameters in the graph neural network, encoder, and decoder with the goal of minimizing the reconstruction loss function, until the loss function value reaches the minimum or is less than a preset threshold, thus obtaining the trained graph neural network, trained encoder, and trained decoder.
[0080] Step 15: Encode the long-term historical traffic flow data of the target area using the trained encoder to obtain a long-term contextual representation, and extract features from the short-term historical traffic flow data of the target area to obtain short-term dynamic features. Then, fuse the long-term contextual representation and the short-term dynamic features, and predict the traffic flow based on the fusion result to obtain the traffic flow prediction result of the target area.
[0081] The traffic flow prediction results described above are used to describe the traffic flow value of each traffic node in the target area at future times.
[0082] Specifically, traffic flow data for the target area at multiple times (all of which are historical times, with the last time being the current time, and the number of times is greater than the number of historical times in step 11) is acquired using sensors and other devices. Based on the long-term historical traffic flow data acquired in this step, a traffic flow embedding vector is generated. Then, it is processed into a format suitable for graph neural networks and encoders, and then sequentially input into the trained graph neural network for spatial augmentation and into the trained encoder for temporal augmentation to obtain long-term contextual representations, while short-term historical data is used. The input is fed into a downstream prediction model (such as the Graph WaveNet (GWN) model), which outputs short-time dynamic features. For each time step to be predicted, a fusion weight is calculated based on the reconstruction error of the long-term context representation, short-term dynamic features, and the step size of the time step to be predicted. The long-term context representation and short-term dynamic features are then weighted and fused based on the fusion weight to obtain the fused representation for the corresponding time step to be predicted. The fusion result is then input into a model used for traffic flow prediction (such as a fully connected layer or a multilayer perceptron) to calculate the traffic flow prediction result for the target area.
[0083] For example, for a downstream prediction task, given a historical data set that is longer than the usual input... First, it is processed into a format suitable for the encoder, and then the encoder trained using the steps described above is used. Extracting its deep spatiotemporal representation .
[0084] To fuse this representation with the hidden states of the downstream prediction model, its shape needs to be adjusted. (Truncation) The end Each block is then reshaped back into its original node-feature space. .
[0085] At the same time, short-term historical data of standard length will be included. Input to downstream prediction model In this context, its output is an intermediate hidden representation. This representation has encoded the spatiotemporal dynamics in the short term.
[0086] Two flexible feature fusion methods are proposed to integrate long-term context. With short-term dynamics Combined .in It is a shallow multilayer perceptron used for feature alignment. Finally, the fused features are... Input to a linear layer to generate the final prediction result. .
[0087] In some embodiments of this application, before performing this step, the model used for traffic flow prediction can be pre-trained. For example, sample data can be input into the model to calculate the predicted value of traffic flow, and then the loss value can be calculated based on the predicted value and the actual value. Using an Adam optimizer, the parameters in the model are trained with the goal of minimizing the loss value. The expression for the loss value is: ; in, Indicates the loss value. Indicates the model's prediction of the th The time step The state value of each traffic node , The real one is in the first place. The time step The state value of each traffic node .
[0088] It is worth mentioning that by constructing a traffic adjacency matrix of traffic nodes, it is possible to mine the spatial correlation and dependency evolution information of traffic nodes. Based on the traffic adjacency matrix and mask vector, features are extracted to achieve information capture in both time and space. Further optimization of the features after spatial and temporal enhancement can further improve the perception of traffic flow evolution and the learning of evolutionary patterns, thereby improving the information accuracy of the final enhanced features. Using the high-precision final enhanced features for traffic flow prediction can effectively improve the accuracy of traffic flow prediction.
[0089] Furthermore, traffic flow data from multiple historical moments is used to train features and predict traffic flow in the target area, avoiding insufficient evolutionary perception caused by using short-term data, effectively learning long-term evolution, and ensuring the reliability and accuracy of traffic flow prediction.
[0090] Furthermore, this application has the following advantages: 1. Innovative Dynamic Graph Structure Learning: The adaptive graph neural network proposed in this application utilizes learnable node embeddings. Generate a data-driven dynamic adjacency matrix By combining road topology priors with traffic state association correction, this method characterizes the time-varying changes in node associations while preserving the physical connectivity of roads, thereby reducing spatial dependency mismatch caused by fixed graph structures. This dynamic adjacency matrix can adaptively adjust the connection weights between nodes according to different input data, thus accurately modeling the complex dynamic characteristics of spatial dependencies evolving over time. In scenarios with abrupt changes in traffic states, missing local data, or changes in associations, it helps improve the stability and predictive reliability of spatial dependency modeling.
[0091] 2. Highly efficient long-range time series modeling capability: This application employs a masked autoencoder pre-training framework, using long-range time series data, far exceeding that of conventional end-to-end models, as input for reconstruction training. This design enables the model to fully learn the long-range periodic patterns and global trends hidden in the data during the pre-training phase.
[0092] 3. Spatiotemporal decoupling pre-training strategy: Node region masked samples are input into the spatial encoding branch, and temporal block masked samples are input into the temporal encoding branch, respectively, to obtain spatial and temporal representations. Based on the prediction results of both for the same unmasked traffic segment, an unmasked block consistency constraint is constructed, and the spatial and temporal encoding branches are jointly updated according to the unmasked block consistency constraint. The masking strategy operates simultaneously on both spatial and temporal dimensions, forcing the model to utilize both spatial and temporal contexts during reconstruction, thereby learning a truly "spatiotemporally coupled" deep representation.
[0093] 4. Plug-and-play general augmentation framework: This application designs a model-independent pre-trained augmentation paradigm. Pre-trained encoder The output representation has a fixed geometric structure, which will be the final output of the pre-trained encoder. q Each time-block representation is reshaped into the same node and time dimensions as the hidden layer of the downstream prediction model; after being mapped to the preset hidden dimensions through a feature alignment network, it is fused with the hidden representation of the downstream prediction model without modifying the original architecture of the downstream model.
[0094] 5. Significant computational efficiency advantages: This application employs an asymmetric encoder-decoder design, where the encoder is responsible for representation learning, and the decoder is only used for pre-training reconstruction tasks. After pre-training is complete, the decoder can be completely discarded. In actual downstream prediction tasks, only the efficient encoder needs to be run for forward propagation. This invention significantly improves prediction accuracy while offering faster inference speed, making it more suitable for latency-sensitive large-scale real-time prediction scenarios.
[0095] The method of this application will be illustrated below with a specific example.
[0096] This embodiment is validated on the publicly available traffic spatiotemporal dataset PEMS03. PEMS03 has 358 sensors and 26208 time steps. The experimental environment configuration is as follows: Intel(R) Xeon(R) Silver 4210 CPU @2.20GHz, NVIDIA RTX 4090 GPU (24GB VRAM), and 128GB of system memory. The software environment is based on PyTorch 1.9.0 and Python 3.9.
[0097] First, obtain the original spatiotemporal data tensor. , The time series data for each sensor were standardized using the Z-Score normalization method, so that the data followed a distribution with a mean of 0 and a standard deviation of 1, in order to eliminate the influence of dimensions and accelerate model convergence.
[0098] The sequence length during the pre-training phase is set to At each time step, a sliding window with a step size of 1 is used to extract the pre-training input sequence from the normalized data. The number of channels Set to 32. Block embedding uses a 2D convolution operation, with the kernel size set to... ,in Step length Therefore, the number of blocks After convolution, the embedded sequence is obtained. .
[0099] Add learnable absolute positional encoding to each block. To obtain an embedded sequence with location information The mask ratio is set to... Generate a binary mask tensor. 25% of the elements are randomly set to 0, while the remaining 75% are kept as 1.
[0100] In this embodiment, the node embedding dimension of the adaptive graph neural network is set to Construct two sets of learnable dynamic node embedding matrices. and The calculation process of the dynamic adjacency matrix is as follows: First, calculate the similarity matrix of node embeddings. .
[0101] Then, sparsity is introduced by applying the ReLU activation function. .
[0102] Finally, SoftMax normalization is performed along each row to obtain the dynamic adjacency matrix. Among them, for the first row and number Column elements .
[0103] The adaptive graph neural network module employs an aggregation strategy of graph isomorphic networks, stacking them. Layer. The node feature update formula for each layer is: .in, It is a time-step input, that is, for each time step Input features ; It is the identity matrix; For the first The learnable scalar parameters of the layer are initialized to 0. For the first A multilayer perceptron with two linear layers and a hidden layer dimension set to 1. The activation function used is ReLU.
[0104] After passing through a two-layer adaptive graphical neural network, the output spatial enhancement features are applied. .
[0105] spatial enhancement features Remodeling into the input format of a Transformer encoder Transformer encoder stack Each layer contains one multi-head self-attention sublayer and one feedforward sublayer. The number of heads in the multi-head attention is set to... Dimensions of each attention head For the first Layer, query, key, and value matrix calculation are as follows .in .
[0106] Attention score is calculated as follows: The output of multi-head attention is obtained through concatenation and linear transformation. .in .
[0107] Each sublayer is followed by residual connections and layer normalization: ; The structure of the feedforward network FFN is as follows .in , .
[0108] Transformer decoder stack The layer has a structure similar to the encoder but shallower. The decoder's input is the temporal augmentation feature output by the encoder. Output reconstructed sequence .
[0109] The reconstruction loss function in the pre-training phase uses mean squared error, calculating only the reconstruction error at the masked position. .in In this embodiment, the set of position indices of the masked elements is used. =206,208.
[0110] The training process uses the Adam optimizer, with an initial learning rate set to... The weight decay is set to The batch size is set to 16. The number of training epochs is set to 100, and an early stopping strategy is adopted: training stops when the validation set loss does not decrease for 10 consecutive epochs.
[0111] For downstream forecasting tasks, given long-term historical data In this embodiment, After undergoing the same block embedding and positional encoding processing as in the pre-training stage, the long-term data is input into the pre-trained encoder. Extract The end Because the input length of the downstream prediction model is Each time step corresponds to and reshape it into .
[0112] short-term historical data Input Graph WaveNet model In this embodiment, The Graph WaveNet model contains multiple spatiotemporal convolutional layers, each consisting of alternating stacks of graph convolutional layers and temporal convolutional layers. After multi-layer extraction, the outputs of each layer are aggregated through skip connections to obtain the intermediate hidden representations. .in .
[0113] This embodiment employs a splicing and fusion method to integrate long-term contextual representations with short-term dynamic features. The Concat operation concatenates along the feature dimensions, resulting in a sequence with dimensions [missing information]. . It is a two-layer multilayer perceptron with a hidden layer dimension of 256 and an output dimension of [missing information]. .
[0114] The fused features Input a linear layer of Graph WaveNet to generate the future Prediction results .
[0115] The regression loss function for downstream tasks uses the mean absolute error: ; During training, the pre-trained encoder The parameters can be frozen or fine-tuned. This embodiment uses a fine-tuning strategy, that is, using the pre-trained parameters as initial values and adjusting them with the downstream model parameters. The parameters of the fusion layer are jointly optimized. The optimizer uses Adam, and the initial learning rate is set to... The batch size is set to 32, and the number of training rounds is set to 50.
[0116] The method in this application introduces an adaptive graph neural network-enhanced pre-training mechanism in traffic flow prediction. By learning the long-term spatiotemporal characteristics of the traffic network before prediction and dynamically adjusting the spatial relationships between road segments according to changes in traffic conditions during the prediction stage, it achieves stable and accurate prediction of complex traffic flow evolution patterns.
[0117] The following is an exemplary description of the traffic flow prediction device based on graph neural networks provided in this application.
[0118] like Figure 2 As shown, this application provides a traffic flow prediction device based on a graph neural network. The traffic flow prediction device 200 includes: The acquisition module 201 is used to acquire traffic flow data of multiple traffic nodes in the target area; the traffic flow data includes the traffic flow values of the traffic nodes at multiple historical times; The mask module 202 is used to generate a traffic flow embedding vector based on all traffic flow data, and add location encoding and mask to the traffic flow embedding vector to obtain a mask vector; The spatial enhancement module 203 is used to divide all historical moments into multiple historical time blocks, generate a traffic adjacency matrix under each historical time block based on the traffic flow values of all traffic nodes in each historical time block, and use a graph neural network to perform spatial enhancement on the mask vector based on all traffic adjacency matrices to obtain spatial enhancement features; the elements in the traffic adjacency matrix are used to describe the correlation between the corresponding two traffic nodes, and the correlation is either a topological adjacency relationship or a state association relationship. The temporal augmentation module 204 is used to perform temporal augmentation on the spatial augmentation features using the encoder to obtain temporal augmentation features, and to train the encoder based on the temporal augmentation features; The prediction module 205 is used to encode the long-term historical traffic flow data of the target area using the trained encoder to obtain a long-term context representation, and to extract features from the short-term historical traffic flow data of the target area to obtain short-term dynamic features. The long-term context representation and the short-term dynamic features are fused, and traffic flow is predicted based on the fusion result to obtain the traffic flow prediction result of the target area.
[0119] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0120] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0121] like Figure 3 As shown, an embodiment of this application provides a terminal device, wherein the terminal device D10 of this embodiment includes: at least one processor D100 ( Figure 3 The diagram shows only one processor, a memory D101, and a computer program D102 stored in the memory D101 and executable on the at least one processor D100, wherein the processor D100 executes the computer program D102 to implement the steps in any of the above method embodiments.
[0122] Specifically, when the processor D100 executes the computer program D102, it acquires traffic flow data of multiple traffic nodes in the target area, then generates a traffic flow embedding vector based on all traffic flow data, adds position encoding and mask to the traffic flow embedding vector to obtain a mask vector, constructs a traffic adjacency matrix based on all traffic nodes, and uses a graph neural network to spatially augment the mask vector based on the traffic adjacency matrix to obtain spatial augmented features, then performs temporal augmentation on the spatial augmented features to obtain temporal augmented features, optimizes the temporal augmented features to obtain the final augmented features, and finally predicts the traffic flow in the target area based on the final augmented features to obtain the traffic flow prediction result for the target area. By constructing a traffic adjacency matrix for traffic nodes, the spatial correlation and dependency evolution information of traffic nodes can be mined. Based on the traffic adjacency matrix and mask vector, features are extracted to achieve information capture in both time and space. Further optimization of the features after spatial and temporal enhancement can further improve the perception of traffic flow evolution and the learning of evolutionary patterns, thereby improving the information accuracy of the final enhanced features. Using the high-accuracy final enhanced features for traffic flow prediction can effectively improve the accuracy of traffic flow prediction.
[0123] Furthermore, traffic flow data from multiple historical moments is used to train features and predict traffic flow in the target area, avoiding insufficient evolutionary perception caused by using short-term data, effectively learning long-term evolution, and ensuring the reliability and accuracy of traffic flow prediction.
[0124] The processor D100 can be a central processing unit (CPU), or it can be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0125] In some embodiments, the memory D101 may be an internal storage unit of the terminal device D10, such as a hard disk or memory of the terminal device D10. In other embodiments, the memory D101 may be an external storage device of the terminal device D10, such as a plug-in hard disk, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on the terminal device D10. Furthermore, the memory D101 may include both internal and external storage units of the terminal device D10. The memory D101 is used to store the operating system, applications, bootloader, data, and other programs, such as the program code of the computer program. The memory D101 can also be used to temporarily store data that has been output or will be output.
[0126] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the various method embodiments above.
[0127] This application provides a computer program product that, when run on a terminal device, enables the terminal device to implement the steps described in the various method embodiments above.
[0128] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying the computer program code to a graph neural network-based traffic flow prediction method device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0129] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0130] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0131] The above description is the preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this invention, and these improvements and modifications should also be considered within the scope of protection of this invention.
Claims
1. A traffic flow prediction method based on graph neural networks, characterized in that, include: Obtain traffic flow data from multiple traffic nodes in the target area; The traffic flow data includes traffic flow values of traffic nodes at multiple historical moments; Based on all traffic flow data, a traffic flow embedding vector is generated, and a location code and a mask are added to the traffic flow embedding vector to obtain a mask vector. All historical moments are divided into multiple historical time blocks. A traffic adjacency matrix is generated for each historical time block based on the traffic flow values of all traffic nodes in each historical time block. Based on all traffic adjacency matrices, a graph neural network is used to spatially augment the mask vector to obtain spatial augmentation features. The elements in the traffic adjacency matrix are used to describe the correlation between corresponding two traffic nodes. The correlation is either a topological adjacency relationship or a state association relationship. The spatial augmentation features are temporally augmented using an encoder to obtain temporally augmented features, and the encoder is trained based on the temporally augmented features. The long-term historical traffic flow data of the target area is encoded using a trained encoder to obtain a long-term contextual representation. Short-term dynamic features are extracted from the short-term historical traffic flow data of the target area. The long-term contextual representation and the short-term dynamic features are fused, and traffic flow is predicted based on the fusion result to obtain the traffic flow prediction result of the target area.
2. The traffic flow prediction method according to claim 1, characterized in that, The process of generating a traffic flow embedding vector based on all traffic flow data includes: All traffic flow data are represented as a third-order tensor, and an initial embedding sequence is extracted from the third-order tensor using a sliding window of a preset size; The initial embedding sequence is convolved to obtain the traffic flow embedding vector.
3. The traffic flow prediction method according to claim 1, characterized in that, The step of adding location encoding and mask to the traffic flow embedding vector to obtain a mask vector includes: Add location encoding to the traffic flow embedding vector to obtain the location embedding vector; A time block mask and a node region mask are generated, and a mask vector is calculated based on the time block mask, the node region mask and the location embedding vector; the time block mask is used to mask continuous time blocks, and the node region mask is used to mask traffic nodes that meet the preset spatial correlation conditions.
4. The traffic flow prediction method according to claim 1, characterized in that, The step of generating a traffic adjacency matrix for each historical time block based on the traffic flow values of all traffic nodes in each historical time block includes: Through the formula: Constructing a traffic adjacency matrix ; in, Indicates the first Each historical time segment The total number of historical time blocks. and The first The first and second learnable embedding matrices of all traffic nodes generated based on traffic flow values for each historical time block. For the embedded dimension.
5. The traffic flow prediction method according to claim 4, characterized in that, The step of spatially augmenting the mask vector using a graph neural network based on all traffic adjacency matrices to obtain spatially augmented features includes: The node feature update formula for each layer in the graph neural network is constructed based on all traffic adjacency matrices. The mask vector is input into the graph neural network for computation to obtain spatial augmentation features.
6. The traffic flow prediction method according to claim 1, characterized in that, The spatial augmentation features are temporally augmented using an encoder to obtain temporally augmented features, including: The spatial enhancement features are reshaped into reshaped features that conform to the encoder input format; The reshaped features are input into the encoder for processing to obtain temporal enhancement features.
7. The traffic flow prediction method according to claim 6, characterized in that, Training the encoder based on the temporal enhancement features includes: The temporal enhancement features are reconstructed using a decoder to obtain a reconstructed vector; A reconstruction loss function is constructed based on the reconstructed vector, the traffic flow embedding vector, and the mask location index set; the reconstruction loss function is used to describe the difference between the reconstructed vector at the mask location and the corresponding traffic flow embedding vector; The traffic flow embedding vector is applied with a first composite mask and a second composite mask to obtain a first mask vector and a second mask vector; the first composite mask and the second composite mask have the same mask ratio but different mask positions; The first mask vector and the second mask vector are respectively input into the graph neural network and the encoder to obtain the first time-enhanced feature and the second time-enhanced feature, and a consistency loss function is constructed based on the first time-enhanced feature and the second time-enhanced feature; The graph neural network and the encoder are jointly trained based on the reconstruction loss function and the consistency loss function.
8. The traffic flow prediction method according to claim 7, characterized in that, The reconstruction loss function is: in, This represents the reconstruction loss function value. Represents the set of mask position indices. This indicates the total number of elements in the position index set. Represents the position in the traffic flow embedding vector The element at that location, Represents the position in the reconstructed vector Elements at the location; The consistency loss function is: in, This represents the value of the consistency loss function. This represents the set of indexes of positions in both the first and second composite masks that are not masked. The total number of elements in the set. and These represent the first and second time-enhanced features at different locations. The representation vector at that location, express The square of the distance.
9. A terminal 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 computer program, it implements the traffic flow prediction method based on graph neural networks as described in any one of claims 1 to 8.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the traffic flow prediction method based on graph neural networks as described in any one of claims 1 to 8.