function [effic]=recog_effic(votes,gt,pat)
% recog_effic - Compute efficiency of classifiers.
%
% [effic]=recog_effic(votes,gt,pat)
% effic .. efficiency of classifiers (TP FN TN FP accur sens spec)
% votes .. matrix of votes (group identifiers) which are results of
%          classification algorithms for each person (rows are
%          classifiers, columns are persons)
% gt .... ground truth (group identifiers of images)
% pat .... identifier of patients
% 
%
% by Eva Janousova, 9/sep/2010 (modified 3/mar/2014).

%------------------------------------------------------------------------%

% 1. create a vector with ground truth of votes:
i_pat=(gt==pat);                                   % indexes of patient images
effic=zeros(size(votes,1),7);                       % allocation of matrix with efficiency measures

% 2. compute efficiency of classifiers:
for i=1:size(votes,1)
    eq =(votes(i,:)==gt(:)');                      % a logic vector: 0..classification is incorrect, 1..classification is correct

    TP=sum(eq(i_pat));                              % true positive
    FN=sum(i_pat)-TP;                               % false negative
    TN=sum(eq(~i_pat));                             % true negative
    FP=sum(~i_pat)-TN;                              % false positive

    accur = (TP+TN) / (TP+TN+FP+FN);                % accuracy
    sens = TP / (TP+FN);                          % sensitivity
    spec = TN / (TN+FP);                          % specificity

    effic(i,:)=[TP FN TN FP accur sens spec];% efficiency results
end

end