Traffic prediction method based on attention mechanism and stacked LSTM

By introducing the attention mechanism and stacked LSTM into the traffic prediction model, and combining the local and global attention mechanisms, the problem that it is difficult for the existing model to consider the influence of multiple factors is solved, and a more accurate prediction of the number of taxis is achieved.

CN114881282BActive Publication Date: 2024-09-10TIANJIN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210311798.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-28
Publication Date
2024-09-10
Estimated Expiration
2042-03-28

AI Technical Summary

Technical Problem

It is difficult for existing traffic prediction models to consider multiple factors that affect the number of taxis at the same time, resulting in insufficient prediction accuracy.

Method used

A traffic prediction method based on the attention mechanism and stacked LSTM is adopted. The local and global attention mechanisms are combined with geographical location information. The temporal attention mechanism is integrated into the LSTM model, comprehensively considering regional and time factors, and dynamically learning the correlation and correlation between different factors. influence weight.

Benefits of technology

It improves the accuracy of taxi quantity prediction, can more effectively consider the interaction between multiple factors, and is suitable for various types of scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114881282B
    Figure CN114881282B
Patent Text Reader

Abstract

The present invention discloses a traffic prediction method based on an attention mechanism and stacked LSTM, wherein step 1, constructing a coding-decoding model framework consisting of a coding part and a decoding part, wherein both the coding part and the decoding part are composed of stacked LSTM modules: wherein the coding part adopts a local attention mechanism and a global attention mechanism, respectively considering the correlation between different factors in the target area and the mutual influence between the number of taxis in different areas; the decoding part adopts a time attention mechanism, further selecting the result of the coding; completing training and prediction, obtaining a prediction sequence of the number of taxis. Compared with the prior art, the present invention aims at the problem that there are many influencing factors in the traffic prediction problem and different factors have different degrees of influence on the traffic flow, comprehensively considers a variety of time and space factors, and considers the mutual influence between different factors, solving the problem that the existing model does not consider all factors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of information technology and intelligent transportation, and in particular to a traffic prediction method based on an intelligent algorithm. Background Art

[0002] As an important part of the urban transportation system, taxis are a convenient means of transportation that can provide comfortable, fast and personalized services. However, due to the large differences in passenger flow in different regions and at different times, there is always a contradiction between the supply and demand of passengers and taxi services. If the traffic flow in different areas within a certain period of time can be known in advance, reasonable taxi dispatch can be achieved. Therefore, it is of great significance to reasonably predict the number of taxis in different regions to improve the management level of the taxi industry and promote the informatization and intelligent development of the transportation network.

[0003] In order to solve the above problems, a traffic prediction model is proposed to predict the number of taxis. However, the number of taxis is affected by many factors, including geographical factors, passenger habits, seasonal factors, etc., and different factors have different influences on the number of taxis. In order to more accurately predict the number of taxis, multiple factors should be considered comprehensively. However, due to the complexity of the problem, it is generally difficult for existing models to consider the impact of multiple factors at the same time. Summary of the invention

[0004] In view of the difficulty of traffic prediction and the difficulty of existing methods to comprehensively consider multiple influencing factors, the present invention discloses a traffic prediction method based on attention mechanism and stacked LSTM, which comprehensively considers geographic location information and time information, and predicts the number of taxis through a stacked LSTM (Long Short-Term Memory) model that incorporates the attention mechanism.

[0005] The present invention is achieved by the following technical solutions:

[0006] A traffic prediction method based on attention mechanism and stacked LSTM, the method comprising the following steps:

[0007] Step 1: Construct an encoding-decoding model framework consisting of an encoding part and a decoding part. Both the encoding part and the decoding part are composed of stacked LSTM modules. The encoding part adopts a local attention mechanism and a global attention mechanism to consider the correlation between different factors in the target area and the mutual influence between the number of taxis in different areas respectively. The decoding part adopts a temporal attention mechanism to further select the encoding results.

[0008] Step 1.1: The encoding part uses the local attention mechanism and the global attention mechanism to encode the input data, which includes the number of taxis, driving distance, driving time and number of passengers. The local attention mechanism is used to dynamically learn the correlation model between the number of taxis in the target area and other factors. The expression is as follows:

