function [lik3 lik5] = likFromTraining( ys, xs, train3s, train5s)
%function [lik3 lik5] = likFromTraining( ys, xs, train3s, train5s)
%Function that returns likelihoods for 3 and 5, given pixel locations (x1 y1) (x2 y2) ... Pixel locations are input as xs and ys, where xs is a row vector will all x values and ys is a row vector with all y values.
%The lik3 and lik5 matrices are [2^n x 1] size vectors, where n is the number of points where features are obtained from.

%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;
    lik3=0; lik5=0;
    return;
elseif size(ys,1)~=1
    fprintf('Error: ys must be a row vector. Press any key to return...');
    pause;
    lik3=0; lik5=0;
    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;
    lik3=0; lik5=0;
    return;
end

%Find number of points
n = size(xs,2);
%Set likelihoods to be zero
lik3 = zeros( 2^n, 1);
lik5 = zeros( 2^n, 1);

%Go over all '3' images
for img = 1:size(train3s, 3)
    binary_string = '';
    %Go over each feature location and add 0 or 1 to a binary string
    for feat_num = 1:n
        feature_value = train3s(ys(feat_num), xs(feat_num), img);
        %If feature is 0.5, add '0' to binary string
        if feature_value==0.5
            binary_string = sprintf('%s%s', binary_string, '0');
        else
            binary_string = sprintf('%s%s', binary_string, '1');
        end
    end
    %Now for this img, binary_string represents the binary feature values. Convert this to decimal (then add 1 to it) and increment the likelihood of 3's at that location
    bin_to_increment = bin2dec(binary_string);
    bin_to_increment = bin_to_increment+1;
    lik3(bin_to_increment) = lik3(bin_to_increment)+1;
end

%Go over all '5' images
for img = 1:size(train5s, 3)
    binary_string = '';
    %Go over each feature location and add 0 or 1 to a binary string
    for feat_num = 1:n
        feature_value = train5s(ys(feat_num), xs(feat_num), img);
        %If feature is 0.5, add '0' to binary string
        if feature_value==0.5
            binary_string = sprintf('%s%s', binary_string, '0');
        else
            binary_string = sprintf('%s%s', binary_string, '1');
        end
    end
    %Now for this img, binary_string represents the binary feature values. Convert this to decimal (then add 1 to it) and increment the likelihood of 5's at that location
    bin_to_increment = bin2dec(binary_string);
    bin_to_increment = bin_to_increment+1;
    lik5(bin_to_increment) = lik5(bin_to_increment)+1;
end

%Divide the likelihoods by number of images
lik3 = lik3/size( train3s, 3);
lik5 = lik5/size( train5s, 3);

