Online Prediction of Ship Roll Motion in Waves Based on Auto-Moving Gird Search-Least Square Support Vector Machine

A novel method based on auto-moving grid search-least square support vector machine (AGS-LSSVM) is proposed for online predicting ship roll motion in waves. To verify the method, simulation data are used, which are obtained by solving the second-order nonlinear diﬀerential equation of ship roll motion using the fourth-order Runge–Kutta method, while the Pier-son–Moskowitz spectrum (P–M spectrum) is used to simulate the irregular waves. Combining the sliding time window with the least square support vector machine (LS-SVM), the samples in the time window are used to train the LS-SVM model, and the model hyperparameters are optimized online by the auto-moving grid search (AGS) method. The trained model is used to predict the roll motion in the next 30seconds, and the prediction results are compared with the simulation data. It is shown that the AGS-LSSVM is an eﬀective method for online predicting ship roll motion in waves.


Introduction
Prediction of ship motion at sea is important for ship's safety and efficient operation. Among various modes of ship motion induced by waves, roll motion is the most important one. Due to the nonlinearity of the restoring moment, the damping moment, and the wave exciting moment, ship roll motion in heavy seas is a typical nonlinear motion. Especially under severe sea conditions, strong nonlinear roll motion will seriously threaten the ship's navigation safety and degrade the ship's maneuverability. Prediction of ship roll motion is of great significance, which can not only provide a guarantee for marine operations such as cargo lightering and landing of shipborne aircraft under wind and wave conditions but also help to improve the safety of navigation and avoid ship capsizing. erefore, a study in this field has received widespread attention and various methods have been applied, such as AR (AutoRegressive) models [1], hybrid models combining deep learning and ARIMA (AutoRegressive Integrated Moving Average) [2], local linear wavelet neural networks [3], gray topological methods combining gray systems theory [4], least square support vector machines [5], and gray sequential limit learning machines [6]. As research progresses, the applicability and accuracy of ship roll motion prediction are being improved.
For ship motion prediction, much research has been carried out. e main prediction methods can be divided into three categories, that is, the linear methods, the nonlinear methods, and the hybrid methods of the first two. e main linear methods include the Kalman filter method, bow wave method, AR method, AutoRegressive Moving Average (ARMA) method, and ARIMA method. e commonly used nonlinear methods include Neural Network (NN) and support vector machine (SVM) methods.
Currently, Kalman filtering is the most widely used filtering method and has been well applied in many fields such as communication, guidance, and control. Richter et al. [7] used the Kalman filter to estimate the ship heave motion in real time. Lin et al. [8] used the Kalman filter and an improved AR model to predict the ship motion. e advantage of the Kalman filter method is that it can estimate the state of a dynamic system from noisy data, and the computation is simple. However, the premise of the known system state equation limits the application of this method to a certain extent, especially for ships sailing at sea. e environmental disturbance makes it difficult to obtain accurate state equations of ship motion. e bow wave method uses wave measurement information at a certain distance from the ship's bow and the historical data of ship motion to predict the ship's motion at subsequent moments. However, in the actual ship navigation, the wave information is difficult to measure and the cost is high. e classic AR, ARMA, and ARIMA methods are also widely used in online prediction of ship motion. Wu et al. [9] made a short-term prediction of ship motion based on the improved AR model. e modeling methods of AR, ARMA, and ARIMA models are simple, and the computation burden is small, but they are mainly suitable for modeling and prediction of linear systems; for the problem of strongly nonlinear ship roll motion, these methods still have certain limitations.
In recent years, with the development of artificial intelligence technology, machine learning methods such as NN and SVM have been increasingly widely used in various fields. Huang et al. [10] used a coarse and fine-tuning fixed gird wavelet network to predict ship roll motion. Yin et al. [11] used RBF networks to conduct online prediction of roll motion during ship maneuvering. Yang et al. [12] proposed an online least square SVM (LS-SVM) method combined with the EMD (Empirical Mode Decomposition) for ship roll prediction. Duan et al. [13] proposed a hybrid AR-EMD-SVR (Support Vector Regression) model for the prediction of nonlinear and nonstationary ship motion. As an excellent machine learning method, SVM has rigorous derivation based on mathematical theory and can obtain the optimal solution in the case of limited samples. It has an excellent performance in nonlinear function fitting, as well as parameter identification and prediction of ship nonlinear motion.
For machine learning algorithms, there are usually two kinds of parameters, that is, model parameters and hyperparameters. e model parameters do not need to be set in advance and can be learned by the model, while the hyperparameters need to be set in advance. For different problems, different data sets, and different models, the hyperparameters are different. Like other machine learning methods, the performance of SVM depends on the selection of its hyperparameters [14]. Different data distributions often have different hyperparameter combinations.
At present, for the prediction of ship roll motion, offline training and then online prediction are usually implemented. e hyperparameters are selected based on experiences in the offline training phase or selected by an optimization algorithm, such as grid search, random search, genetic algorithm, particle swarm optimization, and Bayesian optimization. e problem of offline training the model and selecting the hyperparameters is that it does not consider the complex and changeable sea conditions in actual navigation.
is means that the optimized hyperparameters for the offline data may not be suitable for the online data under different sea conditions.
In order to meet the requirements of online prediction, this paper proposes an effective auto-moving grid search (AGS) method to innovate in the online hyperparameter optimization for LS-SVM. In the AGS method, the offline grid search algorithm is evolved into an online one that can be automatically adjusted by controlling the relative proportion of the grid rather than the actual grid values. is gives the proposed prediction method the features of online updating the sample set, online learning, and real-time predicting. e rest of the paper is organized as follows: Section 2 describes the principles of the algorithm, including LS-SVM, time windows, and AGS; Section 3 presents the data preparation, that is, the acquisition of ship roll motion data by simulation; in Section 4, the prediction results are presented and compared; and Section 5 provides a summary of the innovations and shortcomings of the methodology presented in this paper.

