# Impacts of Weather on Short-Term Metro Passenger Flow Forecasting Using a Deep LSTM Neural Network
## 3 Methodology  
RNN is a class of artificial neural network in which connections between nodes form a directed graph along a temporal sequence. LSTM is a special architecture of RNN, which was first introduced for sequence modeling [28]. It is a useful choice for handling the vanishing gradient problem since it can model long-term dependencies in the data. The vital component in LSTM is a cell. The state of a cell may be changed via control by the input gate, forget gate, and output gate simultaneously. Using this gate mechanism, LSTM has the ability to remove or add extracted hierarchical features and their past states to the cell, which enables LSTM to remember information for long time periods [29]. This state-memory characteristic makes LSTM useful in solving nonlinear time series problems, including a station-level passenger flow forecasting problem. The architecture of a cell in LSTM is illustrated in Figure 4. Its current input data are typically composed of the input vector \(X_{t}\) at time step \(t\), and the hidden output \(h_{t\text{-}1}\) at time step \(t\text{-}1\). The complete work cycle of a cell in LSTM is as follows. First, the three coupled parameters, namely weights and biases (\(w_{i}\), \(b_{i}\)), (\(w_{i}\), \(b_{i}\)), and (\(w_{o}\), \(b_{o}\)), are trained to formulate the nonlinear relationships between the input gate (\(i_{t}\)) and [\(x_{t}\), \(h_{t\text{-}1}\)], the forget gate (\(f_{t}\)) and [\(x_{t}\), \(h_{t\text{-}1}\)], and the output gate (\(o_{t}\)) and [\(x_{t}\), \(h_{t\text{-}1}\)] at time step \(t\), respectively. \(x_{t}\) refers to input data at time step \(t\), and \(h_{t\text{-}1}\) refers to output data in the hidden layer at time step \(t\text{-}1\). The formulations of the three gates are defined in Equations (1)-(3). Second, an input squashing vector (\(\widetilde{C_{t}}\)) is obtained directly based on Equation (4) without any gate effect at time step \(t\). The new state will then be generated and stored in \(C_{t}\) at time step t under the control of \(f_{t}\), \(C_{t\text{-}1}\), \(i_{t}\), and \(\widetilde{C_{t}}\), which is shown in Equation (5). This special architecture shows that a cell can add or remove the previous memories stored in \(C_{t-1}\) with the control of the forget gate. Finally, the hidden output is obtained based on Equation (6) [30]. \[\text{Input gate}:\ i_{t}=\int_{1}(\omega_{t}\cdot[x_{t},h_{t-1}]+b_{i}) \tag{1}\]  
\[\text{Forget gate}:\ f_{t}=\int_{1}\Bigl{(}\omega_{f}\cdot[x_{t},h_{t-1}]+b_{f} \Bigr{)} \tag{2}\]  
\[\text{Output gate}:\ O_{t}=\int_{1}(\omega_{v}\cdot[x_{t},h_{t-1}]+b_{0}) \tag{3}\]  
\[\text{Input squashing}:\ \widetilde{C}_{t}=\int_{2}(\omega_{c}\cdot[x_{t},h_{t-1}]+b_{c}) \tag{4}\]  
\[\text{Cell}:\ C_{t}=f_{t}\odot C_{t-1}+i_{t}\odot\widetilde{C}_{t} \tag{5}\]  
\[\text{Hidden output}:\ h_{t}=O_{t}\odot[\int_{2}(C_{t})] \tag{6}\]  
where \(\int_{1}\) is the recurrent_activation function and \(\int_{2}\) is the activation function. In the source codes of the high-level neural network API, such as Keras and Caffe, \(\int_{1}\) is usually defined as sigmoid [31] or hard sigmoid function [32; 33] and \(\int_{2}\) is defined as tanh function [31; 32; 33]. \(\odot\) refers to Hadamard product [30; 34]. The dataflow in a deep LSTM_NN is shown in Figure 5. There is a total of n training examples in the input data. Each set of input data at time step \(t\) is defined as an input vector \(\left[X_{t}^{m\times s}\right]\), where m is the number of input variables and s refers to the number of time steps. When modeling, the input variables are assembled as an input vector, namely \(\left[v_{Dir},\ v_{M},\ v_{D},\ v_{W},\ v_{H},\ v_{NH},\ v_{Phe\_PF},\ v_{PF\_pre\_1},\ v_{PF\_pre\_2},\ v_{PF\_pre\_3},\ v_{PFT\_pre\_2},\ v_{Temp},\ v_{Rain},\ v_{Hunun},\ v_{Wind}\right]\), which is the combination of endogenous input variables and exogenous input variables introduced in Sections 2.2 and 2.3.