PyBrain库的example之NFQ流程图分析

如下是测试程序。主要分析doEpisode和learn两个函数。

#!/usr/bin/env python
__author__ = 'Thomas Rueckstiess, ruecksti@in.tum.de' from pybrain.rl.environments.cartpole import CartPoleEnvironment, DiscreteBalanceTask, CartPoleRenderer
from pybrain.rl.agents import LearningAgent
from pybrain.rl.experiments import EpisodicExperiment
from pybrain.rl.learners.valuebased import NFQ, ActionValueNetwork
#,ActionValueLSTMNetwork
from pybrain.rl.explorers import BoltzmannExplorer from numpy import array, arange, meshgrid, pi, zeros, mean
from matplotlib import pyplot as plt # switch this to True if you want to see the cart balancing the pole (slower)
render = False #True # plt.ion() env = CartPoleEnvironment()
if render:
renderer = CartPoleRenderer()
env.setRenderer(renderer)
renderer.start() # balancetask. py inside only used 2 sensors, so here can't use(4,3), just use (2,3)
# there is a debug in vesion 0.30, now, new version 0.33 had correct it!!
module = ActionValueNetwork(4,3) #(4,3) # 0.33 had correct it
#module = ActionValueLSTMNetwork(2,3) task = DiscreteBalanceTask(env, 100)
learner = NFQ()
learner.explorer.epsilon = 0.4 agent = LearningAgent(module, learner)
testagent = LearningAgent(module, None)
experiment = EpisodicExperiment(task, agent) def plotPerformance(values, fig):
plt.figure(fig.number)
plt.clf()
plt.plot(values, 'o-')
plt.gcf().canvas.draw() performance = [] if not render:
pf_fig = plt.figure() #while (True):
for _ in xrange(60): #60
# one learning step after one episode of world-interaction!!!
experiment.doEpisodes(1)
agent.learn(2) # 5 # test performance (these real-world experiences are not used for training)
if render:
env.delay = True
experiment.agent = testagent
#r = mean([sum(x) for x in experiment.doEpisodes(5)])
env.delay = False
testagent.reset()
experiment.agent = agent #performance.append(r)
print "update step", len(performance) #print "reward avg", r
print "explorer epsilon", learner.explorer.epsilon
print "num episodes", agent.history.getNumSequences()
print "update step", len(performance) if not render:
plotPerformance(performance, pf_fig) str = raw_input("please input sth to end!")
print "you put :",str

experiment.doEpisodes(1)

agent.learn(2)

图2的注释2部分,可以参考该博文深度强化学习初探 ,但是他文中的公式应该有点问题。应该把Qm+1改为Qm,进一步参考维基百科Q-learning ,如下所示。

Qm+1(st,at)=Qm(st,at)+α[rt+1+γQm(st+1,at+1)−Qm(st,at)]

推荐所用的画图软件process on

  • 用起来挺方便的,在线用谷歌浏览器运行,用户体验挺佳,比visio2010快多了;
  • 可以多用户协作;
  • 目前有一个缺点就是一个框里面的字体格式必须是一样的,不可以修改一个框里面部分的文字的格式。有点类似PS的思想。