[0009]

[0010] Among them, [·;·] represents cascade operation, x a,k represents the time series of the kth factor of the target area a, h t-1 、s t-1 They represent the hidden state and cell state of the LSTM encoding part at time t-1, k represents the index of the influencing factor in the target area, t represents the time, and W l , U l 、v l and b l represents the training parameters;

[0011] Then we get the attention weight That is, the importance of each factor to the time series of the number of taxis is expressed as follows:

[0012]

[0013] Among them, N l Represents the number of factor types in the local target area l;

[0014] Thus, the attention weight of the target area factor is obtained The expression is as follows:

[0015]

[0016] Using global attention mechanism to dynamically learn the correlation model between the number of taxis in different areas The expression is as follows:

[0017]

[0018] Among them, y j represents the time series of the number of taxis in area j, represents the impact of the number of taxis in area j on the number of taxis in the target area, W g , U g 、v g and b g It is represented as a training parameter, and g represents the global area;

[0019] Introduce the prior probability P of taxis traveling between area i and area ji,j , the expression is as follows:

[0020]

[0021] Among them, off ij represents the number of taxis departing from area i and arriving at area j, up i represents the total number of taxis departing from area i;

[0022] Get the value P of the symmetric matrix in the i-th row and j-th column i,j sym , the expression is as follows:

[0023]

[0024] Get the attention weight The expression is as follows:

[0025]

[0026] Among them, λ is a hyperparameter, which indicates the weight of prior information. represents the normalized weight of the number of taxis in area j to the number of taxis in the target area, Represents the value of the a-th row and j-th column in the matrix, where a is the index of the target area;

[0027] The coding result of the number of taxis in all regions is obtained The expression is as follows:

[0028]

[0029] in, represents the time series of the number of taxis in different areas, The attention weights corresponding to each time series representing the number of taxis;

[0030] The hidden state in the LSTM network of the encoding part changes with time. The temporal attention mechanism is used to select the hidden state at different times to obtain the influence of historical data. The expression is as follows:

[0031]

[0032] Among them, W d ', W d 、v d and b d represents the training parameters, d t-1 、s' t-1 They represent the hidden state and cell state of the decoding part LSTM at time t-1, respectively, drepresents the training parameters, h o Represents the hidden state of the LSTM of the encoding part at different times in a time window of length T;

[0033] Attention Weight The expression is as follows:

[0034]

[0035] in, Represents the weight of each influencing factor in the target area, represents the weight of the number of taxis in different regions, Indicates the impact weight of historical data;

[0036] The historical data is fused, and the hidden states of the encoding part LSTM at different times are weighted summed to obtain the hidden states c of the encoding part LSTM at different times t , the expression is as follows:

[0037]

[0038] During model training and prediction, the local area features and global features are cascaded, that is:

[0039]

[0040] in, Represents the input of the encoding part LSTM;

[0041] The update operation of the hidden state of the LSTM in the encoding part is

[0042] Step 1.2: Use represents the prediction result of the number of taxis in the target area at time t, and c obtained by weighting by the attention weight t and the previous forecast Cascade, as the input of the LSTM in the decoding part, the update operation of the hidden state of the LSTM is

[0043] Step 2: Complete training and prediction to obtain the predicted sequence of the number of taxis expression:

[0044]

[0045] in, represents the predicted value of the number of taxis in the target area a at time t, v y , W m , b m , b y represents the training parameters;

[0046] The objective function of the training process is:

[0047]

[0048] Among them, y i is the predicted value and label of region i, and θ is the training parameter.

[0049] Compared with the prior art, the beneficial effects and advantages of the present invention are:

[0050] 1) In view of the fact that there are many influencing factors in traffic forecasting and different factors have different degrees of influence on traffic flow, this paper comprehensively considers multiple temporal and spatial factors, and also considers the mutual influence between different factors, thus solving the problem that the existing model does not consider all factors;

[0051] 2) It adopts local spatial attention mechanism, global spatial attention mechanism and temporal attention mechanism to assign weights to different factors and improve the prediction accuracy;

[0052] 3) Suitable for applications in various types of scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 The overall flow chart of a traffic prediction method based on attention mechanism and stacked LSTM of the present invention is as follows

