function [ outConfusionMat, outAccuracy ] = compute_confusion_matrix( inGt, inPreLabel, inOpt)

% compute confusion matrix for multi-class classification
% input:
%       inGt: the ground truth vector, the class label should begin with 1
%       and continuous number
%       inPreLabel: the predicated label vector
%       inOpt: normal option, 1: normal, 0: NOT normal
% output:
%       outConfusionMat: calculated confusion matrix
%       outAccuracy: calculated accuaracy
%
% implemented by Xiao


m = max(inGt); % the # of classes
outConfusionMat = zeros(m, m);
outAccuracy = 0;

for i = 1: length(inGt)
    row = inGt(i);
    col = inPreLabel(i);
    outConfusionMat(row, col) = outConfusionMat(row, col) + 1;
end
outAccuracy = sum(diag(outConfusionMat))/sum(sum(outConfusionMat));

% normalize the confusion matrix ?
if(inOpt)
    for i = 1: m
        outConfusionMat(i,:) = outConfusionMat(i,:)/sum(outConfusionMat(i,:));
    end
end


end

