## 3 LSTM Network Optimized by GA
### GA-LSTM Model  
In this paper, the GA and LSTM neural network models are combined to construct a ship trajectory prediction model based on GA-LSTM. Firstly, the GA is adopted to optimize the hyperparameters of the LSTM network, and then the best combination of learning rate and the number of hidden-layer neurons is obtained to further improve the nonlinear mapping ability of the model; in addition, the GA-LSTM model constructed by the optimal parameter combination is used as the nonlinear transformation function \(f(\cdot)\) between the input sample and output sample; on this basis, the nonlinear transformation function \(f(\cdot)\) is applied to obtain the position information of the ship at the next moment. The specific operation process of the model is as follows:  
1. Selecting training data set. In order to obtain the best-fitting effect of the function \(f(\cdot)\), the input data of the GA-LSTM model are composed of the navigation information of the ship at the past three moments, which are represented by the vector \(\mathbf{u}\), and the target output is represented by the vector \(\mathbf{M}\). As shown in Formula (11): \[\begin{array}{l}{\mathbf{u}}_{i}=[lat_{i-2},lat_{i-1},lat_{i},lon_{i-2},lon_{i- 1},lon_{i},sog_{i-2},sog_{i-1},sog_{i},og_{i-2},cosg_{i-1},cosg_{i}]^{T}\\ {\mathbf{M}}_{i}=\left[\begin{array}{c}lat_{i+1}\\ lon_{i+1}\end{array}\right]\end{array}\] (11)
2. Optimizing LSTM network parameters with the GA. 1. Taking the learning rate and the number of hidden-layer units of LSTM model as the optimization objects, and then performing the initialization of the population and the chromosome encoding and decoding operations. 2. Calculating the fitness value of each individual in the initial population. 3. Performing selection, crossover, and mutation operations on chromosomes. 4. Decoding chromosomes and calculating the fitness of individuals in the population. The smaller the fitness value in this algorithm, the more the individual should be retained; otherwise, the individual should be eliminated. 5. If the genetic termination conditions are not met, it will return to Step c. If the genetic termination conditions are met, the optimal parameters calculated by the GA are taken as the final parameters of the LSTM network model.
3. Training the GA-LSTM model. Inputting \(\mathbf{u}\) and \(\mathbf{M}\) into the GA-LSTM network of the optimal parameter combination, the output of the GA-LSTM network model is the position of the ship at the next moment. The difference between the target output \(\mathbf{M}\) and the predicted output \(f(\mathbf{u})\) of the model is represented by the error \(\mathbf{e}\), which is \(\mathbf{e}=\mathbf{M}-f(\mathbf{u})\). The GA-LSTM model minimizes the fitting error \(E(\mathbf{e}^{T}\mathbf{e})\) according to the mean square error and finally obtains the best-fitting function \(\widehat{f}(\cdot)\) between the input samples and the output samples.
4. Predicting ship trajectory.  
The experimental data are sent to the GA-LSTM model, and then the ship navigation position at the next moment is calculated by using the best-fitting function \(\widehat{f}\left(\cdot\right)\).  
The ship trajectory prediction model framework is shown in Figure 2. The framework is mainly composed of three parts: data preprocessing, model analysis, and error analysis. Data preprocessing is an essential part of GA-LSTM model, and the data after preprocessing can improve the overall performance of the model to a certain extent. For model analysis, the GA is introduced into the selection of network hyperparameters based on the LSTM network model, which reduces the influence of artificial determination to some extent. For error analysis, visualization and index evaluation are used to further verify the feasibility and performance of the proposed method.