java - why this code runs out of order -


this code , gave inputs follows, removed step of giving actual output value user, calculated in code, still same thing happens

"1" 1st input "0.5" 1st inputs weight "0" second input "0.6" weight "0" desired output "0.002" defined value "0.23" learning rate.

 package neural4copy;  import java.util.scanner;  import java.lang.math;  public class demo {      // inputs declared     private int x[][]=new int[1][2];     //weights declared     private double w[][]=new double[1][2];     private double temp;      private double z[]=new double[1];     private double desiredoutput;     private double actualoutput;     private double error;     private double definedvalue=0.004;     private double weightchange[][]=new double[1][2];     private double learningrate;     private double epilision=0.000000001;     private static double ztotal;      private scanner user_input= new scanner(system.in);      public void getdata(){          for(int j=0;j<x.length;j++){             for(int i=0;i<x[0].length;i++){                 system.out.println("enter "+j+"th neuron "+i+"th input values :");                 x[j][i]=user_input.nextint();                 system.out.println("enter "+j+"th neuron "+i+" weight of input value :");                 w[j][i]=user_input.nextdouble();             }         }          system.out.println("enter desired output :");         desiredoutput=user_input.nextdouble();          system.out.println("enter defined value checking condition");         definedvalue=user_input.nextdouble();          system.out.println("enter learning rate");         learningrate=user_input.nextdouble();          calculate();       }      public void calculate(){          for(int j=0;j<x.length;j++){             for(int i=0; i<w[0].length; i++){                 temp=0;                 temp=x[j][i]*w[j][i];                 z[j]+=temp;              }             ztotal+=z[j];             system.out.println("temp value :"+ztotal);         }             system.out.println("ztotal "+ztotal);          //double negz= -ztotal;          double temp2=1+math.exp(-ztotal);         actualoutput=1/temp2;         //actualoutput=1/(1+math.exp(-ztot));           system.out.println("actualoutput "+actualoutput);          if(math.abs(actualoutput-desiredoutput)>epilision){              calculateerror();         }         else{             printweights();         }           }       public void calculateerror(){         system.out.println("desired out put :"+desiredoutput+" actual out put :"+actualoutput);         error=0.5*((desiredoutput-actualoutput)*(desiredoutput-actualoutput));         system.out.println("error "+error+"\n\n");          //error=0.003;            checkingcondition();      }      public void checkingcondition(){          if(error<definedvalue){              printweights();         }         else{              balanceweights();         }      }       public void balanceweights(){          //system.out.println("new weights are");         for(int j=0;j<w.length;j++){              for(int i=0;i<w[0].length;i++){                  weightchange[j][i]=(-learningrate)*(desiredoutput-actualoutput)*actualoutput*(1-actualoutput)*x[j][i];                 system.out.println("weight change "+weightchange[j][i]);                 w[j][i]+=weightchange[j][i];                  //system.out.print(w[i]+"\t");             }          }         calculate();         }      public void printweights(){         system.out.print("the balanced weights are: ");           for(int j=0;j<x.length;j++){             for(int i=0;i<x[0].length;i++){                 system.out.println("neuron "+j+"weight of input"+i+"=\t"+w[j][i]);             }          }       }    } 

but codes runs out of order, out printing out ztotal first coded in calculate() method. , output start ztotal 335851.72992330056 value not possible,and error doesnot change keep value 0.5 , finall "stackoverflowerror" occurs. why this

this top part of output

weight change 0.0 ztotal :348355.7408125164 temp value :348986.9403243046 ztotal 348986.9403243046 actualoutput 1.0 desired out put :0.0 actual out put :1.0 error 0.5   weight change 0.0 weight change 0.0 ztotal :348986.9403243046 temp value :349618.7111663145 ztotal 349618.7111663145 actualoutput 1.0 desired out put :0.0 actual out put :1.0 error 0.5   weight change 0.0 weight change 0.0 ztotal :349618.7111663145 temp value :350251.053338546 ztotal 350251.053338546 actualoutput 1.0 desired out put :0.0 actual out put :1.0 error 0.5   weight change 0.0 weight change 0.0 ztotal :350251.053338546 temp value :350883.96684099914 ztotal 350883.96684099914 actualoutput 1.0 desired out put :0.0 actual out put :1.0 error 0.5 

ztotal :348355.7408125164 why starts @ high value

i see these values you're getting they're not @ beginning of output, they're further down. see: http://ideone.com/06kymj

at top of output, see:

temp value :0.5 ztotal 0.5 actualoutput 0.6224593312018546 desired out put :0.0 actual out put :0.6224593312018546 error 0.19372780950013005 

this down way output displayed. environments show last few thousand lines , top cut off.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -