clear all
close all
clc
%%%% %%%% NN-tradicional con RADIO
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% data generation %%%% 
N1=5000;
mu = [1 -1];
Sigma = [.9 .4; .4 .3];
c1 = mvnrnd(mu, Sigma, N1);
 plot(c1(:,1),c1(:,2),'ro');
 hold on
%%%%%%%%%%% 
 N2=5000;
mu = [-4 3];
%mu = [-2 1.5];
Sigma = [1 0; 0 2];
c2 = mvnrnd(mu, Sigma, N2);
 plot(c2(:,1),c2(:,2),'bo');
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%% JUGAR CAMBIANDO TIPO DE DISTANCIA 
a=1;
dist=@(z,x) sum(abs(x-z).^a);
%%%% JUGAR CAMBIANDO RADIO 
Radius=1;
 %Radius=15;
 %Radius=50;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 x2=-3:0.2:7;
 x1=-7:0.2:4;
 %%%%%%%%%%%%%%%%%%%%%%%
 for k=1:length(x1)
     if mod(k,10)==0
        k
     end
     %%%%%%%%%%%%%%%%%%%%
    for j=1:length(x2)  
       %%%%%%%%%%%%%%%%%% 
         xtest=[x1(k),x2(j)];
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
            for i=1:N1
              d1(i)=dist(xtest,c1(i,:));
            end
         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
            for i=1:N2
              d2(i)=dist(xtest,c2(i,:));
            end
         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
% %         pos1=find(d1==min(d1));
% %         pos2=find(d2==min(d2));
% %         vaux=[d1(pos1),d2(pos2)];
% %         dec=find(vaux==min(vaux));
           dtot=[d1 d2];
           labels=[ones(1,N1) zeros(1,N2)];
           %%%dsort=sort(dtot);
           pos=find(dtot<Radius);
           Lab=labels(pos);
         %%%%%%%%%%%%%%%%%  
           contneg=0;
           contpos=0;
         %%%%%%%%%%%%%%%%%
           for s=1:length(pos)
               if Lab(s)==1
                   contpos=contpos+1;
               else
                   contneg=contneg+1;
               end
           end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
          if  contpos>contneg
              dec=1;
             plot(xtest(1,1),xtest(1,2),'r.','LineWidth',2,'MarkerSize',10)
          elseif contpos<contneg
              dec=0;
              plot(xtest(1,1),xtest(1,2),'b.','LineWidth',2,'MarkerSize',10)
          else
              plot(xtest(1,1),xtest(1,2),'g.','LineWidth',2,'MarkerSize',10)
          end
    end
 end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axis([-7 7 -3 8])
    