Python Forum
First neural network: Problem with the weight factos
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First neural network: Problem with the weight factos
#1
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Neural network and data analysis from clients survey result pthon3 2 1,864 Mar-17-2022, 02:21 AM
Last Post: jefsummers
  Multilayer Perceptron Neural Network erdemath 3 2,282 Aug-09-2021, 11:07 PM
Last Post: jefsummers
  Neural Network importance weights / coefficients jkaustin 1 2,028 Nov-10-2020, 07:44 PM
Last Post: jefsummers
  Get error message in a GAN neural network tutorial jdude50 0 1,648 Oct-22-2020, 11:11 PM
Last Post: jdude50
  Explain Me Neural Network Ai's Harshil 2 1,972 Oct-22-2020, 04:50 AM
Last Post: Harshil
  construction of Neural Network for solving Differential equations arshad 0 1,607 Jun-04-2020, 09:20 AM
Last Post: arshad
  Neural Network mensagem error Dalpi 2 2,826 May-20-2020, 04:03 PM
Last Post: Dalpi
  coding neural network programmer19890620 4 3,391 Feb-27-2020, 04:26 AM
Last Post: programmer19890620
  Why does this simple neural network not learn? PythonIsGreat 1 2,082 Aug-30-2019, 05:49 PM
Last Post: ThomasL
  Neural network nesrine 0 2,613 Dec-11-2018, 03:48 PM
Last Post: nesrine

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020