Random Number Generation : Is there a faster way of doing this ?
- To: mathgroup at smc.vnet.net
- Subject: [mg43190] Random Number Generation : Is there a faster way of doing this ?
- From: "Christos Argyropoulos M.D." <argchris at otenet.gr>
- Date: Sun, 17 Aug 2003 04:28:02 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
My problem is that I want to generate a large number of samples from Poisson
distributions. Specifically the user has to supply a list of the parameters
for a number of Poisson distributions and then generate a number of such
samples. In the function below poissonparams is a list of the parameters of
the Poisson distributions, and size is the number of samples. In my
application (Analysis of counts of digital gene expression profiles), I
supply a list of 10000 Poisson Parameters and have to generate a big sample
of numbers drawn from the 10000 distributions. Typically > 1k such samples
are required in order to establish a Log Likelihood statistic cutoff down
the road.
For the application at hand the poisson parameter can be zero (in this case
the only point I can sample is the number zero) that is way I do not Map .
My implementation shown below is ok, except for a small problem; it takes
too long. In order to generate 5000 samples from each of the 10000
distributions (this had to be repeated thrice, since I had to analyse 3
profiles) i.e. total 150 million random numbers my system took close to 13
hours. The required overhead to periodically save the data to the HD is a
very small fraction of the total processing time and given limitations of
available RAM cannot be improved.
The question is, is there a faster way of doing this in Mathematica or
should I be prepared to move outside the kernel for the RNG part?
I am using Mathematica 4.2 on a P4 at 2.2 GHz with 256 DDR RAM running
Windows XP
Simulate[poissonparams_List,size_Integer]:=
Module[{},
fnd[x_]:=
Map[If[#\[Equal]0,0,Random[PoissonDistribution[#]]]&,
poissonparams];
Array[fnd,{size}]
]
example of using the code :
In[40]:=
Simulate[{1,2,3,0.5,0},20]
Out[40]=
{{1,1,3,1,0},{1,1,3,1,0},{0,3,1,0,0},{3,4,5,0,0},{2,0,3,0,0},{4,4,3,0,0},{0,
2,
5,0,0},{2,1,2,1,0},{2,1,1,0,0},{2,2,2,2,0},{0,2,4,0,0},{0,2,1,0,0},{2,0,2,
1,0},{2,4,1,0,0},{0,2,6,2,0},{1,0,4,3,0},{0,2,1,0,0},{0,0,5,0,0},{1,0,3,0,
0},{1,1,3,0,0}}
I.e. generates 20 samples from the 5 Poisson Distributions with Parameter
lamda 1, 2, 3, 0.5, and zero
Thanks In advance,
Christos Argyropoulos
- Follow-Ups:
- Re: Random Number Generation : Is there a faster way of doing this ?
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: Random Number Generation : Is there a faster way of doing this ?
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: Random Number Generation : Is there a faster way of doing this ?
- From: jmt <jmt@dxdydz.net>
- Re: Random Number Generation : Is there a faster way of doing this ?