Check if sum over dimension is 0
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!