zoukankan      html  css  js  c++  java
  • 深度学习的激励函数

    1.sigmoid函数

    S(x)=1/(1+exp(-x))

    导数为:S(x)*(1-S(x))。

    这个数值不会超过0.25.。通过sigmoid函数计算的函数值在0~1之间,如果神经网络的层数很多,如果每一层的激励函数采用sigmoid函数,就会产生梯度弥散的问题。因为利用BP函数更新参数的时候,会乘以它的导数,所以会一直减小。并且在比较大或者比较小的时候,会产生饱和效应,导致神经元类似与死亡。

    2.tanh函数

    导数:

    tanh函数的值在-1~1之间。导数小于1.如果每一层用这个激励函数。会导致和sigmoid函数类似的情况。

    3.elu函数

    4.softplus函数

    f(x)=ln(1+ex)

    导数为:

    f(x)=ex1+ex=11+ex。导数比较小

    5.softsign函数

    6.relu函数

    f(x) = max(0, x)。这个函数经常用,可以解决梯度弥散问题,因为它的导师等于1或者就是0。

    7. relu6函数

    f(x) = max(0,6,x)。这个函数可以将激励函数的值数据位于0~6之间。

    解释:这个函数的作用是计算激活函数relu6,即min(max(features, 0), 6)

    还有一些其他的函数变体,这里就不一一介绍。下面使用tensorflow画出的各种函数的图。

    画图代码:

    import tensorflow as tf
    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.linspace(-10,10,100)
    y1 = tf.nn.sigmoid(x)
    y2 = tf.nn.tanh(x)
    y3 = tf.nn.elu(x)
    y4 = tf.nn.softplus(x)
    y5 = tf.nn.softsign(x)
    y6 = tf.nn.relu(x)
    y7 = tf.nn.relu6(x)
    
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        ax1 = plt.subplot2grid((4,2), (0,0))
        ax1.plot(x, sess.run(y1))
        ax1.set_title('sigmoid')
    
        ax2 = plt.subplot2grid((4,2), (0,1))
        ax2.plot(x, sess.run(y2))
        ax2.set_title('tanh')
    
        ax3 = plt.subplot2grid((4,2), (1,0))
        ax3.plot(x, sess.run(y3))
        ax3.set_title('elu')
    
        ax4 = plt.subplot2grid((4,2), (1,1))
        ax4.plot(x, sess.run(y4))
        ax4.set_title('softplus')
    
        ax5 = plt.subplot2grid((4,2), (2,0))
        ax5.plot(x, sess.run(y5))
        ax5.set_title('softsign')
    
        ax6 = plt.subplot2grid((4,2), (2,1))
        ax6.plot(x, sess.run(y6))
        ax6.set_title('relu')
    
        ax7 = plt.subplot2grid((4,2), (3,0))
        ax7.plot(x, sess.run(y7))
        ax7.set_title('relu6')
    
        plt.show()

    参考:http://m.blog.csdn.net/UESTC_C2_403/article/details/73431428

  • 相关阅读:
    常用正则表达式
    玉洁哥的设计模式指摘
    jquery makearray()使用
    html/css技巧总结
    json 数组 对象 xml 之间转换(待补充)
    Html5 Geolocation获取地理位置信息
    JSON.stringify 应用
    url操作一网打尽(一)
    jquery选择器
    JavaScript Window Location
  • 原文地址:https://www.cnblogs.com/lovephysics/p/7220157.html
Copyright © 2011-2022 走看看