clear all;
close all;

hw=csvread(hardwood.csv);
cp=csvread(carpet.csv);

oo=size(hw,1);
ff=size(hw,2);
rand(seed,131);
rr=1:2048;
%randperm(2048);


%1 represents hardwood floor and 0 represents carpet floor
ty=[ones(1,oo) zeros(1,oo)];
tx=[hw;cp];
yy=ty(rr);
xx=tx(:,rr);


%For each feature xx{ii}, it provides information gains igx{ii}
%For each feature xxii}, it also provides split locations slx{ii}
for ii=1:ff
  [slx(ii),fmx(ii),igx{ii}]=calc_ig(xx(ii,:),yy);
end

fnum=find(fmx==max(fmx))
w1=slx(fnum)+1;
fmx(fnum);
in=xx(fnum,w1)

tt1=csvread(test_hw3.csv);
hw=tt1;

f1=find(hw(fnum,:)<in);
f2=find(hw(fnum,:)>=in);


%total on the left side is 1430
length(yy(f1))


%left hand side all 1024 hardwood and 1430-1024=406 carpet
sum(yy(f1))


%right hand side ALL carpets 618
sum(yy(f2))

figure; grid on;
for ii=1:1024
  if(yy(ii)==1)
    hold on;plot(hw(56,ii),hw(52,ii),.);
  else
    hold on;plot(hw(56,ii),hw(52,ii),r.);
  end
end
hold on; line([in in],[0 250]);