function [auc] = roc_auc(pred,labels)
 numpos = sum(labels==+1);
 numneg = sum(labels==-1);
 if numpos==0 | numneg == 0
    auc =  0.5;
 else
  negpred = pred(labels==-1);
  pospred = pred(labels==+1)';
  comp_mat = 1.0*(repmat(negpred,1,numpos) < repmat(pospred,numneg,1) - 1e-4 ) ;  
  comp_mat = comp_mat + 0.5*(abs(repmat(negpred,1,numpos) - repmat(pospred,numneg,1)) < 1e-4); 
  auc = sum(sum(comp_mat))/(numpos*numneg);
 end
