Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insulin unit error and scenario setting error #71

Open
TomatoZ2 opened this issue Oct 25, 2023 · 3 comments
Open

Insulin unit error and scenario setting error #71

TomatoZ2 opened this issue Oct 25, 2023 · 3 comments

Comments

@TomatoZ2
Copy link

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

@jxx123
Copy link
Owner

jxx123 commented Oct 27, 2023

Thanks for reporting this. I will start investigating this soon.

@TomatoZ2
Copy link
Author

TomatoZ2 commented Nov 3, 2023

I set start time at 0:00, and the rendering is OK. It seems that start time of the scenario setting does not take effect during simulation, but it has an impact on the coordinate axes. Maybe you should check the start time in CustomScenario.

def get_env(patient_name):
    start_time = datetime(2018, 1, 1, 0, 0, 0)
    scen = [(7, 60), (12, 59), (16, 74)]
    scenario = CustomScenario(start_time=start_time, scenario=scen)
    env_name = 'simglucose-' + patient_name[:-4] + patient_name[-3:] + '-v0'
    print(env_name)
    register(
        id=env_name,
        entry_point='simglucose.envs:T1DSimEnv',
        kwargs={'patient_name': patient_name,
                'cost_fun': cost_fun,
                'custom_scenario': scenario}
    )
    env = safety_gymnasium.make(env_name)
    return env

The figure below shows the correct scenario.
image

@jxx123
Copy link
Owner

jxx123 commented Mar 16, 2024

Thank you! Do you mind submitting a Pull Request for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants