# Risk Propagation Mechanism and Prediction Model for the Highway Merging Area
## 5 Traffic Accident Risk Prediction Model
### Model  
#### 5.1.1 LSTM  
Risk propagation is a dynamic process, where future risks may be influenced by past risks and have a cumulative effect over time. Traditional statistical models cannot accurately model this dynamic and complex nature, but LSTM (long short-term memory) model, as a deep learning model suitable for modeling sequence data, can effectively solve this problem. An LSTM model can store previous information and predict future risk trends, making it widely applicable in risk forecasting [34]. It is capable of modeling time series data and handling long-term dependencies in sequence data. This makes it particularly suitable for risk prediction, as the time accumulation effect of risk propagation requires a model that can identify and handle long-term dependencies in sequence data. Therefore, the memory and long-term dependency processing capabilities of LSTM models make them a highly suitable tool for risk prediction. An LSTM model introduces \"gates\" to control the flow of information, which allows the network to selectively remember or forget previous information.  
The core of LSTM is the cell, which is controlled by three gates: the input gate, the forget gate, and the output gate. The input gate controls the input of new information, the forget gate controls the forgetting of old information, and the output gate controls the output of the cell state. The specific steps are as follows:  
1. The input gate controls the input of new information by multiplying the input vector with the weight matrix through sigmoid function to produce a numerical vector between 0 and 1.
2. The forget gate controls the forgetting of old information by multiplying the input vector with the weight matrix through sigmoid function to produce a numerical vector between 0 and 1. This vector will be element-wise multiplied with the cell state vector to determine which old information should be forgotten.
3. The cell state is updated by element-wise multiplying the vector generated by the forget gate with the cell state from the previous time step to obtain the old information that needs to be retained and multiplying the vector generated by the input gate with the new information processed by a function element-wise to obtain the new  
Figure 10: Flowchart of the traffic accident risk prediction model.  
information that needs to be added. These two vectors are added together to obtain the updated cell state.
4. The output gate controls the output of the cell state by multiplying the input vector with the weight matrix through sigmoid function to produce a numerical vector between 0 and 1. This vector is then element-wise multiplied with the cell state vector processed by a function to obtain the final output vector. Assuming the current time series is \(t\) and the data input is \(x\), the predicted output is \(h\), and \(c\) is the memory cell. The network structure can be constructed as Figure 11.  
In Figure 11, \(\sigma\) represents the sigmoid activation function; \([h_{t-1},x_{t}]\) is the composite matrix of the previous prediction result \(h_{t-1}\) and the input parameter \(x_{t}\) in this round, which is the input parameter at time \(t\); \(W_{t}\) is the forget gate weight matrix; \(W_{c}\) is the output weight matrix; and \(W_{o}\) is the current state control matrix. The numerical expressions of the forget, input, control, and output gates can be represented by Equations (7)-(11):  
\[f_{t}=\sigma(W_{f}[h_{t-1},x_{t}]+b_{f}) \tag{7}\]  
\[i_{t}=\sigma(W_{t}[h_{t-1},x_{t}]+b_{i}) \tag{8}\]  
\[c_{t}=f_{t}c_{t-1}+\tan(W_{c}[h_{t-1},x_{t}]+b_{c}) \tag{9}\]  
\[o_{t}=\sigma(W_{o}[h_{t-1},x_{t}]+b_{o}) \tag{10}\]  
\[h_{t}=o_{t}\text{tanh}(c_{t}) \tag{11}\]  
where \(b_{f}\), \(b_{i}\), \(b_{c}\), and \(b_{o}\) are bias vectors for the forget, input, control, and output gates, respectively. All other parameters have been described above.