# A Ship Trajectory Prediction Method Based on an Optuna-BILSTM Model
## 2 Methods
### Deep Learning Prediction Models  
#### 2.2.1 BP Neural Network  
A typical BP neural network consists of three layers: the input layer, the hidden layer, and the output layer, each of which has multiple neurons that can run simultaneously, propagating the input signal forward and adjusting the error backward to find the weights that connect the neurons in different layers, thus building a BP neural network model. The structure diagram is shown in Figure 1:  
Suppose the nodes of the input layer neurons of the BP neural network are \(\mathrm{x}=\{\mathrm{x}_{1},\ldots,\mathrm{x}_{n}\}\). Then, the nodes of the hidden layer neurons are \(\mathrm{z}=\big{\{}\mathrm{z}_{1},\ldots,\mathrm{z}_{j}\big{\}}\); the nodes of the output layer neurons are \(\mathrm{y}=\{\mathrm{y}_{1},\ldots,\mathrm{y}_{k}\}\). For the hidden layer and the input layer, the connection weights between the output layer and the hidden layer are \(\mathrm{\mu_{nj}}\) and \(\mathrm{\omega_{jk}}\) and the thresholds between the layers are represented by \(\mathrm{\gamma_{j}}\) and \(\mathrm{\theta_{k}}\), respectively, and the expected output value of the output layer is \(\mathrm{d_{k}}\).  
The output of neurons in the forward-propagation hidden layer of the BP neural network is formulated as  
\[\mathrm{z_{j}}=\mathrm{f}\big{(}\sum_{n=1}^{N}\mathrm{\mu_{nj}}\mathrm{x_{n}} -\mathrm{\gamma_{j}}\big{)} \tag{3}\]  
The output of neurons in the output layer is given by  
\[\mathrm{y_{k}}=\mathrm{f}\big{(}\sum_{j=1}^{j}\mathrm{\omega_{jk}}\mathrm{z_{ j}}-\mathrm{\theta_{k}}\big{)} \tag{4}\]  
It can be seen that the output of the BP neural network is calculated from the connection weights and thresholds in the network.  
Figure 1: Network composition of a BP neural network.  
The error function of the BP neural network is formulated as  
\[\text{E}=\frac{1}{2}\text{$\sum_{k=1}^{k}$}(\text{d}_{k}-\text{y}_{k})^{2} \tag{5}\]  
where \(\text{d}_{k}\) is the actual output of the k samples, and \(\text{y}_{k}\) is the desired output of the samples.  
The variation in output layer weights in the back propagation of BP neural network errors is  
\[\Delta\omega_{jk}=-\eta\frac{\partial\text{E}}{\partial\omega_{jk}}=-\eta\frac {\partial\text{E}}{\partial\left(\sum_{j=1}^{l}\omega_{jk}\text{z}_{j}-\text{ \theta}_{k}\right)}\frac{\partial\left(\sum_{j=1}^{l}\omega_{jk}\text{z}_{j}- \text{\theta}_{k}\right)}{\partial\omega_{jk}}=\eta\delta_{jk}\text{z}_{j} \tag{6}\]  
The variation in the output layer threshold in back propagation is  
\[\Delta\theta_{k}=-\eta\frac{\partial\text{E}}{\partial\theta_{k}}=-\eta\frac {\partial\text{E}}{\partial\left(\sum_{j=1}^{l}\omega_{jk}\text{z}_{j}-\text{ \theta}_{k}\right)}\frac{\partial\left(\sum_{j=1}^{l}\omega_{jk}\text{z}_{j}- \text{\theta}_{k}\right)}{\partial\text{\theta}_{k}}=-\eta\delta_{jk} \tag{7}\]  
The variation in the implied layer weights in backward propagation is  
\[\Delta\mu_{nj}=-\eta\frac{\partial\text{E}}{\partial\mu_{nj}}=-\eta\frac{ \partial\text{E}}{\partial\left(\sum_{n=1}^{n}\mu_{nj}\text{x}_{n}-\gamma_{j} \right)}\frac{\partial\left(\sum_{n=1}^{n}\mu_{nj}\text{x}_{n}-\gamma_{j} \right)}{\partial\text{\eta}_{nj}}=\eta\delta_{nj}\text{x}_{n} \tag{8}\]  
The variation in the implicit layer threshold in back propagation is  
\[\Delta\gamma_{j}=-\eta\frac{\partial\text{E}}{\partial\gamma_{j}}=-\eta\frac {\partial\text{E}}{\partial\left(\sum_{n=1}^{n}\mu_{nj}\text{x}_{n}-\gamma_{ j}\right)}\frac{\partial\left(\sum_{n=1}^{n}\mu_{nj}\text{x}_{n}-\gamma_{j} \right)}{\partial\gamma_{j}}=-\eta\delta_{nj} \tag{9}\]  
In the above equation, \(\eta\) is the learning rate in the network, and the value of \(\eta\) is between 0 and 1.  
The BP neural network represents the most prevalent form of neural networks, embodying the general advantages associated with neural network technology, but it is not perfect. It has merits of self-learning and self-adaptative ability, but a disadvantage is its, slow convergence speed, and it is not suitable for long-term sequence problems.