Message Boards Message Boards

Speed up sampling from truncated distribution

I am struggling trying to speed up a code to generate stochastic vectors, sampled from a truncated Dirichlet distribution. This is a small example:

Bmax = 0.05;
nvar = 100;
niter = 500;
p = 0.10;
smax = 7.;

b = ConstantArray[{0., Bmax}, nvar];

s = Table[If[1 <= i <= p nvar, smax, 1.], {i, 1, nvar + 1}];

RandomVariate[TruncatedDistribution[b, DirichletDistribution[s]], 
niter] // AbsoluteTiming // First

In my laptop, it takes around 2 s to generate that matrix with probability vectors. Is there any way I can speed up the code? I am interested in higher smax values, and I have noticed that the computation time increases very fast, which makes my application unfeasible.

Thanks in advance for any help!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract