x0 = ones(20, 1);
x1 = rand(20, 2)*10;
x = [x0, x1];
test = rand(20, 1);
y = ones(20, 1);
for i=1:20
if x1(i, 1)>6
y(i) = -1;
end
end
j=1;
for i=1:20
if y(i)==-1
u(j) = x1(i, 1);
v(j) = x1(i, 2);
j = j+1;
end
end
scatter(u, v, 'or');
hold on;
j=1;
u=[];
v=[];
for i=1:20
if y(i)==1
u(j) = x1(i, 1);
v(j) = x1(i, 2);
j = j+1;
end
end
scatter(u, v, 'xk');
hold on;
w = [0, 0, 0];
while true
pd = false;
for i=1:20
t = x(i, :);
if w*t'*y(i)<=0
w = w + y(i)*t;
pd = true;
break;
end
end
if pd == false
break;
end
end
w
v = linspace(0, 10, 100);
u = -w(3)/w(2)*v - w(1)/w(2);
plot(u, v, '.');
t = 1;
y(y==-1)=0;
net = newp([0, 10; 0, 10], t);
net = train(net, x1', y');
newt = sim(net, x1');
iw = net.iw;
b = net.b;
ww = [b{1}, iw{1}];
vv = linspace(0, 10, 100);
uu = -ww(3)/ww(2)*v - ww(1)/ww(2);
plot(uu, vv, '.k');
x1 = rand(20, 2)*10;
x = [x0, x1];
test = rand(20, 1);
y = ones(20, 1);
for i=1:20
if x1(i, 1)>6
y(i) = -1;
end
end
j=1;
for i=1:20
if y(i)==-1
u(j) = x1(i, 1);
v(j) = x1(i, 2);
j = j+1;
end
end
scatter(u, v, 'or');
hold on;
j=1;
u=[];
v=[];
for i=1:20
if y(i)==1
u(j) = x1(i, 1);
v(j) = x1(i, 2);
j = j+1;
end
end
scatter(u, v, 'xk');
hold on;
w = [0, 0, 0];
while true
pd = false;
for i=1:20
t = x(i, :);
if w*t'*y(i)<=0
w = w + y(i)*t;
pd = true;
break;
end
end
if pd == false
break;
end
end
w
v = linspace(0, 10, 100);
u = -w(3)/w(2)*v - w(1)/w(2);
plot(u, v, '.');
t = 1;
y(y==-1)=0;
net = newp([0, 10; 0, 10], t);
net = train(net, x1', y');
newt = sim(net, x1');
iw = net.iw;
b = net.b;
ww = [b{1}, iw{1}];
vv = linspace(0, 10, 100);
uu = -ww(3)/ww(2)*v - ww(1)/ww(2);
plot(uu, vv, '.k');