% 070712 gabriel@pads.ufrj.br

close all; clear all;
C = [0.5 0.5 -0.5 -0.5 ; -0.5 0.5 -0.5 0.5];
t = [-1 1 1 -1];
randn('state',0);
E = repmat(C(:,1),1,4) + 0.1*randn(2,4);
F = repmat(C(:,2),1,4) + 0.1*randn(2,4);
G = repmat(C(:,3),1,4) + 0.1*randn(2,4);
H = repmat(C(:,4),1,4) + 0.1*randn(2,4);
X = [E F G H]; t = [-1 -1 -1 -1 1 1 1 1 1 1 1 1 -1 -1 -1 -1];
% P = 1; 
P = 100; for i = 1:16, for j = 1:16, Phi(i,j) = exp(-P*norm(X(:,i)-X(:,j))^2); end; end;
w = inv(Phi)*t'
X = zeros(2,10000);
for i = 1:100,
    for j = 1:100,
        X(:,100*(i-1)+j) = [(i-50.5)/50 ; (j-50.5)/50];
    end;
end;
Y = [E F G H];
figure; hold on;
for n=1:size(X,2),
o = exp(-P*sum((Y-repmat(X(:,n),1,16)).^2,1))*w;
if o < 0,
plot(X(1,n),X(2,n),'b.');
else
plot(X(1,n),X(2,n),'k.');
end;
end;
plot(Y(1,:),Y(2,:),'r.');