random numbers according to user defined distribution ??

Robert Kern robert.kern at gmail.com
Thu Aug 7 17:32:04 EDT 2008


Alex wrote:
> Thanks for the many answers.
> 
> So basically I have to get the inverse of the CDF and use this to
> transform my uniformly distributed random numbers. If my desired
> distribution is simple I can get an analytical solution for the
> inverse, otherwise I have to use numerical methods.
> 
> Okay, things are now much clearer.

It's worth noting that unless if the PPF (the inverse of the CDF) is very 
straightforward, this method is not very good. The numerical errors involved 
cause very poor results in the tails of many distributions. Typically, rejection 
sampling, if done well, will work much better. There are techniques for doing 
this on nearly-arbitrary distributions:

   http://statmath.wu-wien.ac.at/projects/arvag/index.html

If you implement any of these techniques in Python, I would love to see them.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list