Code Monkey home page Code Monkey logo

simglucose's People

Contributors

dependabot[bot] avatar edger-asiimwe avatar hannesvoss avatar jxx123 avatar shurikal avatar yihuicai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simglucose's Issues

Environment creates the same scenario between resets

Consider this minimal example:

import gym
from gym.envs.registration import register

register(
	id='simglucose-adult001-v0',
		entry_point='simglucose.envs:T1DSimEnv',
		kwargs={'patient_name': 'adult#001'}
	)
env = gym.make('simglucose-adult001-v0')
env.seed(0)

env.reset()
>>> Observation(CGM=126.63092222821054)

env.reset()
>>> Observation(CGM=126.63092222821054)

The environment produces the same scenario Observation(CGM=126.63092222821054) on reset(), even on changing the seed unless I make the environment again. This shouldn't be the case as it keeps on generating the same episode.

Is this a potential bug, or am I missing something here? @jxx123

Are there currently any differences in the simulator between basal and bolus

Hi,
I would like to understand if there is any difference between applying in the action basal or bolus insulin. From my understanding, basal should be long-acting and bolus rapid acting. But, here both of them are added, after conversion from the pump, and then passed to the model and solver. So they do not seem to have different effects, am I right? Can I use any of them in my controller.
Thanks a lot.

Units in the Meal Absoption Model

Hi,

I just looked through the meal absoption model in detail and I noticed the following in the script t1dpatient.py:

When you calculate the variable Dbar in line 130, which is in turn used to calculate the nonlinear gastric emptying rate kgut, you add the variables last_Qsto and last_foodtaken. However, the variable last_Qsto is in mg as all the digestion states, whereas the variable last_foodtaken is in g (line 100).

Shouldn't these variables both be in mg, as Dbar is in mg?

Cheers,
Manuel

Patient interface missing observation, state and t

Patient interface is defined as :

"""Base class for patient"""


class Patient(object):
    def step(self, action):
        """
        Run one time step of the patient dynamiBodySimiFace_setPatisetPatient
        Input
            action: a namedtuple
        ------
        Outputs
            t: current time
            state: updated state
            observation: the observable states
        """
        raise NotImplementedError

    @staticmethod
    def model(t, state, action, params):
        """
        ordinary differential equations
        """
        raise NotImplementedError

    def reset(self):
        """
        Reset to the initial state
        Return observation
        """
        raise NotImplementedError

However, the code uses patient.observation, patient.state and patient.t.

Should those properties be part of the interface or not?
Additionally, it seems like the static method model is not really part of required interface, so could be removed.

Subcutaneous glucose computation: Use plasma glucose concentration (G) instead of plasma glucose mass (Gp)

As per equation A17 in the paper:
Man, Chiara Dalla, et al. "The UVA/PADOVA type 1 diabetes simulator: new features." Journal of diabetes science and technology 8.1 (2014): 26-34.

dGs(t)/dt = - ksc * Gs(t) + ksc * G(t)

Hence, in t1dpatient.py, line195,

wouldn't the computation be:
dxdt[12] = (-params.ksc * x[12] + params.ksc * x[3]/params.Vg) instead of dxdt[12] = (-params.ksc * x[12] + params.ksc * x[3])?

Thanks!

The reward function encourages short episodes

I am trying to train a reinforcement learning algorithm to control basal rate using the given gym environment. The problem with reward function is it encourages as short episode as possible. I have tried different algorithms and hyper parameters variations. But the policy always learns to either output 0 or max basal value. To avoid accumulating any more penalty because of the long episode. Can the reward function be improved somehow?

Dbar Modification

Hello, the BG performance after the modification is very strange. After the modification, I found that the control of glucose seems to be more easily. The influence of CHO seems to be weakened.

Deprecated distutils in Python v3.12 causes "no module..." exception

Environment:

  • macOS Sonoma v14.4.1
  • Apple M1 Pro silicon
  • Python v3.12.3 (homebrew package)
  • simglucose installed with pip from cloned source code

Symptom:
Python 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. from simglucose.simulation.user_interface import simulate Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/mariusz/Projects/simglucose/simglucose/__init__.py", line 1, in <module> from gym.envs.registration import register File "/Users/mariusz/Library/Python/3.12/lib/python/site-packages/gym/__init__.py", line 1, in <module> import distutils.version ModuleNotFoundError: No module named 'distutils'

