## 2 Problem Description and Methods
### Prediction and Optimization Methods  
#### 2.2.1 LSTM and BILSTM  
Recurrent Neural Network (RNN) is a class of neural network with short-term memory capability, which has the characteristics of memorability and parameter sharing and can make full use of the historical features of the data, so it has better results in dealing with time series problems. However, RNN also has its drawbacks: if the delay of the time series is too long, RNN has the problem of gradient explosion and disappearance. Long Short-Term Memory (LSTM) Network is a special kind of RNN, which adds memory cells to selectively remember important information and eliminate noisy information, and adds three gating cells: forgetting gate, input gate, and output gate so that LSTM can better control the global memory cells and \"remember\" information for a longer period of time. LSTM has demonstrated excellent performance in processing time series data, making it particularly suitable for handling AIS data with significant time patterns and large volumes of data. Through its ability to effectively extract potential change patterns in information, LSTM is well-suited for achieving nonlinear prediction tasks such as ship trajectory prediction.  
The structure of the LSTM cell is shown in Figure 3. The data of the model are the processed ship trajectory time series, \(x_{t}\) is the data at moment \(t\), \(c\) is the cell state, \(h\) is the hidden state, \(c_{t-1}\) and \(h_{t-1}\) are the long-term memory value and short-term memory  
Figure 2: Sliding time window.  
value at moment \(t-1\), respectively, and the output value is the memory value \(c_{t-1}\) and the output value \(h_{t-1}\) at moment \(t\). The forgetting gate \(f_{t}\) in the unit performs selective memory of information by taking the information of the memory unit \(c_{t-1}\) at the previous moment, \(f_{t}\) as in Equation (4).  
\[f_{t}=\sigma\Big{(}w_{xf}\cdot x_{t}+w_{hf}\cdot h_{t-1}+w_{cf}\cdot c_{t-1}+b_ {f}\Big{)}, \tag{4}\]  
where \(\sigma\) is the sigmoid activation function; \(b_{f}\) is the bias peak; and \(w\) is the matrix of weights between the layer and each gate. The input gate \(i_{t}\) determines the important information to be remembered, and the variables are controlled between [0, 1] by the sigmoid activation function and the output \(i_{t}\), as in Equation (5).  
\[i_{t}=\sigma(w_{xi}\cdot x_{t}+w_{hi}\cdot h_{t-1}+w_{ci}\cdot c_{t-1}+b_{i}), \tag{5}\]  
The state change of the cell \(c_{t}\) is determined by the output of the forgetting gate and the input gate, which is given by Equation (6).  
\[c_{t}=f_{t}c_{t-1}+i_{t}\text{tanh}(w_{xc}\cdot x_{t}+w_{hc}\cdot h_{t-1}+b_{c }), \tag{6}\]  
where tanh denotes the hyperbolic tangent activation function. The output gate \(o_{t}\) performs the transfer of cell state values with the formula as in Equation (7).  
\[o_{t}=\sigma(w_{xo}\cdot x_{t}+w_{ho}\cdot h_{t-1}+w_{co}\cdot c_{t-1}+b_{o}). \tag{7}\]  
The LSTM has better performance in predicting nonlinear time series data, but it can only learn the previous information, while for the training task of ship trajectory, the ship's motion trajectory is vainly coherent, and the ship's position at the next moment is influenced by the combination of the data of the previous moment and the data of the following moment. BILSTM structurally combines the LSTM network in two directions, and through the bidirectional structure, the output layer of the network can effectively use the state information of the previous cell and the state information of the latter cell to fully utilize the data for prediction. Its model structure is shown in Figure 4.  
Figure 3: The structure of the LSTM.  
The hyperparameters of neural networks are often judged by manual experience; thus the selection of hyperparameters in the experiment is random, and the unreasonable selection of hyperparameters will affect the accuracy of ship trajectory prediction. Therefore, this paper selects a heuristic algorithm to optimize the network.