Hybrid neural network training method, traffic flow prediction method, device and medium

Through the hybrid neural network training method, combined with the LSTM module and the first self-attention mechanism module, the attention matrix processed by dimensionality reduction mapping is used to solve the high time complexity problem of space-time correlation learning in traffic flow prediction, and improve the prediction efficiency and accuracy.

CN114742210BActive Publication Date: 2025-08-19ZHEJIANG NORMAL UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210503267.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-10
Publication Date
2025-08-19
Estimated Expiration
2042-05-10

AI Technical Summary

Technical Problem

In the prior art, when using machine learning methods to learn the spatiotemporal correlation of traffic flow data, there is a problem of high time complexity, which leads to low traffic flow prediction efficiency.

Method used

The hybrid neural network training method is adopted, combined with the LSTM module and the first self-attention mechanism module, and the attention matrix processed by dimensionality reduction mapping is improved to improve the prediction efficiency of traffic flow data.

Benefits of technology

Reduces computation time complexity, improves efficiency and accuracy of traffic flow prediction, especially when processing traffic flow data with complex spatiotemporal characteristics.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114742210B_ABST
    Figure CN114742210B_ABST
Patent Text Reader

Abstract

The present application relates to a hybrid neural network training method, a traffic flow prediction method, a computer device, a storage medium, and a computer program product. The method utilizes a hybrid neural network comprising an LSTM module and a first self-attention mechanism module, wherein the LSTM module and the first self-attention mechanism module are coupled, and the first self-attention mechanism module includes an attention matrix processed by dimensionality reduction mapping. After acquiring traffic flow data for multiple road network nodes, the traffic flow data is input into the hybrid neural network for training, thereby obtaining a trained hybrid neural network. This method solves the problem of high time complexity and low traffic flow prediction efficiency when using machine learning methods to learn the complex spatiotemporal correlations of traffic flow data in related technologies, thereby improving the efficiency of traffic flow prediction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a hybrid neural network training method, a traffic flow prediction method, a computer device, a storage medium, and a computer program product. Background Art

[0002] Accurate traffic flow forecasting provides a crucial foundation for traffic operations and management. To this end, several mathematical statistical algorithms have been proposed and applied to traffic forecasting. While these mathematical modeling methods have rigorous derivation and theoretical support, their assumptions and simplifications severely limit their accuracy. Furthermore, because these methods only process the temporal dimension, they struggle to capture the complex spatiotemporal characteristics of traffic flow data.

[0003] Machine learning methods can effectively utilize the vast amount of traffic flow data captured by ITS (Intelligent Transportation System) front-end sensing infrastructure and have been widely used in the field of traffic flow forecasting. These methods are more robust to data outliers and more flexible in modeling nonlinear and complex relationships, improving forecast accuracy. However, related technologies using machine learning methods to learn the complex spatiotemporal correlations in traffic flow data lack flexibility and require high time complexity, resulting in low traffic flow forecasting efficiency. Summary of the Invention

[0004] Based on this, it is necessary to provide a hybrid neural network training method, traffic flow prediction method, computer equipment, computer-readable storage medium and computer program product that can improve the prediction efficiency while ensuring the accuracy of traffic flow prediction in response to the above technical problems.

[0005] In a first aspect, the present application provides a hybrid neural network training method for traffic flow prediction, wherein the hybrid neural network includes an LSTM module and a first self-attention mechanism module, wherein the LSTM module and the first self-attention mechanism module are coupled, and the first self-attention mechanism module includes an attention matrix processed by dimensionality reduction mapping, and the method includes:

[0006] Obtain traffic flow data for multiple road network nodes;

[0007] The traffic flow data is input into the hybrid neural network for training to obtain a trained hybrid neural network.

[0008] In one embodiment, the hybrid neural network further includes a position embedding module, the input end of the position embedding module is connected to the output end of the LSTM module, and the output end of the position embedding module is connected to the input end of the first self-attention mechanism module, wherein the position embedding module is used to positionally encode the output data of the LSTM module.

[0009] In one embodiment, obtaining the attention matrix processed by the dimensionality reduction mapping includes:

[0010] Obtain a query matrix, a key matrix, and a value matrix based on the output data of the LSTM module;

[0011] Obtaining a mapping matrix, and performing dimensionality reduction mapping on the product of the query matrix and the key matrix according to the mapping matrix to obtain a first correlation matrix;