LS-SVM.
LS-SVM is a variant of SVM. By selecting the square loss function, although the LS-SVM loses the important feature of sparseness, it converts the solution of the quadratic optimization problem into the solution of linear equations, which greatly speeds up the computation, and does not affect the accuracy of the computation [15]. In recent years, LS-SVM has been used in many studies such as image classification [16], control of nonlinear systems [17], short-term wind speed prediction [18], and freight volume prediction in logistics systems [19].
Consider a multiple-input single-output system, the set of training sample pairs is (x i , y i ) l i�1 , x i ∈ R m , y i ∈ R, where R is the Euclidean space, m is the dimension of the input in a single sample pair, and l is the total number of sample pairs. LS-SVM maps the input data into a high-dimensional space through nonlinear mapping, thereby transforming the nonlinear regression problem into a linear regression problem. e regression form is expressed as wherex is the input, y(x) is the output, φ(x) is the highdimensional nonlinear mapping used; andw and b are the weight vector and bias vector to be solved. e solution of LS-SVM is transformed into the following optimization problem: where e i is the regression error and C is the penalty parameter.
Using structural risk minimization, the Lagrange function of the objective function and constraint conditions is given as Taking the partial derivative with respect to the variables w, b, e, α in equation (3) and setting the derivatives to zero, the following equation is obtained: After eliminating e i and w, the following equation is obtained: where is the kernel function), and α � [α 1 , α 2 , . . . , α l ] T , y � [y 1 , y 2 , . . . , y l ] T . By introducing the kernel function, it is avoided to solve the specific highdimensional nonlinear mapping φ(x); one only needs to express its inner product through the kernel function.
One of the advantages of SVM is to introduce a kernel function, thereby transforming the complex nonlinear mapping into a relatively simple kernel function. e commonly used kernel functions include linear kernel, polynomial kernel, and Gaussian kernel. For nonlinear problems, Gaussian kernel function is generally used [20], and its expression is as follows: where σ is the parameter of the kernel function. After determining the kernel function, the parameters α and b in (5) are solved to obtain the following regression estimation function:

