function boundary
% boundary(x, y, W) makes a scatter plot of the data 
%  from class1 ('o') and class2 ('+') (respectively 2 x N and 
%  2 x M matrices), and draws the decision boundary for all H 
%  units in W, where each row of W is [th a b], specifying a 
%  unit whose activity is z = 1/(1+exp(a*x + b*y - th)).  The 
%  line for z(x,y) = .2 is dotted; the line for z(x,y) = .5 is 
%  dashed; the line for z(x,y) = .8 is solid.

x = [1     0     0    -1     0     0    -2; ...
     0     1    -1     0     2    -2     0];
y = [-1   -1     -1     1     1     1     1];

figure; hold on;
plotdata(x, y);

plot([2,      1.5, -1.5, 0, -1.5, 1.5, 2], ...
     [-1.75, -1.5, -1.5, 0,  1.5, 1.5, 1.75], 'k-');

axis([-2.5, 2, -2.5, 2.5]);
axis('square');
grid on;

for n = 1:size(x,2);
	text(x(1,n)+0.1, x(2,n)+0.1, [num2str(n)]);
end;
h = text(-1.65, 0.5, '+'); set(h, 'fontsize', 40);
h = text( 0.35, 0.5, '-'); set(h, 'fontsize', 40);

legend('y = +1', 'y = -1', 'boundary');

u1 = mean(x(:, find(y > 0)),2)
u2 = mean(x(:, find(y < 0)),2)

figure; hold on;
plotdata(x, y);

plot(u1(1), u1(2), 'r*');
plot(u2(1), u2(2), 'b^');

plot((u1(1)+u2(1))/2 * ones(1,2), [-2.5,2.5], 'k-');


axis([-2.5, 2, -2.5, 2.5]);
axis('square');
grid on;

for n = 1:size(x,2);
	text(x(1,n)+0.1, x(2,n)+0.1, [num2str(n)]);
end;

text(u1(1)+0.1, u1(2)+0.1, 'u+');
text(u2(1)+0.1, u2(2)+0.1, 'u-');
h = text(-1.45, 0.5, '+'); set(h, 'fontsize', 40);
h = text( 0.75, 0.5, '-'); set(h, 'fontsize', 40);

legend('y = +1', 'y = -1', 'u+', 'u-', 'boundary');
