【问题标题】:Why use derivative of Sigmoid in neural network?为什么在神经网络中使用 Sigmoid 的导数?
【发布时间】:2017-08-01 09:14:58
【问题描述】:

我创建了一个具有典型激活函数(-1 或 1)的简单感知器,它似乎工作正常。 然后我阅读了关于 sigmoid 及其在值之间更平滑过渡的用途,但在使用导数时我总是得到 0.0,这会弄乱计算。 sigmoid 本身很好,对于较小的数字,它的小数,对于较大的数字,它又是 -1 或 1。 那么导数有什么用呢?
我的意思是一个例子:

double actual (-1 or 1 when using the "old" function)
double AdjustWeight(int input1,input2, expected, actual)
{
   double error=expected-actual;   //when actual is derivative, is 0 for me, instead of -1 or 1
 ....
}

【问题讨论】:

    标签: c# neural-network


    【解决方案1】:

    感知器网络是单层的。由于它们的非持续激活函数你不能对它们使用反向传播算法,所以它们不能是多层的。 相反,Sigmoid 函数是一个可微函数,您可以对它们使用反向传播算法。在 Perception 中,您想调整使用的权重:

    W(new) = W(old) + a·(t-x)·y
    

    a是学习率,t是目标值,x是你的输入向量,y是输出。

    当您想使用 Sigmoid 函数时,您必须使用基于梯度的算法。在这些算法中,您根据误差导数调整权重。

    W(new) = W(old) - a·(dE/dW)
    

    在多层网络中,您不能使用感知算法,因为它需要正确的输出,而您不知道隐藏神经元的正确输出。所以在多层网络中你必须使用基于梯度的算法和反向传播来反向传播错误和dE/dW

    在单层神经网络中,您可以使用感知或基于梯度的算法。你不能告诉女巫更好。感知为您提供更好的分组,基于梯度的为您提供更好的抗噪性。

    在基于梯度的算法中,您使用激活函数的导数来找到 dE/dW。如果Z是神经元的总输入(Z = [sum on i] Wi·Xi):

    dE/dWi = Xi·(dE/dZ)
    
    dE/dZ = -f'(Z)·(dE/dY)
    

    在我们的例子中,因为我们使用了 Sigmoid 函数,所以对于二元 Sigmoid,f'(Z) 是 Y(1-Y),对于双极 Sigmoid,f'(Z) 是 0.5(1-Y)(1+Y)。

    通常我们使用以下公式计算误差(成本函数):

    E = 0.5(T-Y)^2
    

    所以我们的方程将转换为:

    dE/dY = Y-T
    
    dE/dZ = -0.5(1+Y)(1-Y)·(Y-T)
    
    dE/dWi = - 0.5Xi·(1+Y)(1-Y)·(Y-T)
    
    W(new) = W(old) + 0.5a·Xi·(1+Y)(1-Y)·(Y-T)
    

    如果您使用以下算法更新权重,我认为您的问题将得到解决。

    【讨论】:

      【解决方案2】:

      以下是Sigmoid函数的微分。 “np.exp”是一样的; 数字 e,一个以自然对数为底的数学常数:自然对数等于 1 的唯一数。它大约等于 2.71828。 (维基百科)

      # This is how mathematical the derivative of sigmoid is computed.
      # Variables are only used as example for differentiation.
      import numpy as np
      
      x = 0.32
      
      sigmoid = 1 / 1 + np.exp(-x)
      differentiate = np.exp(-x) / (1+np.exp(-x)**2
      differentiate_1 = np.exp(-x) - 1 / (1+np.exp(-x)**2
      differentiate_2 = (1+np.exp(-x) / (1+np.exp(-x)**2) - (1/1+np.exp(-x))**2
      differintiate_3 = sigmoid - sigmoid**2
      sigmoid_prime = sigmoid * (1- sigmoid)
      

      传递函数或 sigmoid 函数将值转换为概率 从 0 到 1。Sigmoid prime 有一个很好的曲线,可以转换 0 到 0.5 范围内的值。

      【讨论】:

        猜你喜欢
        • 2012-07-25
        • 2018-01-28
        • 1970-01-01
        • 2019-01-17
        • 2017-07-28
        • 2020-08-30
        • 2014-03-26
        • 2017-06-20
        • 2016-09-19
        相关资源
        最近更新 更多