Documente Academic
Documente Profesional
Documente Cultură
b. Implement a perceptron. Implement the perceptron, and train it to perform the logical
functions NOT (use only one of the inputs), NAND, and NOR. Use a customized script to solve
this problem.
%Ejecución de la red
xr = x;
for i=1:4
yr (i)= xr(i,1)*w(2)+x(i,2)*w(3)+w(1);
if yr (i) >= 0 %Funcion de activacion
Industrial Computing
Artificial Neural Network
Eng. Byron Lima MSc.
yr (i) = 1;
else
yr (i)=0;
end
end
disp('Entradas: [x1 x2]' ); disp(xr)
disp('Salidas:[y]'); disp(yr')
Industrial Computing
Artificial Neural Network
Eng. Byron Lima MSc.
Industrial Computing
Artificial Neural Network
Eng. Byron Lima MSc.
net = perceptron;
net = train(net,x,y);
view(net);
figure(1)
plotpc(net.IW{1},net.b{1});
Industrial Computing
Artificial Neural Network
Eng. Byron Lima MSc.
Industrial Computing
Artificial Neural Network
Eng. Byron Lima MSc.
Zerr=false;
end
w=wfin;
End=(Zerr && End);
pause(0.01);
end
e=e+1;
if End==1
disp("Entrenamiento exitoso...N# epocas:")
disp(e);
end
end
if e>=limit
disp("Entrenamiento incompleto, se ha excedido el numero maximo de
epocas")
end
xr=x;
for i=1:(2*N)
yr(i)=xr(i,1)*w(2)+xr(i,2)*w(3)+w(1);
if yr(i)>=0
yr(i)=1;
else
yr(i)=0;
end
end
disp('Entradas: [X1 X2]');disp(xr)
disp('Salidas: [y]');disp(yr')
% Plot input samples with PLOTPV (Plot perceptron input/target vectors)
figure(1)
plotpv(x',y);
x1=xr(:,1);
m=-wfin(2)/wfin(3);
b=-wfin(1)/wfin(3);
x2=x1*m+b;
hold on;grid on;
plot(x1,x2);
Industrial Computing
Artificial Neural Network
Eng. Byron Lima MSc.
Figure 3: Input space of the perceptron network. The gray area is classified as positive.
X1 y X2
Perceptron network with 2-inputs and 2-outputs is trained to classify input vectors into 4
categories.
Industrial Computing
Artificial Neural Network
Eng. Byron Lima MSc.
Industrial Computing
Artificial Neural Network
Eng. Byron Lima MSc.