[0054] Figure 2 This is a schematic diagram of the algorithm framework of an embodiment of a traffic prediction method based on an attention mechanism and stacked LSTM of the present invention. DETAILED DESCRIPTION

[0055] The technical solution of the present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0056] like Figure 1 As shown, it is a schematic diagram of the overall process of a traffic prediction method based on attention mechanism and stacked LSTM of the present invention. This step includes the following steps:

[0057] Step 1. Construct an encoding-decoding model framework consisting of an encoding part and a decoding part. Both the encoding part and the decoding part are composed of stacked LSTM (long short-term memory network) modules: the encoding part adopts a local attention mechanism and a global attention mechanism, which respectively consider the correlation between different factors in the target area and the mutual influence between the number of taxis in different areas; the decoding part adopts a temporal attention mechanism to further select the encoding results.

[0058] like Figure 2As shown, it is a schematic diagram of the algorithm framework of a traffic prediction method embodiment based on attention mechanism and stacked LSTM of the present invention. It is assumed that there are N areas. Each area has N l The time series of factors (l means local). The time series of the number of taxis is the target series to be predicted. Other factors that affect the number of taxis include travel distance, travel time and number of passengers. Assume that the time window length of each sequence is T. The sequence of the number of taxis is recorded as in, is the number of taxis in area i. N l The sequence of factors is recorded as in, is the time series of the kth factor in region i. represents the N of region i at time t l A sequence of factors.

[0059] In the architecture of the model, both the encoding and decoding parts use LSTM networks. The operation of the LSTM in the encoding part is denoted as f e (·,·), the operation of the LSTM in the decoding part is denoted as f d (·,·). Use and Represents the hidden state and cell state of the LSTM encoding part at time t. Similarly, use and and represent the hidden state and cell state of the decoding part LSTM at time t.

[0060] Step 1.1: The encoding part uses the local attention mechanism and the global attention mechanism to encode the input data, which includes the number of taxis, driving distance, driving time and number of passengers. The local attention mechanism is used to dynamically learn the correlation model between the number of taxis in the target area and other factors. The expression is as follows:

[0061]

[0062] Among them, [·;·] represents cascade operation, x a,k (a stands for aim) represents the time series of the kth factor in the target area, h t-1 、s t-1 They represent the hidden state and cell state of the LSTM encoding part at time t-1, t represents the time, W l , U l 、v l and b l represents the training parameters;

[0063] Then we get the attention weight That is, the importance of each factor to the time series of the number of taxis is expressed as follows:

[0064]

[0065] Among them, N l The number of factor types representing the local target region l;

[0066] This results in the coding of different factors in the target area. The expression is as follows:

[0067]

[0068] Using global attention mechanism to dynamically learn the correlation model between the number of taxis in different areas The influence of the number of taxis in area j on the number of taxis in the target area is expressed as follows:

[0069]

[0070] Among them, y j represents the time series of the number of taxis in area j, W g , U g 、v g and b g It is represented as a training parameter, and g represents the global area (global);

[0071] Because the traffic volume between different areas is affected by people's behavior habits, traffic conditions and other factors, the encoding-decoding architecture proposed in the present invention introduces prior information, and the prior information introduced includes the probability matrix P of the traffic volume between different areas;

[0072] Set the prior probability P of a taxi traveling between area i and area j i,j , the expression is as follows:

[0073]

[0074] Among them, off ij represents the number of taxis departing from area i and arriving at area j, up i represents the total number of taxis departing from area i.

[0075] Using P sym Make the matrix symmetric (that is, the transpose of the matrix is ​​equal to the matrix). i,j sym Represents the value of the i-th row and j-th column of a symmetric matrix. The expression is as follows:

[0076]

[0077] Get the attention weight It represents the normalized weight of the number of taxis in area j to the number of taxis in the target area, where j is the index of all areas. The expression is as follows:

[0078]

[0079] Among them, λ is a hyperparameter, which indicates the weight of prior information. represents the value of the a-th row and j-th column in the matrix, where a is the index of the target region, j is the index of all regions, and j = 1, 2, ... N;

[0080] This results in the coding of the number of taxis in all regions. The expression is as follows:

