0

I'm trying to realize a programme that recognizes images using a neural network with 1 hidden layer. The User is supposed to draw a number and the NN must recognize it. And i'm having some trouble

So I get a 2d array which where 1 is a filled in pixel and vice-versa. I transform that 2d into 1d. Every element of a 1d array turns into a input neuron. I have 16 hidden neurons and 10 output neurons.

As i understand. I need to get the output neuron in the appropriate position to have an Error function of 0.

My looks something like this. Where lvl 1 is input layer, lvl2 - hidden layer, lvl3 - output layer. Eventually, one of the outputs errors gets to around 0, but not the necessary one. The desired array has a 1 in the position in the poistion of the goal function.

Is there something wrong with the logic I implemented?

   public void learn(int[] desired){
     for(int i =0;i<Nl3;i++)
        lvl3.get(i).SetDesired(desired[i]);

     boolean b = false;

    while(true && !b){

      for(Neuro n : lvl3)   
             n.CountError();
       CountL2Errors();
       AdjustWeights(); 

       int i = 0;
        for(Neuro n : lvl3){
            i++;
         if(n.Error < 0.00005 &&  n.Error > -0.00005){
          System.out.println(i+" "+n.Error);
           b = true;
         }
        }

    }
      System.out.println("go");
    }

Im sorry for the sloppy writing, I'm horribly sleepy and this isn't my native language.

private void CountL2Errors(){ 
    for(int i = 0;i<lvl2.size();i++){
       float E = 0;
       for(int j = 0;j<lvl3.size();j++){
         E +=  lvl2.get(i).GetConnectionWeight(j)*lvl3.get(j).Error;
       }
        lvl2.get(i).SetW(E);
    }
}

Lr = 0.2
private void AdjustWeights(){
     for(int i = 0;i<lvl1.size();i++){

       for(int j = 0;j<lvl2.size();j++){
           float w =  lvl1.get(i).GetConnectionWeight(j)*LR*lvl2.get(j).Error*lvl1.get(i).GetOutput();
          lvl1.get(i).SetConnectionWeight(j, w);
       }

    }
Greenmachine
  • 292
  • 1
  • 15

0 Answers0