[0012] The value matrix is subjected to dimensionality reduction mapping according to the mapping matrix, and the attention matrix is obtained according to the first correlation matrix and the value matrix after dimensionality reduction mapping.

[0013] In one embodiment, after performing dimensionality reduction mapping on the product of the query matrix and the key matrix using a mapping matrix to obtain a first relevance matrix, the method further includes:

[0014] The first correlation matrix is processed by one of the following processes: normalization processing, scaling processing, and function mapping processing.

[0015] In one embodiment, obtaining a query matrix, a key matrix, and a value matrix according to the output data of the LSTM module includes:

[0016] The output data of the LSTM module is divided into a plurality of sub-output data, and a corresponding sub-query matrix, a sub-key matrix and a sub-value matrix are obtained according to each sub-output data.

[0017] Obtaining the attention matrix processed by the dimensionality reduction mapping includes:

[0018] Performing dimensionality reduction mapping on the product of the sub-query matrix and the sub-key matrix corresponding to each sub-output data according to the mapping matrix to obtain a first sub-correlation matrix;

[0019] Performing dimensionality reduction mapping on the sub-value matrix corresponding to each sub-output data according to the mapping matrix, and obtaining a sub-attention matrix according to the first sub-correlation matrix and the sub-value matrix after dimensionality reduction mapping;

[0020] The attention matrix is obtained according to a plurality of sub-attention matrices.

[0021] In one embodiment, the hybrid neural network further includes a second self-attention mechanism module, and the second self-attention mechanism module includes a local mask mechanism module.

[0022] In a second aspect, the present application also provides a traffic flow prediction method. The method comprises:

[0023] Obtain traffic flow data of multiple road network nodes in the last unit time;

[0024] The traffic flow data is input into the hybrid neural network trained by the hybrid neural network training method described in the first aspect in the order of generation time, and after being processed by the hybrid neural network, the traffic flow prediction values of the multiple road network nodes in the next unit time are output.

[0025] In a third aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the traffic flow prediction method described in the first or second aspect when executing the computer program.

[0026] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the traffic flow prediction method described in the first or second aspect.

[0027] In a fifth aspect, the present application further provides a computer program product, which includes a computer program that, when executed by a processor, implements the traffic flow prediction method described in the first or second aspect.

[0028] The hybrid neural network training method, traffic flow prediction method, computer device, storage medium, and computer program product described above utilize a hybrid neural network comprising an LSTM module and a first self-attention mechanism module, wherein the LSTM module and the first self-attention mechanism module are coupled, and the first self-attention mechanism module includes an attention matrix processed by dimensionality reduction mapping. After acquiring traffic flow data for multiple road network nodes, the traffic flow data is input into the hybrid neural network for training, thereby obtaining a trained hybrid neural network. This method solves the problems in related arts of high time complexity and low traffic flow prediction efficiency when using machine learning methods to learn the complex spatiotemporal correlations of traffic flow data, thereby improving the efficiency of traffic flow prediction. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 A diagram showing an application environment of a hybrid neural network training method in one embodiment;

[0030] Figure 2 is a schematic diagram of spatiotemporal correlation in a road network in one embodiment;

[0031] Figure 3 1 is a flow chart of a hybrid neural network training method according to an embodiment;

[0032] Figure 4 1 is a structural diagram of LSTM in one embodiment;

[0033] Figure 5 A diagram showing the architecture of a hybrid neural network model according to a preferred embodiment;

[0034] Figure 6 This is a model architecture diagram of the first self-attention mechanism module in a preferred embodiment;

[0035] Figure 7 A schematic diagram of a specific operation method of attention operation in a preferred embodiment;

[0036] Figure 8 Schematic diagram of the attention mechanism in the encoder-decoder in a preferred embodiment;

[0037] Figure 9 is a flow chart of a traffic flow prediction method in one embodiment;

[0038] Figure 10 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0040] The hybrid neural network training method and traffic flow prediction method provided in the embodiments of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The data storage system is used to store traffic flow data. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented as an independent server or a server cluster consisting of multiple servers.

[0041] Research has shown that mathematical modeling and machine learning methods are currently the most commonly used methods for solving traffic flow prediction problems. Mathematical modeling methods have a rigorous derivation process and theoretical support, but the assumptions and simplifications of the problem severely limit the accuracy of the model. In addition, because this method only processes the time dimension, it is difficult to capture the complex spatiotemporal characteristics of traffic flow data. Relatively speaking, machine learning methods can make good use of the large amount of traffic flow data captured from ITS front-end sensing facilities. This method is more robust to outliers in the data and more flexible in modeling nonlinear and complex relationships. Artificial neural networks (ANN), as one of the branches of machine learning, are currently a popular method in the field of traffic flow prediction. Many studies have combined graph neural networks (GNN) and recurrent neural networks (RNN) to learn the spatiotemporal characteristics of traffic flow, achieving good results.

