# Optimized Dynamic Deployment of UAVs in Maritime Networks with Route Prediction
## 4 Proposed Algorithm
### Ship Trajectory-Prediction Algorithm Based on Improved LSTM
First, the SSA algorithm requires the initialization of a population, where each individual represents a set of hyperparameter combinations to be optimized, and the locations of these individuals are randomly generated within the upper and lower ranges \([lb,ub]\). Each individual's performance is evaluated by a fitness function (i.e., mean square error), where a smaller fitness value indicates that the hyperparameter combination is more effective. We categorize the updating strategies of individual positions into three categories; in each iteration, the top 50% of individuals update their positions using strategy 1, i.e., the individual positions are close to the current optimal individual, with the updating Equation (36), where \(x_{\text{best}}(t)\) is the position of the current optimal individual, and \(\epsilon\) is a uniformly distributed random number within the interval of \([-1,1]\), which is used to increase search diversity and avoid falling into local optimality. For the last 50% of individuals, update strategy 2 is used to generate new positions through a global random search, and the update formula is Equation (37), where \(L_{j}\) and \(U_{j}\) are the upper and lower limits of the \(j\)-th dimension, and \(\alpha_{j}\) is a random number in the interval \([0,1]\). After each position update, the algorithm performs boundary processing to ensure that the position \(x_{(i,j)}\) of each dimension stays within the upper and lower limits \([L_{j},U_{j}]\), which is handled by Equation (38). \[x_{i}(t+1)=x_{\text{best}}(t)+\epsilon\cdot|x_{i}(t)-x_{\text{best}}(t)| \tag{36}\]  
\[x_{i}(t+1)=L_{j}+\alpha_{j}\cdot(U_{j}-L_{j}) \tag{37}\]  
\[x_{(i,j)}(t+1)= \begin{cases}L_{j},&\text{if }x_{(i,j)}(t+1)<L_{j}\\ U_{j},&\text{if }x_{(i,j)}(t+1)>U_{j}\\ x_{(i,j)}(t+1),&\text{otherwise}\end{cases}  \tag{38}\]  
After each policy update, the algorithm will recalculate the fitness value of each individual and record the fitness of the current optimal individual. At the end of several iterations, the algorithm outputs the individual with the smallest fitness value, i.e., the optimal hyperparameter combination. The specific pseudo-code of the algorithm is as Algorithm 1:  
```
1:Input ship data (latitude, longitude, SOG, COG)
2:Initialize the LSTM model hyperparameter spaces \(lb\) and \(ub\);
3:Initialize population size, number of iterations, individual position population;
4:The fitness MSE was calculated for each individual in the population;
5:for each episode do
6: Find the current optimal individual \(x_{best}\);
7: For the top 50% of individuals, the individual's position was adjusted using the Equation (36) update strategy;
8: For the latter 50% of individuals, the location was updated using a global random search via the Equation (37);
9: Performs boundary processing by the Equation (38) in the updated position;
10: Reassess the fitness of each individual in the population;
11:endfor
12:Output the optimal individual, i.e., the optimal LSTM hyperparameter combination;
13: Constructing the model: Define an LSTM model with 2 hidden layers and compile the model using the Adam optimizer and MSE loss function. 14:Training LSTM models using optimal hyperparameter combinations;
15:Predicting the next trajectory of a vessel using a trained LSTM model;
16:Evaluate the prediction accuracy and calculate the mean square error;
```  
**Algorithm 1** Optimization of the LSTM model for ship route prediction using the SSA algorithm