function score = measure_model(combined_variances, n_modes, model_evaluation_method, combined_model)
% MEASURE_MODEL: Measure the "goodness" of a model given some
%                of its properties.
%
% Code written by Katherine Smith, 2003
%
%    GENERAL
%
%      score = measure_model(combined_variances, n_modes, model_evaluation_method, combined_model)
%
%    INPUT/S
%
%      -combined_model:
%             The full combined model
%
%      -combined_variances: (obsolete)
%           The combined variances of the model.
%
%      -n_modes:
%           The total number of modes of the model.
% 
%      -method:
%           Method of evaluating a model.
%
%    OUTPUT/S
%
%      -score:
%           A score indicating the "goodness" of the model.
%
%    PENDING WORK
%
%      -Add some comments on process
%
%    KNOWN BUG/S
%
%      -None.
%
%    COMMENT/S
%
%      -Smith: add a small error to avoid zero values
%
%    RELATED FUNCTION/S
%
%      
%
%    ABOUT
%
%      -Created:     November 23rd, 2003
%      -Last update: February 10th, 2004
%      -Revision:    0.0.9
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

Epsilon = 0.0001;
current_method = model_evaluation_method;

% size(combined_variances,2) % see number of modes
if (strcmp(current_method,'determinant')),
          % see Kotcheff        
	padded_variances = zeros(1,n_modes); 
	      % a vector of zeroes the size of modes number
	if(size(combined_variances,2)<= n_modes),
      padded_variances(:,1:size(combined_variances,2)) = combined_variances;
	else
      padded_variances(:,1:n_modes) = combined_variances(:,1:n_modes);
	end
	padded_variances = padded_variances + Epsilon; 
          % Smith: add a small error to avoid 0
	score = prod(padded_variances); 
          % product of vector components i.e. determinant (Kotcheff)
elseif (strcmp(current_method,'minimum_description_length')),
    msgbox('MDL: Not yet implemented');
elseif (strcmp(current_method,'sum_of_log_eigenvalues')),     
	padded_variances = zeros(1,n_modes); 
	      % a vector of zeroes the size of modes number
	if(size(combined_variances,2)<= n_modes),
      padded_variances(:,1:size(combined_variances,2)) = combined_variances;
	else
      padded_variances(:,1:n_modes) = combined_variances(:,1:n_modes);
	end
    padded_variances = padded_variances + 0.0001;
    score = sum(log(padded_variances));
elseif (strcmp(current_method,'specificity')),
    msgbox('Specificity Evaluation: Not yet implemented'); % need ref_points and images score = find_specificity(combined_model, images, 25, ref_points_vec);
elseif (strcmp(current_method,'generalisability')),  
    score = find_generalisability(combined_model, 25); % score = find_generalisability(combined_model........
else
    error('Unknown model evaluation method.');
end