function [koeff]=logistic(X,Y1,numpoints)  
  //Logistic
  for i=1:1:numpoints
	if(Y1(i)==0) then 
		Y1(i)=0;
   end
  end  
  //print(%io(2),Y1);
	
  koeff=[1 1 1]; eta=0.1;
  for k=1:1:100
   grad = zeros(1,3);
  for i=1:1:numpoints
   sigma=1/(1+exp(-koeff*[1 X(i,:)]'));
   grad = grad+(sigma-Y1(i))*[1 X(i,:)];
  end  
  //print(%io(2),sigma,koeff);	
  koeff=koeff-eta*grad;
  end  
endfunction


function [koeff]=getlsfitforlinear(phi,Y,t,lambda)
	if ( ~exists('lambda') ) then
  	 	lambda = 0
	end

	//Matrix inverse gives inaccurate results for large values of "t" 
	//koeff=(phi'*phi + lambda*eye(t+1,t+1))^(-1)*(phi'*Y1'); 
	
	//koeff=(phi'*phi  + lambda*eye(t+1,t+1))\(phi'*Y1');	
	//[koeff,ker]=linsolve((phi'*phi),-(phi'*Y1'));
	
	//The most accuracte of all
	koeff=lsq(phi,Y);
endfunction

 //Generative -- with Gaussian
function [koeff]=gaussianGen(X,numpoints,numpointsinclass1) 
  m11=mean(X(1:numpointsinclass1,1)); 
  m12=mean(X(1:numpointsinclass1,2));
  m1=[m11 m12];

  m21=mean(X(numpointsinclass1+1:numpoints,1));
  m22=mean(X(numpointsinclass1+1:numpoints,2));
  m2=[m21 m22];

  Sw1=zeros(0,0);
  Sw2=zeros(0,0);
  for i=1:1:numpointsinclass1
    Sw1=Sw1+(X(i,:)-m1)'*(X(i,:)-m1);
  end
  for i=numpointsinclass1+1:1:numpoints
    Sw2=Sw2+(X(i,:)-m2)'*(X(i,:)-m2);
  end
 
  pi=numpointsinclass1/numpoints;
  Sigma=(1/numpoints)*Sw1 + 1/(numpoints)*Sw2;
  koeff1=inv(Sigma)*m1';
  koeff0= -0.5*m1*inv(Sigma)*m1' + log(pi);
  print(%io(2),koeff1);
  koeff = [koeff0 koeff1'];
endfunction

//Perceptron
function [koeff]=perceptron(X,numpoints,numpointsinclass1)  
  koeff=[-1 -1 -1]; eta=0.1;
  for k=1:1:100	
  for i=1:1:numpoints	
   if (i<=numpointsinclass1) then
      if (koeff(1) + koeff(2)*X(i,1) + koeff(3)*X(i,2) <= 0) 
		koeff=koeff+eta*[1 X(i,:)];
      end
   end
   if (i>numpointsinclass1) then
      if (koeff(1) + koeff(2)*X(i,1) + koeff(3)*X(i,2) >= 0) 
		koeff=koeff-eta*[1 X(i,:)];
	   end
   end
  end  
  end   
endfunction


  //Fisher
function [koeff,mm]=fisher(X,numpoints,numpointsinclass1)  
  m11=mean(X(1:numpointsinclass1,1)); 
  m12=mean(X(1:numpointsinclass1,2));
  m1=[m11 m12];

  m21=mean(X(numpointsinclass1+1:numpoints,1));
  m22=mean(X(numpointsinclass1+1:numpoints,2));
  m2=[m21 m22];
 
  mm = (m1+m2)/2;
 
  Sw1=zeros(0,0);
  Sw2=zeros(0,0);
  for i=1:1:numpointsinclass1
    Sw1=Sw1+(X(i,:)-m1)'*(X(i,:)-m1);
  end
  for i=numpointsinclass1+1:1:numpoints
    Sw2=Sw2+(X(i,:)-m2)'*(X(i,:)-m2);
  end
  Sw=Sw1+Sw2;
  //print(%io(2),Sw);
  koeff=((m2-m1)/norm(m2-m1))*inv(Sw);
endfunction


//Perpendicular bisector of line joining means
function [koeff,mm]=perpbisectormeans(X,numpoints,numpointsinclass1)  
  m11=mean(X(1:numpointsinclass1,1)); 
  m12=mean(X(1:numpointsinclass1,2));
  m1=[m11 m12];

  m21=mean(X(numpointsinclass1+1:numpoints,1));
  m22=mean(X(numpointsinclass1+1:numpoints,2));
  m2=[m21 m22];

  mm = (m1+m2)/2;
    
  koeff=(m2-m1)/norm(m2-m1);
endfunction
 
