未提供项目说明

skinner的Python项目详细描述


斯金纳

基于Python的强化学习新框架Skinner

它是为初学者的RL。在

目前尚处于开发阶段,api设计不完善,但运行稳定。对于网格世界来说,它已经足够成熟了。在

享受skinner!在

要求

  • 健身房
  • numpy公司

下载

通过pip命令pip install skinner从github或pypi下载。在

设计

我们考虑observer设计模式。env和其中的代理一般都是相互观察的。agent观察env如何行为并获得奖励,env观察agent和其他物体呈现给观看者并记录信息。在

特色

太简单了

使用

快速启动

在示例中运行demo.py。还有其他例子:demo1.py, demo2.py。在

此外,还可以在^{}中观看动画

示例

作者列举了3个例子。建议用户查看代码。在objects.py中定义对象,在simple_grid.py中定义新的环境,然后在脚本中编写演示编程(请参见demo.py)。在

定义环境

如果您只想构建一个简单的env,那么下面是一个选项,一个网格世界。在

#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Demo of RLAn env with some traps and a gold."""fromskinnerimport*fromgym.envs.classic_controlimportrenderingfromobjectsimport*classMyGridWorld(GridMaze,SingleAgentEnv):"""Grid world    A robot playing the grid world, tries to find the golden (yellow circle), meanwhile    it has to avoid of the traps(black circles)    Extends:        GridMaze: grid world with walls        SingleAgentEnv: there is only one agent    """# configure the env# get the positions of the objects (done automatically)CHARGER=...TRAPS=...DEATHTRAPS=...GOLD=...def__init__(self,*args,**kwargs):super(MyGridWorld,self).__init__(*args,**kwargs)self.add_walls(conf['walls'])self.add_objects((*traps,*deathtraps,charger,gold))# Define the condition when the demo of rl will stop.defis_terminal(self):returnself.agent.positioninself.DEATHTRAPSorself.agent.position==self.GOLDorself.agent.power<=0defis_successful(self):returnself.agent.position==self.GOLD# Following methods are not necessary, that only for recording the process of rldefpost_process(self):ifself.is_successful():self.history['n_steps'].append(self.agent.n_steps)else:self.history['n_steps'].append(self.max_steps)self.history['reward'].append(self.agent.total_reward)self.agent.post_process()defpre_process(self):self.history['n_steps']=[]self.history['reward']=[]defend_process(self):importpandasaspddata=pd.DataFrame(self.history)data.to_csv('history.csv')

配置env及其对象

请参见conf.yaml以获取示例。对象类将在objects.py中定义。在

^{pr2}$

定义对象

  1. 对象的形状(默认为圆形)
  2. 绘图的方法(如果形状很简单,不要重写它)
class_Object(Object):props=('name','position','color','size')default_position=(0,0)# set default value to help you reducing the codes when creating an objectclassGold(_Object):defdraw(self,viewer):'''this method is the most direct to determine how to plot the object        You should define the shape and coordinate        '''...classCharger(_Object):defcreate_shape(self):'''redefine the shape, here we define a squre with edges length of 40.        The default shape is a circle        '''a=20self.shape=rendering.make_polygon([(-a,-a),(a,-a),(a,a),(-a,a)])self.shape.set_color(*self.color)

定义代理

  1. 转换函数$f(s,a)$
  2. 奖励函数$r(s,a,s')$
fromskinnerimport*classMyRobot(StandardAgent):actions=Discrete(4)# define the shapesize=30color=(0.8,0.6,0.4)def_reset(self):# define the initial state...def_next_state(self,state,action):"""transition function: s, a -> s'        """...def_get_reward(self,state0,action,state1):"""reward function: s,a,s'->r        """...# define parametersagent=MyRobot(alpha=0.3,gamma=0.9)

示例

代码

请参阅examples中的脚本

结果

纪念

为了纪念伟大的美国心理学家B. F. Skinner(1904-1990)。RL的灵感主要来自他的行为主义。行为主义心理学史上有许多贡献者,他可能是其中最著名的一位。在

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

推荐PyPI第三方库


热门话题
ArrayList中实体对象上的JAVA泛型   带Redis的爪哇芹菜vs单用Redis   java在设备面向横向时隐藏标题栏/通知栏   java JXTreeTable:如何使用ComponentProvider为一列设置渲染器   java创建异常的成本与记录异常的成本相比   java在方法参数中使用setter传递新对象   java在一个类中的方法与另一个类中的方法交互时遇到问题   java如何迭代2个大小相等的ArrayList   Java getDesktop()。open在Windows中工作,但在Mac中不工作   从tomcat切换到jetty后的java“无法启动嵌入式容器”,Spring引导   java如何使用void方法   java如何在解组时在JAXB的ValidationEventHandler中获取节点值?   如何使用Akka Java API创建不响应的TCP接收器   JavaScriptjQuery在java中将记录上传到数据库时的进度条   如何在重新绘制时在java小程序中显示上一个图像