[SciPy-User] scipy.stats: Sampling from an arbitrary probability distribution
Sun Jun 3 09:07:52 CDT 2012
On Sun, Jun 3, 2012 at 7:20 AM, Daniel Sabinasz
> 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?
> Here is what I have already:
> import scipy.stats as st
> class my_pdf(st.rv_continuous):
> def _pdf(self,x):
> return x*x/10.0
> my_cv = my_pdf(name='my_pdf')
> Can I now somehow sample a random number from my_cv?
you can define your own distribution with the pdf, then the generic
methods will calculate the rvs
It will require a large number of calls to generate random numbers,
numerically calculating ppf and cdf, so this won't be efficient.
Using a linear interpolated ppf will be faster, and might be accurate enough.
(I still need to write an example for trying out the ppf interpolation version.)
> Thanks in advance!
> SciPy-User mailing list
More information about the SciPy-User