function [sl,mx,ig,md1,md0,n1,n2,o1,o2]=ura_calc_ig_fn(xx,yy,sig)

 ll=length(yy);
 for ii=2:ll-1
   %spisthesplitlocation
   sp=xx(ii);

   %buildleftandrighttree
   wd=0.5*sig;
   xl=yy(xx<sp);
   xr=yy(xx>=(sp+wd));
   xm=yy(xx>=sp & xx<(sp+wd));


   %length of the node
   m1=length(xm);
 
   %sum of class 1s
   md1=sum(xm);

   %sum of class 0s
   md0=m1-md1;


   %length of the left tree
   l1=length(xl);

   %sum of class 1s
   n1=sum(xl);

   %sum of class 0s
   n2=l1-n1;


   %probabilities
   p1=n1/(n1+n2)+0.00001;
   p2=n2/(n1+n2)+0.00001;


   %entropy of the left tree
   en1 = -p1*log(p1)-p2*log(p2);


   %length of the right tree
   l2=length(xr);

   %sum of class 1s
   o1=sum(xr);
 
   %sum of class 0s
   o2=l2-o1;


   %probabilities
   p1=o1/(o1+o2)+0.00001;
   p2=o2/(o1+o2)+0.00001;


   %entropy of the right tree
   en2 = -p1*log(p1)-p2*log(p2);


   %Calculates information gain
   ig(ii-1)=1-((l1/ll)*en1 + (l2/ll)*en2);
 end

 %find the split location with the maximum information gain
  tmp=find(ig==max(ig));
  sl=tmp(1);
  mx=max(ig);
end