[SciPy-user] Monte Carlo package
Travis Oliphant
oliphant at ee.byu.edu
Wed Jan 25 13:44:15 CST 2006
David Huard wrote:
> I mean an arbitrary user-defined distribution. I want to generate
> samples using a Gibbs sampler, and one of the conditional distribution
> has a weird shape involving a sum of logs... Anyway, there is no
> chance that I can find an analytical expression for this cdf and I
> wondered if there was a routine somewhere that would let me define the
> function and would return samples drawn from this distribution. I
> thought about that since the intsampler of montecarlo does something
> similar for discrete distributions.
>
Well in SciPy stats, there is some (limited) support for this. If you
can define the pdf, then it will first numerically integrate that to get
the CDF and then invert that to generate samples from the distribution.
It will be slow and the convergence of the two piggy-backed numerical
solutions might give you headaches, but...
You might try using the rejection algorithm. There is no simple
interface to such a thing though. It might be a good thing to add (i.e.
specify a known density and a constant so that cg(x) bounds and then
your pdf and then have it generate samples using the rejection method.
-Travis
More information about the SciPy-user
mailing list