A Traffic Flow Prediction Method Based on Transformer and Graph Neural Network

The integration of Transformer and graph neural networks in traffic flow prediction methods addresses the isolation of spatial and temporal features, enhancing prediction accuracy and robustness by dynamically adapting to traffic network changes.

CN119851481BActive Publication Date: 2025-07-15NANJING UNIV OF POSTS & TELECOMM
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510330498.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-20
Publication Date
2025-07-15
Estimated Expiration
2045-03-20

AI Technical Summary

Technical Problem

The existing traffic flow prediction methods fail to effectively integrate spatiotemporal characteristics, making it difficult to cope with complex changes in the traffic network, especially in the event of emergencies.

Method used

The method of combining Transformer and graph neural network is adopted to capture time dependencies through the self-attention mechanism, and the graph attention mechanism strengthens spatial feature learning, and dynamically updates the graph structure to achieve fusion and adaptive adjustment of space-time features.

Benefits of technology

It improves the accuracy and robustness of traffic flow prediction, enables flexible adjustment of prediction strategies in emergencies, and improves the adaptability and accuracy of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119851481B_ABST
    Figure CN119851481B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of intelligent transportation technologies, and specifically provides a traffic flow prediction method based on Transformer and graph neural network, including: obtaining traffic flow time series data from different traffic sensor nodes; using a Transformer encoder to extract the temporal features of each node and generate an embedding vector for each traffic node; calculating the similarity between nodes using cosine similarity based on the embedding vectors between nodes, and constructing a dynamic graph structure to reflect the spatial relationship between nodes; applying the graph attention mechanism in the graph neural network to aggregate the neighbor information of nodes and strengthen the learning of spatial features; fusing temporal features and spatial features, and predicting future traffic flow through a fully connected layer, which can effectively capture the complex spatio-temporal relationships in traffic data and adapt to the changes in the real road structure through the dynamic graph structure, thereby improving the accuracy and robustness of traffic flow prediction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of intelligent transportation technology, and specifically to a traffic flow prediction method based on Transformer and graph neural network. Background Technique

[0002] In today's society, the rapid advancement of urbanization has made urban traffic flow increasingly complex and dynamically changing. The precise management and prediction of traffic flow have become the key core issues in the construction and development of intelligent transportation systems. Efficient and accurate traffic flow prediction can not only provide a scientific basis for the intelligent control of traffic signals, realize the reasonable optimization of traffic resources, but also significantly alleviate traffic congestion, greatly improve the actual utilization efficiency of roads, and thus promote the orderly operation of urban traffic.

[0003] In recent years, deep learning technology has been increasingly widely used in the field of traffic flow prediction. Among them, models combining spatio-temporal data have attracted much attention because they are expected to capture the complex and changeable trends of traffic flow. Among many technologies, graph neural network, with its unique advantages, can effectively mine the inherent spatial dependence relationship of the traffic network and extract valuable information from the topological structure of the traffic network; while sequence models such as Transformer focus on capturing the evolution law presented by traffic flow over time and perform well in processing time series data.

[0004] However, through in-depth research, it is found that most of the existing traffic flow prediction methods have an obvious defect, that is, they often process spatial features and temporal features separately and fail to fully consider the close internal connection between the two. This separated processing method makes the model unable to cope when facing real-time traffic changes and emergencies, and it is difficult to make accurate and timely responses.

[0005] Further analysis of the existing technology shows that it has significant limitations in spatio-temporal feature fusion and dealing with real-time dynamic traffic changes, which directly leads to the prediction accuracy being difficult to meet the actual needs. Specifically, when the current model processes the complex spatial dependence and time series evolution of the traffic network, it cannot achieve the efficient collaborative processing of the two, and it is difficult to dynamically adjust the feature weights according to different spatio-temporal conditions, so it cannot accurately reflect the real change law of traffic flow in different situations.

[0006] In actual application scenarios, this limitation is more prominent. Due to the lack of sufficient self-adaptability of the existing model to the dynamic changes of traffic flow, when encountering emergencies (such as traffic accidents, bad weather, etc.) or common dynamic change scenarios such as road congestion, it cannot flexibly adapt to the changes in the topological structure and adjust the prediction strategy, resulting in a large deviation between the prediction result and the actual traffic condition.

[0007] In summary, there is an urgent need to develop an innovative traffic flow prediction method that can organically integrate spatio-temporal features and has the ability to dynamically adjust the graph structure to effectively cope with the complex changes in traffic flow, thereby providing strong technical support for solving many problems in traffic management. This has become a key task and necessary means in the current research and practice in the traffic field. Summary of the Invention

