# B-Spline Curve Fitting of Hungry Predation Optimization on Ship Line Design
## 5 HPA Algorithm Test
### Comparison with Existing Research
where \(N\) is the number of data points, \(Nod\) is the number of knots and \(\rho^{*}\) is the order of the curve; \(X_{1i}\) and \(X_{2i}\) are the X coordinate values of the \(i\)-th point on the actual curve and the fitted curve, respectively; \(Y_{1i}\) and \(Y_{2i}\) are the Y coordinate values of the \(i\)-th point on the actual curve and the fitted curve, respectively. In the testing process of the AIS method, 201 data points are selected at equal distances. The degree of curve \(\rho\) is 3 (\(\rho^{*}=4\)). In order to further test the ability of the algorithm to withstand interference, a normal fluctuation with a mean of 0 and a variance of 1 was applied to the data points. The minimum BIC value is 1121.09 when \(k=5\). Under the same BIC calculation formula, the HPA algorithm obtains the smallest BIC value of 1040.57 when \(k=9\), as shown in Table 5.  
In the Gray Wolf Optimizer (GWO) for knot placement in B-spline curve fitting [19], the BIC calculation formula is shown in Formula (24). The HPA proposed in this paper is much better than GWO in fitting the function \(f_{4}(x)\). \[ \begin{array}{l}\text{BIC}=N\times\text{LN(MSE)}+\left(\text{LN(N)}\right)2 \times\left(2\times Nod+\rho^{*}\right)\\ \text{MSE}=\frac{1}{N}\sum\limits_{i=1}^{N}\sqrt{\left(X_{1i}-X_{2i}\right)^{2 }+\left(Y_{1i}-Y_{2i}\right)^{2}}\end{array}  \tag{24}\]  
where \(N\) is the number of data points, \(Nod\) is the number of knots and \(\rho^{*}\) is the order of the curve; \(X_{1i}\) and \(X_{2i}\) are the X coordinate values of the \(i\)-th point on the actual curve and the fitted curve, respectively; \(Y_{1i}\) and \(Y_{2i}\) are the \(Y\) coordinate values of the \(i\)-th point on the actual curve and the fitted curve, respectively. The design of the BIC value in this article refers to the mean square error. Compared with the variance, the value will be smaller under the same fitting situation and may even be negative. When the optimal solution fitted by the GWO method is 40 knots, the BIC value is 704. However, the HPA algorithm obtains a minimum BIC value of 230.31 at \(k=4\), as shown in Table 6. Figure 15 records the fitting results of different numbers of knots of test function \(f_{4}(x)\). When the number of knots is small, the increase of knots can greatly improve the curve fitting accuracy, and the BIC value will decrease accordingly. When the inner knot is 4, the shape of the curve can be better fitted. At this time, the BIC value reaches the minimum value. As the number of knots continues to increase, the improvement of fitting accuracy begins to decrease, and the BIC value begins to increase. \begin{table}
\begin{tabular}{c c c c c} \hline
**Inner Knot Number** & **Method** & \(Q_{1}\) & **RMSE** & **BIC** \\ \hline \(\kappa=3\) & HPA & 500.889 & 1.578 & 1313.12 \\  & AIS & 593.977 & 1.719 & 1336.79 \\ \hline \(\kappa=4\) & HPA & 329.117 & 1.279 & 1239.32 \\  & AIS & 381.871 & 1.378 & 1258.60 \\ \hline \(\kappa=5\) & HPA & 169.758 & 0.919 & 1116.86 \\  & AIS & 182.761 & 0.953 & 1121.09 \\ \hline \(\kappa=6\) & HPA & 142.331 & 0.842 & 1092.05 \\  & AIS & 181.051 & 0.949 & 1129.81 \\ \hline \(\kappa=7\) & HPA & 122.786 & 0.782 & 1072.96 \\  & AIS & 178.013 & 0.941 & 1137.01 \\ \hline \(\kappa=8\) & HPA & 102.723 & 0.715 & 1047.71 \\  & AIS & 176.391 & 0.936 & 1145.78 \\ \hline \(\kappa=9\) & HPA & 94.045 & 0.684 & 1040.57 \\  & AIS & 174.515 & 0.931 & 1154.24 \\ \hline \(\kappa=10\) & HPA & 92.984 & 0.680 & 1043.60 \\  & AIS & 172.218 & 0.919 & 1159.61 \\ \hline \end{tabular}
\end{table} 
Table 5: BIC values of AIS and HPA methods at the same knot. In the GWO method, when 40 knots are used, the minimum BIC value [19] is obtained, and the fitting result of the test function \(f_{4}(x)\) shows that the final fitting effect is not ideal, as shown in Figure 14. It can be seen that the HPA algorithm proposed in this paper achieved an accurate fitting of data points when using 40 knots, while the GWO method still cannot solve the cusp fitting when there are 40 knots. We guess that the use of heavy knots may be ignored in GWO.