
function [loglr] = log_likel_ratio(theta, X)

log_of_zero = -1e+16;

log_theta = zeros(size(theta));

% eval log-word probabilities for each class (avoid taking log of zero)

for i=1:2,
  I1 = find(theta(i,:)>0);
  log_theta(i,I1) = log(theta(i,I1));

  I0 = find(theta(i,:)==0);
  log_theta(i,I0) = log_of_zero;
end;

% evaluate log-likelihood ratio for each document in X
% sum_j log theta_{x_j|y=1} - sum_j log theta_{x_j|y=2}

loglr = X*(log_theta(1,:)'-log_theta(2,:)');