[0008] The purpose of the present invention is to provide a traffic flow prediction method based on Transformer and graph neural network, which can effectively capture the complex spatio-temporal relationships in traffic data and adapt to the changes in the real road structure through a dynamic graph structure, thereby improving the accuracy and robustness of traffic flow prediction to solve the problems raised in the above background technology.

[0009] To solve the above technical problems, the present invention provides the following technical solutions:

[0010] A traffic flow prediction method based on Transformer and graph neural network, the method includes:

[0011] S100. Obtain time series data from different traffic sensor devices in the city and the initial road topology graph, and normalize the input of the model by preprocessing the data and using the maximum-minimum normalization method;

[0012] S200. The Transformer encoder module captures long-term dependence relationships through the self-attention mechanism and outputs the embedding vectors of each node for the fusion calculation of time features in the downstream module and the dynamic update of the graph structure;

[0013] S300. Based on the embedding vectors between nodes, calculate the similarity between nodes using cosine similarity, and decide whether to update the dynamic graph according to the degree of change of the topology graph;

[0014] S400. Use the graph attention mechanism in the graph neural network to aggregate the neighbor information of nodes and strengthen the learning of spatial features;

[0015] S500. Fuse the temporal features of node embeddings and the spatial features passing through the graph neural network, and perform traffic flow prediction through a fully connected layer.

[0016] Preferably, S100 includes:

[0017] S101. Deploy a sensor cluster at traffic nodes to collect traffic flow data, including speed, flow, time occupancy, etc. The sensor cluster collects and uploads the data to the data center at a preset time interval;

[0018] S102. Preprocess the collected traffic flow data, including removing abnormal data and performing standard processing to ensure the integrity and consistency of the data;

[0019] S103. Based on the physical connection relationship between traffic nodes (sensors) and roads, establish an initial traffic network topology of traffic nodes and edges. The topology uses traffic nodes (sensors) as the vertices of the graph and roads as the edges of the graph, which is used to reflect the flow paths of traffic flow between different nodes.

[0020] Preferably, S200 includes:

[0021] S201. The shape of the preprocessed multivariate time series data set is , where is the number of features, and represents the length of the time series;

[0022] S202. Define the size of the embedding time window as W, divide the entire data set X into multiple such time slices, and input the data in each slice into the Transformer Encoder in sequence;

[0023] S203. The Transformer Encoder maps each time slice to an embedding vector , where H is the dimension of the embedding vector; take the average of T / W embedding vectors to obtain the embedding vector of each node.

[0024] Preferably, S300 includes:

[0025] S301. During the training of the neural network, after each batch passes through node embedding, it is necessary to recalculate the cosine similarity between two node vectors, and its formula is: ;

[0026] S302. Each node selects at most K nodes with a cosine similarity greater than 0 to itself as its neighbor nodes j, and then connects i and j to obtain the adjacency matrix A' of the graph;

[0027] S303. Subtract A' from the graph adjacency matrix currently used by the model, and use a function to obtain the number q of non-zero elements in the subtracted matrix. Then q / 2 is the number of edges that have changed;

[0028] Set that when q / 2 > Q, update it to the new graph adjacency matrix A; where Q can be flexibly set according to the number of nodes in the distributed network.

[0029] Preferably, S400 includes: constructing a graph neural network based on the adjacency matrix A, using a graph attention-based feature extractor to fuse the information of a node with its neighbors:

[0030] Aggregate features for node i The calculation method is: ;

[0031] Among them, is the output feature of the graph attention layer, which has the same shape as the input ; is the input time window of node i, is the neighbor node of node i obtained from the graph adjacency matrix A, is the trainable weight matrix, represents the points marked as 1 in the adjacency matrix, and the number is the number of all neighbor nodes of node i;

[0032] Among them, the attention coefficient The calculation method is:

[0033] ;

[0034] ;

[0035] Among them, ⊕ represents the concatenation operation, is the coefficient vector learned by the attention mechanism. LeakyReLU is used as the non-linear activation to calculate the attention coefficient, and the softmax function is used to normalize the attention coefficient.

[0036] Preferably, S500 includes:

[0037] S501. After neighborhood feature extraction by the graph neural network, obtain new time series representations of nodes ; In order to fuse the rich feature information in time and space respectively, we use the previously trained node embedding vector pass through a linear layer Linear and perform a residual connection with to obtain , and the formula is as follows:

