# Artificial Intelligence Algorithms for Treatment of Diabetes
## 3 Results  
The results for the 1-D convolutional RNN with LSTM layer for the detection and classification of the four states for one subject (Subject 2) in terms of Total Accuracy (%), Weighted Recall (%), Precision (%), and F1 Score (%) are 94.69 (0.33), 94.69 (0.33), 96.58 (0.20), and 95.31 (0.16), respectively, where the standard deviations are given in parentheses. Some erroneous detections, such as confusing meals and exercise are dangerous since meals necessitate an insulin bolus while exercise lowers BGC, and elimination of insulin infusion and/or increase in target BGC are needed. RNNs with LSTM and 1D convolution layers provide the best overall performance in minimizing such confusions: two meals events are classified as exercise (0.003%) and eight exercise events are classified as meals (0.125%). The performance of the four different RNNs are illustrated for one person in the Tidepool dataset in Figure 8.  
Figure 8 displays a random day selected from the test data to compare the effectiveness of various RNN models in detecting meal and exercise disturbances. Among four possible realizations for the occurrence of events, detecting joint events, Class M and E is more challenging as it usually shows overlaps with Class M and Class E. Several reasons contribute to this challenge. Many people with T1D usually have a small snack before and/or after exercise sessions. Also, exercise alone and exercise and snack together are less frequent than sedentary state and meal consumption, and consequently, there is less information on Class M and E. Furthermore, the AID systems used by subjects record automatically only CGM and insulin infusion values, and meal and physical activity sessions needed to be manually entered into the device, at times an action that may be forgotten by the subject. pulse, and heart rate data in the Tidepool data set. As the use of wearable devices increases, this difference is expected to be reduced [96; 97; 98]. Following the detection of meal and exercise events in historical data, we combine the knowledge in historical data with real-time streaming information to determine the most likely behavior pattern for the subject, and incorporate the estimated behavior pattern in the multivariable AID system for improved decision-making. This improvement is illustrated by simulations conducted with the mvAID connected to a multivariable simulator (mGIPsim) [99]. mGIPsim is a novel software enabling the in silico testing of advanced mvAID systems that improve glycemic control by supplementing the CGM data with additional physiological measurements. The mGIPsim software has descriptions of meals, insulin administration, and physical activities as inputs, and provides glucose and insulin concentrations and physiological variables as outputs for use by mvAID algorithms. mGIPsim can simulate patient behavior for up to one year with random daily variations in meal and physical activity characteristics within ranges specified by the user. It has a heterogenous virtual synthetic patient population that is representative of the actual patient population. mGIPsim is used to generate data for several days in response to daily meal and exercise events. This historical data set is used to extract patterns of behavior for each virtual subject. On the current day, the data generated up to the current time is compared with all patterns of behavior of that subject, and the pattern that matches the most to the current day is selected to provide future meal and exercise information (Figure 9). This pattern information is used by the MPC to incorporate future potential meal and exercise events in the prediction of future glucose values and compute optimal insulin infusion to minimize the deviation of the predicted glucose concentration from the desired glucose concentration. The improvement achieved by this approach is illustrated by two figures that compare the performance of the AID control systems.