![](https://secure.gravatar.com/avatar/5bc3911d30ec66d8a65a05846502f0c4.jpg?s=120&d=mm&r=g)
Hi Maybe this article is of help http://www.google.com/url?sa=t&rct=j&q=plehn%20bruns&source=web&cd=2&ved=0CFoQFjAB&url=http%3A%2F%2Fwww.logistics-journal.de%2Fnot-reviewed%2F2005%2F7%2Fapproximation%2FApproximation_and_Computation_of_Random_Variables_using_Finite_Elements.pdf&ei=CRXNT4eyC6ik4gSoqYWPDA&usg=AFQjCNFLF-Zr3w6opNHWsM3HYGUaTqK8vA Nicky On Jun 4, 2012 3:22 PM, "Sturla Molden" <sturla@molden.no> wrote:
On 03.06.2012 13:20, Daniel Sabinasz wrote:
Hi all,
I need to sample a random number from a distribution whose probability density function I specify myself. Is that possible using scipy.stats?
Sampling a general distribution is typically an MCMC problem, that e.g. can be solved with the Metropolis-Hastings sampler.
http://en.wikipedia.org/wiki/Metropolis%E2%80%93Hastings_algorithm
Because of its recursive nature, a Markov chain like this is better written in Cython, or you can use NumPy to run multiple chains in parallel. (I depends on how many samples you need, of course, anything below a million should be fast enough in Python.)
You might also take a look at PyMCMC: https://github.com/rdenham/pymcmc
Sturla _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user