clear all;
close all;

hw1=csvread(hardwood.csv);
cp1=csvread(carpet.csv);

%Iterationoverthefeatures
 tw1=hw1(:,1:1:end-1); tw2=hw1(:,2:1:end);
 hw=sqrt(tw1.*tw1+tw2.*tw2);

 tp1=cp1(:,1:1:end-1); tp2=cp1(:,2:1:end);
 cp=sqrt(tp1.*tp1+tp2.*tp2);


 % Labels are added
 yy=[ones(1,size(hw,1)) zeros(1,size(cp,1))];
 xx=[hw;cp];


 % Finding the best split and the best feature

 % using information gain
 for ii=1:size(xx,1)
   sig=std(xx(ii,:));
   [slx(ii),fmx(ii),igx{ii},md1(ii),md0(ii),n1(ii),n2(ii), \ldots
   o1(ii),o2(ii)]=ura_calc_ig_fn(xx(ii,:),yy,sig);
 end

 fmxsort=sort(fmx,descend);
 tmp1=find(fmx==fmxsort(1));
 f1=tmp1(1);
 fval=xx(f1,slx(f1));


% Splitting the circular domain
 idxL=find(xx(f1,:)<fval);
 idxR=find(xx(f1,:)>=fval);

 xxL=xx(:,idxL);
 xxR=xx(:,idxR);

 yyL=yy(idxL);
 yyR=yy(idxR);


 % Showing the classification counts
 fprintf(\n);
 fprintf(Left side class 1 = %d\n,sum(yyL));
 fprintf(Left side class 0 = %d\n\n,length(yyL)-sum(yyL));

 fprintf(Right side class 1 = %d\n,sum(yyR));
 fprintf(Right side class 0 = %d\n,length(yyR)-sum(yyR));


% Showing the classes using circles
 figure;
 for ii=1:size(xx,2)
   if yy(ii)==1
     circle(0,0,xx(f1,ii),.,0.01);
   else
     circle(0,0,xx(f1,ii),r.,0.09);
   end
     hold on;grid on;
 end


% Showing the features 1 and 2
 figure;plot(hw1(:,1),hw1(:,2),.);
 hold on;plot(cp1(:,1),cp1(:,2),r.);
 axis([40 240 40 240]);grid on;
 xlabel(Feature 1);ylabel(Feature 2);


% Showing the best features 48 and 49
 figure;plot(hw1(:,48),hw1(:,49),.);
 hold on;plot(cp1(:,48),cp1(:,49),r.);
 axis([40 240 40 240]);grid on;
 xlabel(Feature 48);ylabel(Feature 49);

 figure;plot(md1);hold on;plot(md1,.);grid on;
 hold on;plot(md0,color,r);hold on;plot(md0,r.);
 figure;plot(fmx);grid on;
 xlabel(Feature number);ylabel(Information gain);