这是代码:
import numpy as np
# sigmoid function
def nonlin(x,deriv=False):
if(deriv==True):
return x*(1-x)
return 1/(1+np.exp(-x))
# input dataset
X = np.array([ [0,0,1],
[0,1,1],
[1,0,1],
[1,1,1] ])
# output dataset
y = np.array([[0,0,1,1]]).T
# seed random numbers to make calculation
# deterministic (just a good practice)
np.random.seed(1)
# initialize weights randomly with mean 0
syn0 = 2*np.random.random((3,1)) - 1
for iter in xrange(10000):
# forward propagation
l0 = X
l1 = nonlin(np.dot(l0,syn0))
# how much did we miss?
l1_error = y - l1
# multiply how much we missed by the
# slope of the sigmoid at the values in l1
l1_delta = l1_error * nonlin(l1,True)
# update weights
syn0 += np.dot(l0.T,l1_delta)
print "Output After Training:"
print l1
这是网站:http://iamtrask.github.io/2015/07/12/basic-python-network/
代码第 36 行,l1 误差
乘以输入的导数以及权重。我不知道为什么要这样做,并且花了几个小时试图弄清楚。我刚刚得出这样的结论:这是错误的,但有些事情告诉我,考虑到有多少人推荐并使用本教程作为学习神经网络的起点,这可能是不正确的。
在文章中,他们这样说
Look at the sigmoid picture again! If the slope was really shallow (close to 0), then the network either had a very high value, or a very low value. This means that the network was quite confident one way or the other. However, if the network guessed something close to (x=0, y=0.5) then it isn't very confident.
我似乎无法理解为什么 sigmoid 函数输入的高低与置信度有任何关系。当然,它有多高并不重要,因为如果预测的产出很低,那么它就会非常不自信,不像他们所说的那样,因为它很高,所以应该有信心。
如果您想强调错误,那么将 l1_error
立方化肯定会更好吗?
考虑到到目前为止,我终于找到了一种有前途的方法来真正直观地开始学习神经网络,这真是令人失望,但我再次错了。如果您有一个我可以很容易理解的好地方来开始学习,我将不胜感激。
最佳答案
看看这张图片。如果 sigmoid 函数给你一个高值或低值(相当好的置信度),则该值的导数为低值。如果您在最陡斜率 (0.5) 处获得一个值,则该值的导数为“高”。
当函数给我们一个不好的预测时,我们希望将权重改变一个更大的数字,相反,如果预测良好(高置信度),我们不想改变我们的权重太多。
关于python - 为什么在神经网络中将误差乘以 sigmoid 的导数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45787261/