December 30, 2010

Forward And Reverse Pass Neural Network


Jawab
Forward Pass
Input to top neuron = (0.7 x 0.1)+(0.7 x 0.5) =0.36
= 1/(1+e^(-0,36) )
= 0.5890
Input to bottom Neuron = (0.7 x 0.2) + (0.1 x 0.3) = 0.169
= 1/(1+e^(-0,169) )
= 0.54239
Final Output = 0.5890 + 0.5890 = 0.698
= 1/(1+e^(-0,698) )
= 0.54290

Reverse Pass
Nilai target = 1
Output Error ð = (t-o)(1-o) = (1-0.54290)(1-0.54290) = 0.1134
New weights for output layers
W1+ = w1 + (ð x input) = 0.2 +(0.1134 x 0.36) = 0.2408
W2+ = w1 + (ð x input) = 0.1 + (0.1134 x 0.169) = 0.11928
Error for hidden layers
ð1 = ð x w1 = (0.1134 x 0.2408) x (1-o)o = 0.0068
ð2 = ð x w1 = (0.1134 x 0.11928) x (1-o)o = 0.00336
New hidden layers
W3+ = 0.1 + (0.0068 x 0.1) = 0.10000068
W4+ = 0.5 + (0.0068 x 0.7) = 0.500004746
W5+ = 0.3 + (0.00336 x 0.1) = 0.300000336
W6+ = 0.2 + (0.00336 x 0.1) = 0.200002350

Source code menghitung Forward & Reverse menggunakan bahasa pemrograman Java
public class ForwardAndReversePass {
//inputA
double inputA=0.1;
//inputB
double inputB=0.7;
//to topneuron
double inputAtoTopNeuron=0.1;
double inputBtoTopNeuron=0.5;
//to bottomneuron
double inputAtoBottomNeuron=0.3;
double inputBtoBottomNeuron=0.2;
//from topNeuron
double fromTopNeuron=0.2;
//from bottomneuron
double fromBottomNeuron=0.1;
public void ForwardReversePass(){
double powN1;
double powN2;
double powFneuron;
double e=Math.exp(1);
//------------------FORWARD PASS------------------------
//logika menghitung topNeuron
double finalTopNeuron=(inputA*inputAtoTopNeuron)+(inputB*inputBtoTopNeuron);
//logika menghitung bottomNeuron
double finalBottomNeuron=(inputB*inputBtoBottomNeuron)+(inputA*inputAtoBottomNeuron);
//logika memangkatkan Exp dg hasil totopNeuron
powN1=Math.pow(e,-finalTopNeuron);
//logika memangkatkan Exp dg hasil tobottomNeuron
powN2=Math.pow(e, -finalBottomNeuron);
//logika menghitung Final neuron
double finalNeuron=(1/(1+powN1)*fromTopNeuron)+(1/(1+powN2)*fromBottomNeuron);
//logika memangkatkan e dg - nilai finalNeuron
powFneuron=Math.pow(e, -finalNeuron);
//logika menghitung final output 1/1+e pangkat -nilai finalNeuron
double finalOutput=1/(1+powFneuron);

//------------------REVERSE PASS------------------------
double SepuluhPangkatMinTiga=Math.pow(10,-3);
//variable Nilai target
double Target=1;
//Logika mencari Output error
double OutputError=(Target-finalOutput)*(1-finalOutput)*finalOutput;
//Logika New Weight for output layer
double w1plus=fromTopNeuron+(OutputError*finalTopNeuron);
double w2plus=fromBottomNeuron+(OutputError*finalBottomNeuron);
//Logika Error for hidden layer
double δ1=OutputError*w1plus*((1*finalOutput)-(finalOutput*finalOutput));
double δ2=OutputError*w2plus*((1*finalOutput)-(finalOutput*finalOutput));
//Logika new hidden layer weight
double w3plus=inputAtoTopNeuron+(δ1*SepuluhPangkatMinTiga*inputA);
double w4plus=inputBtoTopNeuron+(δ1*SepuluhPangkatMinTiga*inputB);
double w5plus=inputAtoBottomNeuron+(δ2*SepuluhPangkatMinTiga*inputA);
double w6plus=inputBtoBottomNeuron+(δ2*SepuluhPangkatMinTiga*inputB);
_______________________________________________
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ForwardAndReversePass fr=new ForwardAndReversePass();
fr.ForwardReversePass();
}

}

Di bawah ini adalah hasil eksekusi program yang telah dibuat


untuk download project-nya klik disini
Read More......

December 8, 2010

Program Menghitung Forward Artificial Neural Network menggunakan Java

Soal 1 Single Layer Neuron
 Jawab:

Inputs x Weights = (0.5 x 0.3)+(0.1 x 0.6)+(0.6 x 0.7) = 0.63
Output                = 1/1+(e^−0.63)
                           = 1.533
Soal 2 Tiga Layer Neuron
 Jawab:
Input to Neuron 1 = (0.6 x 0.6)+(0.1 x 0.1) = 0.37
                            = 1/1+(e^−0.37) = 0.5914
Input to Neuron 2 = (0.1 x 0.3)+(0.1 x 0.5) =0.33
                            = 1/1+(e^−0.33) = 0.5817
