//classification task... 
function [X,Y1]=getSimpleData(numpoints)
  X=zeros(numpoints,2);
  Y1=zeros(numpoints,1);
  mean1=[0 2]';
  cov1=0.1*eye(2,2);
  for i=1:1:500
  	point=grand(1,'mn',mean1,cov1); 
   X(i,:)=point';
	Y1(i)=1;
  end

  mean2=[-2 0]';
  cov2=0.1*eye(2,2);

  n_mean=[-16 0]';
  n_cov=0.1*eye(2,2);

  for i=1:1:numpoints-500
  	point=grand(1,'mn',mean2,cov2); 
   if (i>numpoints-600) point=grand(1,'mn',n_mean,n_cov); end
   X(i+500,:)=point';
	Y1(i+500)=0;
  end
endfunction


function [X,Y1]=runClassfier(nummeans,numpoints,lambda)
  close;
  exec('classifiers.sci');
  //  numpointsinclass1=numpoints/2; [X,Y1]=getClassificationData(nummeans,numpoints);
    numpointsinclass1=500; [X,Y1]=getSimpleData(numpoints);
  //plot(X(1:numpointsinclass1,1),X(1:numpointsinclass1,2),"g.",X(numpointsinclass1+1:numpoints,1),X(numpointsinclass1+1:numpoints,2),"r+");
  //X(900:920,1)=X(900:920,1)+30*rand(21,1);
  //Y1(500:520,1)=-Y1(500:520,1);

  // Now the result is in koeff and the fitted polynomial becomes 
  Xplot=[-7:0.02:7; -7:0.02:7]';
  [m1,n1] = size(Xplot);
  
  //Least squares fit
 // koeff1=getlsfitforlinear([ones(numpoints-100,1) X(1:numpoints-100,:)],Y1(1:numpoints-100),3,lambda); 
 // koeff2=getlsfitforlinear([ones(numpoints,1) X],Y1,3,lambda); 
  
  //koeff1=logistic(X(1:numpoints-100,:),Y1(1:numpoints-100),numpoints-100);
  //koeff2=logistic(X,Y1,numpoints);

  koeff1=perceptron(X(1:numpoints-100,:),numpoints-100,numpointsinclass1);
  koeff2=perceptron(X(1:numpoints,:),numpoints,numpointsinclass1);

  //koeff1=gaussianGen(X(1:numpoints-100,:),numpoints-100,numpointsinclass1);
  //koeff2=gaussianGen(X,numpoints,numpointsinclass1);

  x1line=(-Xplot(:,1)*koeff1(2)+0.5-koeff1(1))/koeff1(3);
  x2line=(-Xplot(:,1)*koeff2(2)+0.5-koeff2(1))/koeff2(3);



  //[koeff1,mm]=fisher(X(1:numpoints-100,:),numpoints-100,numpointsinclass1);
  //[koeff2,mm]=fisher(X,numpoints,numpointsinclass1);

  //[koeff1,mm]=perpbisectormeans(X(1:numpoints-100,:),numpoints-100,numpointsinclass1);
  //[koeff2,mm]=perpbisectormeans(X(1:numpoints,:),numpoints,numpointsinclass1);

  //x1line=-(koeff1(1)/koeff1(2))*(Xplot(:,1)-mm(1)) + mm(2);
  //x2line=-(koeff2(1)/koeff2(2))*(Xplot(:,1)-mm(1)) + mm(2);


  plot(X(1:numpointsinclass1,1),X(1:numpointsinclass1,2),"g.",X(numpointsinclass1+1:numpoints,1),X(numpointsinclass1+1:numpoints,2),"r+",Xplot(:,1),x1line,"b",Xplot(:,1),x2line,"m-");
  
xtitle('Test of resilience to noise', '\phi_1', '\phi_2');

hl=legend(['';'';'Without Noise';'With Noise']);

  hl=legend(['cos(t)';'cos(2*t)';'cos(3*t)']);
  meanwt=mean(koeff1);
  varwt=variance(koeff1);
  //print(%io(2),meanwt,varwt,x2line,Xplot);
  //print(%io(2),x2line-x4line);
  
endfunction
