I'm trying to learn about neural networks and coded a simple back-propagation neural network that uses sigmoid activation functions and random weight initialisation. I was trying multiplication with two input values 3 and 2 in the input layer and target output 6 in output layer. When I execute my code the value for w1 and w2 keeps on increasing and doesn't stop at the correct value.
I am new to both Python and neural networks and I'd appreciate assistance.
import numpy as np
al0 = 3
bl0 = 2
import random
w1 =random.random()
w2 =random.random()
b = 0.234
ol1 = 6
def sigm(x,deriv=False):
if deriv==True:
return x*(1-x)
return 1/(1+np.exp(-x))
y = sigm(x)
E = 1/2*(ol1 - y)**2
dsig = sigm(x,True)
dyE = y-ol1
for iter in range(10000):
syn0 = al0*w1
syn1 = bl0*w2
x = syn0 + syn1 + b
dtotal1 = dyE*dsig*al0
w1 = w1 + 0.01*dtotal1
dtotal2 = dyE*dsig*bl0
w2 = w2 + 0.01*dtotal2
w1
w2
xbefore it is assigned. - Matt Cremeensw1andw2to continue to increase as it would appear you continually add a positive amount to them in your loop. - Matt Cremeens