[0038] ;

[0039] Among them, W and b are the weight matrix and bias vector in the Linear layer respectively;

[0040] S502. Pass through a fully connected layer for the traffic flow time window Predict at the next time point, and use the mean absolute error (MAE) and root mean square error (RMSE) as the loss functions of the present invention.

[0041] A system adopting a traffic flow prediction method based on Transformer and graph neural network, the system comprising: a traffic flow collection module and a central server;

[0042] The central server includes a node embedding module, a graph construction module and a traffic flow prediction module;

[0043] The traffic flow collection module is placed on each device to be detected, and is used to collect traffic distributively;

[0044] The node embedding module is used to preprocess the traffic time series of each node and form respective node embedding vectors through the Transformer Encoder;

[0045] The graph construction module is used to calculate the similarity of the node embedding vectors and update the topological graph structure in real time;

[0046] The traffic flow prediction module is used to fuse the node embedding vector features and the spatial features passing through the graph neural network, and make predictions through the fully connected layer.

[0047] A computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the steps in the above-mentioned traffic flow prediction method based on Transformer and graph neural network.

[0048] A computer device, comprising a memory, a processor and a computer program stored on the memory and running on the processor, and when the processor executes the program, it implements the steps in the above-mentioned traffic flow prediction method based on Transformer and graph neural network.

[0049] Compared with the prior art, the beneficial effects achieved by the present invention are:

[0050] By combining the Transformer and graph neural networks, it is possible to effectively capture the spatio-temporal relationships in traffic flow, improving the accuracy and robustness of predictions. The Transformer module uses the self-attention mechanism to extract long-term temporal dependencies, while the graph neural network strengthens spatial feature learning through the graph attention mechanism, ensuring an in-depth understanding of the complex spatial dependencies between nodes in the traffic network. The fusion strategy that combines spatio-temporal features enables the model to adaptively respond to the dynamic changes in traffic flow, especially in the event of emergencies or complex scenarios, where it can flexibly adjust the prediction strategy. In addition, the design of dynamically updating the graph structure effectively addresses changes in road topologies, further enhancing the adaptability and accuracy of the model in practical applications. Overall, the present invention provides a more accurate and adaptive prediction tool for urban intelligent traffic management. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] The accompanying drawings are used to provide a further understanding of the present invention and form a part of the specification, together with the embodiments of the present invention, for explaining the present invention, and do not constitute a limitation to the present invention. In the drawings:

[0052] Figure 1 is a schematic diagram of the technical process of traffic flow prediction in an embodiment of the present invention;

[0053] Figure 2 is a schematic diagram of the model architecture based on the Transformer and graph neural network for traffic flow prediction in an embodiment of the present invention;

[0054] Figure 3 is a schematic diagram of the node embedding module in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0055] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0056] Please refer to Figures 1 - 3 , the present invention provides the following technical solutions:

[0057] Embodiment 1: Combining Figure 1 and Figure 2, the present invention provides a technical solution: a traffic flow prediction method based on Transformer and graph neural network. First, the time series data of each sensor node is input into the Transformer Encoder for node embedding to obtain the time series features of traffic flow, and the node embedding is used as the basis for updating the dynamic road topology graph; Next, the graph attention network constructed by the road topology graph is used to obtain the neighborhood space features of each node, and the corresponding node embeddings are linearly weighted and fused to strengthen the time series and space features; Finally, the traffic flow prediction is made through the fully connected layer. Specifically, the steps are as follows:

[0058] Step 1: Obtain the time series data from different traffic sensor devices in the city and the initial road topology graph, and normalize the input of the model by preprocessing the data and using the maximum-minimum normalization method;

[0059] Deploy a sensor cluster at traffic nodes to collect traffic flow data, including speed, flow, time occupancy, etc. The sensor cluster collects and uploads the data to the data center at a preset time interval;

[0060] Preprocess the collected traffic flow data, including removing abnormal data and performing standard processing to ensure the integrity and consistency of the data;

[0061] Based on the physical connection relationship between traffic nodes (sensors) and roads, establish the initial traffic network topology structure of traffic nodes and edges. The topology structure uses traffic nodes (sensors) as the vertices of the graph and roads as the edges of the graph, which is used to reflect the flow path of traffic flow between different nodes.