Online Learning Algorithm.
e motion of a ship in waves is a dynamic process that constantly changes over time, during which new sample data are continuously generated. If all samples are used for SVM training, the algorithm will inevitably become slower and slower. In addition, the future state has little correlation with the old samples but has a great correlation with the new samples. erefore, the online learning of SVM can be decomposed into a learning process of adding one sample (incremental learning) and eliminating one sample (decremental learning).
is paper uses the method of sliding time window to update the samples, that is, when new samples are added to the training sample set, the oldest samples in the training sample set are deleted to keep the total number of samples in the time window constant. is can not only learn the new features of the system in time but also maintain the stability of the algorithm in terms of time consumption.
e samples in the time window are combined according to Table 1 to form a training sample set used to train the model online. After the model training is completed, the kstep motion prediction of future values is realized using the trained model according to Table 2.

Auto-Moving Grid Search Algorithm.
In machine learning algorithms, adjusting the model hyperparameters is an important task. For the LS-SVM using Gaussian kernel, there are two hyperparameters that need to be adjusted: the penalty parameter C and the kernel parameter σ. e penalty parameter represents the intensity of the penalty for errors. e larger the value, the smaller the tolerance for errors, and the more likely it is to be affected by noise, which may result in overfitting. e kernel parameter σ affects the complexity of mapping the low-dimensional samples to the high-dimensional space. e smaller the value of this kernel parameter, the higher the dimensionality of the mapping; and it is also prone to overfitting, which reduces the generalization ability. us, the hyperparameters should neither be too large nor too small; choosing a suitable hyperparameter combination is extremely important to the performance of SVM.
For the hyperparameter optimization problem, the commonly used methods include grid search [21], random search [22], genetic algorithm [23], particle swarm optimization [24], and Bayesian optimization [25]. Grid search is an exhaustive search method. Its core is to list all combinations of parameters, try every possibility, and select the best hyperparameter combination. Compared with the grid search, the random search does not try all parameter values but selects a fixed number of parameter settings from a specified distribution. Its theoretical basis is that if the random sample point set is large enough, then the global optimal solution or its approximate value can be found. Random search is faster than grid search, but its disadvantage is that its results cannot be guaranteed and are not stable enough. e genetic algorithm is a method to search for the optimal solution by simulating the natural evolution process. Particle swarm optimization originated from the study on predation behavior of birds, and its basic idea is to find the optimal solution through cooperation and information sharing between individuals. e main idea of Bayesian optimization is to use the Gaussian process, consider the previous parameter information, and continuously update the prior. All of the methods mentioned above can be used for offline hyperparameter optimization of SVM. However, for the problem of online prediction of ship motion, there is a limitation to give prediction results within a limited time interval; and it is needed to update the hyperparameters online. Moreover, the running time of the offline optimization methods mentioned above is usually in hundreds of seconds [26], and if they are applied directly to the online case, they will not be able to meet the real-time requirements of the online case due to the large time consumption in parameter optimization. erefore, it is necessary to improve the hyperparameter optimization methods to make them suitable for online prediction of ship motion. Considering the stable and effective characteristics of the grid search method, this paper proposes an improved grid search scheme, the auto-moving grid search (AGS), which can dynamically adjust the hyperparameters online. Figure 1 shows the flowchart and the main idea of the AGS algorithm.
For the two hyperparameters C and σ to be optimized in LS-SVM, the initial parameter combinations C 0 and σ 0 can be selected, and a set of search ratios K � [r 1 , r 2 , r 3 , . . . 1, . . . , r n ] can be defined at the same time. As the time step progresses, the hyperparameters are continuously updated iteratively. At each time, the selection of hyperparameters is based on the following scheme: assuming the value of the hyperparameter to be optimized is W and the search grid is K, the possible value W × K of this round is obtained, which is the search range of this round; the samples in the time window are divided into the training set and validation set with the ratio of 8 : 2 that is commonly used in machine learning algorithms. en, multiple models on the training set are trained at the same time, and each hyperparameter value corresponds to a model. After the model training is completed, the accuracy of each model is verified on the validation set, and the model with the smallest error is selected as the predicting model of the current round, and its corresponding hyperparameter is the optimal hyperparameter at this time. Since each search is performed based on the excellent hyperparameters selected in the previous round, the hyperparameters are continuously optimized and improved to meet the needs of online parameter adjustment.
Besides, the setting of the search ratio K follows the principle of density: the grids adjacent to the Table 2: k-step prediction.

