# An Environmental Perception Framework for Robotic Fish Formation Based on Machine Learning Methods
## 4 The Velocity Prediction of Two Robotic Fishes
### The Tandem Formation
#### 4.2.2 The Construction and Validation of Predictive Models  
We used the data simulated by settings in Table 4 to train the predictive model and use the data simulated by settings in Table 6 to validate the model. The kinematic pressures used to train and validate the predictive model are the average values of \(p_{i}\) at different spacing at a certain \(U\).  
In Section 3, we construct the predictive model of the inlet flow velocity for single robotic fish. We compared the kinematic pressure of the No. 1 fish head (\(p1_{0}\)) and that of the single fish head (\(p_{0}\)) firstly at the different inlet flow velocity \(U\). As shown on the left of Figure 11, \(p1_{0}\) and \(p_{0}\) have few  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Spacing (\(L\))** & **U (\(L\)/s)** \\ \hline
0.2, 0.4, 0.6, 0.8, 1.0 & 0.1, 0.3, 0.5, 0.7, 0.9 \\ \hline \hline \end{tabular}
\end{table}
Table 6: The spacing and velocity setting for validating.  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & \multicolumn{5}{c}{**U (\(L\)/s)**} \\ \hline  & 0 & 0.2 & 0.4 & 0.6 & 0.8 & 1.0 \\ \(p1_{0}\) & 3.66 \(\times\) 10\({}^{-7}\) & 0.000001 & 0.000007 & 0.000021 & 0.000045 & 0.000093 \\  
differences and the predictive model of \(p_{0}\) in Section 3 can be used to predictive \(U\) for No. 1 fish in the tandem formation. The polynomial as the predictive model for No. 1 fish is as follows:  
\[U=0.1693+1.9999*p1_{0}+(-0.8366)*p1_{0}^{2}+0.1400*p1_{0}^{3}\qquad-0.1\leq p1_{0 }\leq 0.6, \tag{8}\]  
Then, we compared the kinematic pressure of the No. 2 fish (\(p2_{7}\)) and that of single fish (\(p_{7}\)) at the different inlet flow velocity \(U\). As shown on the right of Figure 11, \(p2_{7}\) and \(p_{7}\) have some differences and the predictive model of \(p_{7}\) in Section 3 cannot be used to predict \(U\) for No. 2 fish in tandem formation. Therefore, we construct a new predictive model for No. 2 fish and the method is the same as Section 3. While building the predictive model, we used different order of polynomial and calculated the training error. Then, we used the test data to validate the predictive model and calculate the predictive error. The training and predictive error of the model are shown in Table 7.  
We found that the training error and predictive error are very small when the order of polynomial \(n=2\) and \(n=3\). We plot the training data, predictive data and the predictive model in Figure 12, which shows that the fitting effect is almost identical when the order of polynomial is \(n=2\) and \(n=3\). Because the best polynomial of a single robotic fish is third-order, finally we chose the third-order polynomial as the predictive model, which is in the following:  
\[U=-0.1369+(-7.3297)\times p2_{7}+(-5.4535)\times p2_{7}^{2}+17.1535\times p2_{7 }^{3}\qquad-0.3\leq p2_{7}\leq 0, \tag{9}\]  
Equation (9) is applicable to the velocity prediction of No. 2 fish in the tandem formation. It is worth noting that the fluid disturbance in the vertical direction of the fish body caused by the fish body swing is large when the inlet flow velocity is small. Thus, the velocity prediction less than 0.2 \(L/s\) may not be accurate enough.  
\begin{table}
\begin{tabular}{c c c} \hline \hline  & \(p2_{7}\) & \\ \hline order (\(n\)) & training error & predictive error \\
1 & 0.00171 & 0.00128 \\
2 & 0.00004 & 0.00034 \\
3 & 0.00003 & 0.00035 \\
4 & 0.00001 & 0.00045 \\ \hline \hline \end{tabular}
\end{table}
Table 7: The training and predictive error.  
Figure 11: The contrast between the kinematic pressures of fish in the tandem formation and that of single fish.