Algoritma Hebbian
Algoritmanya :
1. Inisialisasi semua bobot:
wij = 0; dengan i = 1,2,3,...,n; dan j = 1,2,3,...,m;
2. Untuk setiap pasangan input s dan target t, lakukan langkah-langkah sebagai
berikut:
a. Set input dengan nilai sama dengan vektor input:
xi = si; (i=1,2,3,...,n)
b. Set output dengan nilai sama dengan vektor output:
yj = tj; (j=1,2,3,...,m)
c. Perbaiki bobot:
wij(baru) = wij(lama) + xi * yj;
(i=1,2,3,...n; dan j=1,2,3,...,m)
d. Perbaiki bias menurut persamaan b(baru) = b (lama) + y
Program Hebbian
Nama File : Hebb.java
public class Hebb {
private int[][] inputData;
private int[] weights;
private int[] targets;
private int bias;
private int output;
public Hebb(){
defineWeights();
defineBias();
defineInputData();
defineTargets();
printData();
printBobotAwal();
modificationWeight();
}
private void printBobotAwal(){
System.out.println("Bobot awal dan bias : "+weights[0]+" "+weights[1]+" "+bias);
}
public void recognize(int x1, int x2){
int net = 0;
net = x1 * weights[0] + x2 * weights[1] + bias;
System.out.println("input "+x1+" dan "+x2+" hasilnya "+ fungsiAktifasi(net));
}
private int fungsiAktifasi(int net){
if(net>=0)return 1;
else return -1;
}
private void printData(){
System.out.print("Data inputan : \n");
System.out.print(" x1 x2 t \n");
for(int i=0;i<4;i++){
for(int j=0;j<2;j++){
System.out.print(" "+inputData[i][j]);
}
System.out.print(" "+targets[i]+"\n");
}
System.out.println();
}
private void modificationWeight(){
System.out.println("Hitung bobot : x1 x2 bias ");
for(int i=0;i<4;i++){
System.out.print("Bobot baru : ");
for(int j=0;j<2;j++){
weights[j] = weights[j] + targets[i] * inputData[i][j];
System.out.print(" "+weights[j]);
}
bias = bias + targets[i];
System.out.print(" "+bias+"\n");
}
}
private void defineWeights(){
weights = new int[2];
for(int i=0;i
weights[i] = 0;
}
}
private void defineBias(){
bias = 0;
}
private void defineTargets(){
targets = new int[4];
targets[0] = -1;
targets[1] = -1;
targets[2] = -1;
targets[3] = 1;
}
private void defineInputData(){
inputData = new int[4][2];
inputData[0][0] = -1;
inputData[0][1] = -1;
inputData[1][0] = -1;
inputData[1][1] = 1;
inputData[2][0] = 1;
inputData[2][1] = -1;
inputData[3][0] = 1;
inputData[3][1] = 1;
}
}
Nama File : Main.java
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Hebb h = new Hebb();
h.recognize(-1, -1);
h.recognize(-1, 1);
h.recognize(1, -1);
h.recognize(1, 1);
}
}
0 komentar:
Post a Comment
Tinggalkan Komentarmu Sob.