필터 지우기
필터 지우기

Check if sum over dimension is 0

조회 수: 1 (최근 30일)
Mike Nguyen
Mike Nguyen 2017년 12월 28일
편집: Geoff Hayes 2017년 12월 28일
I have a matrix A_vk (VxK), and a matrix A_kn (KxN). How to check if A_.k. is 0 or not in which A_.k. = sum (1 to V) sum(1 to N) A_vkn, and A_vk & A_kn are generated form multinational distribution
(A_v1j,A_v2j,...,A_vKj)= mult_rand(X,Phi,Theta)
I generated A_vk and A_kn from here
[A_vk,A_kn]= mult_rand(X,Phi,Theta); Here is mult_rand(X,Phi,Theta)
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 function
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
Hopefully it is easy to understand
matlab matrix

답변 (0개)

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by