# Real-Time Model Predictive Control of Human Bodyweight Based on Energy Intake
## 2 Materials and Methods
### Modelling
#### 2.2.1 Time-Invariant Single-Input, Single-Output (SISO) Transfer Function (TF) Model  
For the system identification process, a SISO TF model with time-invariant parameters is tested. The model has the following general structure [46],  
\[y(k)=\frac{B\!\left(\!z^{-1}\!\right)}{A\!\left(\!z^{-1}\!\right)}u(k-\delta)+ \xi(k) \tag{1}\]  
where \(y(k)\) and \(u(k)\) are the output (bodyweight [kg]), and the input (energy intake [kcal day\({}^{-1}\)]) of the model, respectively; \(\xi(k)\) is additive noise assumed to be zero mean, serially uncorrelated sequence of random variables with variance \(\sigma^{2}\), accounting for measurement noise, modelling errors and effects of unmeasured inputs to the process; \(k\) is the sample of the measurement; \(\delta\) is the time delay of the input, expressed in number of time intervals; \(A\!\left(\!z^{-1}\!\right)\) and \(B\!\left(\!z^{-1}\!\right)\) are two series given by:  
\[A\!\left(\!z^{-1}\!\right)=1+\ a_{1}z^{-1}+\ a_{2}z^{-2}+\ldots+\ a_{n_{k}}z^{ -n_{k}} \tag{2}\]  
\[B\!\left(\!z^{-1}\!\right)=b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+\ldots+b_{n_{k}}z^{-n _{k}} \tag{3}\]  
where \(a_{j}\) and \(b_{j}\) are the model parameters to be estimated; \(z^{-1}\) is the backward shift operator, i.e., \(z^{-1}y(k)=y(k-1)\), with \(y\) and \(k\) defined as in Equation (1); \(n_{a}\) and \(n_{b}\) are the orders of the respective \(A\) and \(B\) polynomials. The model parameters are estimated using a refined instrumental variable (RIV) approach [46]. Normally, the model is referred to as the triad [\(n_{a}\)\(n_{b}\)\(\delta\)].  
In order to test the fitting accuracy of the different models estimated, the goodness of fit is quantified using the coefficient of determination, \(R_{T}^{2}\). Its general expression is given by [46],  
\[R_{T}^{2}=1-\frac{\sigma_{e}^{2}}{\sigma_{y}^{2}} \tag{4}\]  
where \(\sigma_{e}^{2}\) is the variance of the residuals, when comparing the model estimations with the output measured values, and \(\sigma_{y}^{2}\) is the variance in the output. In addition, the Young information criterion (YIC) is estimated. It is given by the following expression [46],  
\[YIC=log\!\left(\frac{\sigma_{e}^{2}}{\sigma_{y}^{2}}\right)+log\!\left(\frac{ 1}{h}\sum_{i=1}^{h}\frac{\sigma_{e}^{2}\rho_{ii}}{\hat{a}_{i}^{2}}\right) \tag{5}\]where \(\sigma_{e}^{2}\) is the variance of the residuals, \(\sigma_{y}^{2}\) is the variance of the output, \(h\) is the number of estimated parameters, \(\hat{p}_{ii}\) are the diagonal elements of the covariance matrix from the parameters estimations and \(\hat{a}_{i}^{2}\) is the square value of the \(i\)-th parameter. The first term of _YIC_ is simply a relative measure of how well the model explains the data. The smaller the model residuals the more negative the term becomes. The second term provides a measure of the conditioning of the instrumental variable cross product matrix. If the model is over-parameterized, then it can be shown that this matrix will tend to singularity and, because of its ill conditioning, the elements of its inverse will increase in value, often by several orders of magnitude. Then, the second term in _YIC_ tends to dominate the criterion function, indicating over-parameterization [46].