[0062] Step 2: The Transformer encoder module captures long-term dependencies through the self-attention mechanism and outputs the embedding vectors of each node, which are used for the fusion calculation of downstream module time features and the dynamic update of the graph structure;

[0063] Graph representation learning is the specific application of representation learning on graphs, aiming to map the representation of each node into a low-dimensional and dense vector space by using the connection relationship between nodes in the graph while effectively maintaining the graph structure. And this research aims to provide a method that can dynamically construct the graph structure without giving the initial graph structure information. And this requires generating vector representations that can accurately describe the characteristics of each node participating in the graph construction.

[0064] In the transportation system, due to the connectivity of roads, it is common for sensor devices at different intersections to generate similar fluctuations within a time window. The purpose of node embedding is to convert the original high-dimensional time-series node features into low-dimensional vectors, with two objectives. One is to facilitate the calculation of the relationships between nodes, thereby constructing a graph structure. The other is to continuously learn during the training process and represent the time-series features and neighborhood features for feature fusion after the graph neural network layer, so as to better utilize the feature information.

[0065] The shape of the preprocessed multivariate time-series dataset is , where is the number of features, represents the length of the time series.

[0066] In this paper, the size of a time window is defined as W, and the entire dataset is divided into multiple such time slices, and the data in each slice is sequentially input into the Transformer Encoder.

[0067] The Transformer Encoder maps each time slice to an embedding vector , where is the dimension of the embedding vector. Taking the average of these embedding vectors, the embedding vector of each node is obtained.

[0068] The following combines with the attached Figure 3 to explain the node embedding module in detail.

[0069] (1) Transformer Encorder layer

[0070] For the Transformer encoder, it converts the input time-series data into an embedding vector . Each layer of the Transformer encoder can be expressed as: ;

[0071] where, is the layer index, , and each Transformer encoder layer contains a self-attention mechanism and a feed-forward neural network.

[0072] (2) Positional encoding

[0073] The positional encoding PE is a matrix with the same shape as the time-series data and is used to provide the position information of the time steps. The positional encoding can be expressed as: , ;

[0074] where is the position of the time step, i is the index of the dimension, and d is the dimension of the feature vector. The sine and cosine functions here are used to generate different frequencies on each dimension. We will add it to the positional encoding and input it into the feed-forward network.

[0075] (3) Transformer self-attention

[0076] The purpose of using the Transformer Encoder is to extract the long-term features of each sensor node feature, which relies on the self-attention mechanism first proposed in 2017.

[0077] The calculation steps of each Transformer encoder layer can be expressed by the following formula:

[0078] ;

[0079] where, , ;

[0080] where Q, K, and V are the query, key, and value respectively, , , , is the weight matrix.

[0081] (4) Transformer Encoder output

[0082] Batch normalization normalizes the data for each feature dimension i, which can be expressed as:

[0083] ;

[0084] where, and are the mean and variance of feature i in this batch of data respectively, and are learnable parameters is a small constant to avoid division by zero.

[0085] Then, after passing through the ReLU (Rectified Linear Unit) activation function to perform a non-linear transformation on the input, which can be expressed as ReLU(x) = max(0, x), it is applied to the output of batch normalization.

[0086] To sum up, the output of the Transformer encoder The complete formula after batch normalization and ReLU activation function is expressed as: ;

[0087] Here is the final output after batch normalization and ReLU activation function. It contains the features of time series data and time-dependent information. For each node feature, there are T / W embedding vectors, and the average of them is taken to obtain the embedding vector of each node : ;

[0088] These embedding vectors will initialize the graph structure and will be fused with spatial features in the downstream attention module to jointly affect the prediction value.

[0089] Step 3: Based on the embedding vectors between nodes, calculate the similarity between nodes using cosine similarity, and decide whether to update the dynamic graph according to the change degree of the topological graph.

[0090] During the neural network training, after each batch passes through node embedding, the cosine similarity needs to be recalculated between every two node vectors, and its formula is: ;

[0091] Each node selects the most K nodes with cosine similarity greater than 0 with itself as its neighbor nodes j, and then connects i and j to obtain the adjacency matrix A' of the graph.

[0092] Subtract A' from the graph adjacency matrix currently used by the model, and use the function to obtain the number q of non-zero elements in the subtracted matrix. Then q / 2 is the number of edges that have changed. Then set when q / 2 > Q (Q can be flexibly set according to the number of nodes in the distributed network), update to the new graph adjacency matrix A.

[0093] Step 4: Use the graph attention mechanism in the graph neural network to aggregate the neighbor information of nodes and strengthen the learning of spatial features.

