【发布时间】:2020-06-21 22:31:21
【问题描述】:
当使用链式法则计算成本函数相对于L层权重的斜率时,公式变为:
d C0 / d W(L) = ... . d a(L) / d z(L) . ...
与:
z (L)是诱导局部场:z (L) = w1(L) * a1(L-1) + w2(L) * a2(L-1) * ...
a (L)输出:a (L) = & (z (L))
&是用作激活函数的 sigmoid 函数
注意L被视为层指示符而不是索引
现在:d a(L) / d z(L) = &' ( z(L) )
&' 是 sigmoid 函数的导数
问题:
但是在这个post 中,James Loy 编写了关于使用 python 从头开始构建一个简单的神经网络的文章,
在进行反向传播时,他没有将 z (L) 作为 @ 的输入987654333@ 替换链式规则函数中的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)吗?
【问题讨论】:
标签: python neural-network backpropagation derivative activation-function