# Traffic Conflict Prediction for Sharp Turns on Mountain Roads Based on Driver Behavior Patterns
## 2 Materials and Methods
### Methodological Framework
#### 2.2.2 LSTM Neural Network Structure Design  
The formation of traffic conflict is a complex, dynamic process, and a prediction model should be able to describe the non-linear relationship between variables and consider the time-series effect. A Long Short-Term Memory network (LSTM) was chosen as the basic model architecture. An LSTM network is an improved recurrent neural network, which can effectively learn and retain long-term dependent information by introducing gated units and memory units, and it performs well in time-series prediction tasks. Figure 5 shows the structure of the constructed LSTM traffic conflict prediction model. The model takes the characteristic variables of the past \(n\) time steps as input and outputs the traffic conflict risk level of the future 1 time step. The model mainly includes the following parts:  
Figure 4: Illustration of the construction of an FP-Tree.  
(1) Input layer: Receives the time series composed of 11 dimensional characteristic variables; the length of the series is n, that is, where \(\mathrm{X}=(\mathrm{x}_{1},\mathrm{x}_{2},\cdots,\mathrm{x}_{n}),\ \mathrm{x}_{t}\in\mathrm{R}^{11}\).  
(2) LSTM layer: Contains m LSTM units, which are used to extract the timing features of the input sequence. Each LSTM unit receives the input of the current moment, \(x_{t}\); the hidden state, \(h_{t-1}\); and the memory state of the previous moment, \(c_{t-1}\), and comprehensively updates the hidden state, \(h_{t}\), and the state of the current moment, \(c_{t}\).  
\[\begin{array}{ll}\dot{\mathbf{i}_{t}}&=\sigma(\mathbf{W}_{ii}\mathbf{x}_{t}+\mathbf{W}_{ii} \mathbf{h}_{t-1}+\mathbf{b}_{i})\\ \mathbf{f}_{t}&=\sigma(\mathbf{W}_{if}\mathbf{x}_{t}+\mathbf{W}_{hf}\mathbf{h}_{t-1}+\mathbf{b}_{f})\\ \mathbf{o}_{t}&=\sigma(\mathbf{W}_{io}\mathbf{x}_{t}+\mathbf{W}_{ho}\mathbf{h}_{t-1}+\mathbf{b}_{o})\\ \widetilde{\mathbf{c}_{t}}&=\tanh(\mathbf{W}_{ic}\mathbf{x}_{t}+\mathbf{W}_{hc}\mathbf{h}_{t-1}+ \mathbf{b}_{c})\\ \mathbf{c}_{t}&=f_{t}\odot\mathbf{c}_{t-1}+\dot{t}_{t}\odot\widetilde{\mathbf{c}_{t}}\\ \mathbf{h}_{t}&=\sigma_{t}\odot\tanh(\mathbf{c}_{t})\end{array}\]  
where \(i_{t},\ f_{t}\), and \(o_{t}\) represent the input gate, forget gate, and output gate, respectively. \(\odot\) denotes element-wise multiplication, while \(\sigma(\cdot)\) stands for the Sigmoid activation function.  
Fully connected layer: Passes the output, \(h_{n}\), of the LSTM layer to a fully connected layer and uses the Softmax function to map it onto a probability distribution of traffic conflict risk levels.  
\[\mathbf{y}=\text{softmax}(\mathbf{W}\mathbf{h}\mathbf{y}\mathbf{h}_{n}+\mathbf{b}_{y}) \tag{1}\]  
where \(\mathbf{y}\in\mathrm{R}^{\mathrm{k}}\) and \(\mathrm{k}\) is the number of categories of traffic conflict risk levels.  
Output layer: Based on the probability distribution of \(\mathbf{y}\), the predicted level of traffic conflict risk is the output.  
\[\hat{y}=\text{argmax}_{\mathbf{y}}y_{i} \tag{2}\]  
By using the memory ability of the LSTM unit, the model can adaptively learn the long-term dependence pattern in the evolution process of traffic conflict and provide timely warning of the conflict risk level in the future period according to the current driving behavior, road condition environment, and other factors to provide decision support for drivers and traffic management departments.