我正在阅读关于PFA的论文 https://arxiv.org/pdf/1112.3605.pdf 并尝试理解作者关于多项分布的代码
我不明白为什么作者使用2个分离的矩阵来测量多项分布而不是纸上所示的单个3-D矩阵x_pik
mult_rand.m
function [x_pk,x_kn] = mult_rand(X,Phi,Theta)
P = size(X,1); [K,N] = size(Theta);
x_pk = zeros(P,K); x_kn = zeros(K,N);
for n=1:N
inz = find(X(:,n))';
map = bsxfun(@times,Phi(inz,:),Theta(:,n)'); % P x K
map = cumsum(map,2);
x_kp = zeros(K,numel(inz));
for m=1:numel(inz)
x_kp(:,m) = x_kp(:,m) + mrand(X(inz(m),n),map(m,:));
end
x_kn(:,n) = sum(x_kp,2);
x_pk(inz,:) = x_pk(inz,:)+x_kp';
end
end
mrand.m
function x = mrand(n,cp)
% cp = cumsum( p );
x = sum(bsxfun(@gt,rand(n,1)*cp(end),cp),2)+1;
x = sparse(x,1,1,numel(cp),1);
end
我不确定mrand.m是如何生成样本的
参考代码: https://github.com/zhegan27/dpfa_icml2015/blob/master/support/