Bab I Mcculloch-Pitts Neuron: %program % Illustration of Various Activation Functions Used in NN's
Bab I Mcculloch-Pitts Neuron: %program % Illustration of Various Activation Functions Used in NN's
Bab I Mcculloch-Pitts Neuron: %program % Illustration of Various Activation Functions Used in NN's
Mcculloch-Pitts neuron
Fungsi aktivasi
%Program
% Illustration of various activation functions used in NN's
x = -10:0.1:10;
tmp = exp(-x);
y1 = 1./(1+tmp);
y2 = (1-tmp)./(1+tmp);
y3 = x;
subplot(221); plot(x, y1); grid on;
axis([min(x) max(x) -2 2]);
title('Logistic Function');
xlabel('(a)');
axis('square');
subplot(222); plot(x, y2); grid on;
axis([min(x) max(x) -2 2]);
title('Hyperbolic Tangent Function');
xlabel('(b)');
axis('square');
subplot(223); plot(x, y3); grid on;
axis([min(x) max(x) min(x) max(x)]);
title('Identity Function');
xlabel('(c)');
axis('square');
0 0
-2 -2
-10 0 10 -10 0 10
(a)
Identity Function (b)
10
-10
-10 0 10
(c)
Contoh 2. Diberikan fungsi and sebagai berikut
Fungsi aktivasi
Program
%AND function using Mcculloch-Pitts neuron
clear;
clc;
%Getting weights and threshold value
disp('Enter weights');
w1=input('Weight w1=');
w2=input('weight w2=');
disp('Enter Threshold Value');
theta=input('theta='); % threshold
x1=[0 0 1 1];
x2=[0 1 0 1];
z=[0 0 0 1];
con=1;
while con
zin=x1*w1+x2*w2;
for i=1:4
if zin(i)>=theta
y(i)=1;
else
y(i)=0;
end
end
disp('Output of Net');
disp(y);
if y==z
con=0;
else
disp('Net is not learning enter another set of weights and Threshold
value');
w1=input('weight w1=');
w2=input('weight w2=');
theta=input('theta=');
end
end
disp('Mcculloch-Pitts Net for AND function');
disp('Weights of Neuron');
disp(w1);
disp(w2);
disp('Threshold value');
disp(theta);
Enter weights
Weight w1=1
weight w2=1
Enter Threshold Value
theta=2
Output of Net
0 0 0 1
Mcculloch-Pitts Net for AND function
Weights of Neuron
1
1
Threshold value
2
Contoh 3. Fungsi XOR menggunakan McCulloch-Pitts neuron
Solution The truth table untuk fungsi XOR :
X1 X2 Y
0 0 0
0 1 1
1 0 1
1 1 0
Program
%XOR function using McCulloch-Pitts neuron
clear;
clc;
%Getting weights and threshold value
disp('Enter weights');
w11=input('Weight w11=');
w12=input('weight w12=');
w21=input('Weight w21=');
w22=input('weight w22=');
v1=input('weight v1=');
v2=input('weight v2=');
disp('Enter Threshold Value');
theta=input('theta='); % thershold
x1=[0 0 1 1];
x2=[0 1 0 1];
z=[0 1 1 0]; % target
con=1;
while con
zin1=x1*w11+x2*w21;
zin2=x1*w21+x2*w22;
for i=1:4
if zin1(i)>=theta
y1(i)=1;
else
y1(i)=0;
end
if zin2(i)>=theta
y2(i)=1;
else
y2(i)=0;
end
end
yin=y1*v1+y2*v2;
for i=1:4
if yin(i)>=theta;
y(i)=1;
else
y(i)=0;
end
end
disp('Output of Net');
disp(y);
if y==z
con=0;
else
disp('Net is not learning enter another set of weights and Threshold value');
w11=input('Weight w11=');
w12=input('weight w12=');
w21=input('Weight w21=');
w22=input('weight w22=');
v1=input('weight v1=');
v2=input('weight v2=');
theta=input('theta=');
end
end
disp('McCulloch-Pitts Net for XOR function');
disp('Weights of Neuron Z1');
disp(w11);
disp(w21);
disp('weights of Neuron Z2');
disp(w12);
disp(w22);
disp('weights of Neuron Y');
disp(v1);
disp(v2);
disp('Threshold value');
disp(theta);
Output
Enter weights
Weight w11=1
weight w12=-1
Weight w21=-1
weight w22=1
weight v1=1
weight v2=1
Enter Threshold Value
theta=1
Output of Net
0 1 1 0
McCulloch-Pitts Net for XOR function
Weights of Neuron Z1
1
-1
weights of Neuron Z2
-1
1
weights of Neuron Y
1
1
Threshold value
1
Tugas
1. Buat model MCCulloch –Pitts untuk menyatakan fungsi logika OR dengan threshold =3
2. Buat model MCCulloch –Pitts untuk menyatakan fungsi logika NOT dengan threshold =1
3. Buat model MCCulloch –Pitts untuk menyatakan fungsi logika ANDNOT dengan threshold =1
4. Buat model MCCulloch –Pitts untuk menyatakan fungsi logika XOR dengan;