function [acc,cfm] = score_lhoods(lhood,gt)
% [acc,cfm] = score_lhoods(lhood,gt)
%    Calculate accuracy and confusion given likelihoods
%    lhood is array of likelihoods, one row per model, one column
%    per test item.
%    gt is a vector of the ground truth rows that should be best in
%    each column.
%    acc is a scalar value, p(correct),  cfm is a NxN confusion matrix.
% 2007-04-17 dpwe@ee.columbia.edu

ntest = length(gt);

% Which is the most likely model for each test item?
[maxv,indx] = max(lhood);

% Overall error rate
acc = mean(indx==gt);
disp(['Classification accuracy = ', num2str(100*acc),'%']);

% Matrix of which track was classified to which class, and ground truth;
cm = 0*lhood;
gtm = 0*lhood;
for i = 1:ntest
  cm(indx(i),i) = 1;
  gtm(gt(i),i) = 1;
end
% So confusion matrix
cfm = gtm*cm';
% rows are true class, columns are reported (model) class
