function y = NBclas(phis,theta)
% Y = NBCLAS(X,THETA)
%
%   Classifies documents represented by word detections in X to one of 
%   two classes, using Naive Bayes model with class-conditional
%   parametrized by THETA, where
%   THETA(I,K) is the estimated prob. of the word K to appear in class I.
%   The predicted label of document k is returned in Y(k).

% (c) Greg Shakhnarovich MIT AI Lab  2002


t1=repmat(theta(1,:),[size(phis,1),1]);
t2=repmat(theta(2,:),[size(phis,1),1]);

% to classify, compare log-likelihoods...
LL1 = sum(log(t1.^phis)+log((1-t1).^(1-phis)),2);
LL2 = sum(log(t2.^phis)+log((1-t2).^(1-phis)),2);
y = 1*ones(size(LL1));
y(find(LL1<LL2))=2;