Prediction
Input  hyperparameters selected in the previous round are denser, and the grids far away are sparser. is setting can not only obtain a larger search range but also make minor adjustments to the hyperparameters selected in the previous round.

Nonlinear Ship Roll
Motion. e linear roll motion of a ship can be described by a second-order linear differential equation with constant coefficients, and an accurate solution can be obtained by conventional methods. But in fact, the ship motion in heavy seas is nonlinear, and the large-amplitude roll motion is more prominent, which is a typical nonlinear motion problem [10]. e nonlinear roll motion of a ship is affected by many factors. It is generally believed that the nonlinear roll motion is mainly caused by the nonlinearity of the restoring moment, the nonlinearity of the damping moment, and the nonlinearity of the wave exciting moment. e nonlinearity of the restoring moment is determined by the ship's static stability curve. In the range of small roll angle, there is a linear relationship between the restoring moment M r and the roll angle φ, that is, M r � DGMφ, where D is the displacement and GM is the transverse metacentric height. As the roll angle increases, the restoring moment exhibits a nonlinear relationship with the roll angle. e general nonlinear restoring moment can be expressed as where C 1 , C 2 , and C 3 are constants. e widely used models of nonlinear roll damping moment mainly include where A, B, and C are constants. When the assumption of small-amplitude waves is not valid, the wave exciting moment has a nonlinear relationship with the roll angle, which will cause the nonlinear roll motion of the ship.

Irregular Waves and the Wave Exciting Moment.
e real ocean waves are random and irregular and cannot be described in a definite form. However, considering the convenience of the study, they can be regarded as a superposition of a certain number of regular waves with different wavelengths, amplitudes, and random phases. In this paper, the Pierson-Moskowitz spectrum (P-M spectrum) is used to simulate the random irregular waves. e expression is as follows: where ω is the wave frequency (rad/s); g is the gravitational acceleration, g � 9.81 m/s 2 ; and U is the wind speed (m/s) at a height of 19.5 m above the sea.
When the significant wave height h 1/3 is known, the wind speed can be approximately estimated by the following formula: Using the wave spectrum, the random wave exciting moment on a ship sailing in irregular waves can be deduced: where x is the angle between the ship's speed V and the direction of wave propagation, called encounter angle; N is the number of random regular waves (cosine waves), K B K T is the effective wave inclination coefficient, ω i and θ i are the frequency and random phase of the i-th regular wave, respectively, ω e i is the corresponding encounter frequency, and ω e i � ω i − ω 2 i V cos x/g in deep water. e irregular waves can be regarded as a random process with an energy spectrum of limited bandwidth. Generally, when the number of cosine wave components N reaches 30, this requirement can be met; thus,N ≥ 30.

Simulation Data.
In this paper, a maritime patrol boat [27] is taken as the study object. Its main parameters are listed in Table 3. e significant wave height is set as h 1/3 � 1.3m, and the number of cosine waves is taken as N � 50. According to the data of the P-M spectrum, when the sea state level is low, the energy of the waves is more dispersed, and the simulated frequency band can be set to be relatively wide; on the contrary, if the sea state level is high, the energy of the waves is more concentrated, and the simulated frequency band can be set to be relatively narrower [28]. Taking the simulated frequency range as 0.5-3.0 rad/s, the wave spectral density S ζ (ω) obtained according to the P-M spectrum is shown in Figure 2. e ship navigating in the waves is affected by the restoring moment, damping moment, and the random wave exciting moment, and they are described by (8), (10), and (13), respectively. e second-order nonlinear differential equation for the ship roll motion can be derived as follows: In order to more comprehensively illustrate the effectiveness of the AGS method, simulation tests are carried out for four encounter angles, namely, 60°, 90°, 120°, and 150°, at the ship speed 18 kn. For equation (14), the analytical solution cannot be obtained, and the fourth-order Runge-Kutta method is used to obtain the numerical solution.
e numerical simulation step is 0.01 s, and the total simulation time is 500 s. For the 50000 sets of roll angle data obtained from the simulation, samples are taken every 50, that is, the sampling step is 0.5 s. As an example, the Mathematical Problems in Engineering 5 simulation results under the encounter angle of 120°are presented, as shown in Figure 3.

