function [et,eu,alphas,bias,sup_vecs]=experiment_usps(method,gamma_A,gamma_I);

% Author: Vikas Sindhwani
% June 2004

l=2;
u=398;

ytrue=[ones(l+u,1),-ones(l+u,1)];

load usps.mat
load Labels.mat
options=ml_options('Kernel','poly', 'KernelParam', 3, ...
                        'NN',6,'gamma_A',gamma_A,'gamma_I',gamma_I);

  p=0;                  
for i=1:10
    for j=i+1:10
         %p=p+1 
         p=p+1;
         x=[train{i};train{j}];          
         xt=[test{i};test{j}];
         yt=[ones(size(test{i},1),1); -ones(size(test{j},1),1)];
         r=sum(yt==-1)/length(yt);
         disp('Computing Kernels');     
         K=calckernel('poly',3,x);
         KT=calckernel('poly',3,x,xt);
         disp('Done.');  
         
         
if strcmp(method,'lapsvm') | strcmp(method, 'laprlsc')
    L=laplacian(x,'nn',options);
end


         
        for k=1:10
            
         ypos=zeros(l+u,1); 
         ypos(Labels(p,k,1:l))=1;
         yneg=zeros(l+u,1); 
         yneg(Labels(p,k,l+1:2*l))=-1;
         y=[ypos;yneg]; 
         lab=find(y);         
         unlab=find(y==0);
         yu=ytrue(unlab);
   
switch method
    
case 'rlsc'
    [alpha,b]=rlsc(K(lab,lab),y(lab),options.gamma_A);
    fu=K(unlab,lab)*alpha; 
    ft=KT(:,lab)*alpha;
    
case 'svm'
    [alpha,b]=svm(K(lab,lab),y(lab),options.gamma_A);
    fu=K(unlab,lab)*alpha; 
    ft=KT(:,lab)*alpha;
    
case 'laprlsc'
    [alpha,b]=laprlsc(K,y,L,options.gamma_A,options.gamma_I);
    fu=K(unlab,:)*alpha;
    ft=KT*alpha;
    
case 'lapsvm'
    [alpha,b]=lapsvm(K,y,L,options.gamma_A,options.gamma_I);
    fu=K(unlab,:)*alpha;  
    ft=KT*alpha; 
    
case 'tsvm'
    [alpha,b,svs]=readtsvmmodel(['results_tsvm/model_' num2str(k) '.' num2str(p)]);
    fu=calckernel('poly',3,svs,x(unlab,:))*alpha;  
    ft=calckernel('poly',3,svs,xt)*alpha;
    sup_vecs{p,k}=svs;    
end

bt=breakeven(ft,yt,@pre_rec_equal);
bu=breakeven(fu,yu,@pre_rec_equal);



et(p,k)=evaluate(sign(ft-bt),yt);
eu(p,k)=evaluate(sign(fu-bu),yu);


alphas{p,k}=alpha;
bias(p,k)=b;

[p k et(p,k) eu(p,k)]

end


        
            
        end
        
    end



function [alpha,b,svs]=readtsvmmodel(file,i)
    [alpha,svs]=svmlread(file);
    b=alpha(9);
    alpha=alpha(10:end);
    svs=svs(10:end,:);

function e=evaluate(a,b);
   e=sum(a~=b)/length(b)*100;
   
function b=get_bias(v,r);
      v1=sort(v);
      p=ceil(r*length(v));
      b=v1(p);