[0081]

[0082] in, represents the time series of the number of taxis in different areas, The attention weights corresponding to each time series representing the number of taxis;

[0083] The hidden state in the LSTM network of the encoding part changes with time. The temporal attention mechanism is used to select the hidden state at different times. The calculation process is as shown in formula (9) to obtain the influence degree of historical data. The expression is as follows:

[0084]

[0085] Among them, W' d , W d 、v d and b d represents the training parameters, d t-1 、s' t-1 They represent the hidden state and cell state of the decoding part LSTM at time t-1, respectively, d represents the training parameters, h o (o=1,2…T) represents the hidden state of the LSTM of the encoding part at different times in the time window of length T;

[0086] Assign weights to the hidden states of the LSTM encoding parts at different times Represents the influence weight of normalized historical data. The expression is as follows:

[0087]

[0088] in, Represents the weight of each influencing factor in the target area, represents the weight of the number of taxis in different regions, Indicates the impact weight of historical data;

[0089] The historical data is fused, and the hidden states of the encoding part LSTM at different times are weighted summed to obtain c t , the expression is as follows:

[0090]

[0091] During model training and prediction, the local area features and global features are cascaded, that is:

[0092]

[0093] in, Represents the input of the encoding part LSTM, such as Figure 2 shown.

[0094] The update operation of the hidden state of the LSTM in the encoding part is

[0095] Step 1.2: Use represents the prediction result of the encoding-decoding algorithm structure of the present invention on the number of taxis in the target area at time t. t and the previous forecast Cascade, as the input of the LSTM in the decoding part, the update operation of the hidden state of LSTM is

[0096] Step 2: Complete training and prediction based on the following expressions:

[0097]

[0098] in, represents the predicted value of the number of taxis in the target area a at time t, v y , W m 、b m 、b y Represents training parameters.

[0099] The objective function of the training process is:

[0100]

[0101] in, is the predicted sequence of the number of taxis in the target area a, y a is the label of the number of taxis in the target area, and θ is the training parameter. Based on this objective function, the encoding-decoding algorithm architecture of the present invention can be trained by back propagation.

[0102] The prediction model of the present invention adopts an encoding-decoding structure that integrates an attention mechanism; the encoding part encodes different influencing factors, adopts a local spatial attention mechanism and a global spatial attention mechanism, learns the influence of different factors on traffic flow and assigns corresponding weights, including multiple spatial factors and corresponding influence degrees; the decoding part adopts a time attention mechanism to further select the encoding results, including time factors and corresponding influence degrees; the encoding-decoding framework structure law of the model, the input can be determined according to actual requirements, and is suitable for applications in various types of scenarios. Based on the local attention mechanism and the global attention mechanism, weights are assigned to the input time series. The local spatial attention is used to learn the correlation between different factors in the target area and its influence on taxi demand. The global spatial attention mechanism is used to learn the mutual influence of the number of taxis in different areas. The local encoding results and the global encoding results are cascaded as the input of LSTM; based on the time attention mechanism, weights are assigned to the time series in the encoding part results, and based on this result, the model is trained and predicted by regression.

[0103] like Figure 2 As shown, it is a schematic diagram of a framework of an embodiment of a traffic prediction method based on an attention mechanism and stacked LSTM of the present invention. In the framework, the input is a time series of different factors, including the number of taxis, travel distance, travel time and the number of passengers. The encoding part of the framework adopts two spatial attention mechanisms, namely the local spatial attention mechanism and the global spatial attention mechanism. The local spatial attention is used to learn the correlation between different factors in the target area. The global spatial attention mechanism is used to learn the mutual influence between the number of taxis in different areas. The encoding part includes geographic location information. The result of the encoding part is input to the decoding part. The decoding part uses the time attention mechanism to further select the encoding result. The decoding part includes time information. The output result of the decoding part is used to predict the number of taxis.

[0104] Assume there are N regions. Each region has N l The time series of the number of taxis is the target series to be predicted. Other time series that affect the number of taxis include travel distance, travel time, and number of passengers. Assuming that the time window length of each sequence is T, the sequence of the number of taxis is recorded as in, is the number of taxis in area i. N l The sequence of factors is recorded as in, is the time series of the kth factor in region i. represents all N in region i at time t l A sequence of factors.

