Re: Efficient Sampling of a PDF



"Greg Heath" <heath@xxxxxxxxxxxxxxxx> writes:

JRP wrote:
If I have a probability density function (PDF) and want to pick 'N'
random samples that will be distributed according to the distribution
described by my PDF, what is an efficient way to do this?

My PDFs are not simple gaussians or uniform distributions. They can
be very complex.

Right now what I do is just generate a bunch of data points, far more
than 'N', randomly mix them up in a vector, then randomly select 'N'
of them. For example, if my PDF has a value PDF(x0) = 0.1 and PDF(x1)
= 0.04, I would generate 100 x0 values and 4 x1 values to put into my
'sampling vector'. In general, if I have PDF(xi) = yi, where yi is of
precision to the hundredth decimel place, then I create 100*yi values
of xi to go into my 'sampling vector'. Later I randomly mix up the
components of this vector and randomly choose 'N' value from it.
However, this seems rather inefficient!!! Especially if I want higher
precision and want to represent values such as PDF(xi) = 0.0002...

Anyone have a more intelligent way of sampling an arbitrary PDF?

Integrate to obtain the CDF. Randomly choose CDF values in (0,1).
Obtain the corresponding values of x via the inverse CDF.

If your PDF is discrete, like it sounds, then 'cumsum' is the
equivalent of integration, and you can use 'histc' to map your uniform
(0,1) values through the CDF and onto your PDF indexes.

See this thread. SeBy's answer is probably better than mine.

http://groups.google.com/group/comp.soft-sys.matlab/browse_thread/thread/f8a17e3ca3859ff7/f803d802032a17ec?lnk=st&q=cdf+cumsum+rand+group%3Acomp.soft-sys.matlab&rnum=4&hl=en#f803d802032a17ec


--
Peter Boettcher <boettcher@xxxxxxxxxx>
MIT Lincoln Laboratory
MATLAB FAQ: http://www.mit.edu/~pwb/cssm/
.



Relevant Pages

  • Re: Efficient Sampling of a PDF
    ... random samples that will be distributed according to the distribution ... of xi to go into my 'sampling vector'. ... Anyone have a more intelligent way of sampling an arbitrary PDF? ... Randomly choose CDF values in. ...
    (comp.soft-sys.matlab)
  • Re: Statistical Indep and Corr of Normal RVs
    ... yet their joint pdf is not a bivariate normal pdf. ... The counter-example you gave sounds like the one I saw before. ... small quasi-hemispherical "ice cream scoop" of probability density at, ... probability-density distribution onto the x and y axes will still be ...
    (sci.stat.edu)
  • Re: can (how do) I use Bayesian inference for this problem
    ... function of the combined total of these marks. ... For any given exercise there is of the order of 150 ... distribution tends to gravitate towards one particular 'bin', ... rather than a multiplicative pdf. ...
    (sci.stat.math)
  • Efficient Sampling of a PDF
    ... If I have a probability density function (PDF) and want to pick 'N' ... random samples that will be distributed according to the distribution ... precision to the hundredth decimel place, ... of xi to go into my 'sampling vector'. ...
    (comp.soft-sys.matlab)
  • Re: Help with multivariate distribution
    ... distribution which you work on. ... The KS test only looks at the empirical cdf of the distribution. ... beta, X has to be between 0 and 1, and of those, how do you ... I can fit a beta pdf to a histogram of the data using optimisation ...
    (sci.stat.math)