Study design and setting
This study was a randomized trial embedded within a single-center parent randomized controlled trial (RCT)16. The parent trial enrolled overweight/obese adults and followed participants longitudinally using mobile health devices and daily self-monitoring. The present trial evaluated an ancillary AI-enabled intervention delivered during the second half of the study period16.
Participants and data collection
The parent trial enrolled 60 overweight or obese adults (≥18 years), including 40 participants with T2D according to the American Diabetes Association criteria16. Participants were assigned to a ketogenic or low-fat, low-calorie diet and self-monitored dietary intake using a smartphone-based application. Physical activity was tracked using a Fitbit Inspire 2, and body weight was measured using a Withing’s body scale. All participants received health education consistent with evidence-based behavioral lifestyle interventions. Participants completed a 3-month baseline observation period followed by a 3-month intervention (mean follow-up: 174 days), generating 6467 longitudinal daily data points from self-monitoring of dietary intake, body weight, physical activity (steps), and glucose-related measures17. These data were used to support transfer learning–based pretraining of a predictive digital twin model.
For the ancillary AI intervention, participants were selected from the subset of individuals with type 2 diabetes who had complete longitudinal self-monitoring data across both the baseline and intervention phases. A total of 19 participants met these criteria and were included in the present analysis. These participants were first stratified based on their study group assignment in the parent trial and relevant health conditions (e.g., with or without early-stage chronic kidney disease), and then independently randomized into the AI intervention group (n = 10) or control group (n = 9) using a simple random allocation procedure. This randomization was conducted separately from the parent trial assignment, ensuring that the AI intervention represented an independent experimental comparison. Data from the initial 3 months were used to train the predictive digital twin, after which continuously streamed data informed an online human-in-loop predictive control (OHLC) model that generated daily recommendations delivered via short message service (SMS). The predictive model was retrained weekly to improve performance. Baseline demographic and clinical characteristics were assessed to ensure comparability between the AI and control groups.
Model construction: Predictive digital twin (transfer-learned ANN)
The PDT at its core utilizes an artificial neural network (ANN) predictive digital twin model that has been trained using transfer learning (TF) strategies to improve its performance (for both data-rich and data-scarce setups) to generate food intake suggestions18,19. As proof of concept, we have the following contributions in this work:
A human-in-the-loop artificial intelligence feedback system.
A transfer-learned predictive digital twin model of patients.
An evolutionary optimization-based online control model in mHealth devices.
Human-in-the-loop oversight was incorporated as a safety and clinical validation layer within the intervention. All AI-generated recommendations were reviewed by a trained nurse or interventionist prior to delivery to participants. The reviewer evaluated the clinical appropriateness, feasibility, and safety of suggested dietary and activity targets, including specific food items and portion sizes. Based on this assessment, a penalty score ranging from 1 (highly appropriate) to 1000 (clinically inappropriate) was assigned and incorporated into the optimization objective function. This process ensured that recommendations aligned with established clinical guidelines and patient-specific considerations before dissemination via SMS.
Figure 1 shows the overall schema of the proposed model. We first build a predictive model where inputs are the daily lifestyle choices, and the outputs are the next day’s glucose and weight levels. Next, we used the predictive model as the core block for the online control model. The control model is built based on the Particle Swarm Optimization (PSO) method, which generates feedback that minimizes glucose and weight outputs. We retrained the models every week. PSO utilizes the fine-tuned model as a core plant to generate dietary suggestions. We employed a pretrain-then-fine-tune transfer learning strategy, in which the model was first trained on pooled data from all participants to learn shared physiological patterns, and subsequently fine-tuned on subgroup-specific data defined by diet and clinical condition.
Fig. 1: Overview of the proposed digital twin framework for personalized lifestyle intervention.
Lifestyle data collected from participants were preprocessed and used to train a deep learning model for glucose and weight prediction. Transfer learning was applied to develop personalized digital twins, which generated optimized dietary and activity feedback through an online control system for individualized lifestyle management.
Predictive digital twin: transfer learning-based artificial neural network to predict patient states
The intervention was designed as a “between-visit” self-management support model. During the 3-month baseline phase, no participants received AI feedback. At the start of the 3-month AI-intervention phase, the AI group began receiving daily personalized SMS containing actionable lifestyle suggestions (e.g., dietary and activity adjustments) generated by the OHLC model. The control group continued usual self-monitoring and diet guidance without daily AI SMS.
The SMS-based intervention consisted of three integrated components. First, personalized dietary recommendations were generated using the predictive digital twin and PSO optimization framework, which produced individualized macronutrient targets that were subsequently translated into specific meal plans using a linear programming approach. Second, the domain of behavioral messaging (e.g., dietary adherence, physical activity encouragement) was informed by the AI-generated targets. Third, motivational message content was selected from a predefined library by the nurse reviewer based on clinical judgment and patient context.
Participants received one SMS message per day containing these combined elements. The system was unidirectional, and participants did not interact directly with the AI system. Adherence to recommendations was not formally quantified but was indirectly assessed through longitudinal behavioral trends.
We start by developing a PDT that will predict next-day blood glucose and body weight based on observed dietary intake, physical activity, and prior physiological state. By definition, a predictive twin models the future behavior and state of any system in consideration. These models utilize historical data to incorporate possible system modes within the model. We construct the PDT to receive self-monitoring data from patients (food intake, weight, exercise regimen, etc.). This allows the twin to simulate the physical object in real-time, in the process offering insights into their performance (weight and blood glucose control).
We construct a simple multilayer perceptron/artificial neural network (with three hidden layers) (ANN) for predictive modeling of daily glucose levels using the health time series data. We utilize a transfer learning strategy to take care of the missing values. In literature, transfer learning strategies have proved to make learning from data efficient, fast, and under sparse data fruitful19. To achieve this goal, we concatenated and sampled all the patient’s data and created the transfer learning dataset to pre-train the ANN model20. Once the pre-training is done, the model is fine-tuned for each patient diet-condition group (1. Keto Diet – Obese and T2D, 2. Keto Diet – Obese, Kidney Disease, and T2D, 3. Low-Fat Diet – Obese and T2D, 4. Low-Fat Diet – Obese, Kidney Disease, and T2D). The training procedure involves sampling data to train a deep learning model for each patient group of interest, where the ANN model weights of the pre-trained model are used as the prior. We compare the performance of the model with classic machine learning models (KNN, Gaussian Process, Decision Tree, Random Forest, Gradient Boosting). Parameters for all the models are tuned using a grid search approach. While many of the above-mentioned algorithms can be used for building the predictive twin (comparable accuracy; later shown in the results section), we selected the transfer learning (TF)-based ANN algorithm for our analysis for two specific reasons:
They adapt to learning complex patterns present in the data, and
The predictive twin can be trained even if there is a low amount of data (data sparsity) for a new patient group.
Figure 2 shows a visual representation of the transfer learning strategy used in this work. We followed the same steps as Faruqui et al.14 The only change was that they fine-tuned their models for each patient, and we fine-tuned for each patient’s diet-condition group.
Fig. 2: Scheme of the transfer learning strategy to train an artificial neural network for predictive modeling.
The upper panel illustrates pretraining of the deep learning model using data from all patients to establish prior model weights. The lower panel demonstrates transfer learning and personalization of the model using data from diet-specific groups to generate posterior weights for individualized prediction. The trained model was used to predict glucose and weight outcomes.
The input features of the predictive model included daily dietary macronutrient intake (carbohydrates, fat, fiber, and protein), physical activity (daily step count), and prior-day physiological measurements (body weight and blood glucose levels). Temporal dependencies were incorporated through the inclusion of lagged variables rather than recurrent neural network architectures.
The artificial neural network was trained using the Adam optimizer with a learning rate of 1 × 10⁻⁵ for 200 epochs. No dropout or explicit regularization techniques were applied. Model training and evaluation followed a sequential design, with the first three months of baseline data used exclusively for training and a subsequent non-overlapping period used for testing, thereby avoiding data leakage.
Online control model: particle swarm algorithm
Once the PDT is developed, we focus on developing the control model of the proposed algorithm. The control model uses PDT (of the patient-diet group) to determine what combination of food intake and exercise would help a patient maintain their blood glucose level and help them lose weight while maintaining their blood glucose level. This highly non-linear problem needs to be optimized efficiently within the search space. We deploy the Particle Swarm Optimization (PSO)21 algorithm as the controller due to its simple implementation; it doesn’t need a gradient form of the objective function and, depending on the setting, is less memory consuming (can be used in both online and off-line setup). For a function defined in a multidimensional vector space (as in our study case), PSO is a robust meta-heuristic optimization algorithm and one of the best optimization algorithms to find the minimum or maximum of the objective function. The PSO algorithm (Step 2 of Fig. 1) is then used with the predictive twin to determine the best parameters to minimize the objective function. The PSO algorithm consists of two components: (1) the Objective function and (2) the constraints.
The OHLC controller used particle swarm optimization (PSO) to identify feasible behavior changes that minimize predicted risk while supporting weight goals and glycemic stability. Constraints for macronutrient recommendations were defined based on diet requirements and clinical team input, enabling clinically sensible search boundaries. Human-in-the-loop input was incorporated as a penalty factor that increased the cost of implausible or undesirable recommendations, allowing nursing expertise to improve safety and appropriateness. The PDT was retrained weekly during the intervention period to incorporate newly accumulated data and adapt guidance over time.
The objective function
To set up PSO for our study, we need an objective function that helps us achieve our goal. For a patient in the low-fat diet group, our goal is to suggest a food and exercise regimen that can help them lose weight (W) till they reach their target weight level \(\left({W}_{G}={W}_{0}-0.2{W}_{0}\right)\). Once they reach their target level, we switch the goal to maintaining that weight. The patients will also need to maintain their Glucose levels (G) within an acceptable range \(\left(70\le G\le 130\right)\). A patient in the keto diet group must attain (or close to) a certain blood ketosis level. To do that, they need to reach a keto ratio (K) of 1.5 or higher. The keto ratio can be computed from the suggested food intake (macronutrients) by the PSO algorithm. The objective function is special in the sense that we don’t want the algorithm to select extreme parameters (in our case, food intake and physical activity suggestions) that cause the glucose level to go near zero or too high a ketone level. To resolve this issue, we introduced a tuning parameter λ, which takes the value of 0 whenever a generated suggestion reaches its desired value; otherwise, it takes a value of 1. This helped control the model to achieve its desired output. We integrated the feedback of the nursing knowledge using a second multiplier (penalty factor, m) for each element of the objective function. Depending on the suggestion provided by the controller, if the predicted glucose/weight/ketone level is too diverse, a nurse can assign a higher penalty and vice versa. In our case, this assigned score ranged from 1 to 1000 to penalize the model if it’s too far away from desired values. At the end of each evaluation phase, the score derived from nursing knowledge is assigned to the model. The details of the decision boundaries considered by the nurses are provided in Appendix 1. Thus, considering the above, the objective function for the PSO algorithm is set as follows:
Objective Function
$$\mathop{\min }\limits_{{\rm{l}}=1,\,\ldots .,{\rm{L}}}\mathop{\sum }\limits_{i=1}^{n}{\lambda }_{1}{{m}_{1}\hat{G}}_{i}+{\lambda }_{2}{m}_{2}{\hat{W}}_{i}+{{\rm{\lambda }}}_{3}{m}_{3}\left(1.5-{{\rm{K}}}_{{\rm{i}}}\right)$$
where,
Tuning parameter,
\({\lambda }_{1}=0\); if \(70\le {\hat{G}}_{i}\le 130\)
\({\lambda }_{2}=0\); if \(\left({W}_{i}-\hat{{W}_{i}}\right)\ge 0\) or \({W}_{G}=\hat{{W}_{i}}\)
\({\lambda }_{3}=0\); if Patient-Diet Group=‘keto-diet’ or \(\left(1.5-{K}_{i}\right)\ge 0\)
\({m}_{i=\{1,\,2,\,3\}}\)=Score assigned by a human-in-the-loop. This is used in conjunction with the tuning parameters \(\left({\lambda }_{i=\{\mathrm{1,2,3}\}}\right)\)
\(K=\frac{{f}_{a}}{(c-{f}_{b}+p)}\); K = Keto ratio, c= carb, fa = fat, fb= fiber, p= protein
\({W}_{G}={W}_{0}-0.2{W}_{0}\); WG= Weight Goal, W0= Patients weight at the start of the study
The scores (m) assigned by the human in the loop can also be automated in future studies by:
1.
Building a lookup table generated by the nurse/s for all the factors to be used during the optimization session.
2.
Building an approximating linear function by using the lookup table. That way, we can approximate the penalty factors even if there is a value present that was not assigned a penalty by the nurse/s.
The constraints
Furthermore, we also define the search space for the proposed model. The model constraints are decided based on the appropriate diet requirement22,23 and discussions with humans (nurse-led research team) in the loop. The constraints may also be adapted (exception case) based on patient-specific needs, based on their physical condition and nutritional needs, thus making the model adaptive not only patient group specific but also patient specific. For this work, the general constraints were defined as follows in Table 1:
Table 1 General constraints for low-fat and ketogenic diet groupsOutcomes
The primary study outcomes were (1) weight change during the intervention period and (2) glycemic stability over time. Model performance was evaluated using Clark Error Grid analysis, reported as the percentage of predictions falling in Zone A. Glycemic stability was operationalized as the absence of statistically significant changes in mean glucose levels within each group from baseline to end of study, as assessed using repeated measures analysis.
Statistical analysis
We used ANOVA to evaluate intervention effects on weight change over time and to assess glucose stability across the study period. Model performance comparisons were summarized using Clark Error Grid Zone A accuracy across diet-condition subgroups. Due to the small sample size, statistical analyses were considered exploratory. Model assumptions for ANOVA were assessed, and results were interpreted with caution, given limited statistical power. Reported p-values reflect both within-group changes over time and between-group differences, as specified in each result.
Ethics and dissemination
This study was conducted in accordance with the ethical principles of the Declaration of Helsinki and in compliance with U.S. federal regulations for the protection of human subjects (45 CFR 46). The study protocol was reviewed and approved by the Institutional Review Board of the University of Texas Health Science Center at San Antonio (Protocol Number: HSC20190528H). Written informed consent was obtained from all participants (in related files). The study was registered at http://ClinicialTrials.gov (NCT05071287). The initial release date was 2021-06-03.