function [Conf,rate] = ccgmeval(y,yt,O)

%ccgmeval Evaluate a class conditional gaussian mixture model.
%
%        Description
%
%        [Conf,rate] = ccgmeval(y,yt,O) evaluates a class conditional
%        gaussian mixture model. The model is given in the cell array
%        O. It exists of the multidimensional mean per class (O{1}), 
%        the covariance matrix per class (O{2}), and the prior 
%        probability of each class (O{3}). y contains the attribute 
%        values for the test data, and yt contains the class of each 
%        case (in a matrix with one column per class, with 1 if the 
%        case belongs to the column's class and 0 otherwise).
%
%        The output of this function is the confusion matrix (Conf) 
%        and the classification performance (rate) of the model on
%        the test data. These are computed using netlab's confmat 
%        function.
%
%        Frederick Ducatelle, januari 2002, University of Edinburgh


M = O{1};
C = O{2};
P = O{3};
dim = size(yt);

yf = zeros(dim);           % This matrix will hold the predictions

for k = 1:dim(1)
% For each class, calculate the nominator of the conditional 
% probability p(C=c|X=x) proportional to (p(C=c)*p(X=x|C=c)):
  for l = 1:dim(2)
    yf(k,l) = P{l}*gauss(M{l},C{l},y(k,:));
  end
  yf(k,:) = yf(k,:)/sum(yf(k,:));        % Normalise the probabilities
end

% Evaluate results:
[Conf,rate]=confmat(yf,yt);
