Hallo everybody,
now I just started with this topic and my code is not really elegant. The basic task is, that the target is always the number in the second place of a list. I thought that would be an easy way to start. However, I'm not sure what exactly is the problem, the output however stays random over the training iterations and it seems like the weight factor between the input and the hidden layer stays the same over the iterations.
The code is as follows.
import numpy
from scipy import special
import random
inodes = 5
hnodes = 3
onodes = 2
lr = 0.01
# weight factor between input and hidden
ihw = numpy.random.normal(0.0, pow(hnodes, -0.5),(hnodes, inodes))
# weight factor between hidden and output
how = numpy.random.normal(0.0, pow(onodes, -0.5),(onodes, hnodes))
inputlist1 = list()
inputlist = list()
trainlist1 = list()
trainlist = list()
controllisty = list()
controllistx = list()
for i in range(100):
# Creating a random List as a test list, with either 1001 or 1002 in the second place
b = random.randint(1001,1002)
inputlist1 = [random.randint(1,100),b ,random.randint(1,100), random.randint(3,100), random.randint(3,100)]
inputlist.append(inputlist1)
pass
for i in range(10^00):
# Creating a random List as a training list, with either 1001 or 1002 in the second place
b = random.randint(1001,1002)
trainlist1 = [random.randint(3,100),b , random.randint(3,100), random.randint(3,100), random.randint(3,100),b]
trainlist.append(trainlist1)
pass
i1 = len(trainlist)
hidden_errors = 0
for i in range(i1):
targetlist = numpy.zeros(shape=(onodes,1)) + 0.01
targetlist[int(trainlist[i][5])-1001]=0.99
del trainlist[i][5]
inputs = numpy.array(trainlist[i], ndmin=2).T
hiddenin = numpy.dot(ihw, inputs)
hiddenout = special.expit(hiddenin)
outputin = numpy.dot(how, hiddenout)
output = special.expit(outputin)
output_errors = (targetlist - output)
hidden_errors = numpy.dot(how.T,output_errors)
how += lr*numpy.dot((output_errors*output*(1.0-output)),numpy.transpose(hiddenout))
ihw += lr*numpy.dot((hidden_errors*hiddenout*(1.0-hiddenout)),numpy.transpose(inputs))
pass
for i in range(len(inputlist)):
inputs = numpy.array(inputlist[i], ndmin=2).T
hiddenin = numpy.dot(ihw, inputs)
hiddenout = special.expit(hiddenin)
outputin = numpy.dot(how, hiddenout)
output = special.expit(outputin)
I would be really greatfull for some help.
Thanks :)
I'm sorry. Here is the code in its correct form.
import numpy
from scipy import special
import random
inodes = 5
hnodes = 3
onodes = 2
lr = 0.01
# weight factor between input and hidden
ihw = numpy.random.normal(0.0, pow(hnodes, -0.5),(hnodes, inodes))
# weight factor between hidden and output
how = numpy.random.normal(0.0, pow(onodes, -0.5),(onodes, hnodes))
inputlist1 = list()
inputlist = list()
trainlist1 = list()
trainlist = list()
for i in range(100):
# Creating a random List as a test list, with either 1001 or 1002 in the second place
b = random.randint(1001,1002)
inputlist1 = [random.randint(1,100),b ,random.randint(1,100), random.randint(3,100),
random.randint(3,100)]
inputlist.append(inputlist1)
pass
for i in range(10^00):
# Creating a random List as a training list, with either 1001 or 1002 in the second place
b = random.randint(1001,1002)
trainlist1 = [random.randint(3,100),b , random.randint(3,100), random.randint(3,100),
random.randint(3,100),b]
trainlist.append(trainlist1)
pass
i1 = len(trainlist)
hidden_errors = 0
for i in range(i1):
targetlist = numpy.zeros(shape=(onodes,1)) + 0.01
targetlist[int(trainlist[i][5])-1001]=0.99
del trainlist[i][5]
inputs = numpy.array(trainlist[i], ndmin=2).T
hiddenin = numpy.dot(ihw, inputs)
hiddenout = special.expit(hiddenin)
outputin = numpy.dot(how, hiddenout)
output = special.expit(outputin)
output_errors = (targetlist - output)
hidden_errors = numpy.dot(how.T,output_errors)
how += lr*numpy.dot((output_errors*output*(1.0-output)),numpy.transpose(hiddenout))
ihw += lr*numpy.dot((hidden_errors*hiddenout*(1.0-hiddenout)),numpy.transpose(inputs))
pass
for i in range(len(inputlist)):
inputs = numpy.array(inputlist[i], ndmin=2).T
hiddenin = numpy.dot(ihw, inputs)
hiddenout = special.expit(hiddenin)
outputin = numpy.dot(how, hiddenout)
output = special.expit(outputin)
now I just started with this topic and my code is not really elegant. The basic task is, that the target is always the number in the second place of a list. I thought that would be an easy way to start. However, I'm not sure what exactly is the problem, the output however stays random over the training iterations and it seems like the weight factor between the input and the hidden layer stays the same over the iterations.
The code is as follows.
import numpy
from scipy import special
import random
inodes = 5
hnodes = 3
onodes = 2
lr = 0.01
# weight factor between input and hidden
ihw = numpy.random.normal(0.0, pow(hnodes, -0.5),(hnodes, inodes))
# weight factor between hidden and output
how = numpy.random.normal(0.0, pow(onodes, -0.5),(onodes, hnodes))
inputlist1 = list()
inputlist = list()
trainlist1 = list()
trainlist = list()
controllisty = list()
controllistx = list()
for i in range(100):
# Creating a random List as a test list, with either 1001 or 1002 in the second place
b = random.randint(1001,1002)
inputlist1 = [random.randint(1,100),b ,random.randint(1,100), random.randint(3,100), random.randint(3,100)]
inputlist.append(inputlist1)
pass
for i in range(10^00):
# Creating a random List as a training list, with either 1001 or 1002 in the second place
b = random.randint(1001,1002)
trainlist1 = [random.randint(3,100),b , random.randint(3,100), random.randint(3,100), random.randint(3,100),b]
trainlist.append(trainlist1)
pass
i1 = len(trainlist)
hidden_errors = 0
for i in range(i1):
targetlist = numpy.zeros(shape=(onodes,1)) + 0.01
targetlist[int(trainlist[i][5])-1001]=0.99
del trainlist[i][5]
inputs = numpy.array(trainlist[i], ndmin=2).T
hiddenin = numpy.dot(ihw, inputs)
hiddenout = special.expit(hiddenin)
outputin = numpy.dot(how, hiddenout)
output = special.expit(outputin)
output_errors = (targetlist - output)
hidden_errors = numpy.dot(how.T,output_errors)
how += lr*numpy.dot((output_errors*output*(1.0-output)),numpy.transpose(hiddenout))
ihw += lr*numpy.dot((hidden_errors*hiddenout*(1.0-hiddenout)),numpy.transpose(inputs))
pass
for i in range(len(inputlist)):
inputs = numpy.array(inputlist[i], ndmin=2).T
hiddenin = numpy.dot(ihw, inputs)
hiddenout = special.expit(hiddenin)
outputin = numpy.dot(how, hiddenout)
output = special.expit(outputin)
I would be really greatfull for some help.
Thanks :)
I'm sorry. Here is the code in its correct form.
import numpy
from scipy import special
import random
inodes = 5
hnodes = 3
onodes = 2
lr = 0.01
# weight factor between input and hidden
ihw = numpy.random.normal(0.0, pow(hnodes, -0.5),(hnodes, inodes))
# weight factor between hidden and output
how = numpy.random.normal(0.0, pow(onodes, -0.5),(onodes, hnodes))
inputlist1 = list()
inputlist = list()
trainlist1 = list()
trainlist = list()
for i in range(100):
# Creating a random List as a test list, with either 1001 or 1002 in the second place
b = random.randint(1001,1002)
inputlist1 = [random.randint(1,100),b ,random.randint(1,100), random.randint(3,100),
random.randint(3,100)]
inputlist.append(inputlist1)
pass
for i in range(10^00):
# Creating a random List as a training list, with either 1001 or 1002 in the second place
b = random.randint(1001,1002)
trainlist1 = [random.randint(3,100),b , random.randint(3,100), random.randint(3,100),
random.randint(3,100),b]
trainlist.append(trainlist1)
pass
i1 = len(trainlist)
hidden_errors = 0
for i in range(i1):
targetlist = numpy.zeros(shape=(onodes,1)) + 0.01
targetlist[int(trainlist[i][5])-1001]=0.99
del trainlist[i][5]
inputs = numpy.array(trainlist[i], ndmin=2).T
hiddenin = numpy.dot(ihw, inputs)
hiddenout = special.expit(hiddenin)
outputin = numpy.dot(how, hiddenout)
output = special.expit(outputin)
output_errors = (targetlist - output)
hidden_errors = numpy.dot(how.T,output_errors)
how += lr*numpy.dot((output_errors*output*(1.0-output)),numpy.transpose(hiddenout))
ihw += lr*numpy.dot((hidden_errors*hiddenout*(1.0-hiddenout)),numpy.transpose(inputs))
pass
for i in range(len(inputlist)):
inputs = numpy.array(inputlist[i], ndmin=2).T
hiddenin = numpy.dot(ihw, inputs)
hiddenout = special.expit(hiddenin)
outputin = numpy.dot(how, hiddenout)
output = special.expit(outputin)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import numpy from scipy import special import random inodes = 5 hnodes = 3 onodes = 2 lr = 0.01 # weight factor between input and hidden ihw = numpy.random.normal( 0.0 , pow (hnodes, - 0.5 ),(hnodes, inodes)) # weight factor between hidden and output how = numpy.random.normal( 0.0 , pow (onodes, - 0.5 ),(onodes, hnodes)) inputlist1 = list () inputlist = list () trainlist1 = list () trainlist = list () for i in range ( 100 ): # Creating a random List as a test list, with either 1001 or 1002 in the second place b = random.randint( 1001 , 1002 ) inputlist1 = [random.randint( 1 , 100 ),b ,random.randint( 1 , 100 ), random.randint( 3 , 100 ), random.randint( 3 , 100 )] inputlist.append(inputlist1) pass for i in range ( 10 ^ 00 ): # Creating a random List as a training list, with either 1001 or 1002 in the second place b = random.randint( 1001 , 1002 ) trainlist1 = [random.randint( 3 , 100 ),b , random.randint( 3 , 100 ), random.randint( 3 , 100 ), random.randint( 3 , 100 ),b] trainlist.append(trainlist1) pass i1 = len (trainlist) hidden_errors = 0 for i in range (i1): targetlist = numpy.zeros(shape = (onodes, 1 )) + 0.01 targetlist[ int (trainlist[i][ 5 ]) - 1001 ] = 0.99 del trainlist[i][ 5 ] inputs = numpy.array(trainlist[i], ndmin = 2 ).T hiddenin = numpy.dot(ihw, inputs) hiddenout = special.expit(hiddenin) outputin = numpy.dot(how, hiddenout) output = special.expit(outputin) output_errors = (targetlist - output) hidden_errors = numpy.dot(how.T,output_errors) how + = lr * numpy.dot((output_errors * output * ( 1.0 - output)),numpy.transpose(hiddenout)) ihw + = lr * numpy.dot((hidden_errors * hiddenout * ( 1.0 - hiddenout)),numpy.transpose(inputs)) pass for i in range ( len (inputlist)): inputs = numpy.array(inputlist[i], ndmin = 2 ).T hiddenin = numpy.dot(ihw, inputs) hiddenout = special.expit(hiddenin) outputin = numpy.dot(how, hiddenout) output = special.expit(outputin) |