## 2 Methods
### Outcome Function and Risk Definition  
This subsection defines the outcome and risk functions for the designed food recommendation system before physical activities for T1D patients. The blood glucose outcome is represented by the average score assigned for the blood glucose levels during and after physical activities. The score was calculated based on the asymmetric reward function previously introduced in [33], designed to reduce  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Parameter** & **Value** \\ \hline \(\xi\) & \(-5.471\) \\ \(\lambda\) & \(15.96\) \\ \(\gamma\) & \(-0.5444\) \\ \(\delta\) & \(1.6898\) \\ \hline \hline \end{tabular}
\end{table}
Table 1: Parameters for continuous glucose monitor (CGM) sensor noise extracted from [32].  
hypoglycemia while rewarding time spent in normoglycemia. The reward function is designed as a piecewise smooth function and gives a strong negative reward for severe hypoglycemia, followed by an exponentially decreasing negative reward for hypoglycemic events starting at severe hypoglycemia, and negative reward when hyperglycemia occurs. Positive rewards from a symmetric linear function are given for glucose values in normoglycemic range. To be specific, the function is given as:  
\[r(BG)=\left\{\begin{array}{ll}-10&:BG<BG_{hypo^{-}}\\ \exp(\frac{\log(19.157)}{BG_{hypo}}BG)-19.157&:BG\in\left[BG_{hypo^{-}},BG_{hypo }\right]\\ \frac{1}{36}BG-2&:BG\in\left[BG_{hypo},BG_{ref}\right]\\ -\frac{1}{72}BG+\frac{5}{2}&:BG\in\left[BG_{ref},BG_{hyper}\right]\\ -5&:BG>BG_{hyper}\end{array}\right., \tag{4}\]  
where \(BG\) is the current blood glucose value. The parameters of the reward function were selected based on the guidelines as described in [33] and can be found in Table 2. A graphical representation of the reward function is shown in Figure 1.  
In order to quantify the risks of hypo- and hyperglycemia, we used clinically defined low and high blood glucose indices (LBGI and HBGI, respectively) as described in Clarke and Kovatchev [34], which measure the frequency and extent of low and high blood glucose readings based on a symmetrization of the blood glucose measurements:  
\[LBGI=\frac{1}{n}\sum_{i=1}^{n}rl(BG_{i})\quad\text{and}\quad HBGI=\frac{1}{n} \sum_{i=1}^{n}rh(BG_{i}), \tag{5}\]  
where \(BG_{i}\) is the measurement \(i\) in mg/dL and \(n\) is the number of measurements during and after the physical activity. The risk functions \(rl(BG)\) and \(rh(BG)\) are defined as follows:  
\[rl(BG)=10\times f(BG)^{2}\quad\text{if}\quad f(BG)<0\quad\text{and 0 otherwise} \tag{6}\]  
\[rh(BG)=10\times f(BG)^{2}\quad\text{if}\quad f(BG)>0\quad\text{and 0 otherwise} \tag{7}\]  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Parameter** & **Description** & **Value** \\ \hline \(BG_{ref}\) & Reference blood glucose & 108 mg/dL \\ \(BG_{hyper}\) & Hyperglycemia blood glucose & 180 mg/dL \\ \(BG_{hypo}\) & Hypoglycemia blood glucose & 72 mg/dL \\ \(BG_{hypo^{-}}\) & Severe hypoglycemia blood glucose & 54 mg/dL \\ \hline \hline \end{tabular}
\end{table}
Table 2: Parameters of the reward function [33].  
Figure 1: The asymmetric reward function. Low blood glucose levels (**a**) are more penalized than (**b**) high blood glucose levels.  
where  
\[f(BG)=1.509\times[(\ln(BG))^{1.084}-5.381], \tag{8}\]  
and \(BG\) is the current blood glucose value.