PyBrain库的example之NFQ流程图分析的更多相关文章

  1. iOS 开源库系列 Aspects核心源码分析---面向切面编程之疯狂的 Aspects

    Aspects的源码学习,我学到的有几下几点 Objective-C Runtime 理解OC的消息分发机制 KVO中的指针交换技术 Block 在内存中的数据结构 const 的修饰区别 block ...

  2. 线程高级应用-心得4-java5线程并发库介绍,及新技术案例分析

    1.  java5线程并发库新知识介绍 2.线程并发库案例分析 package com.itcast.family; import java.util.concurrent.ExecutorServi ...

  3. Volley框架的流程图分析

          接着上一篇Volley框架的使用,这一篇主要主要讲Volley框架运作的原理.主要使用流程图来叙述,简单的分析了整个流程的过程,具体的请参考源代码或者查看我上一篇在文章末尾添上的链接. 一 ...

  4. MVP模式, 开源库mosby的使用及代码分析

    Android中的构架模式一直是一个很hot的topic, 近年来Architecture components推出之后, MVVM异军突起, 风头正在逐渐盖过之前的MVP. 其实我觉得MVP还是有好 ...

  5. HTTP请求库——axios源码阅读与分析

    概述 在前端开发过程中,我们经常会遇到需要发送异步请求的情况.而使用一个功能齐全,接口完善的HTTP请求库,能够在很大程度上减少我们的开发成本,提高我们的开发效率. axios是一个在近些年来非常火的 ...

  6. 如何实现一个HTTP请求库——axios源码阅读与分析 JavaScript

    概述 在前端开发过程中,我们经常会遇到需要发送异步请求的情况.而使用一个功能齐全,接口完善的HTTP请求库,能够在很大程度上减少我们的开发成本,提高我们的开发效率. axios是一个在近些年来非常火的 ...

  7. 【odoo】【知识杂谈】单一实例多库模式下定时任务的问题分析

    欢迎转载,但需标注出处,谢谢! 背景: 有客户反应有个别模块下的定时任务没有正常执行,是否是新装的模块哪些有问题?排查后发现,客户是在一台服务器上跑着一个odoo容器,对应多个数据库.个别库的定时任务 ...

  8. Android OpenGL库加载过程源码分析

    Android系统采用OpenGL绘制3D图形,使用skia来绘制二维图形:OpenGL源码位于: frameworks/native/opengl frameworks/base/opengl 本文 ...

  9. C/C++音视频库ffmpeg的数据包AVPacket分析

    ffmpeg下载地址 http://www.ffmpeg.club/ AVPacket是ffmpeg用来存放编码后的视频帧数据,我们来分析一下这个结构体,先贴出ffmpeg3.2中AVPacket声明 ...

随机推荐

  1. Android面试二之Fragment

    基本概念 Fragment,简称碎片,是Android 3.0(API 11)提出的,为了兼容低版本,support-v4库中也开发了一套Fragment API,最低兼容Android 1.6. F ...

  2. nyoj——297(期望)

    GoroSort 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 Goro has 4 arms. Goro is very strong. You don't me ...

  3. @Primary-在spring中常被忽视的注解

    在spring 中使用注解,常使用@Autowired, 默认是根据类型Type来自动注入的.但有些特殊情况,对同一个接口,可能会有几种不同的实现类,而默认只会采取其中一种的情况下 @Primary  ...

  4. 字符串方法之-indexOf、lastIndexOf、等等一些方法

    1.indexOf():方法可返回某个指定的字符串值在字符串中首次出现的位置(从左往右找). 语法:stringObject.indexOf(searchvalue,fromindex) <sc ...

  5. window.history.go(-1);

    history是你浏览过的网页的url(简单的说就是网址)的集合,也就是你的浏览器里的那个历史记录.它在js里是一个内置对象,就跟document一样,它有自己的方法,go就是其中一个. 这个方法的参 ...

  6. 026——VUE中事件修饰符之使用$event与$prevent修饰符操作表单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Server.Transfer 页面之间传值

    server.transfer 特点: 1:大家熟悉的一个特点,用server.transfer 跳转到新页面时,浏览器的地址是没有改变的(因为重定向完全在服务器端进行,浏览器根本不知道服务器已经执行 ...

  8. leetCode之Median of Two Sorted Arrays

    [题目描述] There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of ...

  9. WiFi无线网络参数 802.11a/b/g/n 详解

    转载自:WiFi无线网络参数 802.11a/b/g/n 详解 如转载侵犯您的版权,请联系:2378264731@qq.com 802.11a/b/g/n,其实指的是无线网络协议,细分为802.11a ...

  10. Linux:ln命令详解(软连接,硬链接)

    ln ln命令用来为文件创件连接,连接类型分为硬连接和软连接(符号连接)两种,默认的连接类型是硬连接.如果要创建软连接必须使用"-s"选项. 硬链接 建立硬链接时,在另外的目录或本 ...