function Nkj = theta2nkj(Theta,alphas,nj)
% Convert topic probabilities per document into topic counts per document

% Inputs:
%   Theta   - K-by-N matrix of topic probabilities per document for K
%             topics and N documents, double
%   alphas  - Dirichlet prior, K-by-1 double vector
%   nj      - 1-by-N double vector of word counts per document
%
% Output:
%   Nkj     - K-by-N matrix of topic counts per document for K topics and N
%             documents, double

%   Copyright 2017 The MathWorks, Inc.

Nkj = Theta.*(nj + sum(alphas)) - alphas;

%Nkj(Nkj<0) = 0;

end