Online Prediction of Roll Motion and Analysis of the Results
In order to verify the effectiveness of the AGS algorithm, the results of two methods for online prediction are compared: one is to use constant hyperparameters and the other is to use those obtained by the AGS algorithm.
In the study, four encounter angles are considered, corresponding to four sets of simulation data. At the same time, four sets of hyperparameters are used for each set of simulation data, making a total of 16 sets of comparison cases. As an example, this section provides a graphical comparison of the prediction results for the 120°encounter angle, as shown in Figures 4-7. Table 4.

Online Prediction Using Constant Hyperparameters.
All samples in the time window are used to train LS-SVM, and the trained model is applied to predict future roll motion. Multistep forward prediction is carried out in an iterative manner and multiple-step prediction is realized through single-step prediction; that is, after each step of prediction, the output value of the current step is updated and used as the input of the next step to predict the roll motion. As an example, the roll motion of the next 60 steps (30 s) is predicted, and the input and the output of each iteration are given in Table 5.
From the perspective of the overall time span, the longer the prediction time, the worse the overall prediction accuracy. To show the prediction accuracy, the values of roll angle at the next 60 th step of each prediction, that is, the prediction values at the next 30 s of every time, are presented in comparison with the simulated ones in Figure 4. Figure 5 shows the error between the predicted value and the simulated value (the simulated value minus the predicted value). Both Figures 4 and 5 are the results for the encounter angle 120°, C 0 � 10, and σ 0 � 10.
To further analyze the prediction accuracy, mean absolute error (MAE), mean square error (MSE), root mean square error (RMSE), and correlation coefficient (CC) are used to evaluate the prediction results. MAE is the average of the absolute value of the difference between the predicted value (denoted by subscript "predict") and the simulated value (denoted by subscript "real"). MSE refers to the mean value of the square of the difference between the predicted value and the simulated value. RMSE is the square root of the mean square of the difference between the predicted value and the simulated value. CC is used to measure the correlation between two sets of data, and its value ranges within (−1, +1); CC � 0 means that the two variables are not CC � Cov y real , y predict �������� � Var y real where n is the number of samples.
Substituting the prediction data and simulation data in Figure 4 into equations (15)- (18), the values of MAE, MSE, RMSE, and CC under the encounter angle 120°can be determined. Besides, similar predictions are conducted for encounter angles 60°, 90°, and 150°. e results of four sets of encounter angles and four sets of hyperparameters, that is, a total of 16 sets of cases are presented in Tables 6-9.

