image thumbnail

Fast Linear binary SVM classifier

by

 

04 Nov 2011 (Updated )

Fast implementation of Linear binary SVM via BLAS/OpenMP API

basicroc.m
function [tp , fp , threshold] = basicroc(y , f , options)

%
%[tp , fp , threshold] = basicroc(y , f , [positive]);
%
% Return the true positive rate, the false positive rate and the threshold
%
%
%  Author : Sbastien PARIS : sebastien.paris@lsis.org
%  -------  Date : 04/09/2006



if nargin < 3
    options.positive = 1;    
    options.nbstep   = 100;
end
if (~any(strcmp(fieldnames(options) , 'positive')))
    options.positive = 1;
end
if (~any(strcmp(fieldnames(options) , 'nbstep')))
    options.nbstep   = 100;
end


yunique            = unique(y);
if (length(yunique)~=1)
    bin                = histc(y , yunique);
else
    bin                = length(y);
end
index              = (yunique==options.positive);
P                  = bin(index); %(y = positive)
if isempty(P) 
    P              = 1; 
end
N                  = sum(bin(~index)); %(y = else)

minf               = min(f);
maxf               = max(f);
stepf              = (maxf - minf)/(options.nbstep - 3);

threshold          = (maxf:-stepf:minf);

tp                 = zeros(1 , options.nbstep - 2);
fp                 = zeros(1 , options.nbstep - 2);

co                 = 1;
for t = threshold
    ind       = (y(f>threshold(co))==options.positive);
    tp(co)    = sum(ind)/(P);
    fp(co)    = sum(~ind)/(N);
    co        = co + 1;

end
tp                 = [0 , tp , 1];
fp                 = [0 , fp , 1];




Contact us