Skip to main content
Journal of Diabetes Science and Technology logoLink to Journal of Diabetes Science and Technology
. 2022 Jun 15;17(6):1482–1492. doi: 10.1177/19322968221102183

Detection of Meals and Physical Activity Events From Free-Living Data of People With Diabetes

Mohammad Reza Askari 1, Mudassir Rashid 1, Xiaoyu Sun 2, Mert Sevil 2, Andrew Shahidehpour 1, Keigo Kawaji 2, Ali Cinar 1,2,
PMCID: PMC10658701  PMID: 35703136

Abstract

Background:

Predicting carbohydrate intake and physical activity in people with diabetes is crucial for improving blood glucose concentration regulation. Patterns of individual behavior can be detected from historical free-living data to predict meal and exercise times. Data collected in free-living may have missing values and forgotten manual entries. While machine learning (ML) can capture meal and exercise times, missing values, noise, and errors in data can reduce the accuracy of ML algorithms.

Methods:

Two recurrent neural networks (RNNs) are developed with original and imputed data sets to assess detection accuracy of meal and exercise events. Continuous glucose monitoring (CGM) data, insulin infused from pump data, and manual meal and exercise entries from free-living data are used to predict meals, exercise, and their concurrent occurrence. They contain missing values of various lengths in time, noise, and outliers.

Results:

The accuracy of RNN models range from 89.9% to 95.7% for identifying the state of event (meal, exercise, both, or neither) for various users. “No meal or exercise” state is determined with 94.58% accuracy by using the best RNN (long short-term memory [LSTM] with 1D Convolution). Detection accuracy with this RNN is 98.05% for meals, 93.42% for exercise, and 55.56% for concurrent meal-exercise events.

Conclusions:

The meal and exercise times detected by the RNN models can be used to warn people for entering meal and exercise information to hybrid closed-loop automated insulin delivery systems. Reliable accuracy for event detection necessitates powerful ML and large data sets. The use of additional sensors and algorithms for detecting these events and their characteristics provides a more accurate alternative.

Keywords: meal detection, physical activity detection, deep neural network, automated insulin delivery

Introduction

Full automation of AID (automated insulin delivery) necessitates reliable prediction of meal and physical activity events. This includes the detection of a meal and estimating its carbohydrates, and the detection of physical activity and its type, intensity, and duration. The detection of these events and the assessment of their characteristics can be achieved in two ways: either by determining the habits, schedule, and patterns of behavior of a person from historical data or by real-time detection of these events and estimation of their characteristics by using wearable devices with multiple sensors that report physiological variables as streaming data. Machine learning (ML) is used in the former case, and ML, data-driven modeling, and systems engineering are used in the latter case. Machine learning from data collected during a clinical experiment has been useful for developing forecasts of potential meals and exercise events and proactive insulin management.1,2

Advanced ML techniques based on deep neural networks have been reported for various detection and prediction tasks for people with Type 1 diabetes (T1D), ranging from development of a recurrent neural network (RNN) to predict adverse glycemic events 3 and detection of retinopathy.4,5 This work focuses on the detection and classification of prior meal and physical activity events from long-term historical data of individuals with T1D. One of the objectives is to assess the need for data reconciliation and imputation because continuous glucose monitoring (CGM) data under free-living conditions may have many missing values, outliers, and incomplete diaries for meals and physical activities. A second objective is to assess the accuracy of classification of meals, physical activities, and their concurrent presence in the individual data sets.

Two different RNN models are used to estimate the probability of events causing large variations in blood glucose concentration (BGC). The main contributions of this work are as follows:

  • • The development of RNN models capable of estimating the occurrence of carbohydrate intake and/or physical activity without requiring additional bio-signals from wearable devices.

  • • The integration of convolution layers with long short-term memory to enable the RNN to accurately detect the events from glucose-insulin input data.

  • • Assessment of the reliability of meal and exercise event detection from free-living data for use in AID systems.

Methods

Free-Living, Self-Reported Data Set of People With T1D

Many self-collected data sets by people with T1D were donated for clinical research to Tidepool and were made available for research as de-identified data sets. Each data set represents the data from a unique donor and includes meal schedules, insulin pump history, and CGM sensor recordings. Fifty data sets include physical activity information. Data lengths vary between a minimum of 30 days duration of recorded information up to 700 days. The donors of data, aged from 15 to 72 years, include 23 males, 21 females, and the remainder who did not announce their biological sex.

Subjects have been using CGM data for adjusting their insulin dosing (AID and SAP [sensor-augmented pump]) therapy for up to two years, and some of whom have lived with diabetes for more than 50 years. Table 1 summarizes the demographic information of the subjects selected for this study.

Table 1.

Subject’s General Demographic Information and the Duration of the Recorded Samples.

