def batch_norm(layer, **kwargs):
"""
Apply batch normalization to an existing layer. This is a convenience
function modifying an existing layer to include batch normalization: It
will steal the layer's nonlinearity if there is one (effectively
introducing the normalization right before the nonlinearity), remove
the layer's bias if there is one (because it would be redundant), and add
a :class:`BatchNormLayer` and :class:`NonlinearityLayer` on top. Parameters
----------
layer : A :class:`Layer` instance
The layer to apply the normalization to; note that it will be
irreversibly modified as specified above
**kwargs
Any additional keyword arguments are passed on to the
:class:`BatchNormLayer` constructor. Returns
-------
BatchNormLayer or NonlinearityLayer instance
A batch normalization layer stacked on the given modified `layer`, or
a nonlinearity layer stacked on top of both if `layer` was nonlinear. Examples
--------
Just wrap any layer into a :func:`batch_norm` call on creating it: >>> from lasagne.layers import InputLayer, DenseLayer, batch_norm
>>> from lasagne.nonlinearities import tanh
>>> l1 = InputLayer((64, 768))
>>> l2 = batch_norm(DenseLayer(l1, num_units=500, nonlinearity=tanh)) This introduces batch normalization right before its nonlinearity: >>> from lasagne.layers import get_all_layers
>>> [l.__class__.__name__ for l in get_all_layers(l2)]
['InputLayer', 'DenseLayer', 'BatchNormLayer', 'NonlinearityLayer']
"""
nonlinearity = getattr(layer, 'nonlinearity', None)
if nonlinearity is not None:
layer.nonlinearity = lasagne.nonlinearities.identity
if hasattr(layer, 'b') and layer.b is not None:
del layer.params[layer.b]
layer.b = None
layer = BatchNormLayer(layer, **kwargs)
if nonlinearity is not None:
layer = L.NonlinearityLayer(layer, nonlinearity)
return layer

源代码地址:

https://gitee.com/devilmaycry812839668/rllab/blob/master/rllab/core/lasagne_layers.py

=================================================

这是经典reinforcement learning框架rllab中的batch_norm的使用。可以看到,在对一个线性层进行batch_norm的时候是不先对线性层的输出进行非线性变换的,而是先对其进行batch_norm,然后再进行非线性变换。而且要注意这里使用的线性层是不使用偏置参数b的,形象的来说,这里建议使用的对 tanh(w*x+b) 的 batch_norm 是这样运行的:

tanh( batch_norm( w*x ) )

而不是:

batch_norm( tanh( w*x + b ) )

    This introduces batch normalization right before its nonlinearity:

It
will steal the layer's nonlinearity if there is one (effectively
introducing the normalization right before the nonlinearity), remove
the layer's bias if there is one (because it would be redundant)


=================================================

batch_norm在强化学习中建议使用的形式的更多相关文章

  1. 强化学习中的无模型 基于值函数的 Q-Learning 和 Sarsa 学习

    强化学习基础: 注: 在强化学习中  奖励函数和状态转移函数都是未知的,之所以有已知模型的强化学习解法是指使用采样估计的方式估计出奖励函数和状态转移函数,然后将强化学习问题转换为可以使用动态规划求解的 ...

  2. 深度强化学习中稀疏奖励问题Sparse Reward

    Sparse Reward 推荐资料 <深度强化学习中稀疏奖励问题研究综述>1 李宏毅深度强化学习Sparse Reward4 ​ 强化学习算法在被引入深度神经网络后,对大量样本的需求更加 ...

  3. 强化学习中REIINFORCE算法和AC算法在算法理论和实际代码设计中的区别

    背景就不介绍了,REINFORCE算法和AC算法是强化学习中基于策略这类的基础算法,这两个算法的算法描述(伪代码)参见Sutton的reinforcement introduction(2nd). A ...

  4. SpiningUP 强化学习 中文文档

    2020 OpenAI 全面拥抱PyTorch,  全新版强化学习教程已发布. 全网第一个中文译本新鲜出炉:http://studyai.com/course/detail/ba8e572a 个人认为 ...

  5. 强化学习中的经验回放(The Experience Replay in Reinforcement Learning)

    一.Play it again: reactivation of waking experience and memory(Trends in Neurosciences 2010) SWR发放模式不 ...

  6. (转) 深度强化学习综述:从AlphaGo背后的力量到学习资源分享(附论文)

    本文转自:http://mp.weixin.qq.com/s/aAHbybdbs_GtY8OyU6h5WA 专题 | 深度强化学习综述:从AlphaGo背后的力量到学习资源分享(附论文) 原创 201 ...

  7. 深度强化学习资料(视频+PPT+PDF下载)

    https://blog.csdn.net/Mbx8X9u/article/details/80780459 课程主页:http://rll.berkeley.edu/deeprlcourse/ 所有 ...

  8. 【整理】强化学习与MDP

    [入门,来自wiki] 强化学习是机器学习中的一个领域,强调如何基于环境而行动,以取得最大化的预期利益.其灵感来源于心理学中的行为主义理论,即有机体如何在环境给予的奖励或惩罚的刺激下,逐步形成对刺激的 ...

  9. 强化学习读书笔记 - 05 - 蒙特卡洛方法(Monte Carlo Methods)

    强化学习读书笔记 - 05 - 蒙特卡洛方法(Monte Carlo Methods) 学习笔记: Reinforcement Learning: An Introduction, Richard S ...

  10. 强化学习(五)—— 策略梯度及reinforce算法

    1 概述 在该系列上一篇中介绍的基于价值的深度强化学习方法有它自身的缺点,主要有以下三点: 1)基于价值的强化学习无法很好的处理连续空间的动作问题,或者时高维度的离散动作空间,因为通过价值更新策略时是 ...

