def __init__(self, patient_name=None, reward_fun=None):
        '''
        patient_name must be 'adolescent#001' to 'adolescent#010',
        or 'adult#001' to 'adult#010', or 'child#001' to 'child#010'
        '''
        seeds = self._seed()
        # have to hard code the patient_name, gym has some interesting
        # error when choosing the patient
        if patient_name is None:
            patient_name = 'adolescent#001'
        patient = T1DPatient.withName(patient_name)
        sensor = CGMSensor.withName('Dexcom', seed=seeds[1])
        hour = self.np_random.randint(low=0.0, high=24.0)
        start_time = datetime(2018, 1, 1, hour, 0, 0)
        # scenario = RandomScenario(start_time=start_time, seed=seeds[2])

        # Added a custom scenario with no meals
        # scen = [(7, 45), (12, 70), (16, 15), (18, 80), (23, 10)]
        scen = [(0, 0)]
        scenario = CustomScenario(start_time=start_time, scenario=scen)
        pump = InsulinPump.withName('Insulet')
        self.env = _T1DSimEnv(patient, sensor, pump, scenario)
        self.reward_fun = reward_fun

        # Added by Jonas -- state space is now 10 * sample_time = 30 minutes long
        self.state_space_length = 10
        self.insulin_history = np.zeros(4)
 def __init__(self,
              patient_name=None,
              custom_scenario=None,
              reward_fun=None,
              animate=False,
              controller_name='',
              results_path=None):
     '''
     patient_name must be 'adolescent#001' to 'adolescent#010',
     or 'adult#001' to 'adult#010', or 'child#001' to 'child#010'
     '''
     seeds = self._seed()
     # have to hard code the patient_name, gym has some interesting
     # error when choosing the patient
     if patient_name is None:
         patient_name = 'adolescent#001'
     patient = T1DPatient.withName(patient_name)
     sensor = CGMSensor.withName('Dexcom', seed=seeds[1])
     hour = self.np_random.randint(low=0.0, high=24.0)
     start_time = datetime(2018, 1, 1, hour, 0, 0)
     if custom_scenario is None:
         scenario = RandomScenario(start_time=start_time, seed=seeds[2])
     scenario = custom_scenario
     pump = InsulinPump.withName('Insulet')
     self.env = _T1DSimEnv(patient,
                           sensor,
                           pump,
                           scenario,
                           controller_name=controller_name,
                           results_path=results_path)
     self.reward_fun = reward_fun
     self.animate = animate
Example #3
0
 def _create_env_from_random_state(self):
     # Derive a random seed. This gets passed as a uint, but gets
     # checked as an int elsewhere, so we need to keep it below
     # 2**31.
     seed2 = seeding.hash_seed(self.np_random.randint(0, 1000)) % 2**31
     seed3 = seeding.hash_seed(seed2 + 1) % 2**31
     seed4 = seeding.hash_seed(seed3 + 1) % 2**31
     hour = self.np_random.randint(low=0.0, high=24.0)
     if self.saved_state is not None:
        seed2=self.saved_state[0]
        seed3=self.saved_state[1]
        seed4=self.saved_state[2]
        hour=self.saved_state[3]
        print('Using state', seed2, seed3, seed4, hour)
     start_time = datetime(2021, 1, 1, hour, 0, 0)
     patient = T1DPatient.withName(self.patient_name, random_init_bg=True, seed=seed4)
     sensor = CGMSensor.withName(self.SENSOR_HARDWARE, seed=seed2)
     if self.harrison_benedict:
         vpatient_params = pd.read_csv(PATIENT_PARA_FILE)
         self.kind = self.patient_name.split('#')[0]
         self.bw = vpatient_params.query('Name=="{}"'.format(self.patient_name))['BW'].item()
         scenario=RandomBalancedScenario(start_time=start_time, seed=seed3, harrison_benedict=self.harrison_benedict, bw=self.bw, kind=self.kind)
     else:
         scenario = RandomScenario(start_time=start_time, seed=seed3)
     pump = InsulinPump.withName(self.INSULIN_PUMP_HARDWARE)
     env = _T1DSimEnv(patient, sensor, pump, scenario,noise=self.noise)
     return env, seed2, seed3, seed4, hour
Example #4
0
    def _create_env_from_random_state(self):
        # Derive a random seed. This gets passed as a uint, but gets
        # checked as an int elsewhere, so we need to keep it below
        # 2**31.
        seed2 = seeding.hash_seed(self.np_random.randint(0, 1000)) % 2**31
        seed3 = seeding.hash_seed(seed2 + 1) % 2**31
        seed4 = seeding.hash_seed(seed3 + 1) % 2**31

        hour = self.np_random.randint(low=0.0, high=24.0)
        start_time = datetime(2018, 1, 1, hour, 0, 0)
        patient = T1DPatient.withName(self.patient_name, random_init_bg=True, seed=seed4)
        sensor = CGMSensor.withName(self.SENSOR_HARDWARE, seed=seed2)
        scenario = RandomScenario(start_time=start_time, seed=seed3)
        pump = InsulinPump.withName(self.INSULIN_PUMP_HARDWARE)
        env = _T1DSimEnv(patient, sensor, pump, scenario)
        return env, seed2, seed3, seed4
