Re: Efficient Sampling of a PDF
- From: Peter Boettcher <boettcher@xxxxxxxxxx>
- Date: Tue, 13 Jun 2006 10:42:39 -0400
"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/
.
- References:
- Efficient Sampling of a PDF
- From: JRP
- Re: Efficient Sampling of a PDF
- From: Greg Heath
- Efficient Sampling of a PDF
- Prev by Date: Re: Going through a cell
- Next by Date: Re: Going through a cell
- Previous by thread: Re: Efficient Sampling of a PDF
- Next by thread: Re: Efficient Sampling of a PDF
- Index(es):
Relevant Pages
|