Bottom Page

• 1 Vote(s) - 1 Average
• 1
• 2
• 3
• 4
• 5
 First neural network: Problem with the weight factos 11112294 Unladen Swallow Posts: 1 Threads: 1 Joined: Jan 2019 Reputation: 0 Likes received: 0 #1 Jan-12-2019, 09:11 PM (This post was last modified: Jan-12-2019, 09:23 PM by 11112294.) 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) ```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) ``` « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Neural network nesrine 0 228 Dec-11-2018, 03:48 PM Last Post: nesrine Developing larger Neural Networks Chriskelm 2 404 Nov-03-2018, 02:47 AM Last Post: brighteningeyes neural network- undefined name with sigmoid function kierie_001 0 309 Oct-18-2018, 04:08 PM Last Post: kierie_001 [neural netrowks]How do i resume training once i have saved the model Prince_Bhatia 0 441 Aug-07-2018, 05:01 AM Last Post: Prince_Bhatia Neural Network Enlargement philphed 3 560 Jul-11-2018, 06:52 AM Last Post: buran Need help with Python + Neural Net Coding ThanosTitan 0 625 Jan-22-2018, 01:25 PM Last Post: ThanosTitan

Forum Jump:

Users browsing this thread: 1 Guest(s)