Explanation: https://docs.python.org/3.11/library/distutils.html

How to set up the input/Controller in this repo to determine the basal rate with only insulin input (without meal)?

I read the code of this repo. Your code is well-written. However, I think I need more clarification about the tutorial to better understand how to use your repo correctly.

In your tutorial, you give an example of BBcontroller that changes the meal "scen=[(7,45), ...]" as input. To my understanding, in BBController the insulin = basal (determined by patient) + bolus (meal). We couldn't change insulin input without meals here, right?

I also try PIDController, which seems to change the insulin intake instead (if I understand correctly). However, the results show that BG drops very quickly (PIDController(P=1, I=1, D=1, target=120)).

My question is: how to set up the input/Controller in your repo to determine the basal rate that makes the BG be a fixed number, let's say 120, if I want to only control the insulin as the input (without meal).

Any hints would be helpful. Thanks in advance.

Set initial BG for simulation

T1DPatient class provides an interface to set the initial states of the patients, but it is not open to user interface.

There is a requirement to allow user set initial BG.

Will need to think about how to open these initial state settings to users gracefully.

Error in risk_index

Hi,
I think there might be an error in risk_index.
In lines 12 and 13
rl = 10 * fBG[fBG < 0]**2 rh = 10 * fBG[fBG > 0]**2
If we pass a list of BG, those lines are removing the elements with fBG(BG)<0 or fBG>0, and afterwards the mean is computed.
But if we look at the paper "Clarke, W., & Kovatchev, B. (2009). Statistical tools to analyze continuous glucose monitor data. Diabetes Technology and Therapeutics, 11(SUPPL.1). https://doi.org/10.1089/dia.2008.0138" the definition LBGI and HBGI for a series of n BG reading is the average of the rl and rh for each BG reading, so we use all n readings.
With the above implementation the rl=0.0 or rh=0.0 samples are removed from the average.
Consider the following example, where we pass 10 samples to risk_index with an horizon of 10

BG | rl | rh
122 | 0.0000 | 0.2277
155 | 0.0000 | 3.5834
144 | 0.0000 | 2.1229
120 | 0.0000 | 0.1441
200 | 0.0000 | 11.6047
350 | 0.0000 | 45.5737
456 | 0.0000 | 69.5785
131 | 0.0000 | 0.8055
70 | 7.7552 | 0.0000
555 | 0.0000 | 90.7512

We get LBGI=7.7552, HBGI=24.93
But, if we take all the 10 samples and compute the average, then we should get LBGI=0.77552, that is, it should divide by 10 not 1 to take all the 10 samples.
What do you think?

How to correctly implement the use of OpenAI Gym - reset() and step() methods are not implemented (NotImplementedError on google Colab)

Hello, first of all I thank you for the immense work and for making the simulator available for free. But I wanted to ask you if there is a version where the methods of the Gym library are already implemented so that you can quickly try some reinforcement learning algorithms. If this were not the case, it would be really useful to me some tips on how to implement the methods step (), reset () etc.

A thousand thanks!

insulin unit and basal dosage

I wonder about insulin unit used in this simulator.

Other thing is basal dosage in basal-bolus controller. The calculation is:
basal = u2ss * BW / 6000
What is the standard used in this controller? Also I can not find out what is u2ss. It is better if there is explanation about variables.

Thank you.

Scenario with no meal in gym env

Hey,

Thank you for this awesome library.

I'm trying to run a gym env without any meal (ideally I would like a controller which can also suggest carb but from what I understood it's not supported).

I did the following:

start_time = datetime.now()
no_meal_scenario = CustomScenario(start_time=start_time, scenario=[])


register(
    id='env-v0',
    entry_point='simglucose.envs:T1DSimEnv',
    kwargs={'patient_name': 'adult#001',
           'custom_scenario': no_meal_scenario}
)


env = gym.make('env-v0')



min_insulin = env.action_space.low
max_insulin = env.action_space.high

observation = env.reset()
for t in range(100):
    env.render(mode='human')
    print(observation)
    action = np.random.uniform(min_insulin, max_insulin)
    
    
    print(action)
    observation, reward, done, info = env.step(action)
    if done:
        print("Episode finished after {} timesteps".format(t + 1))
        break

But I still het carbohydrates inputs sometimes:
image

What is the correct way to do that ?
Thank you !

How can I customize patients?