Subject Gender Age Duration of recordings (days) Missing samples (%) Max gap size
1 M 36 283 12.36 273
2 M 33 368 7.11 71
3 F 72 280 1.10 28
4 M 43 468 10.03 435
5 F 52 655 4.91 233
6 F 26 206 14.45 107
7 M 51 278 6.12 34
8 41 390 8.87 177

Clinical protocols were not used in the collection of the donated data and subjects were not restricted from performing their daily activities. The data set selected for this study provides the type and duration for 40 different types of physical activities such as walking, cycling, running, and hiking. Table 2 summarizes the names and the definition of feature variables used to develop the RNN models. Variable “Time,” introduced in Table 2, represents the time and date of each CGM sample reading.

Table 2.

The Variables Reported and Their Units.

Variable name Description Units
CGM Continuous glucose monitoring values sampled every five minutes mmol/L
Smbg Self-monitoring blood glucose concentration for sensor calibration mmol/L
Rate The basal insulin rate unit/hr
Bolus The actual delivered amount of normal bolus insulin unit
Time UTC time stamp Format: yyyy-mm-dd hh:mm:ss
Duration The actual duration of a suspend, basal, or dual/square bolus milliseconds
Activity.name The type of physical activity
Activity.duration The duration of a physical activity milliseconds
Distance.value Distance traveled during physical activity miles
Nutrition.carbohydrate The carbohydrates entered in a health kit food entry grams

Abbreviations: CGM, continuous glucose monitoring; Smbg, self-monitoring blood glucose; UTC, Universal Time Coordinated.

All information except carbohydrate intake and physical activity are recorded every five minutes. There are many inconsistencies in the sampling rate of feature variables that must be addressed in the preprocessing step. The variables reported and their units are listed in Table 2. The probabilities of carbohydrate intake, physical activity events, or their concurrent presence during one day (24-hour period) obtained by analyzing 15 months of pump, CGM, meal, and physical activity data collected from a randomly selected person (Figure 1) illustrate that while there are peak times for meals and exercise, their high probabilities of occurrence are spread over time windows ranging from one to three hours.

Figure 1.

Figure 1.

The joint probability of carbohydrates intake and physical activity events during a day obtained by analyzing 15 months of the pump-CGM sensor, meal, and physical activity data of a random person with type 1 diabetes (T1D) from the data set. Abbreviations: CHO, carbohydrate.

Data Preprocessing

Real-world data sets can be noisy and incomplete, there may be duplicate CGM readings in some data sets, inconsistencies exist in the sampling rate of CGM and insulin values, and gaps in the time and date information can be found due to insulin pump or CGM sensor disconnection. Hence, before any data interpretation and assessment, the data need to be preprocessed. This involves outlier removal, reconciliation and imputation of missing values, and feature construction.

Outlier Reconciliation

Signal reconciliation and outlier removal is necessary for improvement of CGM data quality to avoid biased results and misleading interpretations. As a simple approach for a variable with Gaussian distribution, observations outside 2.72 standard deviations on either side of average value, known as Inner Tukey Fences, can be labeled outliers and extreme values. The probability distribution of the CGM data shows a skewed distribution compared with the Gaussian distribution. Thus, labeling samples as outliers based only on their probability of occurrence is not the proper way of removing extreme values from CGM data because it can cause loss of useful information, specifically during periods of rapid change and hypo/hyperglycemia episodes. An alternative is to detect outliers, extreme values, and spikes in CGM values from prior knowledge and utilizing other feature variables, namely: “Smbg,” “Nutrition.carbohydrate,” and “Activity.duration.” All missing values of variable “Time” are added to data sets and their corresponding meal, exercise, glucose, and insulin samples are labeled as missing values. For preserving the chronological order of time-series variables, samples are sorted based on the converted epoch time in the data. Table 3 summarizes the procedure for outlier conciliation and denoising of CGM values.

Table 3.

An Algorithm for Outlier Reconciliation and Smoothing CGM Measurements.