[0042] Traditional graph convolutional network (GCN) models require a predefined adjacency matrix based on a distance formula when learning graph structure. This single adjacency matrix cannot dynamically reflect the spatiotemporal correlations between nodes. Furthermore, GCN models have a clear upper limit on their representation capabilities. Because traditional graph convolution operations have been shown to be approximate operations of the Weisfeiler-Lehman (WL) algorithm, the information learned by the model is the overall graph structure, which makes it less capable of distinguishing node heterogeneity. Furthermore, the aggregation of information about neighboring nodes ignores the relationships between distant nodes. To improve the performance of traffic flow prediction models, related techniques have proposed using models that dynamically generate graph representations. Another approach is to improve model performance by adaptively assigning weights through an attention mechanism. Regarding the temporal dimension of traffic flow data, traditional RNNs suffer from exploding or vanishing gradients when processing long sequences, as well as insufficient long-range correlations. Long Short-Term Memory (LSTM), a variant of RNNs, effectively addresses these limitations in processing long sequences. Recently, a new network architecture, the Transformer, has been proposed that dispenses with recursion and convolution operations. It can calculate the correlation between data through the attention mechanism, and is not affected by the distance between the data in the sequence. Based on the above characteristics, the hybrid neural network composed of Transformer and LSTM is very suitable for traffic flow prediction problems with highly nonlinear and complex spatiotemporal characteristics.

[0043] like Figure 2 The figure shows the spatial and temporal correlation in the road network. Figure 2A simple road network is shown in the figure. The color of the dots represents different types of nodes, and the number of human-shaped signs represents the size of the traffic flow data. For example, 4, 5, 6, and 7 are green, 1 and 2 are red, and 3 is gray. Traffic flow is the characteristic data of the node and is also affected by the intrinsic graph structure of the traffic network. Therefore, by calculating the similarity of traffic flow data, the node types can be distinguished and the potential network structure information can be learned. The original Transformer model has less inductive bias and very good scalability. However, its core attention mechanism is to calculate the relevance of nodes at the semantic level. This brings challenges to the application of Transformer in graph structure learning. In addition, the attention operation of Transformer requires This limits its performance and efficiency. The attention calculation between hundreds of nodes in the road network is very large and time-consuming.

[0044] In order to solve the above problem, in one embodiment, Figure 3 As shown, a hybrid neural network training method is provided for traffic flow prediction, wherein the hybrid neural network includes an LSTM module and a first self-attention mechanism module, the LSTM module and the first self-attention mechanism module are coupled, and the first self-attention mechanism module includes an attention matrix processed by dimensionality reduction mapping. Figure 1 The following steps are used as an example to illustrate the terminal in the figure:

[0045] Step S201: Obtain traffic flow data of multiple road network nodes.

[0046] Step S202: input the traffic flow data into the hybrid neural network for training to obtain a trained hybrid neural network.

[0047] The LSTM module is a long short-term memory artificial neural network, and the first self-attention mechanism module is a neural network that includes a self-attention mechanism. The LSTM module and the first self-attention mechanism module can be coupled by connecting the output of the LSTM module to the input of the first self-attention mechanism module, or by connecting the input of the LSTM module to the output of the first self-attention mechanism module. The dimensionality reduction mapping process can be any processing method that can reduce the dimensionality of a data matrix. For example, a mapping matrix can be used to reduce the dimensionality of an attention matrix. The mapping matrix can be a variable parameter matrix that is initially randomly generated and trained and improved by gradient descent based on a hybrid neural network model. Traffic flow data for multiple road network nodes includes multiple dimensions such as speed, flow, and incidence.

[0048] In the above-mentioned hybrid neural network training method, the collected traffic flow data is input into a hybrid neural network model including an LSTM module and a first self-attention mechanism module, and an attention matrix processed by dimensionality reduction mapping is used during the model training process. This reduces the dimension of the data, reduces the computational time complexity, and improves the training speed of the model, thereby improving the prediction efficiency of traffic flow.