随机推荐

  1. 记一次 .NET某游戏币自助机后端 内存暴涨分析

    一:背景 1. 讲故事 前些天有位朋友找到我,说他们的程序内存会偶发性暴涨,自己分析了下是非托管内存问题,让我帮忙看下怎么回事?哈哈,看到这个dump我还是非常有兴趣的,居然还有这种游戏币自助机类型的 ...

  2. 获取前(后)x月的日期

    package com.jesims.busresume.web; import org.springframework.stereotype.Service; import java.text.Da ...

  3. 实战 k8s----初识

    什么是k8s?k8s是谷歌开源的一套完整的容器管理平台,方便我们直接管理容器应用.谷歌称之为,kubernetes,[kubə'netis] ,(跟我一起读库波尔耐题思,重音在耐的音上),由于字母太多 ...

  4. windows离线部署VSCode在Centos7上的远程开发环境

    前言 公司一直使用的是ssh+vim的远程开发方式,习惯了vim之后已经非常方便了.但是还是想尝试一下VSCode的开发方式.就我而言,原因如下 漂亮的语法高亮,并且有补全 基于语法解析的引用查找(尽 ...

  5. JAVA-poi导出excel到http响应流

    导出结果为excel是相对常见的业务需求,大部分情况下只需要导出简单的格式即可,所以有许多可以采用的方案.有些方案还是很容易实现的. 一.可用的解决方案 目前可以有几类解决方案: 字处理企业提供的解决 ...

  6. ubuntu22 python2 pyinstaller 打包报错:'NoneType' object has no attribute 'groups'

    前言 最近有个需求,需要在 ubnutu22 上使用 pyinstaller 打包一个python2 的文件. 中间遇到了一些问题: pip2 install pyinstaller 报错 解决方案: ...

  7. 怎样理解 Vue 的单向数据流?

    数据从父级组件传递给子组件,只能单向绑定. 子组件内部不能直接修改从父级传递过来的数据. 所有的 prop 都使得其父子 prop 之间形成了一个单向下行绑定:父级 prop 的更新会向下流动到子组件 ...

  8. oracle 实现任务编码自增

    业务需求:任务编号前面4位数(通过查询其他表,值不确定),后面5位数实现自增 实现方法如下 1.创建序列 1 create sequence GENERAL_DES_TASK_SEQ_1 2 incr ...

  9. Dotnet算法与数据结构:Hashset, List对比

    哈希集A 是存储唯一元素的集合.它通过在内部使用哈希表来实现这一点,该哈希表为基本操作(如添加.删除和包含)提供恒定时间平均复杂度 (O(1)).此外,不允许重复元素,使其成为唯一性至关重要的场景的理 ...

  10. K8S 中的 CRI、OCI、CRI shim、containerd

    哈喽大家好,我是咸鱼. 好久没发文了,最近这段时间都在学 K8S.不知道大家是不是和咸鱼一样,刚开始学 K8S.Docker 的时候,往往被 CRI.OCI.CRI shim.containerd 这 ...