Final Output         = (0.5914)+(0.5817) = 0.823
                            = 1/1+(e^−0.823) = 0.587
Tuh soal dari dosen-q disuruh bikin program menggunakan bahasa pemrograman tingkat tinggi untuk menghitung Nilai Neuron pada soal no 1 dan 2, nah saya membuat program tersebut menggunakan Java
Ini dia Caranya...

Pertama membuat singleLayerNeuron.class
untuk membuat program Soal 1 ne source code nya


package neuron;
import javax.swing.JOptionPane;
/**
 *
 * @author Udin
 */
public class singleLayerNeuron {
   
double input1=0.5,input2=0.1,input3=0.6;
double weight1=0.3,weight2=0.6,weight3=0.7;

public void OutputSingleLayerNeouron(){
    double pow;
    double e=Math.exp(1);
    double hasilJumlah;
    double output;
//logika menjumlahkan inputs dan weights
hasilJumlah=(input1*weight1)+(input2*weight2)+(input3*weight3);
//logika memangkatkan e- jumlah input dan weight
pow=Math.pow(e,-hasilJumlah);
//logika output 1/1+ e yg sudah dipangkat - jumlah inputs dan weights
output=1/1+pow;
}
}
___________________________________________________________________________

Kedua membuat tigaLayerNeuron.class
untuk membuat program Soal 2
 
package neuron;
import javax.swing.JOptionPane;
/**
 *
 * @author Udin
 */
public class tigaLayerNeuron {
//input1
 double input1=0.6;  
//input2
 double input2=0.1;      
//to neuron1
 double input1toNeuron1=0.6;
 double input2toNeuron1=0.1;
//to neuron2
 double input1toNeuron2=0.5;
 double input2toNeuron2=0.3;
//from Neuron1
 double fromNeuron1=0.4;
//from neuron2
 double fromNeuron2=0.2;
//output
 double output;

 public void outputTigaLayerNeuron(){
      double powN1;
      double powN2;
      double powFneuron;
      double e=Math.exp(1);
   //logika menghitung  Neuron 1
     double toNeuron1=(input1*input1toNeuron1)+(input2*input2toNeuron1);
   //logika menghitung Neuron 2
     double toNeuron2=(input2*input2toNeuron2)+(input1*input1toNeuron2);
   //logika memangkatkan Exp dg hasil toNeuron1
     powN1=Math.pow(e,-toNeuron1);
   //logika memangkatkan Exp dg hasil toNeuron2
     powN2=Math.pow(e, -toNeuron2); 
  //logika menghitung Final neuron
    double finalNeuron=(1/(1+powN1)*fromNeuron1)+(1/(1+powN2)*fromNeuron2);
  //logika memangkatkan e dg - nilai finalNeuron
    powFneuron=Math.pow(e, -finalNeuron);
 //logika menghitung final output 1/1+e pangkat -nilai finalNeuron
    double finalOutput=1/(1+powFneuron);
 }
}

______________________________________________________________________
Ketiga membuat  Main.class
untuk memanggil program Soal1 dan Soal 2, agar saat dicompile bisa tampil.



package neuron;

import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
 *
 * @author Udin
 */
public class Main {

    public static void main(String[] args) {
        int jenisNeuron=0;
        String input="";
        int n;
    singleLayerNeuron sln=new singleLayerNeuron();
        tigaLayerNeuron tln=new tigaLayerNeuron();
        input= JOptionPane.showInputDialog("        ---LAYER NEURON---\n\n" +
                "1 = Single Layer Neuron \n2 = Tiga Layer Neuron\n");
        jenisNeuron=Integer.parseInt(input);
       
    try{
    if(jenisNeuron==1){    
    sln.OutputSingleLayerNeouron();
    }else if(jenisNeuron==2){
    tln.outputTigaLayerNeuron();
    } else if(jenisNeuron<1 || jenisNeuron>2)
    JOptionPane.showMessageDialog(null,"Tidak ada Pilihan ");
   
    JFrame frame=new JFrame();
    n=JOptionPane.showConfirmDialog(frame,"Kembali ke Menu Utama?","Komfirmasi",JOptionPane.YES_NO_OPTION);
    if(n==0)
       Main.main(args);
    else
        JOptionPane.showMessageDialog(null,"Anda sudah Keluar");
    } catch(NumberFormatException e){
      JOptionPane.showMessageDialog(null,"Selesai");
    }
    }
}


pastikan semua class tersebut berada dalam satu package Neuron
nah... setelah membuat program tersebut.. coba dech compile,   seperti ini neh.. hasilnya
coba inputkan angka 1 lalu OK, maka yang muncul adalah single Layer neuron sesuai dengan pilihan

dan jika menginputkan dua, berarti mau liat hasil Tiga Layer neuron

jika di klik OK, maka ada penawaran mau balik ke Menu Utama ga? hehe...seperti ini ne..
 jika dikli Milih Yes maka akan balik ke Menu Utrama dech (Gambar pertama), jika No maka Akan keluar
untuk download project-nya klik disini
Kawan Thanks ya.. n selamat mencoba Okey.. :)
Read More......