[0049] Specifically, the traffic flow data at multiple road network nodes, namely the traffic road network, is a typical graph structure. in represents the nodes in the road network, ε represents the connection edges between nodes, A is the attention matrix, Obtained through attention calculation. During the hybrid neural network training process, at the current time step t, M historical input time steps are used to predict T time steps. Assuming that the past hour is used to predict the next hour, with a time step every 5 minutes, then T = M = 12. In practical applications, the specific durations of M and T time steps can be flexibly adjusted based on the dataset. That is, a mapping function F is obtained, expressed as formula (1).

[0050]

[0051] in X is the input data sequence. represents a set of real numbers. The input and output sequence distributions belong to real vector spaces of dimensions T×N×D and M×N×D, respectively. N is the total number of nodes in the data, and D represents the dimensionality of the traffic flow data. This means that traffic flow data has D features, including traffic speed, volume, and incidence rate.

[0052] LSTM is used to learn the temporal characteristics of traffic flow data. Compared to traditional RNN structures, LSTM retains valuable past information through a gating mechanism, ensuring gradient propagation and better learning of long-range temporal features of sequences. The LSTM structure is used to reduce the dimensionality of the input sequence, avoiding attention operations on excessive tensors and improving model efficiency. LSTM is calculated using the following formula.

[0053] i t =σ(W i [h t-1 , x t ]+b i ) Formula (2)

[0054] f t =σ(W f [h t-1 , x t ]+b f ) Formula (3)

[0055] o t =σ(W o [h t-1 , x t ]+b o ) Formula (4)

[0056]

[0057] C t =f t ⊙C t-1 +i t ⊙C t Formula (6)

[0058] h t =o t ⊙tanh(C t ) Formula (7)

[0059] Among them, i t Represents the input gate, which controls the degree of retention of the input information. t It is the forget gate that controls the forgetting of historical inputs. t Is the output gate, which controls the output of the current state. t represents the input at time t, h t Represents the hidden state at time t. W i 、W f 、W o Represents the trainable weight parameter matrices of the input gate, forget gate, and output gate, respectively, b i 、b f 、b o Represent the bias parameters of the input gate, forget gate, and output gate respectively. σ and tanh are nonlinear activation functions that provide the model with the ability to fit nonlinear relationships. ⊙ is the Hadamard product (bitwise multiplication). is the candidate cell state at time t, C t is the final cell memory state. Figure 4 Shown is the structural diagram of LSTM.

[0060] In some embodiments, the hybrid neural network further includes a position embedding module, the input end of the position embedding module is connected to the output end of the LSTM module, and the output end of the position embedding module is connected to the input end of the first self-attention mechanism module, wherein the position embedding module is used to positionally encode the output data of the LSTM module.

[0061] The position embedding module may implement its position embedding function in at least one of the following ways, including but not limited to: sinusoidal coding, cosine coding, and adaptive coding.

[0062] Specifically, after inputting traffic flow data within a time slice into the LSTM module, the hidden layer output of the LSTM module is bitwise added to the position encoding generated by the position embedding module to achieve position encoding of the LSTM module's output data. Since the input traffic flow data is a tensor within the same time slice, all nodes have no causal or temporal order. When learning node relationships in traffic flow prediction problems, traffic flow data contains certain information about the structural characteristics of the traffic network. Therefore, introducing the position embedding module for position encoding can incorporate this network structural information. In a sense, this is a form of data augmentation, improving model performance by introducing appropriate inductive biases.

[0063] In some embodiments, in order to improve the ability of the hybrid neural network model to distinguish nodes, a sine wave encoding is used to introduce absolute position information to enhance the heterogeneity between nodes. The position encoding formula is as follows:

[0064]

[0065]

[0066] In the above formula, pos represents the position, that is, the row number of the node in the matrix, and i represents the i-th dimension of the input data. model is the model dimension, i.e., the dimension of the hidden layer. The mapping dimension of the positional encoding is consistent with the model dimension, ensuring that the positional encoding can be added to the output after LSTM processing. Furthermore, in some embodiments, a learned positional encoding can be introduced to learn complex spatiotemporal correlations between nodes. Combining the two positional encodings enhances the model's ability to learn relationships between arbitrary nodes in the input.

[0067] In some embodiments, obtaining an attention matrix processed by dimensionality reduction mapping includes: obtaining a query matrix, a key matrix and a value matrix based on the output data of the LSTM module; obtaining a mapping matrix, and performing dimensionality reduction mapping on the product of the query matrix and the key matrix according to the mapping matrix to obtain a first correlation matrix; performing dimensionality reduction mapping on the value matrix according to the mapping matrix, and obtaining an attention matrix based on the first correlation matrix and the value matrix after dimensionality reduction mapping.

