function[val] =   FindClassifier(vector)
% [val] =  MaxCorrelation(vector):
%          Given a subset of features, evaluates the average pairwise correlation between the features and compute the number of features 
%          Biobjective function 
% INPUT:
% vector: Solution to be evaluated
% OUTPUT 
% val: A vector of two values:   1) number of features (number of ones in the vector)
%      and 2) Average pairwise correlation computed from global correlation matrix CorrMatrix
%      
% Last version 11/20/2009. Roberto Santana (roberto.santana@upm.es)
global ProblemClasses 
global AttributesMatrix
ind = find(vector==1);
AuxMatrix = AttributesMatrix(:,ind);  
n = size(vector,2);

val(1) = n - sum(vector);  % Number of features
if(val(1)<n)
   for j=1:10,
      cp = classperf(ProblemClasses);
 
      % Create a 10-fold cross-validation using
      % knn and the features determined by vector.
   
      indices = crossvalind('Kfold',ProblemClasses,10);
    
      for i = 1:10,
          test = (indices == i); train = ~test;
          class = knnclassify(AuxMatrix(test,:),AuxMatrix(train,:),ProblemClasses(train,:));
          % updates the CP object with the current classification results
          classperf(cp,class,test);
      end
      auxvals(j) = cp.CorrectRate;
   end
      val(2) = mean(auxvals); % queries for the correct classification rate
 
else
  val(1) = 0;
  val(2) = 0;
end

return;
