VirtualPatients is a biophysiology platform that allows users to design and evaluate healthcare interventions for in-silico populations and general-purpose healthcare applications. It is simultaneously multiple things:
- A lightweight, Pythonic, and user-friendly patient simulation platform.
- A universal biophysiological engine capable of simulating a wide range of individual differences and biophysiological phenomena.
- A realistic rendering system to simulate and test healthcare interventions identical to proposed clinical studies.
- A generative data engine that transforms offline datasets into diverse simulated data.
🔥 News
- [2024-04-25] Open-sourced offline dataset
- [2024-01-26] Released VirtualPatients V1.0
🐍 100% Python, both front-end interface and back-end biophysiological engine, all natively developed in python.
📐 Differentiability: VirtualPatients is designed to be fully compatible with differentiable simulation.
💥 A unified framework that supports various state-of-the-art physiology solvers, modeling a vast range of individual differences and biophysiological phenomena.
- Embodies the biophysiological parameters of the FDA accepted in silico population. Personal biophysiological parameters 39 patients can be found in vpatient_params.csv
- 19 adults, 10 adolescents, 10 children
Adult | Adolescent | Child | |
---|---|---|---|
Ideal Dataset + Simulations | 10 | 10 | 10 |
Suboptimal Dataset + Simulations | 9 |
- Meal profiles (CHO amount, timing and duration of a meal)
- Insulin intervention (amount and timing of basal/bolus insulin doses)
- Time of simulation and regulation (length & time of day)
- Individualised, intra-personal results
- Inter-personal differences are highlighted across the spectrum of human variation
- Population results are calculated from individual results, as in a clinical trial
- Age, Body Weight (kg), subject-specific optimal basal insulin rate (u/hr), individual carbohydrate ratio (CR, g/U), total daily insulin, and insulin sensitivity (maximum drop in glucose mg/dl per unit of insulin [MD])
- Metabolic testing results may be simulated for individual subjects and incorporated into intervention plans beforehand
- Blood glucose (BG) values and simulated sensor readings (mg/dl per minute)
- Basal/bolus insulin injections (pmol/minute)
- User-specified data from controller
- System states, carbohydrate intake and more ...
The operation of the VirtualPatients simulation is shown in the figure below:
The differential
The
For the latest version, clone the repository and install locally:
git clone https://github.com/yuxuehui/VirtualPatient.git
cd VirtualPatients
pip install -e .
VirtualPatients provides three intervention schemes to meet the personalised needs of different patients:
- Dietary intervention
- Medication intervention
- Combined dietary and medication intervention
(An interface for exercise intervention will be made available soon.)
The intervention scheme is configured using five parameters: info_phase_length
, flag
, meal_time
, default_meal
, and default_insulin
. The details of each parameter are as follows:
-
flag
: Determines the control mode with a value of 0, 1, or 2.0
: Controls carbohydrates only.1
: Controls insulin only.2
: Controls both carbohydrates and insulin.
-
info_phase_length
: the number of time steps per day.3
whenflag=0
, three meals per day.1440
for otherflag
values. Basal/bolus insulin injections are once per minute, so 1440 insulin doses are required in a natural day.
-
meal_time
: Specifies meal times in a list with three elements (in minutes). Default value:[360, 660, 1080]
-
default_meal
: Specifies the default meal size, used whenflag=0
. Formatted as a list with three elements. Default value:[50, 50, 50]
-
default_insulin
: Specifies the default insulin dosage, used whenflag=1
. Formatted as a float. Default value:0.01
Additionally, do not forget change the action_range
according to different intervention schemes and the need of your control methods, which is used to specify the range of values for the action space.
You can use VirtualPatients to evaluate various types of control methods, such as supervised learning and reinforcement learning. Below is an example of a Python implementation using PPO:
from virtual_patient.envs.env_do_all_her_2reward import CBNEnv
from stable_baselines3 import PPO
env = CBNEnv.create( # initialise a environment
info_phase_length=1440,
action_range=args.action_range,
vertex=args.vertex,
reward_scale=args.reward_scale,
n_env=1,
patient_ID=args.patient_ID,
list_last_vertex=[],
flag=0,
meal_time=[300,600,1000],
default_meal=[50,100,100],
default_insulin=0.02
)
optimizer_kwargs = dict(
alpha=0.95,
)
policy_kwargs = dict(
optimizer_kwargs=optimizer_kwargs,
optimizer_class=RMSpropTFLike
)
model = PPO("MlpPolicy", # initialise a PPO model
env,
n_steps=5,
gae_lambda=0.95,
gamma=0.9,
n_epochs=10,
ent_coef=0.0,
learning_rate=float(1e-4),
clip_range=0.2,
use_sde=True,
sde_sample_freq=4,
verbose=1,
tensorboard_log='../logs',
seed=94566)
model.learn( # train
total_timesteps=int(3e7),
callback=TensorboardCallback())
env.close()
VirtualPatients is the result of a collaborative effort between the Web Intelligence Group at Harbin Institute of Technology and Dnurse. It is a large-scale effort that integrates various existing and ongoing research projects into a single system. Below is a list of papers that have contributed to the VirtualPatients project:
- Yu, Xuehui, et al. "Causal prompting model-based offline reinforcement learning." arXiv preprint arXiv:2406.01065 (2024).
- Yu, Xuehui, et al. "KaDGT: How to Survive in Online Personalisation with Highly Low-quality Offline Datasets." arXiv preprint arXiv:2335.20405 (2024).
- Liu, Liangliang, et al. "An interactive food recommendation system using reinforcement learning." Expert Systems with Applications (2024): 124313.
- Yu, Xuehui, et al. "ARLPE: A meta reinforcement learning framework for glucose regulation in type 1 diabetics." Expert Systems with Applications 228 (2023): 120156.
- Yu, Xuehui, et al. "Causal Coupled Mechanisms: A Control Method with Cooperation and Competition for Complex System." 2022 IEEE International Conference on Bioinformatics and Biomedicine (BIBM). IEEE, 2022.
[1] Dalla Man C, Rizza R A, Cobelli C. Meal simulation model of the glucose-insulin system[J]. IEEE Transactions on biomedical engineering, 2007, 54(10): 1740-1749.