[0068] The mapping matrix may be a variable parameter matrix E that is initially randomly generated and trained based on a hybrid neural network model by gradient descent.

[0069] Specifically, the attention operation in the related art combines the input data with three parameter matrices Multiply. Mapped into three different matrices: query, key, and value, denoted as Q, K, and V respectively, with the corresponding dimension denoted as d q d k dv By calculating the correlation matrix P between the Q and K matrices and then weighted summing it with V, we can get the attention score between any two nodes in the input sequence. Here, the correlation between Q and K is calculated by dot product. The huge difference between the dot product results leads to the problem of vanishing gradient after the softmax function, which affects the model prediction performance. To avoid this problem, the dot product results are scaled. is the scaling factor. Therefore, we get a relationship mapping matrix The attention operation formula in the related art is shown in formula (10).

[0070]

[0071] In this embodiment, a mapping matrix E is added between P·V T , To approximate the attention operation, thereby achieving the effect of dimensionality reduction mapping.

[0072] Furthermore, in some embodiments, after using a mapping matrix to perform dimensionality reduction mapping on the product of the query matrix and the key matrix to obtain a first correlation matrix, the method also includes: performing one of the following processing on the first correlation matrix: normalization processing, scaling processing, and function mapping processing.

[0073] The scaling process can be performed by dividing the first correlation matrix by the arithmetic square root of the k vector dimension (i.e., the scaling factor ) to achieve it; the function mapping process can be achieved using the softmax function, which can achieve a nonlinear effect; the normalization process can be to scale the first correlation matrix and then use the softmax function for function mapping.

[0074] Preferably, a mapping matrix E is added between P·V T , And the first correlation matrix is normalized. Specifically, as shown in formula (11), E T After combining with the K matrix, the dot product is calculated with Q to obtain the first correlation matrix, and then the scaling factor is used The first correlation matrix is scaled and substituted into the softmax function. After the softmax function mapping process, it is combined with the mapping matrix E matrix and the parameter matrix V matrix to obtain an approximate attention formula.

[0075]

[0076] In some embodiments, obtaining a query matrix, a key matrix, and a value matrix based on the output data of the LSTM module includes: dividing the output data of the LSTM module into a plurality of sub-output data, and obtaining a corresponding sub-query matrix, a sub-key matrix, and a sub-value matrix based on each sub-output data. Furthermore, in some embodiments, obtaining an attention matrix processed by dimensionality reduction mapping includes: performing dimensionality reduction mapping on the product of the sub-query matrix and the sub-key matrix corresponding to each sub-output data according to the mapping matrix to obtain a first sub-correlation matrix; performing dimensionality reduction mapping on the sub-value matrix corresponding to each sub-output data according to the mapping matrix, and obtaining a sub-attention matrix based on the first sub-correlation matrix and the sub-value matrix after dimensionality reduction mapping; and obtaining an attention matrix based on the plurality of sub-attention matrices.

[0077] The sub-query matrix, sub-key matrix and sub-value matrix corresponding to each sub-output data are generated by equally dividing the query matrix, key matrix and value matrix of the output data according to preset values and performing dimensionality transformation.

[0078] Specifically, the Q, K, and V matrices are divided equally according to a preset value, that is, they are divided into a preset number of attention heads, which are independently responsible for different subspaces. In this way, the model can capture the characteristics of different subspaces in the high-dimensional space without increasing the number of parameters. All sub-output data are operated in parallel using different initial matrices, and then all the output matrices obtained after the operation based on the sub-output data are spliced together. Finally, the model is transformed through a matrix W O The concatenated matrix is transformed to a suitable dimension. The attention operation in this embodiment is shown in formula (12).

[0079] MultiHead(Q,K,V)=Concat(head1,...,head h )W O Formula (12)

[0080] Among them head h is the result of the operation of the i-th attention head. Concat means concatenating multiple matrix blocks of the same dimension along the row direction.

[0081] like Figure 5 The figure shows the architecture diagram of the hybrid neural network model of a preferred embodiment. The output end of the LSTM module is connected to the input end of the encoder (Encoder) and the decoder (Decoder), the output end of the position embedding module (PE) is connected to the output end of the LSTM module, the encoder includes a first self-attention mechanism module (Linear Multi-Head Attention), and the decoder includes a second self-attention mechanism module (Local Masked Multi-Head Attention).