[0105] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Those skilled in the art may make various modifications, equivalent substitutions or variations without departing from the spirit and scope of the present invention, and all modifications, equivalent substitutions or variations made within the spirit and principles of the present application fall within the protection scope of the present invention as defined by the appended claims.

Claims

1. A traffic prediction method based on attention mechanism and stacked LSTM, characterized in that: The method comprises the following steps: Step 1: Construct an encoding-decoding model framework consisting of an encoding part and a decoding part. Both the encoding part and the decoding part are composed of stacked LSTM modules. The encoding part adopts a local attention mechanism and a global attention mechanism to consider the correlation between different factors in the target area and the mutual influence between the number of taxis in different areas respectively. The decoding part adopts a temporal attention mechanism to further select the encoding results. Step 1.1: The encoding part uses the local attention mechanism and the global attention mechanism to encode the input data, and the input data includes at least the number of taxis, driving distance, driving time and number of passengers. The local attention mechanism is used to dynamically learn the correlation model between the number of taxis in the target area and other factors. The expression is as follows: Among them, [·;·] represents cascade operation, x a,k represents the time series of the kth factor of the target area a, h t-1 、s t-1 They represent the hidden state and cell state of the LSTM encoding part at time t-1, k represents the index of the influencing factor in the target area, t represents the time, and W l , U l 、v l and b l represents the training parameters; Then we get the attention weight That is, the importance of each factor to the time series of the number of taxis is expressed as follows: Among them, N l Represents the number of factor types in the local target area l; Thus, the attention weight of the target area factor is obtained The expression is as follows: Using global attention mechanism to dynamically learn the correlation model between the number of taxis in different areas The expression is as follows: Among them, y j represents the time series of the number of taxis in area j, represents the impact of the number of taxis in area j on the number of taxis in the target area, W g , U g 、v g and b g It is represented as a training parameter, and g represents the global area; Introduce the prior probability P of taxis traveling between area i and area j i,j , the expression is as follows: Among them, off ij represents the number of taxis departing from area i and arriving at area j, up i represents the total number of taxis departing from area i; Get the value P of the symmetric matrix in the i-th row and j-th column i,j sym , the expression is as follows: Get the attention weight The expression is as follows: Among them, λ is a hyperparameter, which indicates the weight of prior information. represents the normalized weight of the number of taxis in area j to the number of taxis in the target area, Represents the value of the a-th row and j-th column in the matrix, where a is the index of the target area; The coding result of the number of taxis in all regions is obtained The expression is as follows: in, represents the time series of the number of taxis in different areas, The attention weights corresponding to each time series representing the number of taxis; The hidden state in the LSTM network of the encoding part changes with time. The temporal attention mechanism is used to select the hidden state at different times to obtain the influence of historical data. The expression is as follows: Among them, W' d , W d 、v d and b d represents the training parameters, d t-1 、s' t-1 They represent the hidden state and cell state of the decoding part LSTM at time t-1, respectively, d represents the training parameters, h o Represents the hidden state of the LSTM of the encoding part at different times in a time window of length T; Attention Weight The expression is as follows: in, Represents the weight of each influencing factor in the target area, represents the weight of the number of taxis in different regions, Indicates the impact weight of historical data; The historical data is fused, and the hidden states of the encoding part LSTM at different times are weighted summed to obtain the hidden states c of the encoding part LSTM at different times t , the expression is as follows: During model training and prediction, the local area features and global features are cascaded, that is: in, Represents the input of the encoding part LSTM; The update operation of the hidden state of the LSTM in the encoding part is Step 1.2: Use represents the prediction result of the number of taxis in the target area at time t, and c is obtained by weighting the attention weight t and the previous forecast Cascade, as the input of the LSTM in the decoding part, the update operation of the hidden state of the LSTM is Step 2: Complete training and prediction to obtain the predicted sequence of the number of taxis expression: in, represents the predicted value of the number of taxis in the target area a at time t, v y , W m 、b m 、b y represents the training parameters; The objective function of the training process is: Among them, y i is the predicted value and label of region i, and θ is the training parameter.