I have the basal physiological information of the real patients. Can I customize patients? And what parameters may I lack?

Insulin unit error and scenario setting error

Insulin unit error

The upper limit of the action space has the wrong unit. According to your code, the insulin unit input by the simulator is U/min, but in fact the upper limit unit of your pump parameters is U/hour.

    def bolus(self, amount):
        bol = bol * self.U2PMOL  # convert from U/min to pmol/min
        bol = np.round(bol / self._params['inc_bolus']) * self._params['inc_bolus']
        bol = bol / self.U2PMOL  # convert from pmol/min to U/min
        bol = min(bol, self._params['max_bolus'])
        bol = max(bol, self._params['min_bolus'])
        return bol

The basal insulin injection rate is usually 1 U/hour, and the bolus is about 10 U/hour. Obviously pump parameters are U/hour, not U/min, which results in the upper limit of the action space being too large and the agent unable to converge.

<style> </style>
Name min_bolus max_bolus inc_bolus min_basal max_basal inc_basal sample_time
Cozmo 0 75 0.05 0 35 0.05 1
Insulet 0 30 0.05 0 30 0.05 1

A simple scaling works.

    def bolus(self, amount):
        bol = amount / 60  # convert from U/hour to U/min
        bol = bol * self.U2PMOL  # convert from U/min to pmol/min
        bol = np.round(bol / self._params['inc_bolus']) * self._params['inc_bolus']
        bol = bol / self.U2PMOL  # convert from pmol/min to U/min
        bol = min(bol, self._params['max_bolus'])
        bol = max(bol, self._params['min_bolus'])
        return bol

Scenario setting error

I use gym to implement simglucose, but the CHO intake is inconsistent with my scenario settings.(Code was modified to customize the termination condition, just ignore it)

start_time = datetime(2018, 1, 1, 6, 0, 0)
scen = [(7, 60), (12, 59), (16, 74), (21, 39)]
scenario = CustomScenario(start_time=start_time, scenario=scen)


def get_env(patient_name, reward_fun=None, done_fun=None, seed=None, custom_scenario=scenario):
    env_name = 'simglucose-' + patient_name[:-4] + patient_name[-3:] + '-v0'
    register(
        id=env_name,
        entry_point='simglucose.envs:T1DSimEnv',
        kwargs={'patient_name': patient_name,
                'custom_scenario': custom_scenario,
                'reward_fun': reward_fun,
                'done_fun': done_fun,
                'seed': seed}
    )
    env = gym.make(env_name)
    return env

No CHO at 7:00.
image

Controller is not reset during simulation of patients

I discovered that in a batch simulation, there happens no controller reset between patient simulations, even if the controller reset() method is specified. I think this is a pretty serious flaw because in most cases only the first simulated patient will give correct results.
I will prepare a PR for that issue, but wanted to hear your opinion on this issue first.

Report function does not work

Hi, I just installed the package from pip. I was running the tutorial and failed to get the visualizations.

Reproduce:

from simglucose.simulation.env import T1DSimEnv
from simglucose.controller.basal_bolus_ctrller import BBController
from simglucose.sensor.cgm import CGMSensor
from simglucose.actuator.pump import InsulinPump
from simglucose.patient.t1dpatient import T1DPatient
from simglucose.simulation.scenario_gen import RandomScenario
from simglucose.simulation.scenario import CustomScenario
from simglucose.simulation.sim_engine import SimObj, sim, batch_sim
from datetime import timedelta
from datetime import datetime

# specify start_time as the beginning of today
now = datetime.now()
start_time = datetime.combine(now.date(), datetime.min.time())

# --------- Create Random Scenario --------------
# Specify results saving path
path = './results'

# Create a simulation environment
patient = T1DPatient.withName('adolescent#001')
sensor = CGMSensor.withName('Dexcom', seed=1)
pump = InsulinPump.withName('Insulet')
scenario = RandomScenario(start_time=start_time, seed=1)
env = T1DSimEnv(patient, sensor, pump, scenario)

# Create a controller
controller = BBController()

# Put them together to create a simulation object
s1 = SimObj(env, controller, timedelta(days=1), animate=False, path=path)
results1 = sim(s1)
print(results1)

from simglucose.analysis.report import report
import pandas as pd
from pathlib import Path

result_filename = './results/adolescent#001.csv'
df = pd.read_csv(result_filename, index_col=0)
report(df)

