Traffic flow prediction method and device
By using the encoder and decoder structure of the timing prediction model in traffic flow prediction, the hierarchical feature pyramid is extracted for prediction, which solves the problems of inaccurate traffic prediction and increased training time in the prior art, and achieves more accurate prediction result.
Patent Information
- Application Number
- CN202310103576.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-16
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2043-01-16
AI Technical Summary
In the existing traffic flow prediction methods, models based on convolutional neural networks and recurrent neural networks are difficult to effectively utilize the characteristics of spatiotemporal sequences, resulting in inaccurate prediction results, and there are problems such as gradient disappearance, gradient explosion and inability to train in parallel.
The timing prediction model is adopted to extract the hierarchical feature pyramid in the traffic information through the encoder structure, and input the decoder structure with the initial trend term and the initial residual term. The hierarchical feature pyramid is used to predict the traffic flow, and a multi-layer encoder is used. The and decoder structure includes a timing self-attention module, a spatial self-attention module and a graph convolution module to perform feature extraction and prediction.
It improves the accuracy of traffic flow prediction, solves the problem that model training time increases with the sequence length, and realizes feature extraction and timing generation from local to global, and outputs prediction information is more accurate.
Smart Images

Figure CN116246464B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of traffic monitoring, and in particular to a method and device for predicting traffic flow. Background Art
[0002] Spatiotemporal series prediction is a direction of time series prediction. With the excellent results achieved by deep learning in computer vision and natural language processing, this field has also developed by leaps and bounds. In the field of transportation, by training the model with historical data, the model can learn the regular features in the data and make accurate predictions for the future.
[0003] Most of the existing technologies are based on models that combine convolutional neural networks and recurrent neural networks with graph neural networks. Since convolutional neural networks are a type of model proposed based on image recognition, many models based on convolutional neural networks cannot make good use of the characteristics of time series in spatiotemporal sequences, making it difficult to model the regularity in the data and making it difficult to accurately predict the future. Recurrent neural networks are a type of model proposed based on sequence modeling. The structure of this type of model is designed for sequence modeling, so it can fit the characteristics of spatiotemporal sequences well. However, as the length of the sequence increases, the model has problems such as gradient vanishing or gradient explosion, making the model difficult to train. Not only that, this type of model also has the problem of being unable to be trained in parallel, resulting in the training time increasing with the increase of sequence length.
[0004] Therefore, most existing technologies directly copy the basic architecture of graph neural networks and integrate them into their own models. In this way, they do not combine the data characteristics of spatiotemporal series for prediction, resulting in inaccurate prediction results.
[0005] Therefore, the prior art has defects and needs to be improved and developed. Summary of the invention
[0006] The technical problem to be solved by the present invention is to provide a traffic flow prediction method and device in view of the above-mentioned defects of the prior art, aiming to solve the problem that the prediction results obtained when using a model to predict traffic flow in the prior art are not accurate.
[0007] The technical solution adopted by the present invention to solve the technical problem is as follows:
[0008] A traffic flow prediction method, the method comprising:
[0009] Obtaining traffic flow information in a current time period, and inputting the traffic flow information into a pre-trained time series prediction model;
[0010] Extracting effective features from the traffic flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid;
[0011] An initial trend item and an initial residual item are obtained according to the vehicle flow information, the initial trend item and the initial residual item are input into the decoder structure of the time series prediction model, and the vehicle flow prediction information in the next time period is obtained according to the hierarchical feature pyramid.
[0012] In one implementation, before extracting effective features from the traffic flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid, the method further includes:
[0013] Normalizing the vehicle flow information in the time series prediction model to obtain normalized data;
[0014] Using fast Fourier transform to obtain the Fourier features of each node in the normalized data, and using linear transformation to map the Fourier features of each node to a high dimension;
[0015] Mapping the normalized data to a high dimension using a linear transformation method and then performing temporal position encoding to obtain encoded data;
[0016] The sum of the encoded data and the Fourier characteristics is used as input data of the encoder structure.
[0017] In one implementation, the encoder structure includes a multi-layer encoder; extracting effective features from the vehicle flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid includes:
[0018] After processing the vehicle flow information into input data of an encoder structure, extracting effective features from the vehicle flow information through multiple layers of encoders in sequence, and outputting corresponding feature extraction information after passing through each layer of encoders;
[0019] Extract information based on each of the features to obtain a hierarchical feature pyramid;
[0020] Among them, the feature extraction information output by the previous layer encoder is used as the input data of the next layer encoder.
[0021] In one implementation, each layer of the encoder includes: a temporal self-attention module, a first temporal decomposition module, a spatial self-attention module, and a graph convolution module;
[0022] In each layer of the encoder, the step of extracting effective features from the input data includes:
[0023] Obtain input data, input the input data into the temporal self-attention module, and extract temporal features from the input data;
[0024] Inputting the time series feature into the first time series decomposition module to obtain a first moving average value;
[0025] Inputting the first moving average into the graph convolution module to obtain a static graph feature, and inputting the first moving average into the spatial self-attention module after spatial position encoding to obtain a dynamic graph feature;
[0026] The static image features are spliced with the dynamic image features, and the spliced static image features and dynamic image features are subjected to spatial feature fusion processing to obtain a spatial feature fusion result;
[0027] Inputting the spatial feature fusion result into the first time series decomposition module to obtain a second moving average;
[0028] The second moving average is subjected to time series feature fusion processing to obtain feature extraction information.
[0029] In one implementation, each layer of the encoder further includes: a graph structure learning module;
[0030] Inputting the first moving average into the graph convolution module to obtain static graph features includes:
[0031] If an adjacency matrix exists in the first moving average, inputting the first moving average into the graph convolution module;
[0032] If the adjacency matrix does not exist in the first moving average, the first moving average is input into the graph structure learning module to construct an adaptive adjacency matrix, and the first moving average with the adaptive adjacency matrix is input into the graph convolution module;
[0033] After the first moving average with the adjacency matrix is input into the graph convolution module, neighbor information and node information are obtained, and feature transformations of the neighbor information and the node information are separated to obtain neighbor features and node features, and at the same time, the neighbor features are constrained by using a gated linear unit;
[0034] The neighbor features and the node features are fused to obtain static graph features.
[0035] In one implementation, an initial trend item and an initial residual item are obtained according to the vehicle flow information, the initial trend item and the initial residual item are input into a decoder structure of the time series prediction model, and vehicle flow prediction information in the next time period is obtained according to the hierarchical feature pyramid, including:
[0036] Acquire the normalized traffic flow information, and decompose each traffic flow data in the normalized traffic flow information into an observation value trend item and an observation value residual item;
[0037] Filling the average value of the trend items of the observed values as the trend item of the value to be predicted to obtain the trend item to be predicted, and initializing the residual item to be predicted to zero;
[0038] The observed value trend item and the to-be-predicted trend item are concatenated to obtain an initial trend item, and the observed value residual item and the to-be-predicted residual item are concatenated to obtain an initial residual item;
[0039] The initial trend term and the initial residual term are input into the decoder structure of the time series prediction model, and the traffic flow prediction information in the next time period is obtained according to the hierarchical feature pyramid.
[0040] In one implementation, the decoder structure includes multiple layers of decoders, and each layer of decoders corresponds to a layer of encoder;
[0041] Inputting the initial trend term and the initial residual term into the decoder structure of the time series prediction model, and obtaining the traffic flow prediction information in the next time period according to the hierarchical feature pyramid, including:
[0042] In the time series prediction model, the initial trend item, the initial residual item and the hierarchical feature pyramid are subjected to trend prediction processing in turn through multiple layers of decoders, and corresponding trend item prediction values and residual item prediction values are output after passing through each layer of decoders;
[0043] The trend item prediction value and residual item prediction value output by the last layer decoder are added together, and the fully connected layer is used to process the traffic flow prediction information for the next time period.
[0044] Among them, the trend item input data of the first layer decoder is the initial trend item, and the residual item input data of the first layer decoder is the initial residual item; the trend item prediction value output by the previous layer decoder is used as the trend item input data of the next layer decoder, and the residual item prediction value output by the previous layer decoder is used as the residual item input data of the next layer decoder.
[0045] In one implementation, each layer of the decoder includes: a masked temporal self-attention module, a second temporal decomposition module, a temporal cross-attention module, and a forward propagation module;
[0046] In each layer of the decoder, the step of performing trend prediction processing on the initial trend item, the initial residual item and the hierarchical feature pyramid comprises:
[0047] Obtain trend item input data and residual item input data, add temporal position encoding to the residual item input data and then input the data into the mask temporal self-attention module to obtain a mask temporal processing result;
[0048] Inputting the masked time series processing result into the second time series decomposition module to obtain a first trend term and a first residual term;
[0049] Obtain target feature extraction information output by the corresponding level encoder, and input the target feature extraction information and the first residual term into the temporal cross attention module;
[0050] Extracting effective prediction features from the target feature extraction information in the temporal cross attention module, and fusing the effective prediction features into the first residual term to obtain temporal cross fusion data;
[0051] Inputting the time series cross-fusion data into the second time series decomposition module to obtain a second trend term and a second residual term;
[0052] Inputting the second residual term into the forward propagation module, performing nonlinear change processing on the decoder structure, and obtaining second trend term processing data;
[0053] Inputting the second trend item processed data into the second time series decomposition module to obtain a residual item prediction value and a third trend item;
[0054] The first trend item, the second trend item and the third trend item are added together to obtain a trend item sum, and the trend item sum is subjected to trend feature fusion processing with the trend item input data to obtain a trend item prediction value.
[0055] In one implementation, the traffic flow prediction method further includes:
[0056] The initial time series prediction model is trained using the mean absolute value error loss function, and the graph convolution module of the encoder structure is trained using the cross entropy loss function to obtain a trained time series prediction model; the initial time series prediction model is a Transformer model.
[0057] The present invention also provides a traffic flow prediction device, the device comprising:
[0058] An input module, used to obtain traffic flow information in the current time period, process the traffic flow information into input data, and then input the data into a pre-trained time series prediction model;
[0059] An extraction module, used for extracting effective features in the input data in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid;
[0060] A prediction module is used to obtain an initial trend item and an initial residual item according to the traffic flow information, input the initial trend item and the initial residual item into the decoder structure of the time series prediction model, and obtain traffic flow prediction information in the next time period according to the hierarchical feature pyramid.
[0061] The present invention also provides a terminal, comprising: a memory, a processor, and a traffic flow prediction program stored in the memory and executable on the processor, wherein the traffic flow prediction program implements the steps of the traffic flow prediction method described above when executed by the processor.
[0062] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program can be executed to implement the steps of the traffic flow prediction method as described above.
[0063] The present invention provides a traffic flow prediction method and device, the method comprising: obtaining vehicle flow information in a current time period, inputting the vehicle flow information into a pre-trained time series prediction model; extracting effective features in the vehicle flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid; obtaining an initial trend item and an initial residual item according to the vehicle flow information, inputting the initial trend item and the initial residual item into the decoder structure of the time series prediction model, and obtaining vehicle flow prediction information in the next time period according to the hierarchical feature pyramid. The present invention constructs a hierarchical feature pyramid from local to global after extracting effective features of the vehicle flow information in the encoder structure, and uses the hierarchical feature pyramid to perform time series generation, so that the output vehicle flow prediction information in the next time period is more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 It is a flow chart of a preferred embodiment of the traffic flow prediction method in the present invention.
[0065] Figure 2 It is a principle block diagram of the encoder structure in the present invention.
[0066] Figure 3 It is a data flow principle diagram of the encoder structure and the decoder structure in the present invention.
[0067] Figure 4 It is a principle block diagram of the decoder structure in the present invention.
[0068] Figure 5 This is the verification result of the present invention on the public data sets of PEMSD3, PEMSD4, and PEMSD8.
[0069] Figure 6It is a functional principle block diagram of a preferred embodiment of the traffic flow prediction device in the present invention.
[0070] Figure 7 It is a functional principle block diagram of a preferred embodiment of the terminal in the present invention. DETAILED DESCRIPTION
[0071] In order to make the purpose, technical solution and advantages of the present invention clearer and more specific, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0072] See also Figure 1 , Figure 1 It is a flow chart of traffic flow prediction in the present invention. Figure 1 As shown, the traffic flow prediction described in the embodiment of the present invention includes:
[0073] Step S100: Obtain traffic flow information in the current time period, and input the traffic flow information into a pre-trained time series prediction model.
[0074] Specifically, sensors are set at each intersection to collect traffic flow data and obtain traffic flow information, which can be traffic flow data within one hour before the current time of a certain intersection. The traffic flow information is input into a pre-trained time series prediction model to obtain traffic flow prediction data for the next time period of the intersection.
[0075] like Figure 1 As shown, the traffic flow prediction described in this embodiment also includes:
[0076] Step S200: extracting effective features from the input data in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid.
[0077] Specifically, the time series prediction model follows the encoder-decoder structure in the Tranformer framework, uses the encoder structure to extract effective features from the observations, and generates predictions through the decoder structure. The present invention extracts effective features from vehicle flow information to obtain a hierarchical feature pyramid, so that the prediction of the decoder structure is more accurate.
[0078] In one implementation, before step S200, the step further includes:
[0079] Step S110, normalizing the vehicle flow information in the time series prediction model to obtain normalized data;
[0080] Step S120, using fast Fourier transform to obtain the Fourier features of each node in the normalized data, and using linear transformation to map the Fourier features of each node to a high dimension;
[0081] Step S130, mapping the normalized data to a high dimension by linear transformation and then performing temporal position encoding to obtain encoded data;
[0082] Step S140: Use the sum of the encoded data and the Fourier characteristics as input data of the encoder structure.
[0083] The present invention first normalizes the traffic flow information and performs a fast Fourier transform. As we all know, there are many natural noises in the collected data, which disturb the original signal. Fourier features can reduce the impact of noise on data features, making the model more robust to data features. By using fast Fourier transform, we can obtain the Fourier features of each node in the data, and then use linear changes to map the Fourier features of the node to a high dimension and add it to the input data. The present invention uses a one-dimensional convolution to convert the input dimension to the dimension required for the model input.
[0084] In one implementation, the encoder structure includes a multi-layer encoder; the step S200 specifically includes:
[0085] Step S210, after processing the vehicle flow information into input data of an encoder structure, extracting effective features from the vehicle flow information through multiple layers of encoders in sequence, and outputting corresponding feature extraction information after passing through each layer of encoders;
[0086] Step S220: extract information based on each of the features to obtain a hierarchical feature pyramid.
[0087] Among them, the feature extraction information output by the previous layer encoder is used as the input data of the next layer encoder.
[0088] Specifically, the hierarchical modeling idea is used in the multi-layer encoder to continuously integrate the data features of the time axis to construct a hierarchical feature pyramid from local to global.
[0089] In one embodiment, see Figure 2 Each layer of the encoder includes: a temporal self-attention module, a first temporal decomposition module, a spatial self-attention module and a graph convolution module. In each layer of the encoder, the step of extracting effective features from the input data includes:
[0090] A1. Obtain input data, input the input data into the temporal self-attention module, and extract temporal features from the input data;
[0091] A2. Input the time series feature into the first time series decomposition module to obtain a first moving average value;
[0092] A3, inputting the first moving average into the graph convolution module to obtain static graph features, and performing spatial position encoding on the first moving average and inputting the encoding into the spatial self-attention module to obtain dynamic graph features;
[0093] A4, splicing the static image features with the dynamic image features, and performing spatial feature fusion processing on the spliced static image features and dynamic image features to obtain a spatial feature fusion result;
[0094] A5. Input the spatial feature fusion result into the first time series decomposition module to obtain a second moving average value;
[0095] A6. Perform time series feature fusion processing on the second moving average to obtain feature extraction information.
[0096] Specifically, the encoder is provided with multiple layers, such as three layers. The input data is processed in the first layer encoder, input into the temporal self-attention module to extract the temporal features, the output obtained by the temporal self-attention module is input into the temporal decomposition module, and then the results are respectively input into the spatial self-attention module and the graph convolution module, wherein the part input into the spatial self-attention module is pre-added with the spatial position coding. The outputs obtained by the above two modules are spliced together, and the convolutional neural network is used to fuse the features of the two. The fused results are then input into the temporal decomposition module, and finally the temporal features are fused. The first layer encoder outputs the first degree feature extraction information.
[0097] The data input to the second-layer encoder is the first-degree feature extraction information, and the processing steps are the same as those of the first-layer encoder. After the second-layer encoder completes processing, the second-degree feature extraction information is output; the data input to the third-layer encoder is the second-degree feature extraction information, and the processing steps are the same as those of the first-layer encoder and the second-layer encoder. After the third-layer encoder completes processing, the third-degree feature extraction information is output.
[0098] In this way, after the encoder structure, three groups of hierarchical feature pyramids with different feature extraction degrees and different temporal fusion degrees are obtained.
[0099] The input format of the time series prediction model can be the number of nodes, time series length, and feature dimension. If it is directly input into the original Transformer model, the computational complexity is O((Node*Time) 2 ), this embodiment separates spatial self-attention and temporal self-attention, and the complexity is reduced to O(Time 2 +Node2 ). Node refers to the number of nodes, and Time refers to the length of the time series.
[0100] Since the Transformer model does not distinguish the temporal relationship of data, it is necessary to add corresponding position coding to the input features. The position coding methods of the present invention include two types, one is position coding based on sine curve function, and the other is learnable position coding, and different position coding is added for the spatial attention module and the temporal attention module.
[0101] The present invention uses the spatial self-attention module to calculate feature similarity between nodes and fuse similar node features as implicit spatial modeling. As a supplement, a fixed matrix is used to propagate the features of the graph neural network as explicit spatial modeling, and the results of the two are spliced together to perform feature channel fusion through one-dimensional convolution.
[0102] In one embodiment, each layer of the encoder further includes: a graph structure learning module; the step of "inputting the first moving average into the graph convolution module to obtain static graph features" in step A4 specifically includes:
[0103] If an adjacency matrix exists in the first moving average, inputting the first moving average into the graph convolution module;
[0104] If the adjacency matrix does not exist in the first moving average, the first moving average is input into the graph structure learning module to construct an adaptive adjacency matrix, and the first moving average with the adaptive adjacency matrix is input into the graph convolution module;
[0105] After the first moving average with the adjacency matrix is input into the graph convolution module, neighbor information and node information are obtained, and feature transformations of the neighbor information and the node information are separated to obtain neighbor features and node features, and at the same time, the neighbor features are constrained by using a gated linear unit;
[0106] The neighbor features and the node features are fused to obtain static graph features.
[0107] Specifically, the original graph convolution model uses the same feature transformation parameters for neighbor nodes and self nodes, which is not very reasonable. The present invention redesigns the feature extraction method of the graph convolution model by separating the feature transformation of neighbor information and node information, and then using gated linear units to constrain important neighbor information features for neighbor information. Finally, feature fusion is performed to more accurately extract and fuse neighbor features and node features. The formula is as follows:
[0108] F node=IH (l) W (l) node ;
[0109]
[0110] H (l+1) =σ(F node +F neighbor );
[0111] Wherein, I represents the identity matrix, H represents the node feature, and W (l) node W (l) neighbor Represents the parameters of the node convolution, represents the adaptive adjacency matrix, σ represents the activation function, and W (l) neighbor represents the parameters of the neighbor convolution, the GLU represents the gated linear unit (GatedLinearUnite), which is used to extract the effective features of the neighbor nodes, the l represents the current number of network layers, and the F node represents the feature representation of the current node, the F neighbor represents the feature representation of neighbor nodes, the H (l) Represents the feature representation of the previous layer of graph convolutional network, the H (l+1) Represents the feature representation of the current graph convolutional network output.
[0112] In view of the situation where there is no adjacency matrix, the present invention proposes a method for learning the adjacency matrix for the graph convolution module. The topological structure defined according to the connection relationship is not sufficient to reflect the mutual influence relationship between nodes, so a data-driven approach is used to learn this relationship. In high-dimensional vectors, the direction of the vector is the important feature that determines the relationship between nodes. The present invention improves the calculation method of the adaptive matrix and uses cosine similarity to calculate the relationship between nodes. However, since the Softmax operation will smooth the relationship adjacency matrix, the weights of similar neighbor nodes in the final model are not much different, which undermines the original intention of using GNN for similar feature fusion. If the Topk scheme is used for masking, there is a non-differentiable situation. Therefore, the present invention adopts the Gumbel Softmax function and uses the heavy parameter technique to make the result output a relatively sparse matrix, with better prediction effect, and can ensure that the whole process is differentiable.
[0113] The formula of the graph structure learning module is expressed as:
[0114]
[0115] Wherein, E represents the spatial embedding parameter of the node, which is obtained by random initialization, and the correct node spatial embedding vector is gradually obtained during the training process.
[0116] like Figure 1 As shown, the traffic flow prediction described in this embodiment also includes:
[0117] Step S300: obtaining an initial trend item and an initial residual item according to the vehicle flow information, inputting the initial trend item and the initial residual item into the decoder structure of the time series prediction model, and obtaining vehicle flow prediction information for the next time period according to the hierarchical feature pyramid.
[0118] Specifically, the present invention uses a hierarchical feature pyramid from global to local in the encoder output to generate time series, so that the traffic flow prediction information in the next time period output by the model is more accurate.
[0119] In one implementation, step S300 specifically includes:
[0120] Step S310: acquiring the normalized vehicle flow information, and decomposing each vehicle flow data in the normalized vehicle flow information into an observation value trend item and an observation value residual item;
[0121] Step S320, filling the average value of each of the observed value trend items as the trend item of the value to be predicted to obtain the trend item to be predicted, and initializing the residual item to be predicted to zero;
[0122] Step S330, concatenating the observed value trend item and the to-be-predicted trend item to obtain an initial trend item, and concatenating the observed value residual item and the to-be-predicted residual item to obtain an initial residual item;
[0123] Step S340: input the initial trend term and the initial residual term into the decoder structure of the time series prediction model, and obtain the traffic flow prediction information in the next time period according to the hierarchical feature pyramid.
[0124] Specifically, the normalized vehicle flow information is decomposed into trend items and residual items using the time series decomposition module, the average value of the trend items is used as the trend item of the value to be predicted, and the residual item of the value to be predicted is initialized to zero. That is, the vehicle flow information includes multiple data, each of which is decomposed into trend items and residual items, which are called observed value trend items and observed value residual items. The decoder structure in the present invention can obtain more accurate prediction results by using the output of the encoder, the initial trend item and the initial residual item to predict the final result.
[0125] In one embodiment, the decoder structure includes multiple layers of decoders, and each layer of decoders corresponds to a layer of encoder. The step S340 specifically includes:
[0126] Step S341, in the time series prediction model, the initial trend item, the initial residual item and the hierarchical feature pyramid are subjected to trend prediction processing in turn through multi-layer decoders, and the corresponding trend item prediction value and residual item prediction value are output after passing through each layer of decoders;
[0127] Step S342: Add the trend item prediction value and the residual item prediction value output by the last layer decoder, and use the fully connected layer to process to obtain the traffic flow prediction information for the next time period.
[0128] Among them, the trend item input data of the first layer decoder is the initial trend item, and the residual item input data of the first layer decoder is the initial residual item; the trend item prediction value output by the previous layer decoder is used as the trend item input data of the next layer decoder, and the residual item prediction value output by the previous layer decoder is used as the residual item input data of the next layer decoder.
[0129] Specifically, the decoder is also provided with multiple layers, such as three layers. Figure 3 , the corresponding level encoder of the first layer decoder is the third layer encoder, the corresponding level encoder of the second layer decoder is the second layer encoder, and the corresponding level encoder of the third layer decoder is the first layer encoder. The processing process of each layer decoder is the same, but the input data is different. The input data of the first layer decoder is the initial trend item and the initial residual item, and the third degree feature extraction information output by the third layer encoder is used, and the output data is the first trend item prediction value and the first residual item prediction value; the input data of the second layer decoder is the first trend item prediction value and the first residual item prediction value, and the second degree feature extraction information output by the second layer encoder is used, and the output data is the second trend item prediction value and the second residual item prediction value; the input data of the third layer decoder is the second trend item prediction value and the second residual item prediction value, and the first degree feature extraction information output by the first layer encoder is used to obtain the third trend item prediction value and the third residual item prediction value, and the trend item prediction value and the residual item prediction value are added, and the traffic flow prediction information for the next time period is obtained by processing with the fully connected layer.
[0130] In one embodiment, see Figure 4 Each layer of the decoder includes: a masked temporal self-attention module, a second temporal decomposition module, a temporal cross-attention module and a forward propagation module. In each layer of the decoder, the steps of performing trend prediction processing on the initial trend item, the initial residual item and the hierarchical feature pyramid include:
[0131] Step B1, obtaining trend item input data and residual item input data, adding temporal position encoding to the residual item input data and inputting the data into the mask temporal self-attention module to obtain a mask temporal processing result;
[0132] Step B2, inputting the masked time series processing result into the second time series decomposition module to obtain a first trend term and a first residual term;
[0133] Step B3, obtaining target feature extraction information output by the corresponding level encoder, and inputting the target feature extraction information and the first residual term into the temporal cross attention module;
[0134] Step B4: extracting effective prediction features from the target feature extraction information in the temporal cross attention module, and fusing the effective prediction features into the first residual term to obtain temporal cross fusion data;
[0135] Step B5, inputting the time series cross-fusion data into the second time series decomposition module to obtain a second trend term and a second residual term;
[0136] Step B6, inputting the second residual term into the forward propagation module, performing nonlinear change processing on the decoder structure, and obtaining second trend term processing data;
[0137] Step B7, inputting the second trend item processed data into the second time series decomposition module to obtain a residual item prediction value and a third trend item;
[0138] Step B8: Add the first trend item, the second trend item and the third trend item to obtain a trend item sum, perform trend feature fusion processing on the trend item sum and the trend item input data to obtain a trend item prediction value.
[0139] Specifically, the decoder structure of the present invention uses the output of the encoder, the features to be predicted and the initial trend term to predict the final result. The features to be predicted are composed of the observed value and the residual term of the value to be predicted, and the residual term of the value to be predicted is initialized to zero. The initial trend term is composed of the trend term of the spliced observed value and the average value of the observed value. The decoder structure also uses the traditional time series decomposition algorithm to decompose the generated time series, and finally makes the final prediction by merging the trend term and the residual term. By using the hierarchical feature pyramid from global to local in the encoder output to generate time series, the model can obtain more accurate prediction results. In addition, a gating mechanism similar to that in the gated convolution unit is added between different decoder layers to ensure the effective features of the items to be predicted, thereby improving the model performance.
[0140] The present invention only adds the trend item prediction value and the residual item prediction value output by the last layer of decoder, and uses the fully connected layer to obtain the prediction value of future data. In this way, the time series features from global to local can be learned in the decoder structure, thereby improving the final prediction performance.
[0141] In one embodiment, the traffic flow prediction method also includes: training an initial time series prediction model using a mean absolute value error loss function, and training a graph convolution module of an encoder structure using a cross entropy loss function to obtain a trained time series prediction model; the initial time series prediction model is a Transformer model.
[0142] Specifically, the present invention selects a combined loss function when training the model. First, the mean absolute error loss function is used to measure the deviation of the model's prediction results from the true value, so that the model can make accurate predictions. Secondly, the cross entropy loss function is used to classify the feature modeling results of the graph convolution module, in order to distinguish the different features between nodes as much as possible, thereby reducing the problem of over-smoothing of the model.
[0143] In addition, in the time series decomposition module, the present invention uses a moving average algorithm to obtain the trend cycle term of the time series feature, and then subtracts the trend cycle term from the time series feature to obtain the residual term. By continuously disassembling the trend term and the residual term, the model can model periodic sequences of different degrees in the time series, and finally learn more accurate data features. The formula of the time series decomposition module is expressed as:
[0144] Trend=MA(X T:T+H );
[0145] Residual=X T:T+H -Trend;
[0146] Wherein, the X is input data, and the MA represents a moving average function.
[0147] At the end of the encoder structure, the average pooling layer is used to fuse the features of adjacent time series and gradually build the global feature pattern of the spatiotemporal sequence, and finally summarize the hierarchical time series feature pyramid. In this way, when the decoder structure generates the target sequence to be predicted, it uses the input features of the observation value from the global to the local, so as to make more accurate predictions.
[0148] The present invention uses the Transformer framework to perform time series training to address many problems of convolutional neural networks and recurrent neural networks. The Transformer framework was proposed and widely used to solve natural language processing problems. Therefore, this architecture can solve sequence modeling problems and is well suited to spatiotemporal sequence prediction problems. Secondly, the Transformer framework can be performed through parallel training, thereby solving the problem that the training duration is positively correlated with the sequence length.
[0149] In addition, in the prior art, most technologies must use pre-defined topological structures to propagate features, but in real scenarios, topological structures are often incomplete or even missing, and the lack of topological structures may render the model unusable. The present invention redesigns the module of graph neural networks for spatial modeling for spatiotemporal sequence prediction. By using a data-driven learnable adjacency matrix, the trained model can work normally in the absence of a topological structure. And by using the decomposed spatiotemporal attention mechanism, the model can not only perform long-distance modeling, but also greatly reduce the amount of model calculations. At the same time, the present invention also reduces the over-smoothing problem of graph neural networks by combining loss functions to ensure the extraction of effective features.
[0150] At present, the model has been verified on public datasets such as PEMSD3, PEMSD4, and PEMSD8, and has achieved the following results: Figure 5 It can be seen that the model of the present invention not only achieves excellent results, but also has a significantly improved prediction effect compared to other models.
[0151] In one embodiment, if Figure 6 As shown, based on the above traffic flow prediction method, the present invention also provides a traffic flow prediction device, including:
[0152] An input module 100 is used to obtain traffic flow information in a current time period and input the traffic flow information into a pre-trained time series prediction model;
[0153] An extraction module 200 is used to extract effective features in the vehicle flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid;
[0154] The prediction module 300 is used to obtain an initial trend item and an initial residual item based on the traffic flow information, input the initial trend item and the initial residual item into the decoder structure of the time series prediction model, and obtain the traffic flow prediction information in the next time period based on the hierarchical feature pyramid.
[0155] In one embodiment, the present invention also provides a terminal, such as Figure 7As shown, it includes: a memory 20, a processor 10, and a traffic flow prediction program 30 stored in the memory 20 and executable on the processor 10. When the traffic flow prediction program 30 is executed by the processor 10, the steps of the traffic flow prediction method described above are implemented.
[0156] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program can be executed to implement the steps of the traffic flow prediction method as described above.
[0157] In summary, the present invention discloses a method and device for predicting traffic flow, the method comprising: obtaining traffic flow information in the current time period, inputting the traffic flow information into a pre-trained time series prediction model; extracting effective features from the traffic flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid; obtaining an initial trend item and an initial residual item based on the traffic flow information, inputting the initial trend item and the initial residual item into the decoder structure of the time series prediction model, and obtaining traffic flow prediction information for the next time period based on the hierarchical feature pyramid. The present invention constructs a hierarchical feature pyramid from local to global after extracting effective features of the traffic flow information in the encoder structure, and uses the hierarchical feature pyramid to perform time series generation, so that the output traffic flow prediction information for the next time period is more accurate.
[0158] It should be understood that the application of the present invention is not limited to the above examples. For ordinary technicians in this field, improvements or changes can be made based on the above description. All these improvements and changes should fall within the scope of protection of the claims attached to the present invention.
Claims
1. A traffic flow prediction method, characterized in that: The method comprises: Obtaining traffic flow information in a current time period, and inputting the traffic flow information into a pre-trained time series prediction model; Extracting effective features from the traffic flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid; Obtaining an initial trend term and an initial residual term according to the vehicle flow information, inputting the initial trend term and the initial residual term into a decoder structure of the time series prediction model, and obtaining vehicle flow prediction information in the next time period according to the hierarchical feature pyramid; The time series prediction model follows the encoder-decoder structure in the Tranformer framework, uses the encoder structure to extract effective features from the observations, and generates predictions through the decoder structure; The encoder structure includes a multi-layer encoder; extracting effective features from the vehicle flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid includes: After processing the vehicle flow information into input data of an encoder structure, extracting effective features from the vehicle flow information through multiple layers of encoders in sequence, and outputting corresponding feature extraction information after passing through each layer of encoders; Extract information based on each of the features to obtain a hierarchical feature pyramid; Among them, the feature extraction information output by the previous layer encoder is used as the input data of the next layer encoder; Each layer of the encoder includes: a temporal self-attention module, a first temporal decomposition module, a spatial self-attention module, and a graph convolution module; In each layer of the encoder, the step of extracting effective features from the input data includes: Obtain input data, input the input data into the temporal self-attention module, and extract temporal features from the input data; Inputting the time series feature into the first time series decomposition module to obtain a first moving average value; Inputting the first moving average into the graph convolution module to obtain a static graph feature, and inputting the first moving average into the spatial self-attention module after spatial position encoding to obtain a dynamic graph feature; The static image features are spliced with the dynamic image features, and the spliced static image features and dynamic image features are subjected to spatial feature fusion processing to obtain a spatial feature fusion result; Inputting the spatial feature fusion result into the first time series decomposition module to obtain a second moving average; The second moving average is subjected to time series feature fusion processing to obtain feature extraction information.
2. The traffic flow prediction method according to claim 1, characterized in that: Before extracting effective features from the traffic flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid, the method further includes: Normalizing the vehicle flow information in the time series prediction model to obtain normalized data; Using fast Fourier transform to obtain the Fourier features of each node in the normalized data, and using linear transformation to map the Fourier features of each node to a high dimension; Mapping the normalized data to a high dimension using a linear transformation method and then performing temporal position encoding to obtain encoded data; The sum of the encoded data and the Fourier characteristics is used as input data of the encoder structure.
3. The traffic flow prediction method according to claim 1, characterized in that: Each layer of encoder also includes: a graph structure learning module; Inputting the first moving average into the graph convolution module to obtain static graph features includes: If an adjacency matrix exists in the first moving average, inputting the first moving average into the graph convolution module; If the adjacency matrix does not exist in the first moving average, the first moving average is input into the graph structure learning module to construct an adaptive adjacency matrix, and the first moving average with the adaptive adjacency matrix is input into the graph convolution module; After the first moving average with the adjacency matrix is input into the graph convolution module, neighbor information and node information are obtained, and feature transformations of the neighbor information and the node information are separated to obtain neighbor features and node features, and at the same time, the neighbor features are constrained by using a gated linear unit; The neighbor features and the node features are fused to obtain static graph features.
4. The traffic flow prediction method according to claim 1, characterized in that: Obtaining an initial trend item and an initial residual item according to the vehicle flow information, inputting the initial trend item and the initial residual item into a decoder structure of the time series prediction model, and obtaining vehicle flow prediction information in the next time period according to the hierarchical feature pyramid, including: Acquire the normalized traffic flow information, and decompose each traffic flow data in the normalized traffic flow information into an observation value trend item and an observation value residual item; Filling the average value of the trend items of the observed values as the trend item of the value to be predicted to obtain the trend item to be predicted, and initializing the residual item to be predicted to zero; The observed value trend item and the to-be-predicted trend item are concatenated to obtain an initial trend item, and the observed value residual item and the to-be-predicted residual item are concatenated to obtain an initial residual item; The initial trend term and the initial residual term are input into the decoder structure of the time series prediction model, and the traffic flow prediction information in the next time period is obtained according to the hierarchical feature pyramid.
5. The traffic flow prediction method according to claim 4, characterized in that: The decoder structure includes multiple layers of decoders, and each layer of decoders corresponds to a layer of encoder; Inputting the initial trend term and the initial residual term into the decoder structure of the time series prediction model, and obtaining the traffic flow prediction information in the next time period according to the hierarchical feature pyramid, including: In the time series prediction model, the initial trend item, the initial residual item and the hierarchical feature pyramid are subjected to trend prediction processing in turn through multiple layers of decoders, and corresponding trend item prediction values and residual item prediction values are output after passing through each layer of decoders; The trend item prediction value and residual item prediction value output by the last layer decoder are added together, and the fully connected layer is used to process the traffic flow prediction information for the next time period. Among them, the trend item input data of the first layer decoder is the initial trend item, and the residual item input data of the first layer decoder is the initial residual item; the trend item prediction value output by the previous layer decoder is used as the trend item input data of the next layer decoder, and the residual item prediction value output by the previous layer decoder is used as the residual item input data of the next layer decoder.
6. The traffic flow prediction method according to claim 5, characterized in that: Each layer of the decoder includes: a masked temporal self-attention module, a second temporal decomposition module, a temporal cross-attention module and a forward propagation module; In each layer of the decoder, the step of performing trend prediction processing on the initial trend item, the initial residual item and the hierarchical feature pyramid comprises: Obtain trend item input data and residual item input data, add temporal position encoding to the residual item input data and then input the data into the mask temporal self-attention module to obtain a mask temporal processing result; Inputting the masked time series processing result into the second time series decomposition module to obtain a first trend term and a first residual term; Obtain target feature extraction information output by the corresponding level encoder, and input the target feature extraction information and the first residual term into the temporal cross attention module; Extracting effective prediction features from the target feature extraction information in the temporal cross attention module, and fusing the effective prediction features into the first residual term to obtain temporal cross fusion data; Inputting the time series cross-fusion data into the second time series decomposition module to obtain a second trend term and a second residual term; Inputting the second residual term into the forward propagation module, performing nonlinear change processing on the decoder structure, and obtaining second trend term processing data; Inputting the second trend item processed data into the second time series decomposition module to obtain a residual item prediction value and a third trend item; The first trend item, the second trend item and the third trend item are added together to obtain a trend item sum, and the trend item sum is subjected to trend feature fusion processing with the trend item input data to obtain a trend item prediction value.
7. The traffic flow prediction method according to claim 1, characterized in that: The traffic flow prediction method further includes: The initial time series prediction model is trained using the mean absolute value error loss function, and the graph convolution module of the encoder structure is trained using the cross entropy loss function to obtain a trained time series prediction model; the initial time series prediction model is a Transformer model.
8. A traffic flow prediction device, characterized in that: The device comprises: An input module, used to obtain traffic flow information in a current time period, and input the traffic flow information into a pre-trained time series prediction model; An extraction module, used to extract effective features from the traffic flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid; A prediction module, used to obtain an initial trend item and an initial residual item according to the vehicle flow information, input the initial trend item and the initial residual item into a decoder structure of the time series prediction model, and obtain vehicle flow prediction information in the next time period according to the hierarchical feature pyramid; The time series prediction model follows the encoder-decoder structure in the Tranformer framework, uses the encoder structure to extract effective features from the observations, and generates predictions through the decoder structure; The encoder structure includes a multi-layer encoder; extracting effective features from the vehicle flow information in the encoder structure of the time series prediction model to obtain a hierarchical feature pyramid includes: After processing the vehicle flow information into input data of an encoder structure, extracting effective features from the vehicle flow information through multiple layers of encoders in sequence, and outputting corresponding feature extraction information after passing through each layer of encoders; Extract information based on each of the features to obtain a hierarchical feature pyramid; Among them, the feature extraction information output by the previous layer encoder is used as the input data of the next layer encoder; Each layer of the encoder includes: a temporal self-attention module, a first temporal decomposition module, a spatial self-attention module, and a graph convolution module; In each layer of the encoder, the step of extracting effective features from the input data includes: Obtain input data, input the input data into the temporal self-attention module, and extract temporal features from the input data; Inputting the time series feature into the first time series decomposition module to obtain a first moving average value; Inputting the first moving average into the graph convolution module to obtain a static graph feature, and inputting the first moving average into the spatial self-attention module after spatial position encoding to obtain a dynamic graph feature; The static image features are spliced with the dynamic image features, and the spliced static image features and dynamic image features are subjected to spatial feature fusion processing to obtain a spatial feature fusion result; Inputting the spatial feature fusion result into the first time series decomposition module to obtain a second moving average; The second moving average is subjected to time series feature fusion processing to obtain feature extraction information.
9. A terminal, characterized in that: include: A memory, a processor, and a traffic flow prediction program stored in the memory and executable on the processor, wherein the traffic flow prediction program, when executed by the processor, implements the steps of the traffic flow prediction method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program can be executed to implement the steps of the traffic flow prediction method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Video dense description generation method based on time sequence feature pyramid
CN113392717A
Long-time-sequence traffic flow prediction method based on graph convolution-Informer model
CN113487061A