[0082] Among them, the model architecture diagram of the first self-attention mechanism module is as follows Figure 6 As shown, the first self-attention mechanism module divides the Q, K, and V matrices equally according to a preset value, that is, into a preset number of attention heads, which are independently responsible for different subspaces. The attention matrix of each attention head is calculated according to the calculation method of formula (11), and the final attention matrix is obtained according to formula (12). The specific calculation method of the attention operation in this preferred implementation is as follows Figure 7 As shown. When the model uses h = 4 parallel attention heads, each of which maintains d k =d v =D model / h=12. After research, it was found that encoder-decoder is a common structure of neural networks. The encoder encodes the source sequence and transmits it to the decoder to complete the conversion of the target sequence. The self-attention mechanism in the encoder-decoder captures the global relationship between the input nodes. The calculation of attention between any two nodes is equivalent to forming a correlation coefficient matrix with a dimension of N×N. In other words, as the number of input nodes increases, the amount of calculation will increase quadratically. The attention distribution conforms to the long-tail distribution, and only a few nodes play an important role in it. The self-attention matrix can be approximated using a low-rank matrix with an error of ∈. The original Transformer is mainly used in the field of natural language processing. Transformer uses two masking mechanisms in machine translation tasks: (1) padding mask. In machine translation tasks, the length of the input sequence is not fixed. In order to facilitate computer batch processing of tensors, the language model based on Transformer generally uses the word count of the longest sentence as the batch size. Sentences of insufficient length are padded with 0 to keep the input length the same. In order to avoid the impact of padding on subsequent attention operations, a large negative number is added to the padding part so that the gradient is close to zero after passing through the softmax function. (2) Sequence mask. It is used in the cross-attention operation of the encoder-decoder to avoid label leakage of future parts.

[0083] In some embodiments, the hybrid neural network further includes a second self-attention mechanism module, and the second self-attention mechanism module includes a local mask mechanism module.

[0084] The second attention matrix contains a local mask mechanism module, such as Figure 8 The figure shows a schematic diagram of the attention mechanism in the encoder-decoder in this preferred embodiment. Figure 8 The left side shows the first self-attention mechanism module using dimensionality reduction mapping processing. The depth of the same type of squares represents the size of the attention value in the attention matrix, and the alternating depth indicates that the attention matrix is a sparse matrix. Figure 8The right side shows the second self-attention mechanism module using local masking. The gray masking indicates that the masking mechanism masks the attention between non-neighboring nodes in the attention matrix, retaining only relatively close nodes and improving the ability to extract local features. The local masking mechanism module can be implemented in various ways, such as by diffusing the adjacency matrix k times or by performing the bitwise addition of k-order adjacency matrices. Zeros in the masking matrix are assigned negative infinity, so that the non-local attention value is zero after the softmax function, achieving a local effect.

[0085] In order to enable the encoder-decoder to show better prediction performance in traffic flow prediction, the input data of this preferred embodiment is the feature data of each node in the same time step, in the form of an N×D m Tensor, where N is the number of nodes, D m is the dimension of the embedded data. Their feature dimensions are the same, so no padding or masking is required. Because all nodes in the sequence belong to the same time slice and there is no temporal causal relationship between nodes, sequence masking of the input sequence is not required in the decoder. In the preferred embodiment, the decoder uses local masking to capture local node features. This operation enhances the model's ability to learn graph structure and local features, improving model performance while reducing computational complexity.

[0086] In one embodiment, a traffic flow prediction method is provided, such as Figure 9 FIG. 1 is a flow chart of a traffic flow prediction method according to an embodiment of the present invention. The method includes the following steps:

[0087] Step S801, obtaining traffic flow data of multiple road network nodes in the previous unit time;

[0088] Step S802: input the traffic flow data into a hybrid neural network trained by the hybrid neural network training method in the order of generation time, and output traffic flow prediction values of multiple road network nodes in the next unit time after being processed by the hybrid neural network.

[0089] The hybrid neural network is a hybrid neural network trained using the hybrid neural network training method in any of the above embodiments.

[0090] In order to verify the prediction performance of the hybrid neural network in the above preferred embodiment in traffic flow prediction, the following experiments were conducted:

[0091] 1. Dataset

