TensorLayer官方中文文档1.7.4:API – 强化学习
API - 强化学习¶
强化学习(增强学习)相关函数。
discount_episode_rewards([rewards, gamma, mode]) |
Take 1D float array of rewards and compute discounted rewards for an episode. |
cross_entropy_reward_loss(logits, actions, ...) |
Calculate the loss for Policy Gradient Network. |
log_weight(probs, weights[, name]) |
Log weight. |
choice_action_by_probs([probs, action_list]) |
Choice and return an an action by given the action probability distribution. |
奖励函数¶
tensorlayer.rein.discount_episode_rewards(rewards=[], gamma=0.99, mode=0)[源代码]¶-
Take 1D float array of rewards and compute discounted rewards for an
episode. When encount a non-zero value, consider as the end a of an episode.Parameters: rewards : numpy list
a list of rewards
gamma : float
discounted factor
mode : int
if mode == 0, reset the discount process when encount a non-zero reward (Ping-pong game).
if mode == 1, would not reset the discount process.Examples
>>> rewards = np.asarray([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1])
>>> gamma = 0.9
>>> discount_rewards = tl.rein.discount_episode_rewards(rewards, gamma)
>>> print(discount_rewards)
... [ 0.72899997 0.81 0.89999998 1. 0.72899997 0.81
... 0.89999998 1. 0.72899997 0.81 0.89999998 1. ]
>>> discount_rewards = tl.rein.discount_episode_rewards(rewards, gamma, mode=1)
>>> print(discount_rewards)
... [ 1.52110755 1.69011939 1.87791049 2.08656716 1.20729685 1.34144104
... 1.49048996 1.65610003 0.72899997 0.81 0.89999998 1. ]
损失函数¶
Weighted Cross Entropy¶
tensorlayer.rein.cross_entropy_reward_loss(logits, actions, rewards, name=None)[源代码]¶-
Calculate the loss for Policy Gradient Network.
Parameters: logits : tensor
The network outputs without softmax. This function implements softmax
inside.actions : tensor/ placeholder
The agent actions.
rewards : tensor/ placeholder
The rewards.
Examples
>>> states_batch_pl = tf.placeholder(tf.float32, shape=[None, D])
>>> network = InputLayer(states_batch_pl, name='input')
>>> network = DenseLayer(network, n_units=H, act=tf.nn.relu, name='relu1')
>>> network = DenseLayer(network, n_units=3, name='out')
>>> probs = network.outputs
>>> sampling_prob = tf.nn.softmax(probs)
>>> actions_batch_pl = tf.placeholder(tf.int32, shape=[None])
>>> discount_rewards_batch_pl = tf.placeholder(tf.float32, shape=[None])
>>> loss = tl.rein.cross_entropy_reward_loss(probs, actions_batch_pl, discount_rewards_batch_pl)
>>> train_op = tf.train.RMSPropOptimizer(learning_rate, decay_rate).minimize(loss)
Log weight¶
tensorlayer.rein.log_weight(probs, weights, name='log_weight')[源代码]¶-
Log weight.
Parameters: probs : tensor
If it is a network output, usually we should scale it to [0, 1] via softmax.
weights : tensor
采样选择函数¶
tensorlayer.rein.choice_action_by_probs(probs=[0.5, 0.5], action_list=None)[源代码]¶-
Choice and return an an action by given the action probability distribution.
Parameters: probs : a list of float.
The probability distribution of all actions.
action_list : None or a list of action in integer, string or others.
If None, returns an integer range between 0 and len(probs)-1.
Examples
>>> for _ in range(5):
>>> a = choice_action_by_probs([0.2, 0.4, 0.4])
>>> print(a)
... 0
... 1
... 1
... 2
... 1
>>> for _ in range(3):
>>> a = choice_action_by_probs([0.5, 0.5], ['a', 'b'])
>>> print(a)
... a
... b
... b
艾伯特(http://www.aibbt.com/)国内第一家人工智能门户
TensorLayer官方中文文档1.7.4:API – 强化学习的更多相关文章
- TensorLayer官方中文文档1.7.4:API – 数据预处理
所属分类:TensorLayer API - 数据预处理¶ 我们提供大量的数据增强及处理方法,使用 Numpy, Scipy, Threading 和 Queue. 不过,我们建议你直接使用 Tens ...
- TensorLayer官方中文文档1.7.4:API – 可视化
API - 可视化¶ TensorFlow 提供了可视化模型和激活输出等的工具 TensorBoard. 在这里,我们进一步提供一些可视化模型参数和数据的函数. read_image(image[, ...
- Keras官方中文文档:函数式模型API
\ 函数式模型接口 为什么叫"函数式模型",请查看"Keras新手指南"的相关部分 Keras的函数式模型为Model,即广义的拥有输入和输出的模型,我们使用M ...
- ReactNative官方中文文档0.21
整理了一份ReactNative0.21中文文档,提供给需要的reactnative爱好者.ReactNative0.21中文文档.chm 百度盘下载:ReactNative0.21中文文档 来源: ...
- PyTorch官方中文文档:torch.nn
torch.nn Parameters class torch.nn.Parameter() 艾伯特(http://www.aibbt.com/)国内第一家人工智能门户,微信公众号:aibbtcom ...
- 学习Python 新去处:Python 官方中文文档
Python 作为世界上最好用的语言,官方支持的文档一直没有中文.小伙伴们已经习惯了原汁原味的英文文档,但如果有官方中文文档,那么查阅或理解速度都会大大提升.本文将介绍隐藏在 Python 官网的中文 ...
- django2.0 官方中文文档地址
django2.0 官方开始发布中文文档了,之前还想着一直翻译完成所有有必要的内容,想着可以省事一些了,打开以后看了一下,发现官方的中文文档还没翻译完成, 现在(2018-7-10)最新章节是是 编 ...
- mysql 新手入门 官方文档+官方中文文档附地址
点评: 官方文档地址 官方中文文档地址 sql语句扩展
- PyTorch官方中文文档:torch.optim 优化器参数
内容预览: step(closure) 进行单次优化 (参数更新). 参数: closure (callable) –...~ 参数: params (iterable) – 待优化参数的iterab ...
随机推荐
- 五、XML与xpath--------------爬取美女图片
除了正则表达式处理HTML文档,我们还可以用XPath,先将 HTML文件 转换成 XML文档,然后用 XPath 查找 HTML 节点或元素. 先用一个小实例开头吧(爬去贴吧每个帖子的图片): im ...
- 六、BeautifulSoup4------自动登录网站(手动版)
每天一个小实例:(按照教学视频上自动登录的网站,很容易就成功了.自已练习登录别的网站,问题不断) 这个自己分析登录boss直聘.我用了一下午的时间,而且还是手动输入验证码,自动识别输入验证码的还没成功 ...
- 【实用】需要收藏备用的JQuery代码片段
1 元素屏幕居中 jQuery.fn.center = function () { this.css("position","absolute"); this. ...
- 浅谈format格式化输出
什么是format? 相对于基本格式化输出采用"%"的方法,format的功能强大,该函数把字符串当一个模板,通过传入的参数进行格式化,并且使用大括号"{}"作 ...
- 基于jq的表单填充
//表单填充 formDataLoad: function (domId, obj) { for (var property in obj) { if (obj.hasOwnProperty(prop ...
- 01_JavaSE之OOP--面向对象(类和面向对象的简单认识)
面向对象(一) 一.面向对象概述 谈到面向对象就不得不谈谈面向过程,面向对象也是由面向过程发展而来. 面向过程思想概述 面向过程,简而言之就是分步骤,过程化的去解决问题,代表语言有:Pascal,C等 ...
- 常见JedisConnectionException异常分析
异常内容:我看了很多人的博客,千篇一律都是说redis.conf文件的配置问题,发现并不能解决我的问题,今天写这个博客讲解一下我的解决办法: 遇到这个问题第一步:查看虚拟机的防火墙是否关闭,测试方法就 ...
- Spring boot 整合redis单机版
一.安装redis 这个不多说,网上有各种系统安装redis的操作, redis安装 二.创建sprigboot项目 这个也不多说,不会的前面有相关教程. 三.添加maven坐标 四.编写spr ...
- Yii的数组助手类
获取值 用原生PHP从一个对象.数组.或者包含这两者的一个复杂数据结构中获取数据是非常繁琐的. 你首先得使用isset 检查 key 是否存在, 然后如果存在你就获取它,如果不存在, 则提供一个默认返 ...
- (MonoGame从入门到放弃-3)-放弃MonoGame
又一段时间过去了,这一章没内容了.我真的已经放弃MonoGame的学习了,MonoGame用起来感觉就是在自己实现2d游戏引擎一样,好多现代游戏引擎有的内容都没有...,我只是想做游戏,而不是给引擎添 ...