在openai健身房或rllab中作为强化学习环境的1型糖尿病模拟器(uva/padova模拟器的python实现)

simglucose的Python项目详细描述


葡萄糖

用python实现的1型糖尿病模拟器,用于强化学习目的

这个模拟器是fda批准的一个python实现,仅用于研究目的。该模拟器包括30名虚拟病人、10名青少年、10名成人、10名儿童。

  • 注:simglucose只支持python3。
<表><广告>动画CVGA图 bg跟踪图 风险指数统计 < /广告><正文>动画截图bg trace plot风险指数统计

主要功能

安装

强烈建议使用pip到installsimglucose,按照以下链接安装PIP。

自动安装:

pip install simglucose

手动安装:

git clone https://github.com/jxx123/simglucose.git
cd simglucose

如果安装了pip,则

pip install -e .

如果您没有pip,则

python setup.py install

如果安装了rllab(可选),包将利用rllab中的一些功能。

注意:自动安装版本和手动安装版本之间可能有一些细微的差异。使用git clone和手动安装获取最新版本。

快速启动

使用simglucose作为模拟器并测试控制器

运行模拟器用户界面

fromsimglucose.simulation.user_interfaceimportsimulatesimulate()

您可以自由实现自己的控制器,并在模拟器中进行测试。例如,

fromsimglucose.simulation.user_interfaceimportsimulatefromsimglucose.controller.baseimportController,ActionclassMyController(Controller):def__init__(self,init_state):self.init_state=init_stateself.state=init_statedefpolicy(self,observation,reward,done,**info):'''        Every controller must have this implementation!        ----        Inputs:        observation - a namedtuple defined in simglucose.simulation.env. For                      now, it only has one entry: blood glucose level measured                      by CGM sensor.        reward      - current reward returned by environment        done        - True, game over. False, game continues        info        - additional information as key word arguments,                      simglucose.simulation.env.T1DSimEnv returns patient_name                      and sample_time        ----        Output:        action - a namedtuple defined at the beginning of this file. The                 controller action contains two entries: basal, bolus        '''self.state=observationaction=Action(basal=0,bolus=0)returnactiondefreset(self):'''        Reset the controller state to inital state, must be implemented        '''self.state=self.init_statectrller=MyController(0)simulate(controller=ctrller)

这两个示例也可以在examples\folder中找到。

实际上,您可以通过模拟指定更多的模拟参数

simulate(sim_time=my_sim_time,scenario=my_scenario,controller=my_controller,start_time=my_start_time,save_path=my_save_path,animate=False,parallel=True)

OpenAI健身房使用

  • 使用默认奖励
importgym# Register gym environment. By specifying kwargs,# you are able to choose which patient to simulate.# patient_name must be 'adolescent#001' to 'adolescent#010',# or 'adult#001' to 'adult#010', or 'child#001' to 'child#010'fromgym.envs.registrationimportregisterregister(id='simglucose-adolescent2-v0',entry_point='simglucose.envs:T1DSimEnv',kwargs={'patient_name':'adolescent#002'})env=gym.make('simglucose-adolescent2-v0')observation=env.reset()fortinrange(100):env.render(mode='human')print(observation)# Action in the gym environment is a scalar# representing the basal insulin, which differs from# the regular controller action outside the gym# environment (a tuple (basal, bolus)).# In the perfect situation, the agent should be able# to control the glucose only through basal instead# of asking patient to take bolusaction=env.action_space.sample()observation,reward,done,info=env.step(action)ifdone:print("Episode finished after {} timesteps".format(t+1))break
  • 定制奖励功能
importgymfromgym.envs.registrationimportregisterdefcustom_reward(BG_last_hour):ifBG_last_hour[-1]>180:return-1elifBG_last_hour[-1]<70:return-2else:return1register(id='simglucose-adolescent2-v0',entry_point='simglucose.envs:T1DSimEnv',kwargs={'patient_name':'adolescent#002','reward_fun':custom_reward})env=gym.make('simglucose-adolescent2-v0')reward=1done=Falseobservation=env.reset()fortinrange(200):env.render(mode='human')action=env.action_space.sample()observation,reward,done,info=env.step(action)print(observation)print("Reward = {}".format(reward))ifdone:print("Episode finished after {} timesteps".format(t+1))break

RLLab用法

pip install simglucose
0

高级用法

您可以创建仿真对象,并运行批处理仿真。例如,

pip install simglucose
1

脱机运行分析

pip install simglucose
2

发行说明

2018年10月9日

  • controllerpolicy方法通过info['patient\u state']访问所有当前患者状态

2018年2月26日

  • 支持定制化的奖励功能。

2018年10月1日

  • 添加了在创建健身房环境时选择患者的解决方法:通过传递患者姓名的Kwargs来注册健身房环境。

2018年7月1日

  • 添加了OpenAI健身房支持,使用gym.make('simglucose-v0')创建环境。
  • 注意事项:健身房不提供患者姓名选择。请立即进行。患者姓名必须在simglucose.envs.t1dsimenv的构造函数中硬编码

报告问题

通过创建问题来解决任何错误、增强功能甚至讨论。

如何贡献

以下说明最初来自sklearn的贡献说明

促进simglucose的首选工作流是 主存储库on github,在分支上克隆和开发。步骤:

  1. 从项目存储库转移 点击页面右上角的"fork"按钮。这创造 github用户帐户下的代码副本。有关的详细信息 如何分叉存储库请参见本指南。

  2. 将simglucose repo的fork从github帐户克隆到本地磁盘:

    pip install simglucose
    
    3
  3. 创建功能分支以保存您的开发更改:

    pip install simglucose
    
    4

    始终使用功能分支。最好不要在master分支上工作!

  4. 在功能分支上开发功能。使用git add添加更改的文件,然后使用git commit文件:

    pip install simglucose
    
    5

    要在git中记录更改,请将更改推送到github帐户:

    pip install simglucose
    
    6
  5. 遵循这些说明 从分叉创建拉取请求。这将向提交者发送电子邮件。

(如果上面的任何一个对你来说都是魔法的话你,请查一下 git文档在Web上,或向朋友或其他贡献者寻求帮助。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android Action_Edit Intent无法像以前一样调用App Gallery来编辑图片   确保JRE兼容性的java适当程序(32或64位)   java JSONArray。for循环中的add(JSONObject)正在替换for循环中的旧值,数组由循环中的最后一个值组成   java需要帮助创建一个返回数组的方法,该数组的元素是另一个数组的平方   使用SmbFile w/groovy XmlSluper()创建xml。解析()Java   检查大小后的java ArrayIndexOutOfBoundsException   乘法表中的第k个最小元素   java 401 on请求,其中指定了'permitAll()'   java如何附加ORC文件   java hibernate类模型   java IDEA没有看到由自定义注释处理器生成的方法   Servlet中未声明java SerialVersionId   java linkedlist到达列表末尾时   java如何正确对齐EditText光标?   java 6编译器1.6上的eclipse重写方法错误   java如何在基于Jersey的RESTful Web服务中读取post数据   java如何在活动中正确使用接口?   Java的JIT编译器的工作速度有多快?