[0092] Two real-world traffic datasets, METR-LA and PEMS-BAY, which are popular in the field of traffic flow prediction, are used in the experiments. The METR-LA dataset is collected by circular detectors on Los Angeles County highways, while the PEMS-BAY dataset is collected by the Performance Measurement System (PeMS) of the California Department of Transportation. The two datasets are aggregated into 5-minute windows, which means there are 12 time steps per hour. The details of the datasets are shown in Table 1. The traffic flow speed data of the past hour is used as input to predict the traffic flow speed of the next hour. The predefined adjacency matrix is generated by the distance-based formula, which is defined as Equation (13).

[0093]

[0094] where d ij represents the real physical distance from i to j, σ 2 is the standard deviation of the distance, ∈ is the control adjacency matrix W ij The sparsity threshold.

[0095] Table 1

[0096]

[0097] 2. Baseline Model

[0098] This model is compared and evaluated with traditional statistical algorithms and graph neural network models. The baseline models are as follows:

[0099] (1) Historical Average (HA): It uses previous data of the same period to make predictions.

[0100] (2) Support Vector Regression (SVR): This model uses a linear support vector machine to regress time series.

[0101] (3) DCRNN: Diffused Convolutional Recurrent Neural Network, which treats the graph convolution operation as a diffusion process and uses the Gate Recurrent Unit (GRU) to capture temporal features.

[0102] (4) STGCN: A spatiotemporal graph convolutional network based on GNN and RNN, which adopts two spatiotemporal convolution modules to learn spatiotemporal features through the integration of graph convolution and GRU.

[0103] (5) Graph WaveNet (GWN): This model is based on two convolution operations and does not require a predefined adjacency matrix. It mainly consists of diffuse graph convolution and gated one-dimensional dilated convolution.

[0104] (6) AGRCN: It uses node-adaptive parameter learning and data-adaptive graph generation to capture spatial features without using a predefined adjacency matrix. Stacked GRU layers are used as encoders for multi-step prediction.

[0105] 3. Experimental Setup

[0106] This model was deployed using PyTorch 1.9.0. The data was divided into three groups, including training set, validation set, and test set, with a ratio of 7:1:2. The model was trained by the Adam optimizer. Z-Score normalization was applied to the input data to make the training go smoothly and the network converge more easily. The training epochs were 100 and the batch size was 32. The learning rate, deactivation rate, and weight decay rate were set to 0.001, 0.1, and 0.0001, respectively. All models were evaluated using three widely used indicators, including mean absolute error (MAE), mean absolute percentage error (MAPE), and root mean square error (RMSE), defined as Formula (14), Formula (15), and Formula (16), respectively.

[0107]

[0108]

[0109]

[0110] where x i and represents the true value and predicted value at time step i, and Ω represents the number of observation samples.

[0111] 4. Experimental Results and Analysis

[0112] Table 2 summarizes the performance of our model and baseline models at three time granularities: 15 minutes, 30 minutes, and 60 minutes. Across different models, the errors of the three evaluation metrics for neural network models are generally significantly lower than those for traditional mathematical statistical models (HA and SVR). Traditional statistical models only consider temporal features, while neural network models take into account the graph structure. This indicates that learning the graph structure is a crucial component of modeling the spatiotemporal characteristics of traffic flow data. GWN and AGCRN use adaptive matrices during graph convolution to compensate for the shortcomings of extracting features from a fixed topology. This adaptive adjacency matrix requires no prior knowledge and is learned and modified via stochastic gradient descent. This significantly improves the performance of GWN and AGCRN over DCRNN and STGCN, which use predefined graph structures. The proposed model achieves the best results across all metrics, indicating that our model is better at learning graph structure information than traditional GNN models. Notably, even without using a predefined graph, our model has a significant performance advantage over GNN and AGCRN. This means that our model is more capable of learning spatiotemporal relationships.

[0113] Table 2

[0114]

[0115] 5. Time Consumption Comparison

[0116] The experiment compared the computation time of the linear attention (Linear) and the original full attention (Vanilla) operation proposed in the preferred embodiment of this application, and the results are shown in Table 3. The proposed model can effectively reduce the complexity and time consumption of the original attention mechanism. The time consumption (Reduction by Linear) is reduced by about 27% to 45% on the two datasets, showing a significant advantage. This is mainly due to the dimensionality reduction mapping of the attention matrix, which avoids The time complexity and memory consumption of the improved linear self-attention operation are When k<<N, the time complexity of attention operation is reduced to a linear level.

[0117] Table 3

[0118]

[0119] VI. Ablation Experiment

