function [result_3s result_5s accuracy] = classifyTestData( test_threes, test_fives, ys, xs, train_threes, train_fives)
%function [result_3s result_5s accuracy] = classifyTestData( test_threes, test_fives, ys, xs, train_threes, train_fives)
%function that returns a matrix of results for 3s and 5s based on bayes formula applied. Bayes formula will be applied using features at positions given by ys and xs
result_3s=[];
resulr_5s=[];
accuracy=[];
%Check size of ys and xs to make sure they are row vectors of same size
%if xs or ys are not row vectors, then exit
if size(xs,1)~=1
    fprintf('Error: xs must be a row vector. Press any key to return...');
    pause;
    return;
elseif size(ys,1)~=1
    fprintf('Error: ys must be a row vector. Press any key to return...');
    pause;
    return;
end
%if size(xs) and size(ys) is not the same, then exit
if size(xs,2)~=size(ys,2)
    fprintf('Error: xs and ys must have same number of elements. Press any key to return...');
    pause;
    return;
end

% number of features
n = size(xs,2);

[liks3 liks5] = likFromTraining_multi( ys, xs, train_threes, train_fives);

%Testing the three images
for img_num = 1:size( test_threes, 3)
    %Create a feature vector of all 255.5s
    feature_vector = ones( 1, n)*255.5;
    for feat_num = 1:n
        %If particular feature being see in the current image is 0,5, then set feature_vectoro to 0.5
        if test_threes( ys(feat_num), xs(feat_num), img_num)==0.5
            feature_vector(feat_num) = 0.5;
        end
    end
    %Apply BayesRule for the above feature
    posteriors = BayesRule_multi( feature_vector, [liks3 liks5], [.5 .5]);
    post3 = posteriors(1);
    post5 = posteriors(2);
    result_3s( img_num) = (post3>post5);
end
%Testing the five images
for img_num = 1:size( test_fives, 3)
    %Create a feature vector of all 255.5s
    feature_vector = ones( 1, n)*255.5;
    for feat_num = 1:n
        %If particular feature being see in the current image is 0,5, then set feature_vectoro to 0.5
        if test_fives( ys(feat_num), xs(feat_num), img_num)==0.5
            feature_vector(feat_num) = 0.5;
        end
    end
    %Apply BayesRule for the above feature
    posteriors = BayesRule_multi( feature_vector, [liks3 liks5], [.5 .5]);
    post3 = posteriors(1);
    post5 = posteriors(2);
    result_5s( img_num) = (post5>post3);
end

accuracy_3 = sum(result_3s)
accuracy_5 = sum(result_5s)
accuracy = (accuracy_3 + accuracy_5)/(size( test_threes, 3) + size(test_fives, 3))

