I am generating Poisson deviates for some numerical work. Mathematica 9.0.1 is very slow in generating these random numbers, as can be seen below.
In[1]:= nobs = 100000;
In[2]:= AbsoluteTiming[
m = RandomReal[{1, 5}, nobs];
m1 = Map[RandomVariate[PoissonDistribution[#]] &, m];
]
Out[2]= {10.194500, Null}
In[3]:= Mean[m1] // N
Out[3]= 2.99884
I need fast Poisson deviates for any vector m (i.e., it does not need to contain Uniform draws). The above is very slow for serious numerical work. A comparable function in Julia, is significantly faster, as can be seen below.
function pois(nobs::Integer)
m1=rand(Uniform(1,5), nobs)
for i in 1:nobs
m1[i]=rand(Poisson(m1[i]))
end
m1
end
In [16]: @time draws=pois(nobs);
elapsed time: 0.005883954 seconds (800200 bytes allocated)
Is there any way one can speed up the Mathematica Poisson random number generation? Compilation does not work, unfortunately, and none of the distribution functionality is vectorized automatically.
Hopefully, future versions will address this aspect.
RandomVariate[MultivariatePoissonDistribution[1, m-1]]
is equally slow, in case anyone was about to try. $\endgroup$