Professional Documents
Culture Documents
Pada MATLAB, fungsi yang dipakai untuk membangun jaringan perceptron adalah newp. Perintah newp akan membuat sebuah perceptron dengan spesifikasi tertentu (jumlah unit input, jumlah neuron,fungsi aktivasi, dll) Fungsi : net = newp(PR,S) net = newp(PR,S,TF,LF) PR: matriks berukuran Rx2 yang berisi nilai minimum dan maksimum, dengan Radalah jumlah variabel input (ada R buah masukan) S : jumlah neuron (target) TF: fungsi aktivasi biner(defaultnya adalah fungsi treshold, dalam MATLAB disebut hardlim) LF: Fungsi pembelajaran (default : learnp, dipakai untuk mengubah bobot sehingga diperoleh bobot yang mendekati target) Arsitektur jaringan terlihat seperti gambar berikut :
Berarti input pertama jaringan syaraf ini memiliki nilai minimum 0 dan nilai maksimum 1, demikian pula, input kedua memiliki nilai minimum 0 dan maksimum 1.
% mengetahui ukuran output jaringan syaraf ini >> JumlahOutput=net.outputs{1}.size JumlahOutput = 1
% mengetahui ukuran bias jaringan syaraf ini >> JumlahBias=net.biases{1}.size % mengetahui ukuran bias jaringan syaraf ini JumlahBias = 1 % mengetahui jumlah bobot input pada jaringan syaraf ini >> JumlahBobotInput=net.inputWeights{1}.size JumlahBobotInput = 1 2
% mengetahui bobot-bobot input pada jaringan syaraf ini >> BobotInput=net.IW{:} BobotInput = 0 0 %mengetahui jumlah lapisan pada jaringan syaraf ini >> JumlahBobotLapisan=net.LW{:} JumlahBobotLapisan = [] % mengetahui bobot-bobot bias pada jaringan ini >> BobotBias=net.b{1} BobotBias = 0
Menggambar hubungan antara vektor input dengan vektor target pada perceptron menggunakan perintah plotpv.
>> P=[0 0 1 1;0 1 0 1]; >> T=[0 0 1 0]; >> plotpv(P,T);
net=newp([0 1;0 1],1); net.IW{1,1}=[-0.8 -1.3]; net.b{1}=0.6; P=[0 0 1 1;0 1 0 1]; T=[0 0 1 0]; plotpv(P,T);
% jaringan syaraf yang ada dikembalikan sesuai inisialisasi fungsinya >> net=init(net); >> net.IW{1,1} ans = 0 0 >> net.b{1}
ans = 0
% mencari mean square >> EmEsE=mse(E); >> BobotInputAkhir=net.IW{1,1} % tampilkan hasil BobotInputAkhir = 1 -2
>> MSE=EmEsE MSE = 0.2500 >> >> >> >> >> >> >> >> >> >> >> >> %pelatihan dengan nilai epoh di ubah menjadi 4 P=[0 0 1 1;0 1 0 1]; T=[0 0 1 0]; net=newp(minmax(P),1); net=init(net); % nilai epoh diubah menjadi 4 net.adaptParam.passes=4; [net,Y,E]=adapt(net,P,T); plotpv(P,T); plotpc(net.IW{1,1},net.b{1}); EmEsE=mse(E); BoboInputAkhir=net.IW{1,1}
BoboInputAkhir = 1 -2
>> BoboBiasAkhir=net.b{1} BoboBiasAkhir = -1 >> MSE=EmEsE MSE = 0 >> % simulasi input data baru tertentu terhadap jaringan syaraf yang telah selesai melakukan pembelajaran >> a=sim(net,[1;0]) a = 1 >> a=sim(net,[1;1]) a = 0 >> a=sim(net,[0;0]) a = 0 >> a=sim(net,[0;1])
a = 0 % informasi tentang output jaringan, error adaptasi, bobot input, bobot bias, dan mean square error pada setiap epoh, dan menyimpannya dalam file HasilPerceptron.m >> fb=fopen('HasilPerceptron.m','w'); >> P=[0 0 1 1;0 1 0 1]; >> [m n]=size(P); >> fprintf(fb,'Data input (P):\n') ans = 16 >> for i=1;n, fprintf(fb,'%d %d\n',P(:,i)); end; n = 4 >> >> >> >> >> >> >> >> %Target T=[0 0 1 0]; fprintf(fb,'Target (T):\n'); fprintf(fb,'%d\n',T); %bentuk jaringan syaraf dengan perceptron net=newp(minmax(P),1); plotpv(P,T); linehandle=plotpc(net.IW{1},net.b{1});
>> %set eror awal E=1 >> E=1; >> >> >> >> >> >> >> %kembalikan nilai bobot sesiau inisialisasi fungsinya net=init(net); fprintf(fb,'Bobot Input Awal(w):%4.2f %4.2f\n',net.IW{1,1}); fprintf(fb,'Bobot Bias Awal(b):%4.2f\n',net.b{1}); linehandle=plotpc(net.IW{1},net.b{1}); Epoh=0; MaxEpoh=100;
>> %pembelajaran kerjakan sampai sum squere eror(SSE)=0 atau epoh>maxEpoh >> while(sse(E)&(Epoh<MaxEpoh)), fprintf(fb,'\n'); Epoh=Epoh+1; fprintf(fb,'Epoh ke-%1d \n',Epoh); [net,Y,E]=adapt(net,P,T); fprintf(fb,'Output Jaringan (Y):'); for i=1:n, fprintf(fb,'%1d',E(i)); end; fprintf(fb,'\n'); fprintf(fb,'Eror Adapatasi (E):'); for i=1:n, fprintf(fb,'%1d',E(i)); end; fprintf(fb,'\n'); fprintf(fb,'Bobot Input Baru (W):%4.2f %4.2f \n',net.IW{1,1}); fprintf(fb,'Bobot Bias Baru (b) : %4.2f \n',net.b{1}); fprintf(fb,'Sum Square Error (SSE):%4.2f \n',sse(E)); linehandle=plotpc(net.IW{1},net.b{1},linehandle); drawnow; >> Y E pause(2);
end;
Y = 1 E = -1 Y = 0 E = 0 Y = 0 E = 0 Y = 0 E = 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 -1 0 -1 1 1 1
>> fprintf(fb,'\n'); >> fprintf(fb,'Bobot Input Akhir (W):%4.2f %4.2f \n',net.IW{1,1}); >> fprintf(fb,'Bobot Bias Akhir (b):%4.2f \n',net.b{1}); >> %vektor yang akan disimulasikan >> p=[0.5 0.1 0.7 0.2 0.5; 0.5 0.1 0.1 0.4 0.3]; >> %simulasi >> a=sim(net,p) a = 0 >> >> >> >> >> >> >> >> >> 0 0 0 0
plotpv(p,a); ThePoint=findobj(gca,'type','line'); set(ThePoint,'Color','green'); pause(2); hold on; plotpv(P,T); plotpc(net.IW{1},net.b{1}); hold off; fclose(fb);
HasilPerceptron.m
Data input (P): 0 0 0 1 1 0 1 1 Target (T): 0 0 1 0 Bobot Input Awal(w):0.00 0.00 Bobot Bias Awal(b):0.00 Epoh ke-1 Output Jaringan (Y):-1-10-1 Eror Adapatasi (E):-1-10-1 Bobot Input Baru (W):-1.00 -2.00 Bobot Bias Baru (b) : -3.00 Sum Square Error (SSE):3.00 Epoh ke-2 Output Jaringan (Y):0010 Eror Adapatasi (E):0010 Bobot Input Baru (W):0.00 -2.00 Bobot Bias Baru (b) : -2.00 Sum Square Error (SSE):1.00 Epoh ke-3 Output Jaringan (Y):0010 Eror Adapatasi (E):0010 Bobot Input Baru (W):1.00 -2.00 Bobot Bias Baru (b) : -1.00 Sum Square Error (SSE):1.00 Epoh ke-4 Output Jaringan (Y):0000 Eror Adapatasi (E):0000 Bobot Input Baru (W):1.00 -2.00 Bobot Bias Baru (b) : -1.00 Sum Square Error (SSE):0.00 Bobot Input Akhir (W):1.00 -2.00 Bobot Bias Akhir (b):-1.00