Jst - Metode Hebb Rule dengan Java
Program sederhana ini akan melakukan training pada tabel AND ataupun OR, yang kemudian dilakukan pengujian untuk pengenalan pola pada salah satu tabel tersebut. metode yang digunakan adalah dengan hebb rule, silahkan untuk dipakai sebagai bahan pembelajaran serta pengembangan.
untuk bacaan materi hebb rule bisa di unduh disini Pengantar.pdf
source code
untuk bacaan materi hebb rule bisa di unduh disini Pengantar.pdf
source code
/*
* Program ini ditulis dikomputer
* Iskandar M. Alawi.
*/
import java.util.*;
/*
*Administrator @ Iskandar M. Alawi
*/
public class HebbRule {
public static void main(String[] args) {
int x11 = 0, x12 = 0;
int x21 = 0, x22 = 0;
int x31 = 0, x32 = 0;
int x41 = 0, x42 = 0;
int t1 = 0, t2 = 0, t3 = 0, t4 = 0;
double w01=0, w02=0;
double w11 = 0, w12;
double w21, w22;
double w31, w32;
double w41, w42;
double y1, y2, y3, y4;
double b01;
double xb11, xb12;
double xb21, xb22;
double xb31, xb32;
double xb41, xb42;
double bb1, bb2, bb3, bb4;
int pili;
int iter=0;
int buji;
double yuji1, yuji2, yuji3, yuji4;
double net1, net2, net3, net4;
Scanner input = new Scanner(System.in);
System.out.println("Contoh Pembelajran JST dengan tabel OR");
System.out.println("--------------------------------------\n");
System.out.println("Masukan dari w1 dan w2 adalah 1 & 0");
System.out.println("\nbatas normal dari nilai w adalah -0.5 - o.5");
System.out.print("Masukkan nilai w1 : ");
w01 = input.nextDouble();
System.out.print("Masukkan nilai w2 : ");
w02 = input.nextDouble();
System.out.print("Masukkan nilai bias/b = ");
b01 = input.nextDouble();
//System.out.print("Masukkan jumlah iterasi : ");
//iterasi = input.nextInt();
System.out.println("\nPilih tabel yang dipake");
System.out.println("1. Tabel AND");
System.out.println("2. Tabel OR");
System.out.print("Tabel yang dipilih adalah : ");
pili = input.nextInt();
switch(pili)
{
case 1:
System.out.println("\nDengan Tabel AND dicari fd");
x11=1; x12=1;
x21=1; x22=0;
x31=0; x32=1;
x41=0; x42=0;
t1= x11 & x12;
t2= x21 & x22;
t3= x31 & x32;
t4= x41 & x42;
break;
case 2 :
System.out.println("\nDengan Tabel OR dicari fd");
x11=1; x12=1;
x21=1; x22=0;
x31=0; x32=1;
x41=0; x42=0;
t1= x11 | x12;
t2= x21 | x22;
t3= x31 | x32;
t4= x41 | x42;
break;
}
// cek tabel
//while(iter <=5)
w11 = x11 * t1; w12= x12 * t1; y1=t1; xb11=w01+w11; xb12=w02+w12; bb1=b01+y1;
w21 = x21 * t2; w22= x22 * t2; y2=t2; xb21=xb11+w21; xb22=xb12+w22; bb2=bb1+y2;
w31 = x31 * t3; w32= x32 * t3; y3=t3; xb31=xb21+w31; xb32=xb22+w32; bb3=bb2+y3;
w41 = x41 * t4; w42= x42 * t4; y4=t4; xb41=xb31+w41; xb42=xb32+w42; bb4=bb3+y4;
System.out.println("tabel iterasi pertama untuk pilihan tabel: " +pili);
System.out.println("x1 x2 t dw1 dw2 db x1b x2b bb");
System.out.println("--------------------------------------------");
System.out.println(+x11+" "+x12+" "+t1+" "+w11+" "+w12+" "+y1+" "+xb11+" "+xb12+" "+bb1);
System.out.println(+x21+" "+x22+" "+t2+" "+w21+" "+w22+" "+y2+" "+xb21+" "+xb22+" "+bb2);
System.out.println(+x31+" "+x32+" "+t3+" "+w31+" "+w32+" "+y3+" "+xb31+" "+xb32+" "+bb3);
System.out.println(+x41+" "+x42+" "+t4+" "+w41+" "+w42+" "+y4+" "+xb41+" "+xb42+" "+bb4);
// uji pengenalan pola
//bias = b01
// b01 >= new y=1
// b01 < net y=0
System.out.print("\nMasukkan bias untuk uji training = ");
buji = input.nextInt();
net1 =(x11*xb41)+(x12*xb42)+bb4;
if (net1>=buji)
yuji1 = 1;
else
yuji1 = 0;
net2 =(x21*xb41)+(x22*xb42)+bb4;
if (net2>=buji)
yuji2 = 1;
else
yuji2 = 0;
net3 =(x31*xb41)+(x32*xb42)+bb4;
if (net3>=buji)
yuji3 = 1;
else
yuji3 = 0;
net4 =(x41*xb41)+(x42*xb42)+bb4;
if (net4>=buji)
yuji4 = 1;
else
yuji4 = 0;
System.out.println("\ntabel yg dipilih uji training thd data");
System.out.println("x1 x2 net y(uji)");
System.out.println("--------------------");
System.out.println(+x11+" "+x12+" "+net1+" "+yuji1);
System.out.println(+x11+" "+x12+" "+net2+" "+yuji2);
System.out.println(+x11+" "+x12+" "+net3+" "+yuji3);
System.out.println(+x11+" "+x12+" "+net4+" "+yuji4);
if ((t1==yuji1)&&(t2==yuji2)&&(t3==yuji3)&&(t4==yuji4))
System.out.println("\nJST Mengenali POLA");
else
System.out.println("\nJST TIDAK Mengenali POLA");
}}
Comments
Post a Comment
Please Don't make SPAM HERE !