# Real-Time Model Predictive Control of Human Bodyweight Based on Energy Intake
## 2 Materials and Methods
### Modelling
#### 2.2.2 Time-Variant Parameters Models  
As it is expected that the relationship between energy intake and bodyweight varies throughout the monitored period (i.e., behaves in a time-varying way), a dynamic auto-regression with exogenous variables (DARX) modelling approach is tested further. The model structure is similar to that described in Equation (1) but allowing the model parameters in the \(A\) and \(B\) series to vary over time [46]. The DARX expression is given by,  
\[y_{t}=\frac{B\big{(}z^{-1},t\big{)}}{A\big{(}z^{-1},t\big{)}}u_{t-\delta}+ \frac{1}{A\big{(}z^{-1},t\big{)}}e_{t} \tag{6}\]  
in which the previous \(A\) and \(B\) series described by Equations (2) and (3) are now expressed as,  
\[A\big{(}z^{-1},t\big{)}=1+\ a_{1,t}z^{-1}+\ a_{2,t}z^{-2}+\ldots+\ a_{n_{a},t}z^{-n_{a}} \tag{7}\]  
\[B\big{(}z^{-1},t\big{)}=b_{0,t}+b_{1,t}z^{-1}+b_{2,t}z^{-2}+\ldots+b_{n_{b},t} z^{-n_{b}} \tag{8}\]  
In order to estimate the time-variable model parameters, \(a_{i,t}\) and \(b_{i,t}\), it is necessary to make some assumptions about the nature of their temporal variability. In this approach, it is assumed that they show a stochastic evolution described by a general random walk process [46] and they are estimated using a sliding window approach, similarly to the work of [47]. By this sliding window approach, the effect of obsolete data is minimized. In terms of the biological process, this time variation of the parameters allows the modelling approach accounting for external influences to the process, such as environmental or health aspects, which are not explicitly taken into account in the model [47]. Following a similar procedure, a dynamic linear regression modelling approach is also tested. The DLR is the simplest state space model using time-variant parameters. Its general expression is given by:  
\[y_{t}=T_{t}+\sum_{i=1}^{m}b_{i,t}u_{i,t} \tag{9}\]  
where \(y_{t}\) is the output or dependent variable (bodyweight); \(T_{t}\) is a trend or low frequency component \(b_{i,t}\) are time-varying parameters over the observational interval which reflect possible changes in the regression relationship; and \(u_{i,t}\) are the inputs of the model (energy intake), which are assumed to affect the dependent variable \(y_{t}\)[46]. In this study, on each discrete time instant \(t\), for feed amount or composition the linear relation can be written as:  
\[BW_{t}=c_{1,t}+c_{2,t}EI_{t} \tag{10}\]  
with \(BW\) the measured bodyweight (kg) and \(EI\) the energy intake (kcal day\({}^{-1}\)) at time \(t\). \(c_{1,t}\) (kg) and \(c_{2,t}\) (kg\(\cdot\)kg\({}^{-1}\)) are the time-variant model parameters estimated at time \(t\). More specifically, the parameter \(c_{1,t}\) is expected to resemble the general bodyweight trend exhibited by each individual. Also, the parameter \(c_{2,t}\), is expected to resemble the energy efficiency at time \(t\) (defined as change of bodyweightper change of energy intake). The fitting agreement is tested using the normalized root mean square error (_NRMSE_) given by,  
\[NRMSE=1-\frac{\|BW_{ref}-BW_{fit}\|}{\|BW_{ref}-avg(BW_{ref})\|} \tag{11}\]  
where \(BW_{ref}\) is the weight curve used as reference, \(BW_{fit}\) is the weight curve obtain by the model and \(avg(BW_{ref})\) is the average value of the bodyweight reference curve. The _NRMSE_ provides a value in the range \((-\infty,\,1]\), being \(1\) a perfect fitting agreement. Besides, the prediction accuracy of the DARX and DLR models is also tested. The accuracy of the model predictions is investigated by applying the recursive estimation algorithm combining different window sizes \(S\) and prediction horizons \(F\) to each dataset. In this work, window sizes ranging from \(3\) to \(15\) weeks and a prediction horizons ranging from \(1\) to \(7\) weeks have been tested. As a result, for each dataset, \(91\)\((13\times 7)\) combinations of window size and prediction horizon are evaluated.