[0094] Based on the adjacency matrix A, construct a graph neural network, use a graph attention-based feature extractor to fuse the information of nodes with their neighbors. For node i to aggregate features The calculation method is as follows:

[0095] ;

[0096] Where is the output feature of the graph attention layer, which has the same shape as the input is the input time window of node i, is the neighbor node of node i obtained from the graph adjacency matrix A. is the trainable weight matrix.​ It represents the number of points marked as 1 in the adjacency matrix, and the quantity is the number of all neighbor nodes of node i.

[0097] The calculation method of the attention coefficient is as follows:

[0098] ;

[0099] ;

[0100] where ⊕ represents the link operation, is the coefficient vector learned by the attention mechanism. We use LeakyReLU as the non-linear activation to calculate the attention coefficient and use the softmax function to normalize the attention coefficient.

[0101] Step 5: Fuse the temporal features of the node embeddings and the spatial features passing through the graph neural network, and perform traffic flow prediction through a fully connected layer.

[0102] After the neighborhood feature extraction by the graph neural network, we can obtain the new time series representation of nodes. To fuse the rich feature information in time and space respectively, we pass the previously trained node embedding vector through a linear layer Linear and perform a residual connection with to obtain , and the formula is as follows:

[0103] ;

[0104] where W and b are the weight matrix and bias vector in the Linear layer respectively.

[0105] Predict the next time point of the traffic flow time window through a fully connected layer, and use the mean absolute error MAE and the root mean square error RMSE as the loss function of the present invention.

[0106] Embodiment 2: The computer-readable storage medium of this embodiment stores a computer program, and when the program is executed by a processor, it implements the steps in a traffic flow prediction method based on Transformer and graph neural network in Embodiment 1.

[0107] The computer-readable storage medium of this embodiment can be an internal storage unit of the terminal, such as the hard disk or memory of the terminal; the computer-readable storage medium of this embodiment can also be an external storage device of the terminal, such as a plug-in hard disk, a smart memory card, a secure digital card, a flash card, etc. equipped on the terminal; further, the computer-readable storage medium can also include both the internal storage unit and the external storage device of the terminal.

[0108] The computer-readable storage medium of this embodiment is used to store computer programs and other programs and data required by the terminal, and the computer-readable storage medium can also be used to temporarily store the data that has been output or will be output.

[0109] Embodiment 3: The computer device of this embodiment includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the steps in a traffic flow prediction method based on Transformer and graph neural network in Embodiment 1.

[0110] In this embodiment, the processor can be a central processing unit, or other general-purpose processors, digital signal processors, application-specific integrated circuits, off-the-shelf programmable gate arrays, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.; the memory can include a read-only memory and a random access memory, and provides instructions and data to the processor. A part of the memory can also include a non-volatile random access memory. For example, the memory can also store information about the device type.

[0111] Those skilled in the art should understand that the content disclosed in the embodiment can be provided as a method, a system, or a computer program product. Therefore, this solution can be in the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Moreover, this solution can be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories and optical memories, etc.) containing computer-usable program codes.

[0112] This solution is described with reference to the flowcharts and / or block diagrams of the methods and computer program products according to the embodiments of this solution. It should be understood that each flow and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the flows and / or blocks in the flowchart and / or block diagram can be implemented; these computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate for implementing the process Figure 1means for one process or multiple processes and / or methods Figure 1 means for the functions specified in one box or multiple boxes.

[0113] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured article including an instruction device, and the instruction device implements the process Figure 1 means for one process or multiple processes and / or methods Figure 1 the functions specified in one box or multiple boxes.

[0114] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in Figure 1 means for one process or multiple processes and / or methods Figure 1 one box or multiple boxes.

[0115] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), etc.

