# An LSTM-Based Method Considering History and Real-Time Data for Passenger Flow Prediction
## 3 Materials and Methods
### HRPFP Model  
#### 3.2.1 The Process of HRPFP Model  
This paper proposes the HRPFP model to predict the passenger number for each station at a certain line using the history data and the real-time collected passenger number. Taking one bus station as example, we obtain the history passenger data collected a few days ago, and combine these data with the point of interest (POI) data based on Xgboost to form a new dataset which contains more information. Then, we feed these data into a history data encoding neural network based on the LSTM to produce a vector that contains the history passenger information. Next, we obtain the passenger number of the previous four time periods from automatic fare collections (AFCs) and feed these data into the real-time data encoding neural network to form a vector that contains the real-time information. Then, we use a simple neural network to make the history vector and the real-time vector having the same shape. After that, we add these two vectors and produce an information vector containing both history and real-time information. Then, we encode the information vector using a multi-layer neural network to obtain the predicted passenger number for the next two time periods. The detailed process of the HRPFP model is shown in Figure 2.  
In Figure 2, we can see that the HRPFP model has larger data dimensions than other LSTM passenger number prediction models. Besides, the HRPFP model also has an input containing real-time collected information. Larger data dimensions and real-time collected information can help to improve the predicted accuracy. That is why the HRPFP model had a better performance than other models theoretically.  
From Figure 2, we can also obtain the forward propagation formula of the model. Let us assume that the final output of the history data encoding structure is \(S_{fix}\), and the output of the real-time data encoding structure is \(S_{rx}\). We use a linear mapping for both \(S_{hx}\) and \(S_{rx}\) to ensure these two vectors have the same shape. This is the major function for weights \(W_{hx}\) and \(W_{rx}\). The Equations (12) and (13) show these projections.  
\[Q_{h}=W_{hx}S_{hx}+b_{hx} \tag{12}\]  
\[Q_{r}=W_{rx}S_{rx}+b_{rx} \tag{13}\]To reduce the deviation caused by a too large value, we use a SoftMax function to project every element in both \(Q_{h}\) and \(Q_{r}\) into [0,1].  
\[I_{h}=S(W_{ltx}S_{ltx}+b_{ltx}) \tag{14}\]  
\[I_{r}=S(W_{ltx}S_{ltx}+b_{ltx}) \tag{15}\]  
Figure 2: The structure of the HRPFP model.  
where \(S\) is the SoftMax function. Then, we use \(I_{lt}\) and \(I_{r}\) to form an information vector, that is \(I_{v}=I_{lt}+I_{r}\). After this, we use a three-layer neural network to decode the information vector \(I_{v}\) and obtain the predicted passenger number for a period. Because the length of the output sequence is small, we use this decoding structure instead of the LSTM structure to improve the model speed. The decoding network can be expressed as:  
\[D_{1}=W_{d1}I_{v}+b_{d1} \tag{16}\]  
\[D_{2}=\sigma(W_{d2}D_{1}+b_{d2}) \tag{17}\]  
\[P=W_{d3}D_{2}+b_{d3} \tag{18}\]  
where \(\sigma\) is the Sigmoid function.  
The loss function of this model is the square error between real values and predicted values, so the target is \(\min(P-V)^{2}\), where \(P\) is the predicted values and \(V\) is the real values.