www.pudn.com > snippets(1).rar > classify_npairs.m, change:2009-10-12,size:510b


function result = classify_npairs(classifier, test_data)
%
% classify test data with a bank of 2-class SVMs (n-pairs)

num_classes = size(classifier,1);
num_data = size(test_data,1);

votes = zeros(num_data,num_classes);

for u = 1:num_classes
  for v = u+1:num_classes

    curr_class = svmfwd(classifier{u}{v}, test_data);

    for w = 1:num_data
      if curr_class(w)==1
	votes(w,u) = votes(w,u)+1;
      else
	votes(w,v) = votes(w,v)+1;
      end
    end

  end
end

[maxval, result] = max(votes, [], 2);