A traffic flow prediction method and system based on hierarchical attention
By employing a hierarchical attention approach, hourly, daily, and weekly channels are established. CGCN and RGAT are used to dynamically learn node weights, and RCAT is combined with fused features to solve the problem of low traffic flow prediction accuracy, achieving more precise traffic flow prediction.
Patent Information
- Application Number
- CN202311312678.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-11
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2043-10-11
AI Technical Summary
Existing traffic flow forecasting methods struggle to effectively capture the dynamic changes of specific stations and different stations under different cycle patterns, resulting in low forecast accuracy.
A hierarchical attention approach is adopted, which establishes three independent scale channels of hour, day, and week. The node weights are dynamically learned by using Coupled Graph Convolutional Network (CGCN) and Residual Graph Attention (RGAT), and traffic features are fused by Residual Channel Attention (RCAT) to achieve multi-angle dynamic learning.
It improves the accuracy of traffic flow prediction, enabling it to better fit dynamic traffic scenarios and capture the spatial, temporal, and semantic correlations between roads in the traffic network.
Smart Images

Figure CN117195976B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of traffic management, in particular to a traffic flow prediction method and system based on hierarchical attention. BACKGROUND
[0002] Accurate traffic flow prediction is an important research topic in the field of urban computing, as it can optimize traffic resource allocation and improve the efficiency of intelligent transportation systems. The large amount of traffic data generated every day provides important insights into the long-term evolution of traffic dynamics, which is indispensable for future traffic management and planning. Although there are potential benefits to utilizing traffic flow data, real-time accurate prediction of traffic flow is still a complex and multi-faceted task.
[0003] Currently, there is a trend in recent urban traffic flow prediction methods to use multivariate time series prediction to analyze the multi-period time patterns of traffic data. For example, the patent document CN113673769A entitled "Traffic flow prediction method based on multivariate time series interpolation graph neural network" discloses that the inflow and outflow of traffic are used as features of the station node itself, spatial feature sequences are learned through graph attention networks, dynamic correlations between different times are captured through time attention, and traffic flow features are obtained through long short-term memory networks.
[0004] Despite these advances, because the traffic flow at a specific station can dynamically change over time and the traffic flow at different stations exhibits different periodic patterns over time periods, the traffic data in the station exhibits dense spatio-temporal dynamics and variable multi-period time patterns, making it difficult to dynamically learn from multiple perspectives of traffic flow, and the accuracy of traffic flow prediction still faces challenges. SUMMARY
[0005] Therefore, the present application aims to provide a traffic flow prediction method and system based on hierarchical attention, which can solve the problem of difficulty in dynamically learning from multiple perspectives of traffic flow and low accuracy of traffic flow prediction, and improve the accuracy of predicting traffic flow at a specific station or different stations under different periodic patterns.
[0006] According to the traffic flow prediction method based on hierarchical attention provided by the present application, the method comprises:
[0007] Collecting historical traffic flow data of a target station, preprocessing the historical traffic flow data to obtain a traffic flow data sequence;
[0008] Three different scale channels are established, namely, a minute scale channel, a day scale channel and a week scale channel, and the three different scale channels all adopt a network structure of an input layer, a cycle layer and an output layer;
[0009] The traffic flow data sequence is divided into the three different scale channels to obtain corresponding traffic flow data subsequences;
[0010] The traffic flow data subsequences are taken as the input layer data, a relationship matrix of the traffic flow data subsequences is updated by using a coupled graph convolution network (CGCN) and a residual graph attention (RGAT) in the cycle layer, node embedding is learned at each time interval, and time sequence features of predicted traffic flow under the corresponding scale channel are obtained at the output layer;
[0011] The time sequence features of the predicted traffic flow under each scale channel are integrated by a residual channel attention (RCAT) to obtain the final predicted traffic flow.
[0012] Compared with the prior art, the traffic flow prediction method based on hierarchical attention can capture the space-time mode of traffic flow of different periods by establishing three independent scale channels of the minute scale channel, the day scale channel and the week scale channel, and effectively model the spatial, temporal and semantic correlation between roads in the traffic network; each channel adopts the network structure of the input layer, the cycle layer and the output layer, and the coupled graph recurrent unit (CGRU) is used in the cycle layer to obtain the aggregated edge weighted flow state, and the residual graph attention (RGAT) is used to dynamically learn the node weight, so as to better adapt to the real dynamic flow scene; the residual channel attention (RCAT) is used to fuse the flow features extracted by the three scale channels, and the final predicted traffic flow result is calculated, so that the traffic flow state under different space-time is dynamically learned from multiple angles, and the accuracy of the predicted traffic flow is further improved.
[0013] Further, the step of collecting historical traffic flow data of the target station, and pre-processing the historical traffic flow data to obtain a traffic flow data sequence comprises:
[0014] The historical traffic flow data is defined as a directed graph G (V, E), wherein the node V represents a station, the edge E represents the traffic flow between two stations, and the feature vector of each node V is composed of the historical on-off flow of the station;
[0015] The historical traffic flow data at t time is represented as and represent the traffic flow data of each hour, each day and each week respectively, wherein N is the number of nodes, r is the number of features, h represents hour, d represents day, and w represents week.
[0016] Further, the step of dividing the traffic flow data sequence into the three different scale channels to obtain corresponding traffic flow data sub-sequences respectively comprises:
[0017] Initializing a relationship matrix of the traffic flow data sub-sequences under different scale channels, calculating the similarity of historical traffic flow between stations, and taking the similarity as the weight of the edge.
[0018] Further, the step of initializing the relationship matrix of the traffic flow data sub-sequences under different scale channels, calculating the similarity of historical traffic flow between stations, and taking the similarity as the weight of the edge comprises:
[0019] A preset time interval τ, starting from the initial time t0, the function Mapping the traffic flow data sub-sequences to three different relationship matrices, the mapping formula is represented as:
[0020]
[0021] Wherein, , , , D and W represent the number of time intervals per day and per week respectively, wherein the function The specific operation process is:
[0022] Applying singular value decomposition SVD to the flow data to obtain a plurality of low-rank sub-matrices, and the low-rank sub-matrices are represented as:
[0023] ,
[0024] Wherein, and are low-rank sub-matrices of flow data , and and represent time-based and space-based sub-matrices respectively;
[0025] The similarity of the i-th row and the j-th row of is calculated based on the Gaussian kernel method, and the expression of the similarity as the weight of the edge is:
[0026] ,
[0027] Wherein, exp( ) represents the similarity, represents the weight of the edge of node i and node j, is the standard deviation, represents the feature vector of the i-th spatial position, a feature vector representing the jth spatial position;
[0028] at the initial time The elements of the node connection with little influence are discarded to initialize the relationship matrix, and the initialization process is represented as:
[0029] ,
[0030] where Max() represents the maximum value of elements, is a diagonal matrix, .
[0031] Further, the step of taking the traffic flow data subsequence as the input layer data, updating the relationship matrix of the traffic flow data subsequence in the cycle layer by using the coupled graph convolution network CGCN and the residual graph attention RGAT, and learning node embedding at each time interval, and obtaining the time sequence feature of the predicted traffic flow under the corresponding scale channel in the output layer includes:
[0032] The coupled graph convolution network CGCN is used to learn the relationship matrix between stations, and the traffic flow features in each time interval and the initial relationship matrix are taken as the input of graph convolution, and each layer of graph convolution extracts the expression of the corresponding station feature and the relationship matrix under the scale channel as:
[0033] ,
[0034] where K is a hyperparameter in the graph convolution network, representing the number of convolution kernels in each layer, i.e. the number of convolution kernels used in each layer, k is an index variable, representing the kth convolution kernel in the ith layer of the graph convolution network, represents the weight parameter of the kth convolution kernel in the m-1th layer, represents the total number of convolution layers, is the station feature representing the m-1th layer, is the relationship matrix representing the m-1th layer, and the is represented as:
[0035] ,
[0036] wherein, respectively represent the relationship matrix of the m-2th layer, and is obtained by SVD based on time and space Low-rank submatrix, , is the parameter of the learnable fully connected layer, and T represents the period;
[0037] evaluating the attention score of each layer relationship matrix to aggregate the site features of different layers , the aggregated feature F of the convolution is expressed as: , the as output data of the coupled graph convolution network CGCN,
[0038] wherein the is expressed as:
[0039] ,
[0040] wherein, and are learnable parameters in the fully connected layer.
[0041] Further, the step of taking the traffic flow data subsequence as the input layer data, updating the relationship matrix of the traffic flow data subsequence in the recurrent layer by using the coupled graph convolution network CGCN and the residual graph attention RGAT, and learning the node embedding at each time interval, and obtaining the time sequence feature of the predicted traffic flow under the corresponding scale channel in the output layer includes:
[0042] Adopting the residual graph attention RGAT to learn adaptive node-specific weights and embeddings to capture the dynamic traffic of each node;
[0043] edge-weighted flow state aggregating flow data of different edges input into the residual graph attention RGAT, and using the scaled dot product method to calculate the attention score , the attention score is expressed as:
[0044] ,
[0045] wherein, denotes the attention score between station a and station b, and are respectively the randomly initialized node embeddings of station a and station b at the corresponding scale, and are respectively the edge-weighted traffic flow features of station a and station b at time interval τ, aggregating traffic information from different edges, and denote respectively the concatenation operation and the inner product operation, and are respectively the learnable parameters value of the key value key and the feature information, is the dimension of the key value key and the learnable parameter value, and q represents the query;
[0046] After obtaining the attention score, a weighted sum of the relevance of all stations is calculated to obtain the latent state , which contains edge weight and node weight information, L represents L consecutive time series, and the latent state The formula is:
[0047] ,
[0048] where Softmax() represents a normalization activation function, and in the scale channel, the output latent state of RGAT is used in the recurrent layer in the encoder and the decoder to capture the time series feature , and the output layer in the decoder is composed of the latent state .
[0049] Further, the step of integrating the time series features of the predicted traffic flow in each scale channel through the residual channel attention RCAT to obtain the final predicted traffic flow comprises:
[0050] Through the P-layer dynamic residual channel attention mechanism, different weights are adaptively assigned to the flow features of each time scale, and the result after adaptive weighting of the scale channel P times is expressed as:
[0051] ,
[0052] wherein , represents the concatenation of the outputs of the hourly, daily, and weekly scale channels, represents an activation function, wherein , represents an average pooling operation, represents the learnable parameters of the pth layer fully connected network;
[0053] After applying adaptive weighting P times to the results of the three scale channels, the final prediction result is obtained by combining the results of the three scale channels, and the expression of combining the three scale channels is:
[0054] ,
[0055] wherein represents the final prediction result, represents the result after applying adaptive weighting P times to the s th scale channel.
[0056] A traffic flow prediction system based on hierarchical attention according to an embodiment of the present application, the system comprises:
[0057] A data preprocessing module for collecting historical traffic flow data of a target station, preprocessing the historical traffic flow data to obtain a traffic flow data sequence;
[0058] A channel module is built to establish three different scale channels, i.e., a minute scale channel, a day scale channel and a week scale channel, which all adopt a network structure of an input layer, a cycle layer and an output layer;
[0059] A data classification module is used to divide the traffic flow data sequence into the three different scale channels to obtain corresponding traffic flow data subsequences;
[0060] A prediction data module is used to take the traffic flow data subsequences as the input layer data, update a relation matrix of the traffic flow data subsequences by using a coupled graph convolution network (CGCN) and a residual graph attention (RGAT) in the cycle layer, learn node embedding at each time interval, and obtain a time sequence feature of predicted traffic flow under a corresponding scale channel in the output layer;
[0061] A data fusion module is used to integrate the time sequence features of predicted traffic flow under each scale channel by using a residual channel attention (RCAT) to obtain a final predicted traffic flow.
[0062] Another aspect of the present application also provides a computer readable storage medium, which stores one or more programs, and the programs are executed by a processor to implement any of the above traffic flow prediction methods.
[0063] Another aspect of the present application also provides a computer device, which comprises a memory and a processor, wherein: the processor is used to store a computer program; and the processor is used to execute the computer program stored on the memory to implement any of the above traffic flow prediction methods.
[0064] Additional aspects and advantages of the present application will be given in part in the following description, become apparent from the following description, or be understood by those skilled in the art from the embodiments of the present application. BRIEF DESCRIPTION OF DRAWINGS
[0065] Figure 1 A flow chart of a traffic flow prediction method based on hierarchical attention proposed for the first embodiment of the present application;
[0066] Figure 2 An overall architecture diagram of a traffic flow prediction method MSRGCN based on hierarchical attention in the second embodiment of the present application;
[0067] Figure 3 A flow chart of a traffic flow prediction method based on hierarchical attention proposed for the second embodiment of the present application;
[0068] Figure 4 A schematic diagram of the spatio-temporal dependency in different regions in a hierarchical attention-based traffic flow prediction method according to a second embodiment of the present application;
[0069] Figure 5 A CGCN framework diagram in the hourly scale channel of a hierarchical attention-based traffic flow prediction method according to a second embodiment of the present application;
[0070] Figure 6 An RGAT framework diagram in the hourly scale channel of a hierarchical attention-based traffic flow prediction method according to a second embodiment of the present application;
[0071] Figure 7 A structural schematic diagram of a hierarchical attention-based traffic flow prediction system according to a third embodiment of the present application. DETAILED DESCRIPTION
[0072] In order to facilitate the understanding of the present application, the present application will be described more fully below with reference to the accompanying drawings. Several embodiments of the present application are shown in the drawings. However, the present application can be realized in many different forms and is not limited to the embodiments described herein. On the contrary, these embodiments are provided for the purpose of making the disclosure of the present application more thorough and comprehensive.
[0073] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs. The terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the present application. As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0074] Referring to Figure 1 , a flowchart of a hierarchical attention-based traffic flow prediction method according to a first embodiment of the present application is shown, which comprises steps S01 to S05, wherein:
[0075] Step S01: Collect historical traffic flow data of a target site, and pre-process the historical traffic flow data to obtain a traffic flow data sequence;
[0076] Specifically, the historical traffic flow data is defined as a directed graph G(V, E), wherein the node V represents a site, the edge E represents the traffic flow between two sites, and the feature vector of each node V is composed of the historical boarding and alighting flows of the site;
[0077] The historical traffic flow data at time t is represented as and , respectively, represent the traffic flow data per hour, per day and per week, where N is the number of nodes, r is the number of features, h represents hour, d represents day, and w represents week.
[0078] Step S02: three different scale channels are established, which are an hour scale channel, a day scale channel and a week scale channel, and the three different scale channels all adopt a network structure of an input layer, a recurrent layer and an output layer;
[0079] Step S03: the traffic flow data sequence is divided into the three different scale channels to obtain corresponding traffic flow data subsequences;
[0080] It should be noted that the relationship matrix of the traffic flow data subsequence under different scale channels is initialized, the similarity of historical traffic flow between stations is calculated, and the similarity is taken as the weight of the edge;
[0081] Specifically, a preset time interval τ is set, starting from an initial time t0, and the function The traffic flow data subsequence is mapped to three different relationship matrices, and the mapping formula is represented as:
[0082]
[0083] wherein, , , D and W represent the number of time intervals per day and per week, respectively, and the function The specific operation process is as follows:
[0084] The singular value decomposition (SVD) is applied to the flow data to obtain a plurality of low-rank submatrices, and the low-rank submatrices are represented as:
[0085] ,
[0086] wherein, and are low-rank submatrices of the flow data , and represent time-based and space-based submatrices, respectively;
[0087] The similarity of the i-th row and the j-th row of is calculated based on a Gaussian kernel, and the expression of the similarity as the weight of the edge is:
[0088] ,
[0089] wherein, exp( ) represents the similarity, a weight of an edge representing node i and node j, is a standard deviation, is a feature vector representing the i-th spatial position, is a feature vector representing the j-th spatial position;
[0090] at the initial time elements of node connections with little influence are discarded to initialize the relation matrix, and the initialization process is represented as:
[0091] ,
[0092] where Max() represents taking the maximum value element by element, is a diagonal matrix, .
[0093] Step S04: taking the traffic flow data subsequence as the input layer data, updating the relation matrix of the traffic flow data subsequence in the recurrent layer by using the coupled graph convolutional network CGCN and the residual graph attention RGAT, learning node embedding at each time interval, and obtaining the time sequence feature of the predicted traffic flow under the corresponding scale channel in the output layer;
[0094] Specifically, first, the coupled graph convolutional network CGCN is used to learn the relation matrix between stations, and the traffic flow features in each time interval and the initial relation matrix are taken as the input of graph convolution, and each layer of graph convolution extracts the corresponding station features and the expression of the relation matrix under the scale channel as follows:
[0095] ,
[0096] where K is a hyperparameter in the graph convolutional network, representing the number of convolution kernels in each layer, i.e., the number of convolution kernels used in each layer, k is an index variable, representing the k-th convolution kernel in the i-th layer of the graph convolutional network, represents the weight parameter of the k-th convolution kernel in the m-1 layer, represents the total number of convolution layers, is the station feature representing the m-1 layer, is the relation matrix representing the m-1 layer, and the is represented as:
[0097] ,
[0098] wherein, respectively represent the relation matrix of the m-2 layer, and is Low-rank sub-matrices based on time and space are obtained by SVD, 、 are parameters of the learnable fully connected layer, and T represents the period;
[0099] The attention score of each layer relationship matrix is evaluated to aggregate the site features of different layers The aggregated features F of the convolution are expressed as: The as the output data of the coupled graph convolution network CGCN,
[0100] wherein the is expressed as:
[0101] ,
[0102] wherein, and are learnable parameters in the fully connected layer;
[0103] Secondly, the residual graph attention RGAT is adopted to learn adaptive node-specific weights and embeddings, capturing the dynamic traffic of each node;
[0104] The edge-weighted flow state aggregating the flow data of different edges is input into the residual graph attention RGAT, and the attention score is calculated using the scaled dot product method The attention score is expressed as:
[0105] ,
[0106] wherein, denotes the attention score between station a and station b, and are the randomly initialized node embeddings of station a and station b on the corresponding scale respectively, and are the edge-weighted traffic flow features of station a and station b respectively in the time interval τ, aggregating the traffic information from different edges, and denote the concatenation operation and the inner product operation respectively, and are the learnable parameters value of the key value key and feature information, is the dimension of the key value key and the learnable parameter value, and q represents the query;
[0107] After obtaining the attention score, the weighted sum of the relevance of all stations is calculated to obtain the latent state wherein the edge and node weighting information is contained, L denotes L continuous time series, and the latent state The formula is:
[0108] ,
[0109] wherein Softmax() denotes a normalization activation function, and in the scale channel, the recurrent layer in the encoder and the decoder uses the output latent state of the RGAT to capture the time series feature The output layer in the decoder is composed of the latent state .
[0110] Step S05: integrating the time series features of the predicted traffic flow in each scale channel through the residual channel attention RCAT to obtain the final predicted traffic flow;
[0111] Specifically, by the P-layer dynamic residual channel attention mechanism, different weights are adaptively assigned to the flow features of each time scale, and the result after adaptive weighting of the scale channel P times is expressed as:
[0112] ,
[0113] wherein , denotes the concatenation of the outputs of the hourly, daily, and weekly scale channels, denotes an activation function, wherein , denotes an average pooling operation, denotes the learnable parameters of the p-layer fully connected network;
[0114] After applying adaptive weighting P times to the results of the three scale channels, the final prediction result is obtained by combining the results of the three scale channels, and the expression of combining the three scale channels is:
[0115] ,
[0116] wherein denotes the final prediction result, denotes the result after applying adaptive weighting P times to the s-th scale channel.
[0117] In summary, according to the traffic flow prediction method based on hierarchical attention described above, by building three independent scale channels of hour scale channel, day scale channel and week scale channel, the space-time and semantic correlation between roads in the traffic network is effectively modeled by capturing the traffic flow spatio-temporal patterns of different periods; each channel adopts the network structure of input layer, cycle layer and output layer, and in the cycle layer, the coupled graph recurrent unit CGRU is used to obtain the aggregated edge weighted flow state, and then the residual graph attention RGAT is used to dynamically learn the node weight, so as to better adapt to the real dynamic flow scene; then the residual channel attention RCAT is used to fuse the traffic flow features extracted by the three scale channels, and the final predicted traffic flow result is calculated, so as to dynamically learn the traffic flow state under different space-time from multiple angles, thereby further improving the accuracy of the predicted traffic flow.
[0118] Referring to Figure 2 , which is a whole architecture diagram of the traffic flow prediction method MSRGCN based on hierarchical attention in the second embodiment of the present application;
[0119] Referring to Figure 3 , which is a flow chart of the traffic flow prediction method based on hierarchical attention in the second embodiment of the present application, the method comprises steps S101 to S105, wherein:
[0120] Step S101: dividing the traffic flow data into three time scales according to the intervals of each hour, each day and each week, and designing three independent scale channels of different periods;
[0121] It can be understood that in a region divided into residential, commercial and industrial areas, the space-time dependency of different areas may change over time, such as Figure 4 As shown in FIG. 18, the traffic between areas such as stations A and B may show regularity on the hour, day and week patterns.
[0122] The traffic flow of a specific station may dynamically change over time, for example, during the peak travel period at 18:00, the residential area may have a higher spatial dependency with the commercial area (i.e., stations A and B), but this dependency may drop significantly at 20:00. In addition, areas that are close to each other (e.g., residential and commercial areas) may exhibit strong periodicity on the three time scales, while areas that are far apart (e.g., industrial areas) may mainly exhibit a weekly pattern. Therefore, accurately modeling this complex spatial dependency is crucial for developing an accurate traffic flow prediction model, and this complexity requires the development of complex techniques that can capture the complex temporal dependency and patterns behind the traffic flow data, so the traffic flow data can be divided into three time scales according to the intervals of each hour, each day and each week, and three independent scale channels of different periods are designed.
[0123] Step S102: Initialize the relationship matrix at different time scales using traffic flow data, and calculate the similarity of historical traffic flow between stations as the weight of the edge;
[0124] Specifically, for a given τ time interval, starting from the initial time t0, the function Mapping traffic state signals from three periodic scales to three different relationship matrices can be represented as:
[0125]
[0126] wherein, , Can be used to perform graph convolution operations on the directed graph G of the traffic network to learn the spatial dependencies at the hourly, daily, and weekly scales.
[0127] wherein the function The specific operation process is described as follows: first, singular value decomposition SVD is applied to the traffic data to obtain a plurality of low-rank sub-matrices.
[0128] Taking the weekly scale as an example, it can be expressed as:
[0129] ,
[0130] wherein, , and is a low-rank sub-matrix of , , represent time-based and space-based sub-matrices, respectively. In order to reduce the dimension and as accurately as possible to describe the relationship between stations, redundant information is filtered out from the space-based sub-matrix . The similarity of the i-th row and the j-th row of is calculated as the edge weight value in the adjacency matrix using the Gaussian kernel-based method, which can be represented as:
[0131] ,
[0132] wherein exp( ) represents the similarity, denotes the weight of the edge between node i and node j, is the standard deviation, denotes the feature vector of the i-th spatial position, denotes the feature vector of the j-th spatial position.
[0133] In actual operation, A large number of nodes can reduce system efficiency. In contrast to traditional methods that retain all elements in the relationship matrix regardless of their values, the relationship matrix can be initialized by discarding elements that are negligible and do not affect node connections, which can maintain the sparsity of the relationship matrix and reduce computational cost. The process can be expressed as:
[0134]
[0135] where Max() represents taking the maximum value by element, is a diagonal matrix such that .
[0136] and The initialization process is similar to .
[0137] Step S103: Coupled Graph Convolutional Network (CGRU) is used to obtain the aggregated edge-weighted traffic state.
[0138] It should be noted that the time variation of the spatial correlation between stations that can occur in capturing traffic data at different time intervals, such as morning, afternoon, evening, night, etc. To solve this difficulty, first introduce a graph convolution method that uses a coupled mapping mechanism to learn the relationship matrix between stations, which reflects the similarity and influence of traffic flow patterns between stations. For example, as shown in Figure 5 , the structure of CGCN is shown. The traffic flow features and the initial relationship matrix in each time interval are used as inputs for graph convolution. Each layer of graph convolution can extract the corresponding station features and relationship matrix at the hour scale, which can be represented as:
[0139]
[0140] where K is a hyperparameter in the graph convolution network, representing the number of convolution kernels in each layer, i.e. the number of convolution kernels used in each layer, k is an index variable, representing the kth convolution kernel in the i-th layer of the graph convolution network, represents the weight parameters of the kth convolution kernel in the m-1th layer, represents the total number of convolution layers, is the station feature representing the m-1th layer, is the relationship matrix representing the m-1th layer, can be represented as:
[0141] where, are the relation matrices of m-2 layers, and are low-rank sub-matrices obtained by SVD, , are the parameters of the learnable fully connected layer, and T represents the period.
[0142] To aggregate the traffic information from different edges, the attention score of each layer relation matrix needs to be evaluated , which is represented as follows:
[0143] ,
[0144] where, where, and are the learnable parameters in the fully connected layer, is the aggregated feature representation of the convolution, which is the output of the CGCN.
[0145] Step S104: learn adaptive node-specific weights and embeddings using residual graph attention RGAT to capture the dynamic traffic patterns of each node;
[0146] It should be noted that traffic flow prediction also faces the challenge of handling different time intervals of possibly varying traffic modes, such as peak hours, off-peak hours, weekends, holidays, etc. To address this challenge, RGAT is used to learn adaptive node-specific weights and embeddings to capture the dynamic traffic patterns of each node. As shown in Figure 6 For the RGAT of the hour channel, we input the edge-weighted traffic state that aggregates the traffic information from different edges into the RGAT, and use the scaled dot product method to calculate the attention score , which can be represented as: ,
[0147] where, denotes the attention score between station a and station b at the hour scale, and are the randomly initialized node embeddings of station a and station b at the corresponding scale, and are the edge-weighted traffic features of station a and station b at time interval τ, which aggregate traffic information from different edges, and denote the concatenation operation and the inner product operation, respectively, and are the learnable parameters of the key value key and feature information value, respectively, is the dimension of the key-value pair key and learnable parameter value, and q represents the query.
[0148] After obtaining the attention scores, we compute the weighted sum of the relevance of all stations to obtain the latent state , which contains edge and node weighting information, and the formula is as follows:
[0149] ,
[0150] where softmax() represents a normalization activation function;
[0151] In each hourly scale channel, the recurrent layers in the encoder and decoder use the output latent state of RGAT to capture the time series features. In addition, the output layer in the decoder is composed of the latent state .
[0152] The daily scale channel and the weekly scale channel have the same running logic as the hourly scale channel.
[0153] Step S105: After applying adaptive weighting P times to the results of the three scale channels through the residual channel attention RCAT, the results of the three scale channels are combined to obtain the final prediction result;
[0154] Specifically, traffic flow is a complex spatiotemporal phenomenon that exhibits different periodic patterns at different time scales, such as hourly, daily, and weekly. These patterns reflect the influence of various factors such as traffic demand, road network structure, weather conditions, and special events. Therefore, in order to obtain accurate and reliable traffic flow predictions, it is necessary to effectively and efficiently integrate traffic features extracted from these time scales. To achieve this goal, a P-layer dynamic residual channel attention mechanism is adopted, which can adaptively assign different weights to traffic features at each time scale according to the relevance and importance of the prediction task. The dynamic residual channel attention mechanism can also enhance the representation features by adding residual connections between input and output channels, which can facilitate information flow and alleviate the gradient vanishing problem, which can be expressed as:
[0155] ,
[0156] where, represents an activation function, , represents the concatenation of the outputs of the hourly, daily, and weekly scale channels; represents the average pooling operation, represents the learnable parameters of the p-th layer fully connected network.
[0157] After applying adaptive weighted P times to the results of the three scale channels, we obtain the final output by combining the results of the three scale channels, which can be expressed as: ,
[0158] wherein, represents the final prediction result, represents the result of the s-th scale channel after applying adaptive weighted P times.
[0159] In summary, according to the traffic flow prediction method based on hierarchical attention described above, by building three independent scale channels of hour scale channel, day scale channel and week scale channel, the spatial, temporal and semantic correlation between roads in the traffic network is effectively modeled to capture the traffic flow spatiotemporal patterns of different periods. Each channel adopts a network structure of input layer, recurrent layer and output layer, and in the recurrent layer, a coupled graph recurrent unit CGRU is used to obtain an aggregated edge-weighted flow state, and a residual graph attention RGAT is used to dynamically learn node weights to better fit the real dynamic flow scenario. Then, through the residual channel attention RCAT, the traffic flow features extracted by the three scale channels are fused, and the final predicted traffic flow result is calculated, so as to dynamically learn the traffic flow state under different space-time from multiple angles, thereby further improving the accuracy of predicting traffic flow.
[0160] Referring to Figure 7 , a structure schematic diagram of a traffic flow prediction system based on hierarchical attention in a third embodiment of the present application is shown, and the system comprises:
[0161] A data preprocessing module 10 is configured to collect historical traffic flow data of a target site, preprocess the historical traffic flow data, and obtain a traffic flow data sequence.
[0162] A channel building module 20 is configured to build three different scale channels, which are a hour scale channel, a day scale channel and a week scale channel. The three different scale channels all adopt a network structure of input layer, recurrent layer and output layer.
[0163] A data classification module 30 is configured to divide the traffic flow data sequence into the three different scale channels to obtain corresponding traffic flow data subsequences.
[0164] A prediction data module 40 is configured to take the traffic flow data subsequences as the input layer data, update the relationship matrix of the traffic flow data subsequences by using a coupled graph convolution network CGCN and a residual graph attention RGAT in the recurrent layer, learn node embedding at each time interval, and obtain the time sequence features of the predicted traffic flow under the corresponding scale channel in the output layer.
[0165] a data fusion module 50 configured to integrate the time series features of the predicted traffic flow under each scale channel by a residual channel attention RCAT to obtain a final predicted traffic flow.
[0166] In summary, according to the traffic flow prediction method based on hierarchical attention described above, by building three independent scale channels of hour scale channel, day scale channel and week scale channel, the spatial, temporal and semantic correlation between roads in the traffic network is effectively modeled by capturing the traffic flow spatio-temporal pattern of different periods; each channel adopts the network structure of input layer, recurrent layer and output layer, and in the recurrent layer, the coupled graph recurrent unit CGRU is used to obtain the aggregated edge weighted flow state, and then the residual graph attention RGAT is used to dynamically learn the node weight, so as to better fit the real dynamic flow scene; then the residual channel attention RCAT is used to fuse the flow features extracted by the three scale channels, and the final predicted traffic flow result is calculated, so as to realize dynamic learning of traffic flow state under different space-time from multiple angles, thereby further improving the accuracy of predicted traffic flow.
[0167] In the description of the present specification, the description referring to the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" and the like means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In the present specification, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0168] The above-described embodiments only express several implementation manners of the present application, and the description is relatively specific and detailed, but it should not be understood as a limitation on the scope of the present application. It should be noted that for those skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A traffic flow prediction method characterized by, The method comprises: Collecting historical traffic flow data of a target site, preprocessing the historical traffic flow data to obtain a traffic flow data sequence; Establishing three different scale channels, which are a hourly scale channel, a daily scale channel and a weekly scale channel, and each of the three different scale channels adopts a network structure of an input layer, a recurrent layer and an output layer; Dividing the traffic flow data sequence into the three different scale channels to obtain corresponding traffic flow data subsequences; Taking the traffic flow data subsequences as the input layer data, updating a relation matrix of the traffic flow data subsequences by using a coupled graph convolution network CGCN and a residual graph attention RGAT in the recurrent layer, learning node embedding at each time interval, and obtaining time sequence features of predicted traffic flow under a corresponding scale channel in the output layer; specifically comprising: The CGCN (coupled graph convolution network) is used to learn the relation matrix between stations, and traffic flow features in each time interval are used as input of the CGCN and the initial relation matrix As input of the graph convolution, each layer of the graph convolution extracts the corresponding station features in the scale channel and the relation matrix The expression is as follows: , wherein K is a hyper-parameter in the graph convolution network, representing the number of convolution kernels in each layer, i.e., the number of convolution kernels used in each layer, k is an index variable, representing the kth convolution kernel in the i-th layer of the graph convolution network, represents the weight parameter of the kth convolution kernel in the m-1th layer, represents the total number of convolution layers, is a site feature representing the m-1th layer, is a relationship matrix representing the m-1th layer, wherein is represented as: , wherein, respectively represent the relation matrix of m-2 layers, and is Low-rank sub-matrices based on time and space are obtained by SVD, , are parameters of the learnable fully connected layer, and T represents a period; evaluating the attention scores of each layer relation matrix to aggregate site features of different layers The aggregated features F of the convolution are represented as: The aggregated features F of the convolution are represented as: as output data of the coupled graph convolution network CGCN, wherein the is represented by: , wherein, and are learnable parameters in the fully connected layer; Integrating the time sequence features of the predicted traffic flow under each scale channel by a residual channel attention RCAT to obtain final predicted traffic flow.
2. The traffic flow prediction method according to claim 1, characterized in that, The step of collecting historical traffic flow data of a target site, preprocessing the historical traffic flow data to obtain a traffic flow data sequence comprises: Defining the historical traffic flow data as a directed graph G(V, E), wherein a node V represents a site, an edge E represents traffic flow between two sites, and a feature vector of each node V is composed of historical boarding and alighting flows of the site; The historical traffic flow data at time t is denoted as and , respectively, represent the hourly, daily, and weekly traffic flow data, where N is the number of nodes, r is the number of features, h represents hour, d represents day, and w represents week.
3. The traffic flow prediction method according to claim 1, characterized in that, The step of dividing the traffic flow data sequence into the three different scale channels to obtain corresponding traffic flow data subsequences comprises: Initializing a relation matrix of the traffic flow data subsequences under different scale channels, calculating a similarity of historical traffic flow between sites, and taking the similarity as a weight of an edge.
4. The traffic flow prediction method according to claim 3, characterized in that, The step of initializing a relation matrix of the traffic flow data subsequences under different scale channels, calculating a similarity of historical traffic flow between sites, and taking the similarity as a weight of an edge comprises: The function is defined as follows: The traffic flow data sub-sequence is mapped to three different relation matrices, and the mapping formula is expressed as: wherein, , , , D and W represent the number of time intervals per day and per week, respectively, wherein the function is specified as follows: Applying singular value decomposition, SVD, to traffic data to obtain a plurality of low-rank sub-matrices, denoted as: , wherein, and are low-rank sub-matrices of the streaming data , and denote time and space based sub-matrices, respectively. Gaussian kernel-based method calculation The similarity of the i-th row and the j-th row is calculated as an expression of the weight of the edge as follows. , where exp( ) represents the similarity, denotes the weight of the edge between node i and node j, is the standard deviation, denotes the feature vector of the i-th spatial position, denotes the feature vector of the j-th spatial position; At the initial time The elements of the node connections that have a negligible impact are discarded to initialize the relation matrix, the initialization process is represented as: , where Max() denotes the element-wise maximum, is a diagonal matrix, .
5. The traffic flow prediction method according to claim 1, characterized in that, The step of taking the traffic flow data subsequences as the input layer data, updating a relation matrix of the traffic flow data subsequences by using a coupled graph convolution network CGCN and a residual graph attention RGAT in the recurrent layer, learning node embedding at each time interval, and obtaining time sequence features of predicted traffic flow under a corresponding scale channel in the output layer comprises: Learning adaptive node-specific weights and embedding by using a residual graph attention RGAT to capture dynamic flow of each node; Edge-weighted stream state of aggregating stream data of different edges Input into the residual graph attention RGAT and calculate attention scores using the scaled dot-product method The attention scores are expressed as: , wherein, denotes the attention score between station a and station b, and are the randomly initialized node embeddings of station a and station b respectively in the corresponding scale, and are the edge-weighted traffic flow features of station a and station b respectively in time interval τ, aggregating traffic information from different edges, and denote the concatenation operation and the inner product operation respectively, and are the key value key and the learnable parameter value of the feature information respectively, is the dimension of the key value key and the learnable parameter value, and q denotes the query; After obtaining the attention score, a weighted sum of the relevance of all sites is calculated to obtain a latent state where the edge and node weight information is contained, L represents L consecutive time series, and the latent state The formula is: , where Softmax() denotes a normalization activation function, and in the scale channel, the recurrent layers in the encoder and decoder use the output latent state of RGAT to capture time-series features, and the output layer in the decoder consists of the latent state .
6. The traffic flow prediction method according to claim 1, characterized in that, The step of integrating the time sequence features of the predicted traffic flow under each scale channel by a residual channel attention RCAT to obtain final predicted traffic flow comprises: Adaptively assigning different weights to flow features of each time scale by a P-layer dynamic residual channel attention mechanism, and a result of scale channel adaptive weighting P times is expressed as: , wherein, represents a concatenation of outputs of the hourly, daily, and weekly scale pathways, represents an activation function, wherein , represents a mean pooling operation, represents the learnable parameters of the p-th fully connected network; After applying adaptive weighting P times to results of the three scale channels, obtaining a final prediction result by combining results of the three scale channels, and an expression of combining the three scale channels is: , wherein, denotes the final prediction result, denotes the result after applying adaptive weighted Pth order to the s-th scale channel.
7. A traffic flow prediction system applied to a traffic flow prediction method according to any one of claims 1 to 6, characterized in that, The system comprises: The data preprocessing module is configured to collect historical traffic flow data of a target site, and preprocess the historical traffic flow data to obtain a traffic flow data sequence. The channel building module is configured to build three different scale channels, i.e., an hour scale channel, a day scale channel, and a week scale channel, which all have a network structure of an input layer, a recurrent layer, and an output layer. The data classification module is configured to divide the traffic flow data sequence into the three different scale channels to obtain corresponding traffic flow data subsequences. The prediction data module is configured to take the traffic flow data subsequences as the input layer data, update a relation matrix of the traffic flow data subsequences by using a coupled graph convolution network (CGCN) and a residual graph attention (RGAT) in the recurrent layer, learn node embedding at each time interval, and obtain time series features of predicted traffic flow under a corresponding scale channel in the output layer. The data fusion module is configured to integrate the time series features of the predicted traffic flow under each scale channel by using a residual channel attention (RCAT) to obtain final predicted traffic flow.
8. A computer-readable storage medium, characterized in that, The readable storage medium stores one or more programs, which are executed by the processor to implement the traffic flow prediction method according to any one of claims 1-6.
9. A computer device, comprising: The computer device includes a memory and a processor. The processor is configured to store a computer program. The processor is configured to execute the computer program stored in the memory to implement the traffic flow prediction method according to any one of claims 1-6.
Citation Information
Patent Citations
Graph neural network traffic flow prediction method based on multivariate time sequence interpolation
CN113673769A