gpt4 book ai didi

python - 反向传播中 sigmoid 导数输入的困惑

转载 作者:行者123 更新时间:2023-12-02 19:24:57 26 4
gpt4 key购买 nike

使用链式法则计算成本函数相对于该层权重的斜率时L ,则公式变为:

d C0 / d W(L) = ... . d a(L) / d z(L) . ...

与:

z (L) being the induced local field : z (L) = w1(L) * a1(L-1) + w2(L) * a2(L-1) * ...

a (L) beeing the ouput : a (L) = & (z (L))

& being the sigmoid function used as an activation function

请注意L被视为图层指示器而不是索引

现在:
d a(L) / d z(L) = &' ( z(L) )

&'是 sigmoid 函数的导数

问题:

但是在这个post这是 James Loy 写的关于用 python 从头开始​​构建一个简单的神经网络,
在进行反向传播时,他没有给出 z (L)作为 &' 的输入替换d a(L) / d z(L)在链式法则函数中。相反,他给了它 output = last activation of the layer (L)作为输入的 sigmoid 导数 &'

def feedforward(self):
self.layer1 = sigmoid(np.dot(self.input, self.weights1))
self.output = sigmoid(np.dot(self.layer1, self.weights2))

def backprop(self):
# application of the chain rule to find derivative of the loss function with respect to weights2 and weights1
d_weights2 = np.dot(self.layer1.T, (2*(self.y - self.output) * sigmoid_derivative(self.output)))

请注意,在层 L 之上的代码中是层2这是最后一层或输出层。和sigmoid_derivative(self.output)这是当前层的激活作为 sigmoid 函数导数的输入,用作激活函数。

问题:

我们不应该使用这个sigmoid_derivative(np.dot(self.layer1, self.weights2))而不是这个sigmoid_derivative(self.output)

最佳答案

事实证明,使用了&( z(L) )output,只是为了适应sigmoid_derivative 的实现方式。

这是sigmoid_derivative的代码:

def sigmoid(x):
return 1.0/(1+ np.exp(-x))

def sigmoid_derivative(x):
return x * (1.0 - x)

sigmoid_derivative的数学公式可以写为:&' (x) = &(x) * (1-&(x))

因此,为了得到上面的公式,将 &(z) 而不是 z 传递给 sigmoid_derivative 以返回:&(z) * (1.0 - &(z))

关于python - 反向传播中 sigmoid 导数输入的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62505150/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com