function Nwk = phi2nwk(Phi,beta0,nk)
% Convert word probabilities per topic into word counts per topic

% Inputs:
%   Phi     - W-by-K matrix of word probabilities per topic for W words and
%             K topics, double
%   beta0   - Concentration parameter of the Dirichlet prior, double scalar
%   nk      - 1-by-K double vector with word counts per topic
%
% Output:
%   Nwk     - W-by-K matrix of word counts per topic for W words and K
%             topics, double

%   Copyright 2017 The MathWorks, Inc.

T = size(Phi,1);

Nwk = Phi.*(nk + beta0) - beta0/T;

%Nwk(Nwk<0) = 0;

end
