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 ...
随机推荐
- [HAOI2009]毛毛虫
题目描述 对于一棵树,我们可以将某条链和与该链相连的边抽出来,看上去就象成一个毛毛虫,点数越多,毛毛虫就越大.例如下图左边的树(图 1 )抽出一部分就变成了右边的一个毛毛虫了(图 2 ). 输入输出格 ...
- 几个重要的shell命令:diff patch tar find grep
diff diir_1.0/ dir_2.0/ -urNB > dir_2.0.patch u:union以合并的格式来输出文件的差异信息 r:递归的对比所有的子目录下的文件 U:将不存在的文件 ...
- "abc123 ,def456",反转字母,其他位置不变
"abc123 ,def456",反转字母,其他位置不变. 无意间看到个有意思的面试题,忽然来了兴趣想着来做一下. 操作字符串用正则的效率比较高,但第一反应还是用原生来操作.下面说 ...
- php+redis 学习 二 悲观锁
<?php header('content-type:text/html;chaeset=utf-8'); /** * redis实战 * * 实现悲观锁机制 * */ $timeout = 5 ...
- Python自动化测试、性能测试成长路线图
Python自动化测试成长路线图 性能测试成长路线图
- MySQL Server 5.0安装教程
相信很多朋友刚开始接触mysql数据库服务器,下面是mysql的安装教程,步骤明细也有详细的说明. 工具/原料 mysql MySQL安装的图解 1 打开下载的mysql安装文件mysql-5 ...
- Mysql给某一台主机授权访问,修改root密码
ubuntu上用的是phpstudy,安装好之后,敲mysql,提示没有,需要安装mysql的客户端. 安装好之后直接敲mysql,敲 mysql 再敲use mysql 再敲mysql -uroot ...
- Egret学习笔记 (Egret打飞机-5.实现子弹对象)
上一章把飞机添加到屏幕上,但是飞机要发射子弹对吧?那么这一章我们就来实现一下发射子弹,并实现一个简单的子弹对象池 先来捋一捋思路 1.创建一个子弹对象 2.然后添加一个bitmap,显示子弹贴图 3. ...
- Jar程序使用MyBatis集成阿里巴巴druid连接池
在写jar程序,而不是web程序的时候,使用mybatis作为持久层,可以集成POOLED连接池,而阿里的druid不能用,确实很郁闷.不过有办法. 首先准备好数据库配置文件 然后对Druid进行一个 ...
- FreeImage库如何转换图片格式?
FreeImage下载地址:http://freeimage.sourceforge.net/ //freeimagemain.h #ifndef FREEIMAGEMAIN_H #define FR ...