## 3 Gaussian-Process-Based MPC
### Gaussian Process for Uncertainty Modeling
The Gaussian process can be established in the following form:  
\[\mathbf{Y}=f(\mathbf{X})=\mathcal{N}(\mathbf{\mu},\mathbf{K})\]  
With  
\[\mathcal{N}(\mathbf{\mu},\mathbf{K})=(2\pi)^{-\frac{\pi}{2}}|\mathbf{K}|^{-\frac{1}{2}} \text{exp}\bigg{(}-\frac{1}{2}(\mathbf{x}-\mathbf{\mu})^{\text{T}}\mathbf{K}(\mathbf{x}-\mathbf{ \mu})\bigg{)} \tag{48}\]  
where the kernel matrix, denoted as \(\mathbf{K}_{i,j}\), is calculated using the squared exponential kernel \(k_{\text{SE}}(\mathbf{x}_{i},\mathbf{x}_{j})\). The optimal values of the hyperparameters \(\sigma\) and \(\mathbf{M}\) in \(k_{\text{SE}}\) can be determined by maximizing the marginal log-likelihood, which is expressed as follows:\[\log\mathcal{N}(\mu,\mathbf{K})=\log\left(2\pi\right)^{-\frac{n}{2}}|\mathbf{K}|^{- \frac{1}{2}}\mathrm{exp}\Big{(}-\tfrac{1}{2}(x-\mu)^{\mathrm{T}}\mathbf{K}(x-\mu) \Big{)} \tag{49}\] \[=-\tfrac{1}{2}(\mathbf{x}-\mu)^{\mathrm{T}}\mathbf{K}(\mathbf{x}-\mu)-\tfrac{1} {2}\mathrm{log}\,|\mathbf{K}|-\tfrac{n}{2}\mathrm{log}\,2\pi\]  
To forecast data, the following procedure is employed:  
\[\mathbf{Y}=\mathcal{N}(\mathbf{\mu},\mathbf{\Sigma}) \tag{50}\] \[ \begin{bmatrix}\mathbf{Y}\\ \mathbf{Y}\end{bmatrix} =\mathcal{N}\bigg{(} \begin{bmatrix}\mathbf{\mu}\\ \mathbf{\mu}^{\prime}\end{bmatrix} , \begin{bmatrix}\mathbf{K}(\mathbf{X},\mathbf{X})+\sigma_{n}^ {2}\mathbf{I}&\mathbf{K}(\mathbf{X},\mathbf{X}^{\prime})\\ \mathbf{K}(\mathbf{X}^{\prime},\mathbf{X})&\mathbf{K}(\mathbf{X}^{\prime},\mathbf{X}^{\prime})+\sigma_ {n}^{2}\mathbf{I}\end{bmatrix} \bigg{)} \tag{51}\]  
Here, \(\mathbf{Y}^{\prime}\) follows a Gaussian distribution, where \(\left.\mathbf{Y}\right|_{\mathbf{Y},\mathbf{X},\mathbf{X}^{\prime}}=\mathcal{N}\big{(}\mathbf{m}^ {\prime}|\mathbf{\Sigma}^{\prime}\big{)}\). The unknown variables can be determined using the following equations:  
\[\mathbf{m}^{\prime}=\mathbf{K}\big{(}\mathbf{X}^{\prime},\mathbf{X}\big{)}^{\mathrm{T}}\Big{(} \mathbf{K}(\mathbf{X},\mathbf{X})+\sigma_{n}^{2}\mathbf{I}\Big{)}^{-1}(\mathbf{Y}-\mathbf{\mu})+\mathbf{ \mu}^{\prime} \tag{52}\]  
\[\mathbf{\Sigma}^{\prime}=\mathbf{K}\big{(}\mathbf{X}^{\prime},\mathbf{X}^{\prime}\big{)}+ \sigma_{n}^{2}\mathbf{I}-\mathbf{K}\big{(}\mathbf{X}^{\prime},\mathbf{X}\big{)}^{\mathrm{T}} \Big{(}\mathbf{K}(\mathbf{X},\mathbf{X})+\sigma_{n}^{2}\mathbf{I}\Big{)}^{-1}\mathbf{K}\big{(}\mathbf{ X},\mathbf{X}^{\prime}\big{)} \tag{53}\]  
Among these equations, \(\sigma_{n}^{2}\) represents Gaussian noise, \(\mathbf{X}^{\prime}\) signifies the predicted input value, and \(\mathbf{Y}^{\prime}\) indicates the predicted output distribution. Within the context of this research, the GP model is utilized to estimate the mathematical model within a specific operational range of the AUV. When integrated with MPC, the input for the next iteration becomes the mean value of the predicted Gaussian distribution. The optimization objective is defined as follows:  
\[ \begin{array}{l}L=\sum\limits_{i=1}^{p}\bigg{(}\Big{(}\hat{\mathbf{x}}(k+i|k)- \mathbf{x}_{ref}\Big{)}^{\mathrm{T}}\mathbf{Q}\Big{(}\hat{\mathbf{x}}(k+i|k)-\mathbf{y}_{ref} \Big{)}^{\mathrm{T}}\\ \quad\quad+\mathbf{u}(k+i-1|k)^{\mathrm{T}}\mathbf{R}\mathbf{u}(k+i-1|k)+\mathbf{\Delta u}^{ \mathrm{T}}\mathbf{S}\mathbf{\Delta u}\Big{)}\end{array}  \tag{54}\]  
with \(p(\mathbf{x}(k+i)|\mathbf{x}(k+i-1))\sim\mathbf{N}\big{(}\mathbf{m}^{\prime},\mathbf{\Sigma}^{ \prime}\big{)}\). The initial GP model \(\mathcal{N}(\mathbf{\mu},\mathbf{\Sigma})\) can be obtained by fitting samples within the set working range. In the subsequent simulation, the CasADi toolkit will be used for optimization. Based on the introduction provided in the previous section, we employ Gaussian processes to learn the AUV model data containing noise. Leveraging this model, we aim to enhance the predictive capabilities of the MPC algorithm, optimizing the accuracy and reliability of our predictions. The relevant process is shown in Figure 2.  
In conclusion, Gaussian Process Regression provides a powerful tool to model uncertainties and enhance AUV control.