Trouble with Neural Network coding

In summary, the conversation discusses the process of making a neural network in python and the issues faced in setting the initial input weights. It is suggested to research and experiment with different initial weight distributions, as well as starting with a simple network to track the learning process.
  • #1
saminator910
96
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:
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...
 
Technology news on Phys.org
  • #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.
 

Related to Trouble with Neural Network coding

1. What is a neural network?

A neural network is a type of artificial intelligence that is designed to mimic the way the human brain processes information. It is composed of interconnected nodes or neurons that work together to perform complex tasks such as image recognition, language translation, and predictive analysis.

2. What are some common challenges in coding neural networks?

Some common challenges in coding neural networks include choosing the right architecture, selecting appropriate activation functions and learning rates, dealing with overfitting, and determining the best approach for input data preprocessing.

3. How do you troubleshoot issues with neural network coding?

To troubleshoot issues with neural network coding, it is important to first identify the source of the problem. This could involve checking the data inputs, reviewing the code for errors, or experimenting with different hyperparameters. It is also helpful to consult with other experts and refer to online resources for guidance.

4. Can neural networks be used for any type of problem?

Neural networks can be used for a wide range of problems, including classification, regression, and pattern recognition. However, they may not always be the best approach and other machine learning methods such as decision trees or support vector machines may be more suitable for certain types of problems.

5. How can I improve the performance of my neural network?

To improve the performance of a neural network, you can try adjusting the hyperparameters, increasing the amount of training data, or using different types of neural network architectures. It is also important to regularly evaluate and fine-tune the model to ensure it is performing optimally.

Similar threads

  • Programming and Computer Science
Replies
2
Views
935
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
34
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top