[0120] To demonstrate the effectiveness of each component of our proposed model, we conducted ablation experiments. Table 4 shows the average values of three metrics over 12 time steps. En-de, PE, and Mask represent encoder-decoder, position embedding, and local masking, respectively. This model includes all four elements. Experimental results demonstrate that the model can effectively extract temporal features through LSTM. The decoder structure also further improves model performance due to the local masking mechanism. The linear attention mechanism effectively captures the spatial relationships between nodes. By enhancing the position embedding, the model can more effectively learn the spatial features between nodes.

[0121] Ablation experiments demonstrate the effectiveness of each model component. If the model only uses LSTM modules, it only learns the temporal dimension of the data. The addition of the encoder-decoder takes into account the spatiotemporal correlations between nodes. However, the original attention-based encoder-decoder can only calculate semantic similarity. To better capture the spatiotemporal correlations between nodes, the encoder-decoder incorporates positional and structural information by incorporating local masks and positional encodings, significantly improving the model's accuracy. The local masking strategy significantly improves accuracy because it enhances the model's ability to extract local features.

[0122] Table 4

[0123]

[0124] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.

[0125] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 10As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a hybrid neural network training method and a traffic flow prediction method are implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse.

[0126] Those skilled in the art will understand that Figure 10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0127] In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor implements the traffic flow prediction method in the above embodiment when executing the computer program.

[0128] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the traffic flow prediction method in the above embodiment is implemented.

[0129] In one embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the traffic flow prediction method in the above embodiment is implemented.

[0130] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0131] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.

[0132] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0133] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.

Claims

1. A hybrid neural network training method for traffic flow prediction, characterized in that: The hybrid neural network includes an LSTM module and a first self-attention mechanism module, the LSTM module is coupled to the first self-attention mechanism module, the first self-attention mechanism module includes an attention matrix processed by dimensionality reduction mapping, and the method includes: Obtain traffic flow data for multiple road network nodes; Inputting the traffic flow data into the hybrid neural network for training to obtain a trained hybrid neural network; The hybrid neural network further includes a position embedding module, wherein an input end of the position embedding module is connected to an output end of the LSTM module, and an output end of the position embedding module is connected to an input end of the first self-attention mechanism module, wherein the position embedding module is used to perform position encoding on the output data of the LSTM module; Obtaining the attention matrix processed by the dimensionality reduction mapping includes: Obtain a query matrix, a key matrix, and a value matrix based on the output data of the LSTM module; Obtaining a mapping matrix, and performing dimensionality reduction mapping on the product of the query matrix and the key matrix according to the mapping matrix to obtain a first correlation matrix; The value matrix is subjected to dimensionality reduction mapping according to the mapping matrix, and the attention matrix is obtained according to the first correlation matrix and the value matrix after dimensionality reduction mapping.

2. The hybrid neural network training method according to claim 1, characterized in that: After performing dimensionality reduction mapping on the product of the query matrix and the key matrix using a mapping matrix to obtain a first relevance matrix, the method further includes: The first correlation matrix is processed by one of the following processes: normalization processing, scaling processing, and function mapping processing.

3. The hybrid neural network training method according to claim 1, characterized in that: Obtaining a query matrix, a key matrix, and a value matrix according to the output data of the LSTM module includes: The output data of the LSTM module is divided into a plurality of sub-output data, and a corresponding sub-query matrix, a sub-key matrix and a sub-value matrix are obtained according to each sub-output data.

4. The hybrid neural network training method according to claim 3, characterized in that: Obtaining the attention matrix processed by the dimensionality reduction mapping includes: Performing dimensionality reduction mapping on the product of the sub-query matrix and the sub-key matrix corresponding to each sub-output data according to the mapping matrix to obtain a first sub-correlation matrix; Performing dimensionality reduction mapping on the sub-value matrix corresponding to each sub-output data according to the mapping matrix, and obtaining a sub-attention matrix according to the first sub-correlation matrix and the sub-value matrix after dimensionality reduction mapping; The attention matrix is obtained according to a plurality of sub-attention matrices.

5. The hybrid neural network training method according to claim 1, characterized in that: The hybrid neural network also includes a second self-attention mechanism module, which includes a local mask mechanism module.

6. A traffic flow prediction method, characterized in that: The method comprises: Obtain traffic flow data of multiple road network nodes in the last unit time; The traffic flow data is input into a hybrid neural network trained by the hybrid neural network training method according to any one of claims 1 to 5 in the order of generation time, and after being processed by the hybrid neural network, the traffic flow prediction values of the multiple road network nodes in the next unit time are output.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Highway traffic flow prediction method

    CN111275971A