首页 > 其他分享 >batch_norm在强化学习中建议使用的形式

batch_norm在强化学习中建议使用的形式

时间:2023-06-09 09:33:41浏览次数:44  
标签:layer nonlinearity batch norm BatchNormLayer 强化 normalization

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)



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

 

标签:layer,nonlinearity,batch,norm,BatchNormLayer,强化,normalization
From: https://www.cnblogs.com/devilmaycry812839668/p/17468231.html

相关文章

  • 2.2类神经网路训练不起来怎么办 (二): 批次 (batch) 与动量 (momentum)
    1.Batch(批次)对抗临界点的两个方法就是batch和momentum  将一笔大型资料分若干批次计算loss和梯度,从而更新参数.每看完一个epoch就把这笔大型资料打乱(shuffle),然后重新分批次.这样能保证每个epoch中的batch资料不同,避免偶然性.epoch是指将数据集分成batch后,......
  • 浅谈mysql索引类型(normal、unique、full textl) 的区别和使用场景
    mysql索引类型mysql索引类型normal,unique,fulltext的区别是什么?normal:表示普通索引unique:表示唯一的,不允许重复的索引,如果该字段信息保证不会重复例如身份证号用作索引时,可设置为uniquefulltextl:表示全文搜索的索引。FULLTEXT用于搜索很长一篇文章的时候,效果最好。用在......
  • 正则化(regularization)和归一化(normalization)
    正则化:批量归一化和dropout批量归一化和dropout作为正则化器来克服深度学习模型中的过度拟合问题。 来源您遇到过导致过拟合的大型数据集吗?过度拟合的原因之一是网络中的权重很大。具有较大网络权重的网络可能是网络不稳定的标志,其中输入的微小变化可能导致输......
  • mybatis-plus 批量插入方法saveBatch 踩坑
    1、问题描述由于我在数据库的一张表设置了两个主键,所以创建的实体我想都加上@TableId注解但是这样在mybatis-plus中一个实体只能有一个@TableId注解标识的主键2、然后我在批量插入时就遇到了问题,我使用的saveBatch方法进行的批量插入,在插入时实体的两个id我都设置值了,但是......
  • 标准化(Standardization)、归一化(Normalization)
    归一化:1)把数据变成(0,1)或者(1,1)之间的小数。主要是为了数据处理方便提出来的,把数据映射到0~1范围之内处理,更加便捷快速。2)把有量纲表达式变成无量纲表达式,便于不同单位或量级的指标能够进行比较和加权。归一化是一种简化计算的方式,即将有量纲的表达式,经过变换,化为无量纲的表达式,成为......
  • 强化学习:连续控制问题中Actor-Critic算法的linear baseline
    最近在看连续控制问题,看到了一个Actor-Critic算法中手动扩展features和设置linearbaseline的方法,这些方法源自论文:《BenchmarkingDeepReinforcementLearningforContinuousControl》。  对于低维的features我们可以手动扩展:  代码实现:returntorch.cat([observations,ob......
  • 强化学习基础篇[3]:DQN、Actor-Critic详细讲解
    强化学习基础篇[3]:DQN、Actor-Critic详细讲解1.DQN详解1.1DQN网络概述及其创新点在之前的内容中,我们讲解了Q-learning和Sarsa算法。在这两个算法中,需要用一个Q表格来记录不同状态动作对应的价值,即一个大小为$[状态个数,动作个数]$的二维数组。在一些简单的强化学习环境中,比如......
  • 训练简单小游戏的强化学习工具箱
    详细先上效果图:启动界面主界面设置界面服务器界面(使用highchart模板画出每一局得分情况)配置的两款简单小游戏以及训练效果:贪吃蛇“是男人就下一百层”(修改)*原图像太大被迫修改大小使用说明:####【设置窗口】→在上面的主界面中点击倒三角形状的键,屏幕上会弹出一个黑色的设置窗。在......
  • 强化学习基础篇【1】:基础知识点、马尔科夫决策过程、蒙特卡洛策略梯度定理、REINFORCE
    强化学习基础篇【1】:基础知识点、马尔科夫决策过程、蒙特卡洛策略梯度定理、REINFORCE算法1.强化学习基础知识点智能体(agent):智能体是强化学习算法的主体,它能够根据经验做出主观判断并执行动作,是整个智能系统的核心。环境(environment):智能体以外的一切统称为环境,环境在与智能体......
  • 强化学习基础篇[2]:SARSA、Q-learning算法简介、应用举例、优缺点分析
    强化学习基础篇[2]:SARSA、Q-learning算法简介、应用举例、优缺点分析1.SARSASARSA(State-Action-Reward-State-Action)是一个学习马尔可夫决策过程策略的算法,通常应用于机器学习和强化学习学习领域中。它由Rummery和Niranjan在技术论文“ModifiedConnectionistQ-Learning(MCQL)......