# A Ship Trajectory Prediction Method Based on an Optuna-BILSTM Model
## 2 Methods
### Deep Learning Prediction Models
#### 2.2.2 BILSTM Model  
1. Recurrent Neural Networks  
In the traditional architecture of artificial neural networks, the recurrent neural network (RNN) is characterized by its fully connected layers, spanning from input to hidden layers and culminating at the output layer, with the nodes between each layer lacking interconnections. This ordinary neural network is relatively powerless in dealing with time-series problems and is improved on the basis of the BP neural network. Recurrent neural networks (RNN) exhibit a profound capacity for time-series modeling and feature extraction, underpinned by the recursive connectivity within its architecture. This principle posits that the output of a given sequence element is contingent upon its predecessor, which is encapsulated by the network's ability to retain prior information for incorporation into current output calculations. Contrary to isolated connections in traditional models, the nodes across hidden layers in an RNN are intricately linked, incorporating both the current input layer's output and the preceding hidden layer's output. This integration allows for the juxtaposition of current and past data, facilitating the generation of outputs that are significantly more informative and contextually relevant. Figure 2 shows the structure of the recurrent neural network after unfolding by time, where x, s, and o denote the sequence vectors of the output layer, the hidden layer, and  
the output layer. U denotes the data information input to the hidden layer that is affected by the weights; V denotes the output of the hidden layer adjusted by the weight matrix; and W denotes the information conduction between the same hidden layers adjusted by the parameters. In the structure of the RNN after time unfolding, the value of the hidden layer \(\rm{s_{t}}\) is determined by the input at moment \(\rm{x_{t}}\) and the output value of the hidden layer \(\rm{s_{t-1}}\) together. The computational principle of the recurrent neural network is as follows:  
\[\rm{s_{t}}=f(Ux_{t}+Ws_{t-1}+b) \tag{10}\]  
where \(\rm{x_{t}}\) denotes the data information input for moment \(\rm{t}\), \(\rm{f}\) denotes the nonlinear activation function, U is the weight matrix of \(\rm{s_{t}}\), and \(\rm{b}\) is the bias term in the neural network. \[\rm{o_{t}}=g(Vs_{t}+c) \tag{11}\]  
where \(\rm{o_{t}}\) denotes the output of the \(\rm{tth}\) layer in the network, \(\rm{g}\) is the activation function, and V denotes the weight parameter from the hidden layer to the output layer. It can be seen from the structure that the output of RNN can be multiple and ordered, and the state information of the previous part of the moment can be retained in the hidden layer, so the RNN has the ability to preserve and transmit the state of long-time-series data information, which can be used to study time-series prediction tasks. 2. Long- and short-term memory neural networks  
The RNN can only make comparisons with the last output, but as time passes and the number of times increases, it is likely that the gradient disappears, and the prediction model loses its meaning and does not achieve the expected results for long-time-series data prediction. The long short-term memory network (LSTM) enhances the architecture of recurrent neural networks in several ways. Firstly, it modifies the structure of its neurons. Secondly, it increases the number of memory cells to store historical information from past moments with long time intervals. Thirdly, it introduces a gate structure to add, delete, and process data information. These modifications ensure that the current moment of cellular information processing maintains a strong temporal correlation with past information, even when separated by a long time. Consequently, LSTM effectively addresses the gradient-disappearance phenomenon observed in RNNs when predicting long-time-sequence data. \(\rm{X_{t}}\) and \(\rm{h_{t}}\) in Figure 3 are the input and output of the cell, respectively, and the memory cell \(\rm{C_{t}}\) is used to maintain the cell state \(\rm{h_{t}}\).