function [labels] = two_class_test(M, fm_test, thresh)

%function [labels] = two_class_test(M, fm_test, thresh)
%
% TWO_CLASS_TEST  -- This function tests a two-class classifier
%                    with an optional threshold
%
% Input Parameters:
%   M        --  Classifier matrix produced with train_classifier
%   fm_test  --  A feature matrix with instances to classify
%   thresh   --  A threshold (tau'), as given in equation (9.3), which
%                can be either positive or negative
%
% Output Parameters:
%   labels   --  A vector of integers, one per instance in fm_test.
%                1 is the first class in M, 2 is the second class, etc.
%

if size(M,1) > 2
    error('This function only accepts two-class classifiers.');
end

if ~exist('thresh','var') | isempty(thresh)
    thresh = 0;
end

d1 = sum((fm_test - repmat(M(1,:),[size(fm_test,1) 1])).^2,2);
d2 = sum((fm_test - repmat(M(2,:),[size(fm_test,1) 1])).^2,2);
eta = log(d1./d2);

labels = 1 + (eta > thresh);