## 2 KNN-BILSTM Model
### BILSTM Algorithm  
Traffic flow data were used as time-series data, and information between adjacent nodes could be transferred to each other. In recurrent neural networks (RNNs), the output of neurons in the previous moment can be used as the input of neurons in the next moment so that the RNN has a memory function in short-term time series prediction. However, RNNs cannot preserve long-term historical data and have poor performance in long-term memory, with vanishing and exploding gradients. To overcome this shortcoming, a modified model of the RNN, the LSTM, is proposed, whose purpose is to allow memory cells to determine when to forget certain information in order to determine the optimal delay for time-seriesproblems. A typical LSTM consists of an input layer, a recursive hidden layer with memory blocks as the basic unit, and an output layer. The memory block contains self-connected memory cells with stored temporal states and three adaptive multiplication gate cells (input, output, and forgetting gates) that control the flow of information in the block. Three additional gates provide a sequential simulation of the write, read, and reset operations on the block. The multiplication gates can learn to open and close. Therefore, [24] pointed out that LSTM memory cells can store and access information over a long period of time, mitigating the vanishing gradient problem. This was calculated as follows:  
\[\text{Forgotten Gate}:\ f_{t}=\sigma(W_{f}[h_{t-1},x_{t}]+b_{f}) \tag{2}\]  
\[\text{Input gate}:\ i_{t}=\sigma(W_{i}[h_{t-1},x_{t}]+b_{i}) \tag{3}\]  
\[\widetilde{C}=\text{tanh}(W_{c}[h_{t-1},x_{t}]+b_{c}) \tag{4}\]  
\[\text{Unit status}:\ C_{t}=f_{t}C_{t-1}+i_{t}\widetilde{C}_{t} \tag{5}\]  
\[\text{Output gate}:\ o_{t}=\sigma(W_{o}[h_{t-1},x_{t}]+b_{o}) \tag{6}\]  
\[h_{t}=o_{t}\text{tanh}(C_{t}) \tag{7}\]  
The one-way LSTM model derives information for a given time in the future only from historical data. In traffic flow prediction, time series prediction not only refers to the historical information of the current moment but also takes into account the information of the future moment to achieve an accurate prediction of the long-term traffic flow. Therefore, based on the LSTM model, the BILSTM model was proposed to improve the prediction accuracy. The BILSTM model uses a double-layer LSTM model unit structure and simultaneously transmits information through forward and backward propagation. Forward propagation is calculated from time \(1-t\), and the information output at each time is retained. Backward propagation is calculated from time \(t-1\), and the information output at each time is retained. Finally, the output state variables of the two results are concatenated as the final result. Table 1 lists the structural parameters of the model network. \[\overset{\rightarrow}{h}_{t}=LSTM(x_{t},\overset{\rightarrow}{h}_{t-1}) \tag{8}\]  
\[\overset{\leftarrow}{h}_{t}=LSTM(x_{t},\overset{\leftarrow}{h}_{t-1}) \tag{9}\]  
\[yt=\bigg{(}W_{\overset{\rightarrow}{hy}}\overset{\rightarrow}{h}_{t}+W_{ \overset{\leftarrow}{hy}}\overset{\leftarrow}{h}_{t}+b_{y}\bigg{)}g \tag{10}\]  
BILSTM Model Prediction Process  
When the BILSTM model predicts, as shown in Figure 1, it first assumes that its input samples are \(x_{t-1}\), \(x_{t}\), \(x_{t+1}\), and then calculates through two separate LSTM units:  
(a) First, input the samples \(x_{t-1}\), \(x_{t}\), \(x_{t+1}\) into the LSTM unit in sequence according to the forward calculation, and obtain the forward state output \(\bigg{\{}h^{f}_{t-1},h^{f}_{t},h^{f}_{t+1}\bigg{\}}\); \begin{table}
\begin{tabular}{c c} \hline \hline
**Parameter** & **Meaning** \\ \hline \(\sigma\) & Sigmoid activation \\ \(\text{tanh}\) & Activation function \\ \(\text{W}\) & Weight matrix \\ \(\text{b}\) & Bias term \\ \(f_{t}\) & The forget gate outputs at time \(t\) \\ \(h_{t-1}\) & Input from the previous unit \\ \(\widetilde{C}\) & Memory cell output \\ \(C_{t-1}\) & The state of the previous memory cell \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Network structure parameters.