Step 1: Remove all values higher than 400mg/dL and all negative values.
Step 2: Calculate the change in CGM values from each two consecutive CGM readings (at times (k and k−1) reported.
Step 3: If |CGMkCGMk1|>30mg/dL , the CGM observation CGMk is labeled as an outlier or extreme value unless one of the following cases is satisfied:
• If the self-monitored BGC value is available at sampling time k and |CGMkSmbgk|<18mg/dL .
•  CGMkCGMk1>30mg/dL , and any carbohydrate intake event(s) occurred in the last 45 minutes.
•  CGMkCGMk1<30mg/dL , and any bolus insulin injection is performed in the last 30 minutes.
•  CGMkCGMk1<30mg/dL,andanyexerciseeventsexistinthelast30minutes.
Step 4: Start searching through CGM observations and extract Qiqi consecutive samples without any missing observations. qi denotes the se of real numbers of dimension qi.
Step 5: Construct the Hankel matrix AiLi×Ji from the vector of CGM observations where Ji=floor(qi/2) , and Li=qiJi+1 . Then, calculate the SVD of the Hankel matrix as Ai=UiSiViT . Where URLi×Li and VRLj×Lj consist of the left and the right singular eigenvectors of AAT , the diagonal matrix SRLi×Lj denotes square roots of eigenvalues of AAT and “ T ” denotes the transpose operation.
Step 6: Starting from the lowest eigenvalue of diagonal matrix Si , remove eigenvalues corresponding to cumulative sum less than 5% of the total sum of eigenvalues. The reduced Si matrix is labeled S~i
Step 7: Reconstruct the Hankel matrix Ai from modified matrix S~i , Ui , and Vi and perform diagonal averaging to retrieve the denoised vector of CGM.
Step 8: Repeat steps 4 to 7 for all segments of CGM readings.

Abbreviations: BGC, blood glucose concentration; CGM, continuous glucose monitoring; SVD, singular value decomposition.

Reconciliation and Imputation of Missing Values in Data

Gaps in data are filled with the label “missing values.” The administered basal insulin is a piecewise constant variable calculated by the closed-loop AID system or determined by predefined infusion/injection scenarios. Therefore, basal insulin gaps with durations lower than two hours were filled with either forward or backward imputation method. Other missing values include long-duration basal insulin gaps that were imputed from the values at the same schedule of the previous day. This approach is justifiable because basal insulin recordings of subjects show daily patterns and small variations from day-to-day (Figure 2). Missing bolus insulin values are also imputed based on patterns of bolus administration, considering that bolus administration policy is infrequently modified.

Figure 2.

Figure 2.

The normalized histograms of the (a) difference in daily basal insulin flow rate and (b) difference in nearest infused insulin.

While CGM data are reported every five minutes, often gaps of various time window lengths exist in reported data. Accurate imputation of missing CGM values and reconciliation of erroneous values is important because otherwise they may cause biased predictions. One effective solution to imputing missing CGM values is employing probabilistic principal component analysis (PPCA) on the incomplete time-series data. Probabilistic principal component analysis has been shown to be an effective solution to the dimensionality reduction problem, linearly transforming the data into a lower multidimensional latent space in which the maximum variance of the transformed feature is explained. Gaussian conditional distribution of the latent variables is assumed in PPCA. 6 This formulation of the PPCA facilitates tackling the problem of missing values in the data based on the maximum likelihood estimation of the mean and variance of the original data.

To estimate missing CGM values, feature variables of matrix XN×M are mapped into a Hankel matrix by stacking lagged values of each feature variable CGM, basal and bolus insulin, carbohydrate intake, and exercise information. After estimating latent variables by using PPCA, the value of each missing CGM reading is calculated by diagonal averaging the reconstructed Hankel matrix. In this study, CGM gaps up to 25 consecutive missing samples (two hours) are imputed by PPCA. If longer gaps in CGM values exist in the data, imputing their values may be risky.

Feature Extraction

Extracting feature variables from raw data is the first step of training the RNN model. For each observation, four different types of feature variables, such as frequency domain, statistical domain, nonlinear domain, and model-based feature variables, are calculated and added to the data set to enhance the prediction power of RNN models. Qualitative trend analysis of variables represents different patterns of the variable caused by external factors within a specified time. 7 A pairwise combination of the sign and magnitude of the first and second derivatives of CGM values can be used to indicate meal consumption, insulin bolusing, and physical activity.8,9 Hence, the first and second derivatives of CGM values calculated by fourth-order backward difference method are added to the feature variables.

In addition, pairwise multiplication of the sign and the magnitude of the first and second derivatives and their covariance, Pearson correlation coefficient, and Gaussian kernel similarity are extracted. Numerous statistical feature variables, such as mean, standard deviation, variance, and skewness from the specified time window of CGM values, are obtained. Other feature variables include the covariance and correlation coefficients, from pairs of CGM values and derivatives are extracted and augmented the data. A longer time window of CGM values from the last 24-hour samples is used for frequency-domain feature extraction. The magnitude and frequency of the top three dominant peaks in the power spectrum of CGM values, conveying past long-term variation of the blood glucose, are included in modeling.

Plasma insulin concentration (PIC) is another useful variable for analyzing the dynamics of glycemic behavior. Postprandial hyperglycemia reduces PIC level in the bloodstream and the exogenous injection of insulin elevates PIC level, stimulating the blood glucose uptake in skeletal muscles and tissues.10,11 Currently, PIC values cannot be measured in real time and noninvasively. The PIC is estimated by adaptive state observers for insulin-glucose dynamic models and used in this work. Real-time estimation of PIC can be achieved by incorporating either Hovorka’s insulin-glucose model or Bergman’s minimal dynamic model with unscented Kalman filter state observer.12-14 One benefit of model-based PIC estimation is that other external disturbances, including gut absorption rate, are simultaneously estimated. Gut absorption rate represents the cumulative absorbed long and fast-acting carbohydrates which results in an enhancement in BGC estimation.15,16 In this work, real-time estimation of PIC has been performed by integrating a particle filter with discretized Hovorka’s model for use in designing a glycemic event predictor.

Feature Selection and Dimensionality Reduction

Reducing the number of feature variables by identifying and eliminating the redundant feature variables decreases the computational burden of their extraction and hinders over-parameterized modeling. In this work, a two-step feature selection procedure is employed to obtain the optimal subset of feature variables to boost the efficiency of the classifier. In the first step, the deviance statistic test is performed to filter out features with low significance (P-value > .05). In the second step, the training split of all data sets was used in the wrapper feature selection strategy to maximize the accuracy of the classifier in estimating glycemic events. Consequently, the top 20 feature variables with the highest contribution to the classification accuracy enhancement were used for model development.

Event Detection With Recurrent Neural Networks

Real-time detection of events disturbing glycemic homeostasis requires solving a supervised classification problem. Hence, all samples need labeling by using the information provided in data sets. An alternative is the determination of the class of a disturbance (meals, exercise) labels for each sample from “Activity.duration” and “Nutrition.carbohydrate.” In order to determine assignment to a class, let N be total number of samples and T(k)=ceil(Activity.duration(k)/(3×105)) be the sample duration of physical activity at each sampling time k. Define labels for classes “Meal and Exercise” (M and E), “no Meal but Exercise” (E), “no Exercise but Meal” (M), and “neither Meal nor Exercise” (No M and E), respectively as:

{MandE:={i|kik+T(k)1,k=1,,N,T(k)0Nutrition.carbohydrate(j)0,j=k+1,,k+T(k)}E:={i|kik+T(k)1,k=1,,N,T(k)0,Nutrition.carbohydrate(j)=0,j=k+1,,k+T(k)}M:={k|1kN,T(k)=0,Nutrition.carbohydrate(j)0}NoMorE:={k|1kN,T(k)=0,Nutrition.carbohydrate(j)=0}

Two different configurations of the RNN models are studied to assess their accuracy and performance in estimating the probabilities of carbohydrate intake, physical activity, and their concurrent occurrence at each sampling time. Due to time-series nature of feature variables, they (CGM, PIC, and CGM derivatives, past recorded samples of all feature variables) are stacked together to build the tensor of the model inputs. Both models use a past window of two hours, corresponding to 24 past samples of the recorded CGM and insulin pump data, and extracted features. Event (M, E) estimations are performed one sampling time backward. In other words, when an event is detected by the algorithm, it is attributed to have taken place in the immediate past sampling time. The values of several feature variables such as CGM, the first and second derivatives of CGM, and PIC convey information regarding exogenous insulin, physical activity, and carbohydrate intake in the past signal readings. Therefore, estimating the concurrent occurrence of the external disturbances should be performed one step backward as the effect of disturbance variables needs to be seen first and then parameter adjustment and event prediction be made. The schematic diagram of workflow for data processing, feature extraction, and modeling is illustrated in Figure 3.

Figure 3.

Figure 3.

The schematic diagram of workflow for data processing, feature extraction, and modeling. Online CGM values and insulin pump data are preprocessed and stacked with the past recoded data. All samples are segmented into three different time windows: the current samples are used for model-based feature extraction, two-hour window of the past data are used for statistical and nonlinear feature variables, and past day samples of the data are used for the frequency domain features. Voting and k-fold cross-validation are employed to assign the current state to one of the four classes. Abbreviations: CGM, continuous glucose monitoring; PIC, plasma insulin concentration.

The first RNN model consists of a masking layer to filter out unimputed samples, followed by a long short-term-memory (LSTM) layer, two dense layers, and a softmax layer to estimate the probability of each class. The feedback connection in the LSTM layer captures the sequentially of the information fed to the model. Rectified linear unit components and dense layers are included to better imitate nonlinearity of the data.

In the second RNN model, two series of one-dimensional (1D) convolution layers with max pooling were added to the structure of the first model and one of the dense layers is removed. Repeated 1D convolution layers improve the strength of the feature maps of the input data in predicting events. Max pool units in the second model summarizes feature maps, avoids over-parameterization, and reduces complexity of the model.

All data sets are preprocessed by the procedures presented and feature variables are rescaled to have zero-mean and unit variance. Although adequate samples of the data are available for model training, stratified six-fold cross-validation is applied to 90% of samples in each data set to reduce the variance of predictions. Each sample in the tensor of the data is assigned with weights proportional to the inverse of their class sizes to ensure all classes are well-trained and avoid biased predictions. Due to randomness in the nature of NNs, the models are trained five times with different random seeds to assess the variation of the results. Hyperparameters of all models are obtained through the Adaptive Moment Estimation (Adam) optimization algorithm and 2% of the training sample size was chosen as the size of the training batches. For each data set, the number of adjustable parameters, including weights, biases, the size of filter kernels, the learning rate, and forgetting factors, remain constant.

The average performance indexes of various RNN studied (Table 4) are calculated based on the following performance indices.

Table 4.

The Average Performance Indexes of Recurrent Neural Network (RNN) Models With LSTM and LSTM With 1D Convolution Layers for Event Prediction Problem.

Subject no./model Accuracy (%) Weighted sensitivity (%) Weighted precision (%) Weighted specificity (%)
1{LSTMLSTM(with1DConvolution) 92.03 (0.37)94.61 (0.15) 92.03 (0.37)94.61 (0.15) 94.59 (0.29)97.67 (0.20) 95.11 (0.52)
99.07 (0.13)
2{LSTMLSTM(with1DConvolution) 93.17 (0.21)94.69 (0.33) 93.17 (0.21)94.69 (0.33) 96.17 (0.09)96.58 (0.20) 95.54 (0.26)
98.11 (0.18)
3{LSTMLSTM(with1DConvolution) 89.93 (0.22)88.98 (0.28) 89.93 (0.22)88.98 (0.28) 93.98 (0.24)93.53 (0.09) 90.09 (0.29)
91.58 (0.30)
4{LSTMLSTM(with1DConvolution) 92.55 (0.27)94.67 (0.31) 92.55 (0.27)94.67 (0.31) 95.49 (0.09)96.62 (0.17) 95.76 (0.26)
97.40 (0.37)
5{LSTMLSTM(with1DConvolution) 94.41 (0.21)91.65 (0.26) 94.41 (0.21)91.65 (0.26) 96.46 (0.10)96.16 (0.12) 87.59 (0.05)
90.15 (0.25)
6{LSTMLSTM(with1DConvolution) 94.50 (0.27)95.67 (0.26) 94.50 (0.27)95.67 (0.26) 95.15 (0.22)96.69 (0.09) 78.64 (0.38)
81.88 (0.33)
7{LSTMLSTM(with1DConvolution) 91.81 (0.22)89.95 (0.22) 91.81 (0.22)89.95 (0.22) 95.43 (0.22)94.19 (0.17) 91.94 (0.17)
87.00 (0.29)
8{LSTMLSTM(with1DConvolution) 89.19 (0.22)90.99 (0.18) 89.19 (0.22)90.99 (0.18) 99.68 (0.27)97.68 (0.19) 98.63 (0.22)
95.50 (0.37)

Abbreviations: 1D, 1-dimensional; LSTM, long short-term memory.

The standard deviation is reported in parentheses.

The highest performance indexes for each model are reportd in bold font values.

AccuracyScore=AllcorrectlypredictedeventsTotalnumberofevents=iNi,iijNi,j,i,j[M&E,E,M,NoMandE]
WeightedSensitivity=Actualeventi×ThenumberofcorrectlypredictedeventsiAlleventspredictedasiTotalnumberofevents=j(iNj,i)*(Ni,ijNi,j)ijNi,j
Weightedspecificity=Thenumberofactualeventi×CorrectlypredictedeventsotherthaniIncorrectlypredictedeventi+CorrectlypredictedeventsotherthaniTotalnumberofactualevents=iNj,i(j,jiNj,jj,jiNj,j+j,jiNi,j)ijNi,j
WeightedPrecision=Thenumberofactualeventi×ThenumberofcorrectlypredictedeventiThenumberofpredictedeventiTotalnumberofevents=iNj,ij(Ni,ijNi,j)ijNi,j

where Ni,j denotes the number of actual event “ i ” which is predicted as “ j ”.

Results

The data sets of eight randomly selected individuals with T1D containing physical activity and carbohydrate intake information for 30 to 90 weeks of recorded data are used for classification and testing the performance of the two RNNs. The performance of each classifier is evaluated by test data with three to eleven weeks of sensor and insulin pump recordings. Each classification operation is repeated five times to take into account the randomness of outcomes from RNNs, and the average of each performance index is reported in Table 4.

Figure 4 illustrates the classification performance of the two models in detecting meal and exercise events affecting the BGC for one day of test data of a randomly selected subject (Subject 2). Red bars denote incorrectly predicted classes and blue colored bars indicate their actual events. To have a better demonstration of the importance of outlier rejections and missing sample imputations, same RNN models are trained with unprocessed data for the same subject. In the model training step, the data set with outliers and unimputed missing samples is utilized to adjust the hyperparameters of both models. The optimization algorithm, the random seed, the number of layers, and learnable parameter remain the same as that of previous models.

Figure 4.

Figure 4.

One step backward predicted meal and exercise events for the test data of one randomly selected subject (Subject 2). Vertical green bars represent correctly predicted classes. Vertical red bars denote incorrectly predicted classes and their actual labels are shown by blue bars. Classification labels: No M/E, no meal or exercise; E, only exercise; M, only meal; M and E, meal and exercise. Abbreviations: 1-D, one-dimensional; LSTM, long-short-term memory.

Discussion of Results

Between the two different types of RNN models investigated in this study, the LSTM RNN models with 1D convolution layers achieve the highest accuracy for five subjects out of eight (Table 4). The weighted sensitivity, precision, and specificity values are all in the range 89.9% to 99.7% except for the specificity for subject 5 (81.9%).

Having fewer samples (because of missing values), the unimputed data set carries less information on the CGM and insulin pump data, carbohydrate intake, and physical activity than the preprocessed data set. The accuracy of correct event detection with unimputed data (missing values and outliers) (Figure 5) is lower than the results obtained from models with imputed data samples and with reconciled outliers (Table 5).

Figure 5.

Figure 5.

Concurrent meal-exercise events predicted form the data set (subject no. 2) with outliers and unimputed samples. Vertical green bars represent correctly predicted classes. Vertical red bars denote incorrectly predicted classes and their actual labels are shown by blue bars. Classification labels: No M/E, no meal or exercise; E, only exercise; M, only meal; M and E, meal and exercise. Abbreviations: 1-D, one-dimensional; LSTM, long-short-term memory.

Table 5.

Confusion Matrices Calculated From the Predicted and Actual Classes for Data From Subject 2.

Predicted Actual
No M, E E M M+E
(a) LSTM (with preprocessed data)
No M, E 11 154 12 46 2
E 310 598 2 0
M 263 21 593 1
M+E 217 5 27 6
Total samples 11 944 636 668 9
Correctly predicted 93.39% 94.03% 88.77% 66.67%
(b) LSTM with 1D convolution layers (with preprocessed data)
No M, E 11 297 14 8 1
E 274 596 2 2
M 311 8 655 1
M+E 62 20 3 5
Total samples 11 944 636 668 9
Correctly predicted 94.58% 93.42% 98.05% 55.56%
(c) LSTM (without imputed samples)
No M, E 9841 42 41 1
E 345 411 23 1
M 224 61 510 1
M+E 151 88 43 4
Missing samples 1383 34 51 2
Total samples 11 944 636 668 9
Correctly predicted 93.18% 64.62% 82.66% 57.14%
(d) LSTM with 1D convolution layers (without imputed samples)
No M, E 9912 71 24 2
E 366 441 19 1
M 214 23 522 1
M+E 69 67 47 3
Missing samples 1383 34 56 2
Total samples 11 944 636 668 9
Correctly predicted 93.85% 73.26% 85.29% 42.86%

Abbreviations: 1D, 1-dimensional; LSTM, long short-term memory.

Classification results obtained from (a) regular LSTM RNN model trained with the preprocessed data, (b) LSTM with 1D convolution layers RNN model trained with the preprocessed data, (c) regular LSTM NN model trained with unprocessed data, and (d) LSTM with 1D convolution layers RNN model trained with the unprocessed data. Tables (c) and (d) are calculated from test split with 1475 fewer observations (due to missing data and outliers). The percentages of events detected correctly are listed in the column “% correct.”

Confusion matrices corresponding to models trained with processed and unprocessed data are shown in Table 5. Some meal and exercise events are misclassified. For example, for the RNN with 1D convolution layers and imputed data out of 11 944 “No M or E” events, 274 are identified as “E” (2.29%), 311 as “M” (2.6%), and 62 as “M and E” (0.05). This may be partly caused by some physical activities of daily living or snacks not reported as meals. A comparison of Figures 4 and 5 and Table 5 indicate that the number of misclassified events in models without sample imputation and outlier removal for the LSTM and LSTM with 1D convolution RNNs increases without data imputation. For this, RNN when imputed data are used, two meal events are classified as exercise, eight as “No M or E,” and three as “M and E.” When unimputed data are used, the classification results become 19, 24, and 47, respectively. Similarly, 8 “E” events are classified as “M,” 14 as “No M or E,” and 20 as “M and E” with imputed data. These misclassifications increase to 23 “M,” 71 “No M or E,” and 67 for “M and E” with unimputed data. In particular, predicting meal events as physical activity and vice versa are troublesome for an AID system as it will infuse insulin during physical activity or suggest carbohydrate intake after meal events. Therefore, outlier rejection and imputing unmeasured observations enhance the accuracy and reliability of classifiers by preserving information on meal and exercise events rather than excluding samples in developing the RNN models.

Another reason which makes the prediction of “M and E” difficult is the lack of enough information. Many people may prefer having a small snack before or after exercise rather than consuming a rescue carbohydrate during physical activity. Such cases are not recorded in the data. Furthermore, the AID systems used by the subjects receive automatically only the CGM values, and meal and physical activity need to be announced manually to the device. In long-term use, meal and exercise announcement may sometimes become inconvenient, and recording of this information could be ignored. Although carbohydrate consumption and physical activity are two prominent disturbances that disrupt BGC regulation, their opposite effect on BGC makes the prediction of “M and E” less important than only carbohydrate intake or only physical activity, since their effects can be balanced by their concurrent presence.

Figure 4 and Table 5 indicate that detecting the occurrence of physical activity (E) is more challenging compared to detection of carbohydrate intake (M) and no meal or exercise (No M and E). One reason behind the difficulty of physical activity estimation from self-recorded insulin-glucose information has to do with the lack of objective information from wearable devices, which could have eliminated missed manual entries of physical activity information.

The fraction of correctly estimated physical activity samples to all actual physical activity samples for the two RNN models reveals that their series of convolution-max pool layers could elicit informative feature maps for classification efficiently. In the RNN model with 1D convolution layers, the over-parameterization issue was addressed by employing a series of convolution operations followed by max pool layers to decrease the number of adjustable parameters. Although augmented features such as the first and second derivatives of CGM and PIC enhance the prediction power of the RNN models, the secondary feature maps, extracted from all primary features, are a better fit for this classification problem. Besides, repeated 1D kernel filters in convolution layers suit better to the time-series nature of the data as opposed to utilizing the primary input features selected for both RNN models.

Several approaches have been published for meal detection8,9,17-19 using data collected in clinical studies. The amount of missing information and outliers are lower in this case. This paper uses free-living data with much longer time series of data and higher levels of missing information and outliers. Developing RNN models for detecting physical activity and meal events and their concurrent presence requires massive amounts of free-living data to develop accurate models.

One limitation of the RNN approach is the necessity of large data sets, and data in free-living can provide such data. Data preprocessing for reconciling missing data and outliers is critical and the manuscript reports a powerful approach for data reconciliation. Another limitation of this approach is that RNN models are inclined to give more “false alarms” as opposed to “missed alarms.” This observation comes from the fact that insulin-CGM data are highly imbalanced (long sedentary periods, and infrequent meal and exercise events) and trained models gravitate toward capturing “important events,” even if prediction yields more “false alarms.” The evaluation of “false alarm” vs “missed alarm” should be made and the assessment of the safety of conservative vs aggressive action of the insulin delivery system must be considered to ensure the safety of users.

It was expected to have misclassifications of concurrent physical activity and meal events—people having snacks before, during, or at the end of exercise with sedentary state where BGC do not vary too much. The results from unseen split of the data show that in most subjects, no matter how well the BGC is regulated, the discrimination of simultaneous meal-physical activity events is rather challenging.

Conclusions

Two RNN models were developed for the detection of meal and exercise events causing large glycemic variations and their performances were compared by using real-world free-living data without clinical supervision. Long-short-term memory with 1D convolution RNNs using imputed data provide the best performance. The reliability of event and trend detection from historical data is important for use in decision-making and in fully-automated AID systems. Determining the patterns of behavior of a person using an AID system improves the system performance by taking future disturbances into account when estimating future BGC and proactively adjusting the aggressiveness of the AID system. 20 The use of information from additional sensors such as those in wearable devices and meal estimation from algorithms processing CGM data can further enhance the event detection accuracy, rather than relying exclusively on free-living data from CGMs, insulin pumps, and manual entries by the user.21-25

Acknowledgments

Financial support from JDRF under Grant No. 1-SRA-2019-S-B and the Hyosung S. R. Cho Endowed Chair to Ali Cinar at Illinois Institute of Technology is gratefully acknowledged.

Footnotes

Abbreviations: AID, automated insulin delivery; BGC, blood glucose concentration; CGM, continuous glucose monitoring; CHO, carbohydrate; MDI, multiple insulin injections; PIC, plasma insulin concentration; RNN, recurrent neural network; SAP, sensor-augmented pump.

The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.

Funding: The author(s) disclosed receipt of the following financial support for the research, authorship, and/or publication of this article: This work was supported by JDRF under grant 1-SRA-2019-S-B.

References

  • 1. Garcia-Tirado J, Brown SA, Laichuthai N, et al. Anticipation of historical exercise patterns by a novel artificial pancreas system reduces hypoglycemia during and after moderate-intensity physical activity in people with type 1 diabetes. Diabetes Technol Ther. 2021;23:277-285. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 2. Garcia-Tirado J, Diaz JL, Esquivel-Zuniga R, et al. Advanced closed-loop control system improves postprandial glycemic control compared with a hybrid closed-loop system following unannounced meal. Diabetes Care. 2021;44:2379-2387. [DOI] [PubMed] [Google Scholar]
  • 3. Mosquera-Lopez C, Dodier R, Tyler N, Resalat N, Jacobs P. Leveraging a big dataset to develop a recurrent neural network to predict adverse glycemic events in type 1 diabetes. IEEE J Biomed Health Inform. 2019;1. doi: 10.1109/JBHI.2019.2911701. [DOI] [PubMed] [Google Scholar]
  • 4. Albahli S, Ahmad Hassan Yar GN. Automated detection of diabetic retinopathy using custom convolutional neural network. J Xray Sci Technol. 2022;30(2):275-291. [DOI] [PubMed] [Google Scholar]
  • 5. Lam C, Yi D, Guo M, Lindsey T. Automated detection of diabetic retinopathy using deep learning. AMIA Jt Summits Transl Sci Proc. 2018;2017:147-155. [PMC free article] [PubMed] [Google Scholar]
  • 6. Tipping ME, Bishop CM. Probabilistic principal component analysis. J R Stat Soc Ser B Stat Methodol. 1999;61:611-622. [Google Scholar]
  • 7. Cheung JT-Y, Stephanopoulos G. Representation of process trends—part I. A formal representation framework. Comput Chem Eng. 1990;14:495-510. [Google Scholar]
  • 8. Samadi S, Rashid M, Turksoy K, et al. Automatic detection and estimation of unannounced meals for multivariable artificial pancreas system. Diabetes Technol Ther. 2018;20(3):235-246. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 9. Samadi S, Turksoy K, Hajizadeh I, Feng J, Sevil M, Cinar A. Meal detection and carbohydrate estimation using continuous glucose sensor data. IEEE J Biomed Health Inform. 2017;21(3):619-627. [DOI] [PubMed] [Google Scholar]
  • 10. DeFronzo RA. Pathogenesis of type 2 diabetes : metabolic and molecular implications for identifying diabetes genes. Diabetes Rev. 1997;5:177-266. [Google Scholar]
  • 11. Defronzo RA. From the triumvirate to the “ominous octet”: a new paradigm for the treatment of type 2 diabetes mellitus. Diabetes. 2009;58(4):773-795. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 12. Eberle C, Ament C. The Unscented Kalman Filter estimates the plasma insulin from glucose measurement. Biosystems. 2011;103(1):67-72. [DOI] [PubMed] [Google Scholar]
  • 13. Hajizadeh I, Rashid M, Turksoy K, et al. Plasma insulin estimation in people with type 1 diabetes mellitus. Ind Eng Chem Res. 2017;56:9846-9857. [Google Scholar]
  • 14. Sevil M, Rashid M, Hajizadeh I, et al. Chapter 9—Automated insulin delivery systems for people with type 1 diabetes. In: Chappel E, ed. Drug Delivery Devices and Therapeutic Systems. London, England: Academic Press; 2021:181-198. [Google Scholar]
  • 15. Holst JJ, Gribble F, Horowitz M, Rayner CK. Roles of the gut in glucose homeostasis. Diabetes Care. 2016;39:884-892. [DOI] [PubMed] [Google Scholar]
  • 16. Rashid M, Samadi S, Sevil M, et al. Simulation software for assessment of nonlinear and adaptive multivariable control algorithms: glucose–insulin dynamics in type 1 diabetes. Comput Chem Eng. 2019;130:106565. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 17. Zheng M, Ni B, Kleinberg S. Automated meal detection from continuous glucose monitor data through simulation and explanation. J Am Med Inform Assoc. 2019;26:1592-1599. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 18. Daniels J, Herrero P, Georgiou P. A deep learning framework for automatic meal detection and estimation in artificial pancreas systems. Sensors (Basel). 2022;22:466. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 19. Dassau E, Bequette BW, Buckingham BA, Doyle FJ, III. Detection of a meal using continuous glucose monitoring: implications for an artificial β-cell. Diabetes Care. 2008;31:295-300. [DOI] [PubMed] [Google Scholar]
  • 20. Askari MR, Hajizadeh I, Rashid M, Hobbs N, Zavala VM, Cinar A. Adaptive-learning model predictive control for complex physiological systems: automated insulin delivery in diabetes. Annu Rev Control. 2020;50:1-12. [Google Scholar]
  • 21. Breton MD, Brown SA, Karvetski CH, et al. Adding heart rate signal to a control-to-range artificial pancreas system improves the protection against hypoglycemia during exercise in type 1 diabetes. Diabetes Technol Ther. 2014;16(8):506-511. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 22. DeBoer MD, Cherñavvsky DR, Topchyan K, Kovatchev BP, Francis GL, Breton MD. Heart rate informed artificial pancreas system enhances glycemic control during exercise in adolescents with T1D. Pediatr Diabetes. 2017;18(7):540-546. [DOI] [PubMed] [Google Scholar]
  • 23. Jacobs PG, Resalat N, El Youssef J, et al. Incorporating an exercise detection, grading, and hormone dosing algorithm into the artificial pancreas using accelerometry and heart rate. J. Diabetes Sci Technol. 2015;9:1175-1184. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 24. Turksoy K, Bayrak ES, Quinn L, Littlejohn E, Cinar A. Multivariable adaptive closed-loop control of an artificial pancreas without meal and activity announcement. Diabetes Technol Ther. 2013;15(5):386-400. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 25. Turksoy K, Hajizadeh I, Hobbs N, et al. Multivariable artificial pancreas for various exercise types and intensities. Diabetes Technol Ther. 2018;20(10):662-671. [DOI] [PMC free article] [PubMed] [Google Scholar]

Articles from Journal of Diabetes Science and Technology are provided here courtesy of Diabetes Technology Society

RESOURCES