Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Trouble with Neural Network coding

  1. Aug 13, 2013 #1
    I'm trying to make a neural network in python, but I'm having a lot of trouble. Specifically after I have the network set up, what weights to initially assign to each neuron's inputs, the threshold, and evolving the networks to do what you want.

    Here is my neuron class.

    Code (Text):
    class Neuron:
        def __init__(self, inputs):
            self.k = inputs
            self.t = random.gauss(0,10)
            self.b = 1
            self.x_avg = inputs**-1
            self.x = []
            for a in range(0,inputs):
                #self.x.append(self.x_avg)
                self.x.append(random.gauss(0,10))
        def clear(self):
            self.x = []
            self.b = 1
            self.x_avg = 0
        def out(self,*insa):
            y = []
            ins=insa[0]
            for a in ins:
                y.append(a*self.x[ins.index(a)])
            sums = sum(y)-self.t
            out = (1+e**-sums)**-1
            return out
       
        #def update(self, x_index):
        #def update(perchange):
        def reset(self):
            self.t = random.gauss(0,10)
            self.x =[]
            for a in range(0,self.k):
                #self.x.append(self.x_avg)
                self.x.append(random.gauss(0,10))
        #def update(self, branch, val):
           
    I am wondering what I should be setting my initial input weights to be? nothing seems to be working...
     
  2. jcsd
  3. Aug 15, 2013 #2
    Usually, if my neural net hasn't lost too many brain cells, weights are initially set to random values. But the distribution or range of values can depend on the functions you are using inside your neurons.

    Google for
    neural network initial weights
    and see that this is an active area of research with what look like reasonable suggestions for you

    If nothing seems to be working with your code then I would suggest trying a VERY simple net, with perhaps only one or two neurons and an extremely simple goal you are certain that one or two neurons is sufficient to learn. Track the learning process as you resent each example to it and see that it seems to be mostly converging in the right direction. When you make the problem simple enough that sometimes helps make it possible to discover the errors.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Trouble with Neural Network coding
Loading...