function [rate, cRates] = confusionMatrix_getRates(cm)
% Returns accuracy rates, based on a pre-computed confusion matrix
%
% Inputs:
%
%   cm - the confusion matrix; "#true items in class = sum(column)"
%
% Outputs: 
%
%   rate - overall accuracy (correct/all)
%
%   cRates - vector of classwise accuracies (correct/all within each
%            class). For two classes 1="positive" and 2="negative" the
%            rates can be named ["sensitivity", "specificity"].
%

rate = sum(diag(cm)) / sum(sum(cm));

if nargout==1, return, end;

cRates = zeros(size(cm,1));
for ic=1:size(cm,2)
    cRates(ic) = cm(ic,ic)/sum(cm(:,ic));
end
