% lda testing
function [I, hypo] = lda_ts(fea, lab, w, w0, cn)
% test lda using w and w0

if nargin == 4
    cn = 2;
elseif nargin < 4
    disp('lda_ts(fea, lab, w, w0, [cn])');
    return;
end

tsnum = size(fea,2);
hypo = zeros(1, tsnum);

if cn == 2                  % 2 classes
    for i=1:tsnum
        v = fea(:,i)' * w + w0;
        if v>0
            hypo(i) = 1;
        elseif v<0
            hypo(i) = -1;
        else
            hypo(i) = sign(rand-0.5);
        end
    end

    I = (hypo ~= lab);

else                        % multiple classes
    
    for i = 1:tsnum
        v = zeros(1,cn);
        for k = 1:cn
            v(k) = fea(:,i)'*w(:,k) + w0(k);
        end
        [c,j] = max(v);
        hypo(i) = j;
    end
    
    I = (hypo ~= lab);
    
end