MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Random Number Generation : Is there a faster way of doing this ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43194] Re: [mg43190] Random Number Generation : Is there a faster way of doing this ?
  • From: jmt <jmt at dxdydz.net>
  • Date: Mon, 18 Aug 2003 02:50:53 -0400 (EDT)
  • References: <200308170828.EAA04316@smc.vnet.net>
  • Reply-to: jmt at dxdydz.net
  • Sender: owner-wri-mathgroup at wolfram.com

If n is the length of the sample list, and m the number of lists, your problem 
is O(n m).
I have made timings on my machine (Pentium 350MHz, Mathematica 5.0), with n=m
10 -> 0.98s
25->5.85s
40->15.88s
80->62.77s
200->393.09s

I let you calculate the timing for n=10000 and m=5000.

I tried using a MathLink function, calling the GNU Scientific Library ; the 
speed is roughly eight times better for short series, but longer series make 
this code less efiicient - probably transfer times on the link.

Contact me directly if interested in this code.


On Sunday 17 August 2003 10:28, Christos Argyropoulos M.D. wrote:
  > 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


  • Prev by Date: Re: how to specify something is "real"
  • Next by Date: RE: Merging objects before tumbling animation
  • Previous by thread: Random Number Generation : Is there a faster way of doing this ?
  • Next by thread: Re: Random Number Generation : Is there a faster way of doing this ?