# Artificial Intelligence Algorithms for Treatment of Diabetes
## 2 Methods
### Merging ML with Automatic Control to Improve Glucose Regulation  
People with diabetes have mental models of their own metabolism and can provide additional information to their AID systems manually that enable the algorithms used in automated decisions to improve the insulin dose computed. The most prevalent manual information announces potential impending glucose excursions during meals and physical activity, including user-reported meal information for computation of an insulin bolus and increase in the target BGC and reduction of basal insulin infusion before starting an exercise session. The first generation of AID systems automated the manual activities that were performed repeatedly by the user [92]. Various control algorithms were proposed over the years for AID systems, and eventually converged on using model predictive control (MPC) systems. In MPC, a dynamic model representing the metabolism of the user forecasts the future behavior of the BGC based on hypothesized future control actions that are optimized in real-time to bring future BGC as close to its desired trajectory as possible, despite various disturbances such as meals and physical activities.  
The second generation of AID systems aims to move from hybrid to automated operation and reduce manual inputs to a few urgent situations [52; 53]. This can be achieved by measuring and interpreting additional variables in real-time to infer the presence and properties of disturbances to glucose homeostasis. Further, the expected behavior of a person can be modeled using historical data sets and the model can be used to improve insulin dosing decisions. This multivariable AID (mvAID) captures additional information from a wearable device (i.e., blood volume pulse, heart rate, electrodermal activity, accelerometer data) to provide real-time information to AID. Such information can be interpreted by ML models to infer the presence of physical activities, classify their type, estimate their intensity, and predict their effects on glucose levels in the near future [19; 62; 69; 93; 94; 95].  
While the current mvAID with physiological data streaming in real-time improves BGC regulation and ML of personal habits enhances BGG regulation, it does not leverage the full promise of AI. It has limited capability to address the challenges created by the human in the loop, where the user who has access to data and information such as a potential hypoglycemia episode changes their behavior and reduces the accuracy of the BGC predictions and control decisions (insulin doses) made by the mvAID system (Figure 7). MPC uses the predicted (future) BGC values to compare them against the desired future BGC levels and conducts optimization in real-time to bring the predicted BGC values to the desired (target) values by modifying future insulin doses. The use of the daily behavior patterns captured by ML improves the model prediction accuracy of the used MPC and updates the parameters of the MPC for tighter regulation of BGC. The RNN models developed in the previous section can capture these patterns and provide information to the MPC on the specific pattern that is evolving on a given day in order to predict future disturbances more accurately.  
Figure 7: Lengths of historical data to capture many behavior patterns of a person (red), recent past data for use by MPC (green) and challenges in data missing values, outliers). Confidence limits in the prediction of future BGC, and disturbance effects.