[0116] Finally, it should be noted that the above are only the preferred embodiments of the present invention and are not used to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some of the technical features. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A traffic flow prediction method based on Transformer and graph neural network, characterized in that: The method includes: S100. Obtain the time series data from different traffic sensor devices in the city and the initial road topology map, and normalize the input of the model by preprocessing the data and using the maximum-minimum normalization method; S200. The Transformer encoder module captures long-term dependencies through the self-attention mechanism and outputs the embedding vectors of each node for the fusion calculation of time features of the downstream module and the dynamic update of the graph structure; S300. Based on the embedding vectors between nodes, calculate the similarity between nodes using cosine similarity, and determine whether to update the dynamic graph according to the degree of change of the topology map; S400. Use the graph attention mechanism in the graph neural network to aggregate the neighbor information of nodes and strengthen the learning of spatial features; S500. Fuse the temporal features of node embeddings and the spatial features passing through the graph neural network, and perform traffic flow prediction through a fully connected layer; Among them, the S200 includes: S201. The shape of the preprocessed multi-variable time series dataset is , where is the number of features, and represents the length of the time series; S202. Define the size of the embedding time window as W, divide the entire dataset X into multiple such time slices, and input the data in each slice into the Transformer Encoder in sequence; S203. The Transformer Encoder maps each time slice to an embedding vector , where H is the dimension of the embedding vector; average the T / W embedding vectors to obtain the embedding vector of each node ; The S300 includes: S301. During the neural network training, after each batch is embedded by nodes, it is necessary to recalculate the cosine similarity between two node vectors, and its formula is: ; S302. Each node selects at most K nodes with a cosine similarity greater than 0 with itself as its neighbor nodes j, and then connects i and j to obtain the adjacency matrix A' of the graph; S303. Subtract A' from the graph adjacency matrix currently used by the model, and use a function to obtain the number q of non-zero elements in the subtracted matrix, then q / 2 is the number of edges that have changed; Set that when q / 2 > Q, update it to the new graph adjacency matrix A; where Q can be flexibly set according to the number of nodes in the distributed network.

2. The traffic flow prediction method based on Transformer and graph neural network according to claim 1, characterized in that, The S100 includes: S101. Deploy a sensor cluster at traffic nodes to collect traffic flow data, including speed, flow, and time occupancy. The sensor cluster collects and uploads data to the data center at a preset time interval; S102. Preprocess the collected traffic flow data, including removing abnormal data and performing standard processing to ensure the integrity and consistency of the data; S103. Based on the physical connection relationship between traffic sensor nodes and roads, establish an initial traffic network topology structure of traffic nodes and edges. The topology structure uses traffic nodes as the vertices of the graph and roads as the edges of the graph to reflect the flow paths of traffic flow between different nodes.

3. The traffic flow prediction method based on Transformer and graph neural network according to claim 1, characterized in that, The S400 includes: Construct a graph neural network based on the adjacency matrix A, use a graph attention-based feature extractor to fuse the information of nodes with their neighbors: For the aggregated features of node i The calculation method is as follows: ; Among them, is the output feature of the graph attention layer, which has the same shape as the input and is the input time window of node i, is the neighbor node of node i obtained from the graph adjacency matrix A, is the trainable weight matrix, represents the number of points marked as 1 in the adjacency matrix, and the number is the number of all neighbor nodes of node i; Among them, the attention coefficient The calculation method is as follows: ; ; where ⊕ represents the linking operation, is the coefficient vector learned by the attention mechanism. The LeakyReLU is used as the non-linear activation to calculate the attention coefficients, and the softmax function is used to normalize the attention coefficients.

4. The traffic flow prediction method based on Transformer and graph neural network according to claim 1, wherein The S500 includes: After neighborhood feature extraction by the graph neural network, we obtain the new time series representation of the nodes ; To fuse the rich feature information in time and space respectively, we use the node embedding vectors obtained from the previous training through a linear layer Linear and perform residual connection with to obtain . The formula is as follows: ; Where W and b are the weight matrix and bias vector in the Linear layer respectively.

5. A system adopting the traffic flow prediction method based on Transformer and graph neural network as described in any one of claims 1-4, characterized in that: The system includes: a traffic flow collection module and a central server; The central server includes a node embedding module, a graph construction module, and a traffic flow prediction module; The traffic flow collection module is placed on each device that needs to be detected to collect traffic flow distributedly; The node embedding module is used to preprocess the traffic time series of each node and form respective node embedding vectors through the Transformer Encoder; The graph construction module is used to calculate the similarity of node embedding vectors and update the topology graph structure in real time; The traffic flow prediction module is used to fuse the node embedding vector features and the spatial features passing through the graph neural network, and make predictions through a fully connected layer.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it implements the steps in a traffic flow prediction method based on Transformer and graph neural network according to any one of claims 1-4.

7. A computer device, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, characterized in that, When the processor executes the program, it implements the steps in a traffic flow prediction method based on Transformer and graph neural network according to any one of claims 1-4.

Citation Information

Patent Citations

  • Time-space correlation traffic flow prediction method based on deep learning

    CN119274345A