I found all errors raised in the plot function is regarding to BG which is defined by BG = df.unstack(level=0).BG. I tried both single day/ >1 days and looks the plot functions always raise error. What shape should BG be?

About CR and CF values in Quest.csv

Hi,

When I compute CR and CF values manually, they do not match with the values given in Quest.csv. I computed them as follows. I know body weight (BW in vpatient_params.csv) and total daily insulin (TDI in Quest.csv) so CR=5.7*BW/TDI and CF=1960/TDI. How did you calculate CR and CF values in Quest.csv?

Thanks.

pip 0.2.8 broken

The 0.2.8 version does not install for me
0.2.7 still works.

Collecting simglucose==0.2.8
  Using cached simglucose-0.2.8.tar.gz (600 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-htmoxn_c/simglucose_8ebacb09a20d4579b013c17371400350/setup.py", line 11, in <module>
          reqs = parse_requirements("requirements.txt")
        File "/tmp/pip-install-htmoxn_c/simglucose_8ebacb09a20d4579b013c17371400350/setup.py", line 6, in parse_requirements
          with open(filename) as f:
      FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.

Clarity on calculation of parameters apha and beta

The empting rate, kempt(qsto) of the liquid compartment of the stomach in this code is described below which I understand is kqut in this case.

if Dbar > 0:
    aa = 5 / 2 / (1 - params.b) / Dbar
    cc = 5 / 2 / params.d / Dbar
    kgut = params.kmin + (params.kmax - params.kmin) / 2 * (
        np.tanh(aa * (qsto - params.b * Dbar)) -
        np.tanh(cc * (qsto - params.d * Dbar)) + 2)
else:
    kgut = params.kmax

In this paper, A System Model of the Oral Glucose Absorption: Validation on Gold Standard Data shows that the parameters alpha (aa) and beta (cc) are as follows:
image
Translating it to python would yield the code below

aa = 5 / ( 2 * Dbar * (1 - params.b))
cc = 5 / (2 * Dbar * params.d)

I understand both yield the same result. For purposes of consistency and readability of the code with the equations in the @paper, do you think we can adopt the later option for this case?

@jxx123

Import Error

I keep getting following error, when working on apply_customized_controller.py:

ImportError: cannot import name 'simulate' from partially initialized module 'simglucose.simulation.user_interface' (most likely due to a circular import)

How do I fix this?

Risk index calculation error in report generation

I also met a similar issue when generating report, seems the numpy calculations return an object which is not compatible with DataFrame object in pandas library:

Traceback (most recent call last): File "/home/alan/simglucose/sim_origin.py", line 6, in <module> simulate(start_time=datetime.combine(datetime.now().date(), datetime.min.time()),controller=BBController(),cgm_seed=123412,animate=False,parallel=True) File "/home/alan/simglucose/simglucose/simulation/user_interface.py", line 383, in simulate results, ri_per_hour, zone_stats, figs, axes = report(df, save_path) File "/home/alan/simglucose/simglucose/analysis/report.py", line 251, in report ri_per_hour, ri_mean, fig_ri, ax5 = risk_index_trace(BG, visualize=False) File "/home/alan/simglucose/simglucose/analysis/report.py", line 102, in risk_index_trace fBG_df = pd.concat(fBG, axis=1).transpose() File "/home/alan/.local/lib/python3.10/site-packages/pandas/core/reshape/concat.py", line 372, in concat op = _Concatenator( File "/home/alan/.local/lib/python3.10/site-packages/pandas/core/reshape/concat.py", line 462, in __init__ raise TypeError(msg) TypeError: cannot concatenate object of type '<class 'numpy.float64'>'; only Series and DataFrame objs are valid

My dependencies are:

pandas: 2.0.2
numpy: 1.24.3
Python: 3.10.6

Originally posted by @yihuicai in #42 (comment)

How to start simulator

Hello,
Per the instructions I installed simglucose correctly I believe. Now I'm trying to start it.
So I copy and paste this in to my CMD line:
from simglucose.simulation.user_interface import simulate
simulate()
And I get an error.
Can you please help?
Thanks!
Mark

Input meal size different from recorded meal size

Hi! Thanks for this package, super helpful. I was wondering why the inputted meal size and the actual recorded value in the output files differ. For example in the advanced usage example, the input size of the first meal is 45, but in the out put file, it registers as 15.

From the code, it seems there is a division between meal size and sample time (= 3).

Could you give more details on this? Thanks!

Risk Index probably incorrect

UPDATE: See my update in a post below - this also has a problem.

This here is simply adding two means:

RI = LBGI + HBGI

However, adding up two means (or taking the mean) of sub-sequences that are different in length does not equal the mean of the whole sequence:
Screenshot_20230824_120745

Instead we have to weigh the each individual mean by the length of sequence it represents. Like this:

weight_rl = len(rl) / horizon
weight_rh = len(rh) / horizon
RI = weight_rl*LBGI + weight_rh*HBGI

While risk index is not explicitly defined in any paper I can find (neither here nor here) - only the low and high risk indicies are defined:
Screenshot_20230824_120215

it is not unreasonable to assume that it should be defined such that risk function applied to the whole trajectory would result in the same mean as the combination of low and high risk indicies, e.g.:

Screenshot_20230824_120424

The nice thing about weighing the LBGI and HBGI is that the final risk then is still bounded between 0 and 100.

How did you obtain the parameters in vpatient_params.csv?

Hi,

Where did you get the in-silico patient parameters in vpatient_params.csv? I have checked the internet and UVa-Padova S2008, S2013, S2018 papers but could not see the sources of their synthetic patient parameters. Can you please share your source or explain how you generate the parameters?

Thanks.

Sensor sample_time affects reported CHO and Insulin

First of all, thanks a lot for the implementation of this simulation!

While inspecting and playing around with the implementation I have found that the sensors sample_time affects the reported CHO and Insulin.

Using the second scenario defined in advanced_scenario.py and comparing the Dexcom (sample_size = 3.0) and GuardianRT (sample_size = 5.0), I come to the following with the Dexcom sensor:

        mini_step: BG:  49.677, measured CGM:   48.167, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.004644444444444445
        mini_step: BG:  99.354, measured CGM:   96.334, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.00928888888888889
        mini_step: BG:  149.032, measured CGM:  144.882, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.013933333333333336
BG:     149.032, measured CGM:  144.882, carbo (CHO):   0.000, insulin: 0.013933333333333336
        mini_step: BG:  49.677, measured CGM:   48.548, carbo (CHO):    15.000 (tmp_CHO:45.000), insulin:       0.004644444444444445
        mini_step: BG:  99.354, measured CGM:   97.096, carbo (CHO):    15.000 (tmp_CHO:0.000), insulin:        0.00928888888888889
        mini_step: BG:  149.032, measured CGM:  146.033, carbo (CHO):   15.000 (tmp_CHO:0.000), insulin:        0.013933333333333336
BG:     149.032, measured CGM:  146.033, carbo (CHO):   15.000, insulin:        0.013933333333333336
        mini_step: BG:  49.677, measured CGM:   48.937, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.42131111111111114
        mini_step: BG:  99.355, measured CGM:   97.874, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.8426222222222223
        mini_step: BG:  149.033, measured CGM:  147.163, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 1.2639333333333334
BG:     149.033, measured CGM:  147.163, carbo (CHO):   0.000, insulin: 1.2639333333333334

Note, that these are three steps around 7am, when according to the scenario 45 units of CHO are to be consumed.

The same simulation using GuardianRT:

        mini_step: BG:  29.806, measured CGM:   29.051, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.002786666666666667
        mini_step: BG:  59.613, measured CGM:   58.101, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.005573333333333334
        mini_step: BG:  89.419, measured CGM:   87.152, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.008360000000000001
        mini_step: BG:  119.225, measured CGM:  116.202, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.011146666666666668
        mini_step: BG:  149.032, measured CGM:  145.639, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.013933333333333334
BG:     149.032, measured CGM:  145.639, carbo (CHO):   0.000, insulin: 0.013933333333333334
        mini_step: BG:  29.806, measured CGM:   29.436, carbo (CHO):    9.000 (tmp_CHO:45.000), insulin:        0.002786666666666667
        mini_step: BG:  59.613, measured CGM:   58.872, carbo (CHO):    9.000 (tmp_CHO:0.000), insulin: 0.005573333333333334
        mini_step: BG:  89.419, measured CGM:   88.309, carbo (CHO):    9.000 (tmp_CHO:0.000), insulin: 0.008360000000000001
        mini_step: BG:  119.225, measured CGM:  117.745, carbo (CHO):   9.000 (tmp_CHO:0.000), insulin: 0.011146666666666668
        mini_step: BG:  149.032, measured CGM:  147.478, carbo (CHO):   9.000 (tmp_CHO:0.000), insulin: 0.013933333333333334
BG:     149.032, measured CGM:  147.478, carbo (CHO):   9.000, insulin: 0.013933333333333334
        mini_step: BG:  29.807, measured CGM:   29.733, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.15278666666666668
        mini_step: BG:  59.614, measured CGM:   59.467, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.30557333333333336
        mini_step: BG:  89.422, measured CGM:   89.200, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.45836000000000005
        mini_step: BG:  119.231, measured CGM:  118.933, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.6111466666666667
        mini_step: BG:  149.043, measured CGM:  148.751, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.7639333333333334
BG:     149.043, measured CGM:  148.751, carbo (CHO):   0.000, insulin: 0.7639333333333334

The comparison between these two sensors shows the difference in reported CHO and insulin:
Dexcom_GuardianRT_comparison
It seems that this is only a cosmetic error (I am guessing this by comparing the trajectories of BG). I am happy to provide a PR...

The logs from above have been created with with:

diff --git i/examples/advanced_tutorial.py w/examples/advanced_tutorial.py
index 1249c88..f194ad9 100644
--- i/examples/advanced_tutorial.py
+++ w/examples/advanced_tutorial.py
@@ -29,8 +29,8 @@ controller = BBController()
 
 # Put them together to create a simulation object
 s1 = SimObj(env, controller, timedelta(days=1), animate=False, path=path)
-results1 = sim(s1)
-print(results1)
+#results1 = sim(s1)
+#print(results1)
 
 # --------- Create Custom Scenario --------------
 # Create a simulation environment
@@ -46,7 +46,7 @@ env = T1DSimEnv(patient, sensor, pump, scenario)
 controller = BBController()
 
 # Put them together to create a simulation object
-s2 = SimObj(env, controller, timedelta(days=1), animate=False, path=path)
+s2 = SimObj(env, controller, timedelta(days=1), animate=True, path=path)
 results2 = sim(s2)
 print(results2)
 
diff --git i/simglucose/simulation/env.py w/simglucose/simulation/env.py
index 45a43cb..c96a6b1 100644
--- i/simglucose/simulation/env.py
+++ w/simglucose/simulation/env.py
@@ -79,6 +79,8 @@ class T1DSimEnv(object):
             insulin += tmp_insulin / self.sample_time
             BG += tmp_BG / self.sample_time
             CGM += tmp_CGM / self.sample_time
+            print(f"\tmini_step: BG:\t{BG:4.3f}, measured CGM:\t{CGM:3.3f}, carbo (CHO):\t{CHO:3.3f} (tmp_CHO:{tmp_CHO:3.3f}), insulin:\t{insulin}")
+        print(f"BG:\t{BG:4.3f}, measured CGM:\t{CGM:3.3f}, carbo (CHO):\t{CHO:3.3f}, insulin:\t{insulin}")
 
         # Compute risk index
         horizon = 1

Does this simulator has the property of time-delay?

I'm interested in whether this simulator is time-delayed or not? In the provided gym environment, if the patient was injected with certain amount of insulin, would this affect the patient's subcutaneous glucose (or obs) in the following few env steps, other than just next step?

Scenario Simulations

Hi,

First of all, thank you very much for your framework, it's quite comprehensive and useful !

Is there any possibility to generate scenarios/simulations where we can enforce not changing the insulin input, while inputting the carbohydrate intake. In other words, scenarios where patient eat, but not taking the required insulin. Also the vice-versa, where the patient's carbohydrate intake is 0 (not eating anything), while the insulin intake is as normal.

If there's possibility to simulate such scenarios, can you kindly give some pointers or guidance ?

Regards,
Kasun

Patient Parameter Documentation

@jxx123 Are there any future considerations for documenting the patient parameters in the patient_param.csv file.

I came across a paper that has the meaning and units of the different parameters used in the patient_param.csv, refer to Physical Activity into the Meal Glucose–Insulin Model of Type 1 Diabetes: In Silico Studies which to my understanding are the same as used in the UVA/PADOVA simulator.

I understand there is another issue #27 that is open.

Do you think we can make arrangements to add that? - possibly a markdown file in the params folder. Would be glad to do that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.