Online Prediction Using the AGS Algorithm.
en, the AGS algorithm is used to predict the roll motion online. e dimension of sample input, the number of sample pairs in the time window, and the initial hyperparameters are consistent with those used in the method with fixed hyperparameters.
For the AGS algorithm, a set of search ratios K � [0.002, 0.01, 0.2, 0.6, 1, 2, 5, 100, 2000] is chosen; the grid setting follows the principle of sparse on both sides and dense in the middle. Assuming that the excellent hyperparameters in the previous round are C i and σ i , it can be determined that the search range of C in this round is K × C i , and the search range of σ in this round is K × σ i . e 250 sample pairs in the time window are divided into a training set and a validation set according to the commonly used ratio of 8 : 2 in machine learning algorithms. e excellent hyperparameters of this round are selected based on the principle of least square error, which are used for prediction.
In the specific implementation, considering that the time complexity of searching for C and σ simultaneously is too large (the order of time complexity is O(n 2 ), a compromise solution is selected: C and σ are updated separately and alternately, and only one of them is optimized in each round, reducing the time complexity to O(n). Figure 6 shows the comparison between the simulated value and the predicted value obtained by using the AGS algorithm to optimize the hyperparameters online, and Figure 7 shows the error (the simulated value minus the predicted value). Both Figures 6  and 7 are the results for the encounter angle 120°, C 0 � 10, and σ 0 � 10.
When using the AGS algorithm for prediction, the hyperparameters of LS-SVM are optimized at each time step according to the distribution of samples in the time window, and the hyperparameters obtained from each step of optimization are shown in Figure 8.
Substituting the prediction data and simulation data in Figure 6 into equations (15)- (18), the values of MAE, MSE, RMSE, and CC under the encounter angle 120°can be obtained. In addition, similar predictions are conducted for encounter angles 60°, 90°, and 150°. e results of four sets of encounter angles and four sets of hyperparameters, that is, a total of 16 sets of cases are presented in Tables 6-9.
Comparing the prediction results in Figures 4 and 6, as well as the errors in Figures 5 and 7, it can be seen that the prediction accuracy of the AGS algorithm is higher. Besides, the results in Tables 6-9 show that the AGS algorithm achieves dynamic updating of the hyperparameters online and high prediction accuracy in a variety of cases. In particular, for the last set of cases in Table 9, the AGS algorithm has much higher prediction accuracy than the method with fixed hyperparameters. As can be seen from the comparison of results, the AGS method, which can realize the online adjustment of the hyperparameters, has greater advantages over the method of determining the hyperparameters offline.
Another concern in using the AGS method is the time consumption of updating the hyperparameters. e computations in this paper are carried out on a portable   Table 5: 60-step prediction.
Mathematical Problems in Engineering     computer equipped with an Intel Core i5-8300H (2.30 GHz) processor. e CPU time consumption of the AGS solution is larger, but still within the sampling interval of 0.5 s. It can meet the timeliness requirements of online predictions.

Conclusions
is paper proposes a novel AGS-LSSVM algorithm for the online prediction of ship roll motion in waves. e method is based on LS-SVM, combined with the time window method to update the samples set, and uses the AGS algorithm to update the model hyperparameters online, which can realize the prediction of ship roll motion in the next 30 s.
Considering that the computational time of the methods updating hyperparameters offline often exceeds tens or even hundreds of seconds, which cannot meet the requirement of updating parameters online, this paper makes an effort to overcome this shortcoming of offline algorithms and proposes the AGS-LSSVM algorithm. e design idea of the AGS-LSSVM algorithm is as follows: the system state of the ship at the adjacent moments does not change much; thus, the hyperparameters of the current moment can be adjusted based on the hyperparameters of the previous moment. In this paper, instead of using the fixed value of the grid, a grid ratio is used, and the grid for the current moment is obtained by combining the grid ratio and the previous hyperparameters.
rough this improvement, the fixed grid is transformed into the auto-moving grid to realize the online adjustment of hyperparameters, and the searching space of hyperparameters is reduced so that the computational time can meet the timeliness requirement.
To illustrate the effectiveness of the AGS algorithm, 16 cases are selected for prediction and the results are compared with those obtained by the method with fixed hyperparameters. From the comparison of the prediction results and the corresponding values of MAE, MSE, RMSE, and CC indices obtained by the two methods, it can be seen that the AGS-LSSVM algorithm realizes the online update of the hyperparameters and improves the prediction accuracy largely. It is an effective method for the online prediction of ship roll motion.
Although only the ship roll motion is predicted in this paper, the proposed method is universal and can be used to predict other modes of ship motion in waves. It can also be extended to online predicting ship maneuvering motion in waves. Besides, in this paper, the offline grid search solving process is decomposed to obtain an online grid search scheme, and this idea can also be used to improve other offline algorithms to evolve them into online algorithms.
However, in this paper, only the simulation data obtained from the equation of ship roll motion are used, and the prediction ability of the proposed method for ship roll motion at real sea still needs to be verified. In addition, the AGS algorithm used in this paper only optimizes the two hyperparameters in LS-SVM, and there is still a lack of effective optimization methods for the hyperparameters in the sample construction, such as the input order of the sample and the length of the time window. ese will be the focus of future study.

Data Availability
e data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
e authors declare that they have no conflicts of interest.