# A Ship Trajectory Prediction Method Based on an Optuna-BILSTM Model
## 3 BILSTM neural network
### Pre-Processing of Data
#### 2.3.4 Prediction Model Evaluation Metrics  
This study selects the root mean square error (RMSE) as the evaluation metric to assess the quality of the model's predictive performance.  
The error between the prediction point \(\mathrm{P^{\prime}}\) and the observation point \(\mathrm{P}\) at the i-th moment in the model can be expressed as  
\[\mathrm{e_{\lambda}}=\lambda_{\mathrm{i}}^{\prime}-\lambda_{\mathrm{i}} \tag{23}\]  
\[\mathrm{e_{\varphi}}=\varphi_{\mathrm{i}}^{\prime}-\varphi_{\mathrm{i}} \tag{24}\]  
In this context, \(\mathrm{e_{\lambda}}\) and \(\mathrm{e_{\varphi}}\) represent the longitude and latitude errors, respectively, between the predicted point \(\mathrm{P^{\prime}}\) and the observed point \(\mathrm{P}\) at the i-th time instance. Here, \(\lambda_{\mathrm{i}}^{\prime}\) and \(\varphi_{\mathrm{i}}^{\prime}\) denote the predicted longitude and latitude values, while \(\lambda_{\mathrm{i}}\) and \(\varphi_{\mathrm{i}}\) stand for the actual longitude and latitude values. In this paper, in order to be able to evaluate the prediction results of the model more intuitively, the surface arc distance between the observation point and the prediction point is used as the evaluation criterion, in which the surface arc distance \(\mathrm{dist_{i}}\) between the observation point and the prediction point is calculated as follows:  
\[\mathrm{S_{i}}=\mathrm{sin}\big{(}\lambda_{\mathrm{i}}^{\prime}\big{)}* \mathrm{sin}(\lambda_{\mathrm{i}})*\mathrm{cos}\big{(}\varphi_{\mathrm{i}}^{ \prime}-\varphi_{\mathrm{i}}\big{)}+\mathrm{cos}\big{(}\lambda_{\mathrm{i}}^{ \prime}\big{)}*\mathrm{cos}(\lambda_{\mathrm{i}}) \tag{25}\]  
\[\mathrm{dist_{i}}=\mathrm{R}*\mathrm{arccos}(\mathrm{S_{i}})*\mathrm{\pi}/180 \tag{26}\]  
where \(\mathrm{R}\) denotes the mean radius of the earth and takes the value of 6371.004 km.  
The formula for calculating the root mean square error is shown below:  
\[\mathrm{RMSE_{\lambda}}=\sqrt{\frac{1}{n}\mathrm{\sum}_{i=1}^{n}\big{(} \lambda_{\mathrm{i}}^{\prime}-\lambda_{\mathrm{i}}\big{)}^{2}} \tag{27}\]  
\[\mathrm{RMSE_{\varphi}}=\sqrt{\frac{1}{n}\mathrm{\sum}_{i=1}^{n}\big{(} \varphi_{\mathrm{i}}^{\prime}-\varphi_{\mathrm{i}}\big{)}^{2}} \tag{28}\]  
\[\mathrm{RMSE_{dist}}=\sqrt{\frac{1}{n}\mathrm{\sum}_{i=1}^{n}\big{(} \mathrm{dist_{i}}\big{)}^{2}} \tag{29}\]  
In the above equation, \(\mathrm{RMSE_{\lambda}}\), \(\mathrm{RMSE_{\varphi}}\) and \(\mathrm{RMSE_{dist}}\) represent the root mean square error in the longitude, latitude, and distance directions, respectively; \(\mathrm{n}\) represents the number of test samples; \((\lambda_{\mathrm{i}},\varphi_{\mathrm{i}})\) represents the true value of the i-th sample; \((\lambda_{\mathrm{i}}^{\prime},\varphi_{\mathrm{i}}^{\prime})\) represents the predicted value of the i-th sample, and \(\mathrm{dist_{i}}\) represents the error of the distance between the predicted value and the true value of the surface arc of the i-th sample.  
The formula for calculating the accuracy is as follows:  
\[\mathrm{MAPE_{\\[\text{MAPE}_{\varphi}=\frac{100\%}{n}\sum_{i=1}^{n}\left|\frac{\varphi_{\text{i}}- \varphi_{\text{i}}^{\prime}}{\varphi_{\text{i}}}\right| \tag{31}\]  
MAPE is primarily utilized to quantify the proportion of deviation between model-predicted values and actual values. By computing the average, it offers an intuitive percentage indicator regarding the prediction accuracy. Lower MAPE values signify a higher prediction accuracy, making it particularly suitable for assessing the average error level of prediction results.