Example #5
0
    def seed(self, seed=None):
        print('_seed called')
        self.np_random, seed1 = seeding.np_random(seed=seed)
        # Derive a random seed. This gets passed as a uint, but gets
        # checked as an int elsewhere, so we need to keep it below
        # 2**31.
        seed2 = seeding.hash_seed(seed1 + 1) % 2**31
        seed3 = seeding.hash_seed(seed2 + 1) % 2**31

        hour = self.np_random.randint(low=0.0, high=24.0)
        start_time = datetime(2021, 1, 1, hour, 0, 0)
        patient = T1DPatient.withName(self.patient_name)
        sensor = CGMSensor.withName(self.SENSOR_HARDWARE, seed=seed2)
        scenario = RandomScenario(start_time=start_time, seed=seed3)
        pump = InsulinPump.withName(self.INSULIN_PUMP_HARDWARE)
        self.env = _T1DSimEnv(patient, sensor, pump, scenario)
        return [seed1, seed2, seed3]
 def __init__(self, patient_name=None, reward_fun=None):
     '''
     patient_name must be 'adolescent#001' to 'adolescent#010',
     or 'adult#001' to 'adult#010', or 'child#001' to 'child#010'
     '''
     seeds = [0, 0, 0, 0, 0] #self._seed()
     # have to hard code the patient_name, gym has some interesting
     # error when choosing the patient
     if patient_name is None:
         patient_name = 'adolescent#001'
     print(patient_name)
     patient = T1DPatient.withName(patient_name)
     sensor = CGMSensor.withName('Dexcom', seed=seeds[1])
     # sensor = CGMSensor.withName('Navigator', seed=seeds[1])
     # sensor = CGMSensor.withName('GuardianRT', seed=seeds[1])
     hour = 0 #self.np_random.randint(low=0.0, high=24.0)
     start_time = datetime(2018, 1, 1, hour, 0, 0)
     scenario = RandomScenario(start_time=start_time, seed=seeds[2])
     pump = InsulinPump.withName('Insulet')
     self.env = _T1DSimEnv(patient, sensor, pump, scenario)
     self.reward_fun = reward_fun
    def __init__(self,
                 patient_name=None,
                 reward_fun=None,
                 scen=None,
                 start_time=None,
                 sensor_name=None,
                 pump_name=None):  #, scenario_tup=None, startTime=None
        '''
        patient_name must be 'adolescent#001' to 'adolescent#010',
        or 'adult#001' to 'adult#010', or 'child#001' to 'child#010'
        '''
        seeds = self._seed()
        # have to hard code the patient_name, gym has some interesting
        # error when choosing the patient
        if patient_name is None:
            patient_name = 'adolescent#001'

        if sensor_name is None:
            sensor_name = 'Dexcom'

        if pump_name is None:
            pump_name = 'Insulet'

        print(patient_name)
        print(sensor_name)
        print(pump_name)
        print(scen)

        patient = T1DPatient.withName(patient_name)
        sensor = CGMSensor.withName(sensor_name, seed=seeds[1])
        #hour = self.np_random.randint(low=0.0, high=24.0)
        #start_time = datetime(2018, 1, 1, hour, 0, 0)

        scenario = CustomScenario(
            start_time=start_time, scenario=scen
        )  #RandomScenario(start_time=start_time, seed=seeds[2])
        pump = InsulinPump.withName(pump_name)
        self.env = _T1DSimEnv(patient, sensor, pump, scenario)
        self.reward_fun = reward_fun
    def __init__(self, patient_name=None, reward_fun=None, Initial_Bg=0):
        '''
        patient_name must be 'adolescent#001' to 'adolescent#010',
        or 'adult#001' to 'adult#010', or 'child#001' to 'child#010'
        '''
        seeds = self._seed()
        # have to hard code the patient_name, gym has some interesting
        # error when choosing the patient
        if patient_name is None:
            patient_name = 'adolescent#001'
        patient = T1DPatient.withName(patient_name, Initial_Bg)
        sensor = CGMSensor.withName('GuardianRT', seed=seeds[1])  #Dexcom
        hour = 20  #self.np_random.randint(low=0.0, high=24.0)
        start_time = datetime(2018, 1, 1, hour, 0, 0)
        # scenario = RandomScenario(start_time=start_time, seed=seeds[2])
        # custom scenario is a list of tuples (time, meal_size)
        # scen = [(0,float(Initial_Bg)),(13, 45), (16, 10), (18, 35), (22, 10)]#, (23, 10)]
        scen = [(13, 45), (16, 10), (18, 35), (22, 10)]  #, (23, 10)]
        scenario = CustomScenario(start_time=start_time, scenario=scen)

        pump = InsulinPump.withName('Insulet')
        self.env = _T1DSimEnv(patient, sensor, pump, scenario)
        self.reward_fun = reward_fun