Need alternative to randsample for probability vectors with 0s in MATLAB -


i have question similar one: weighted random numbers in matlab

at point, use randsample in program follows:

t = [0 .5 .5; .5 0 .5; .5 .5 0] choices = 1:3  = 1:3     t(i) = transpose(randsample(choices,1,true,t(i,:))); end 

thus t(i) describes each person neighbor select.

my t matrix, when read rowwise describes probability of person select neighbor. example, first row says 1st person select node 2 or 3 50% probability each. cannot select own node 1. scale model, have equal probability of selecting neighbor, 1/number of neighbors. have hardcoded t matrix here brevity's sake.

i tried use histc suggested in linked topic, since there 0 in each row of t matrix, don't think cumulative sum accurately sets bins rows 0 in middle (here second row of t).

i tried use bsxfun, , able sensical output when looking @ each row of t matrix individually, failed put in loop. feel solution may here, i'm not sure understand how function operating in context.

so, have ideas of how can speed randsample function? @ moment, iterate 10000x, , major bottleneck in program. works need to, it's far slow.

so want, each person, pick neighbour among other persons, uniform probability.

i way. should pretty fast.

n = 7;                      %// number of persons t = ceil((n-1)*rand(1,n));  %// step 1 t = t + (t>=(1:n));         %// step 2 

for each k, generated t(k) randomly picked set {1, 2, ..., k-1, k+1, ..., n} uniform distribution. achieve this, 2 steps used:

  1. a random value picked {1, ..., n-1};
  2. if value greater or equal k incremented 1.

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -