In this part, you are required to demonstrate the capability of a single-layer perceptron to model the following logic gates:
AND , OR , NOT , XOR
Generate the output curves/surfaces for these perceptron-models as the input/s vary continuously from 0.0 to 1.0 (hint: mesh function can come in handy)
And Gate
%input perseptrons
p=[0 0 1 1;0 1 0 1];
%Output Perseptrons
t=[0 0 0 1];
%creation of new pereceptron
net=newp([0 1;0 1],1)
%plot input/outpur
plotpv(p,t);
grid on;
%train the perceptron at 100 iterations
net.trainParam.passes=100;
%assign perceptron to net value
[net,a,e]=train(net,p,t);
%Border Line of the Active function
plotpc(net.iw{1,1},net.b{1})
%To plot the mesh Surface
y = ones(11,11);
input = 0:0.1:1;
for i = 0:10
for j = 0:10
y(i + 1,j + 1) = sim(net,[i/10;j/10]);
end
end
mesh(input,input,y)
colormap([1 0 0; 0 1 1])
Or Gate
%input perseptrons
p=[0 0 1 1;0 1 0 1];
%Output Perseptrons
t=[0 1 1 1];
%creation of new pereceptron
net=newp([0 1;0 1],1)
%plot input/outpur
plotpv(p,t);
grid on;
%train the perceptron at 100 iterations
net.trainParam.passes=100;
%assign perceptron to net value
[net,a,e]=train(net,p,t);
%Border Line of the Active function
plotpc(net.iw{1,1},net.b{1})
a=sim(net,[1;1])
%To plot the mesh Surface
y = ones(11,11);
input = 0:0.1:1;
for i = 0:10
for j = 0:10
y(i + 1,j + 1) = sim(net,[i/10;j/10]);
end
end
mesh(input,input,y)
colormap([1 0 0; 0 1 1])
Not Gate
%input perseptrons
p=[0 1];
%Output Perseptrons
t=[1 0];
%creation of new pereceptron
net=newp([0 1],1)
%plot input/outpur
plotpv(p,t);
grid on;
%train the perceptron at 100 iterations
net.trainParam.passes=100;
%assign perceptron to net value
[net,a,e]=train(net,p,t);
%Border Line of the Active function
plotpc(net.iw{1,1},net.b{1})
a=sim(net,1)
Neural Model for Random Data
%in/Out values
%------------------
%| In1 | In2 |Out|
%|------|------|---|
%| 100 | 200 | 0 |
%| 0.15 | 0.23 | 0 |
%| 0.33 | 0.46 | 0 |
%| 0.42 | 0.57 | 1 |
%------------------
input=[ 100 0.15 0.33 0.42;150 0.23 0.46 0.57];
%here we can use the output value as 0 and 1.
%Because we are using hardlimit threshold function.
%The values are 0 or 1
target=[0 0 0 1];
%creation of new pereceptron
net=newp([0 1;0 1],1);
%plot input/outpur
plotpv(input,target);
grid on;
%train the perceptron at 100 iterations
net.trainParam.passes=100;
%assign perceptron to net value
[net,a,e]=train(net,input,target);
%Active border line
plotpc(net.iw{1,1},net.b{1})
hold on
%second Inputs
p2=[0.20 0.6 0.1;0.20 0.9 0.4];
t2=sim(net,p2)
plotpv(p2,t2);
[net, a, e]= train(net,p2,t2);
plotpc(net.iw{1,1},net.b{1});
hold off
No comments:
Post a Comment