4 Jun
2012
4 Jun
'12
3:21 p.m.
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