Name: Vélez Cortés Eduardo Arturo
Group: 2MM12 Date: 20/04/2020
Practice 3: Neural Networks Perceptron
In this practice we create a neuronal network used to classify among apples and oranges.
The next figure shows the 3D plot of the plane that divides both sides of the classification.
If we insert the point blue of the image, in the side of the oranges we obtain the valued
that we imagined.
Name: Vélez Cortés Eduardo Arturo
Group: 2MM12 Date: 20/04/2020
With the vector of the other point we obtain the apple:
Name: Vélez Cortés Eduardo Arturo
Group: 2MM12 Date: 20/04/2020
Here is the code used to generate this program:
clear all;
close all;
clc;
P1=[1 -1 -1]; %The orange side
P2=[1 1 -1]; %The apple side
P=[P1 ; P2]
T=[-1 1];
[m,n]=size(P)
N=1;
W=rand(N,n)
b=rand(N,1)
Name: Vélez Cortés Eduardo Arturo
Group: 2MM12 Date: 20/04/2020
epoch= input('Iteration Number: ') % -- ask the user --
for i=1:epoch
for j=1:2
a= hardlims(W*[P(j,1);P(j,2);P(j,3)]+b);
e= T(j)-a;
wnew = W + e*[P(j,1) P(j,2) P(j,3)];
bnew = b + e;
W= wnew;
b= bnew;
end
end
%% 3d plot
[x,y] = meshgrid(-2:0.1:2);
pv = [0,-(b/W(2)),0];
ph = [-(b/W(1)),0,0];
pz = [0,0,-(b/W(3))];
Phv= pv-ph;
Phz= pz-ph;
Vn= cross(Phv, Phz);
z = ( Vn(1)*(x-ph(1)) + Vn(2)*y )/( Vn(3) );
figure (1)
hold on;
surf (x,y,z)
plot3 (1,-1,-1, 'b o');
plot3 (1,1,-1, 'r o');
xlabel('x');
ylabel('y');
zlabel('z');
%% While cycle
desition = 1;
while (desition == 1)
Vector = input('Introduce the point value among [], and in a vector form:
')
Pi = Vector;
a=hardlims(W*[Pi(1,1);Pi(1,2);Pi(1,3)]+b);
if a == -1
imshow('Orange.jpeg');
else
imshow('Apple.jpeg');
end
desition = input('Again (yes:1 No:0): ')
end