% This script is to plot the data set and the decision line using the 
% euclidean distances.

% load the data files
%
load s1.dat;
load s2.dat;

% plot the data sets
%
hold on;
box on;
grid on;
plot(s1(:,1),s1(:,2),'k*');
plot(s2(:,1),s2(:,2),'k+');
axis([-8 8 -8 8]);
title('set1, set2 & test vectors');


% Define the test set
%
x1=[-1,-1];
x2=[0,0];
x3=[1/2,1/2];
x4=[1/2,-1/2];
[m,n] = size(s1);

% Setup files for storing the results
%
FID = fopen('set1_original','w');

% adjust the data so that the required mean is obtained
for k=1:m
b(k,1) = s1(k,1) - 1.2299 ;
b(k,2) = s1(k,2) + 0.2579 ;   
fprintf(FID,'%7.6f   %7.6f\n', b(k,1),b(k,2));
end;
mean_1 = mean(b);
[m,n] = size(s2);

% Setup files for storing the results
%
FID = fopen('set2_original','w');

% adjust the data so that the required mean is obtained
%
for k=1:m
c(k,1) = s2(k,1) -0.6351;
c(k,2) = s2(k,2) +0.8489;
fprintf(FID,'%7.6f   %7.6f\n', b(k,1),b(k,2));
end;
mean_2 = mean(c);

% plot the test set
%
hold on;
box on;
grid on;
plot(x1(1),x1(2),'kv');
plot(x2(1),x2(2),'kv');
plot(x3(1),x3(2),'kv');
plot(x4(1),x4(2),'kv');
axis([-5 5 -5 5]);

% find the decision region
%
index = 1;
 
for i = -5:0.1:5,
   for j = -5:0.1:5,
      old_dist = dist(mean_1, [i, j]');
      new_dist = dist(mean_2, [i, j]');
      if (old_dist >= new_dist-0.1) 
         if (old_dist <= new_dist+0.1)
            orig_pts(index, 1) = i;
            orig_pts(index, 2) = j;
            index = index + 1;
        end;
      end;
   end;
end;

% plot the decision line points
%
grid on;
hold on;
box on;
plot(orig_pts(:,1),orig_pts(:,2),'k-'); 
legend(' set 1',' set2','test vectors');

% end of file
%
