python - Why multiply the error by the derivative of the sigmoid in neural networks? -
here code:
import numpy 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 make calculation # deterministic (just practice) np.random.seed(1) # initialize weights randomly mean 0 syn0 = 2*np.random.random((3,1)) - 1 iter in xrange(10000): # forward propagation l0 = x l1 = nonlin(np.dot(l0,syn0)) # how did miss? l1_error = y - l1 # multiply how missed # slope of sigmoid @ 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
here website: http://iamtrask.github.io/2015/07/12/basic-python-network/
line 36 of code, l1 error multiplied derivative of input dotted weights. have no idea why done , have been spending hours trying figure out. reached conclusion wrong, telling me thats not right considering how many people recommend , use tutorial starting point learning neural networks.
in article, that
look @ sigmoid picture again! if slope shallow (close 0), network either had high value, or low value. means network quite confident 1 way or other. however, if network guessed close (x=0, y=0.5) isn't confident.
i cannot seem wrap head around why highness or lowness of input sigmoid function has confidence. surely doesn't matter how high is, because if predicted output low, unconfident, unlike said should confident coz it's high.
surely better cube l1_error if wanted emphasise error?
this real let down considering point looked had found promising way intuitively start learning neural networks, yet again wrong. if have place start learning can understand easily, appreciated.
Comments
Post a Comment