[SciPy-Dev] Sampling from arbitrary distributions

Andrew Nelson andyfaff at gmail.com
Fri Apr 1 00:56:52 EDT 2016


Hi all,
I have a need to take samples from an arbitrary continuous statistical
distribution. By arbitrary I mean it doesn't have an exact functional form.
Rather, the distribution was created by sampling a physical process and
then histogramming.
I then wish to randomly sample from this distribution for a monte carlo
simulation. Whilst I could (in this circumstance) sample with replacement
from my original measurement I thought it might be quite cool to subclass
scipy.stats.rv_continuous to do it, see the gist for further info.

https://gist.github.com/andyfaff/9a7930f3d93a99f478cdadae4d1bb3b2

This way one gets lots of other benefits for free (e.g. the CDF, PPF,
calculation of statistical moments, etc). I was wondering if this might be
a useful thing to add to scipy.stats. I'm not overly familiar with the
stats module so I thought I'd ask this again on the dev list (I asked this
question on the user list a couple of days ago).

The class does store state because it needs to do interpolation, etc. It
was suggested that the "Histogram distribution would be the continuous
analog to the arbitrary finite number of points discrete distribution, so
might fit as well."
Don't get too caught up by it working on histogrammed data, it should be
straightforward to modify it to act for a distribution that has no analytic
functional form, but where PDF(x) is known for many x.

A.

-- 
_____________________________________
Dr. Andrew Nelson


_____________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20160401/d67a8253/attachment.html>


More information about the SciPy-Dev mailing list