function probs = calculateProbs(s1, condVars, givenVars, conds, given, printLatex)
% CALCULATEPROBS calculates the vector of probabilities 
% for all the combinations of conditions and givens.

% start
if (nargin == 3)
    display('\begin{tabular}{c}'); 
    probs = calculateProbs(s1, condVars, givenVars, [], [], 1);
    display('\end{tabular}');
else
    % recursing through combinations
    if (nargin == 6)
        % check if all conditions are specified
        szConds = size(conds);
        szGiven = size(given);
        if szConds(1) == length(condVars)
            if szGiven(1) == length(givenVars)
                % base case
                p = calculateProb(s1, conds, given);
                probs = [p];
                % display in latex
                sconds = condsToStr(conds);
                sgiven = condsToStr(given);
                if (printLatex)
                    display(sprintf('  $\\tilde{P}(%s|%s) = %4.8f$\\\\', sconds, sgiven, p));
                end
            else
                % branch for current given
                i = szGiven(1) + 1;
                v = givenVars(i);
                % when var is 1
                given(i, 1:2) = [v 1];
                probs = calculateProbs(s1, condVars, givenVars, conds, given, printLatex);
                % when var is 0
                given(i, 1:2) = [v 0];
                p2 = calculateProbs(s1, condVars, givenVars, conds, given, printLatex);
                sz = size(probs);
                probs((sz(1)+1):(sz(1)*2), 1:sz(2)) = p2;
            end
        else
            % branch for current cond
            i = szConds(1) + 1;
            v = condVars(i);
            % when var is 1
            conds(i, 1:2) = [v 1];
            probs = calculateProbs(s1, condVars, givenVars, conds, given, printLatex);
            % when var is 0
            conds(i, 1:2) = [v 0];
            p2 = calculateProbs(s1, condVars, givenVars, conds, given, printLatex);
            sz = size(probs);
            probs((sz(1)+1):(sz(1)*2), 1:sz(2)) = p2;
        end
    else
        error('incorrect arguments.');
    end
end