MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Random sampling of an arbitrary distribution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59765] Random sampling of an arbitrary distribution
  • From: "Owen, HL \(Hywel\)" <h.l.owen at dl.ac.uk>
  • Date: Sat, 20 Aug 2005 03:14:01 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com
  • Thread-index: AcWUARxuDvWrfvuaR3+oCqvYT5AXyAQ0WQ5g

Hi folks,

Apologies if this is an old question, but I did search the various
archives and didn't come up with anything yet.

I would like to generate a number of sample values which are distributed
according to an arbitrary probability distribution, e.g. not Uniform,
Normal, or any of the ones in the ContinuousDistributions package. Given
a pure function distfn, I can see how to sample it over the range
distmin to distmax using the following:

MonteCarloSample[distfn_, distmin_, distmax_] := Module[{a, b},
    While[(a = Random[Real, {distmin, distmax}]; b = Random[];
        b > distfn[a])];
    a]

This is fine and works well, except when distmin and distmax are widely
apart when it becomes inefficient. Does anyone know an alternative
method which:
a) allows samples to be drawn from an arbitrarily large range (e.g. up
to infinity if desired)
b) remains efficient at large range values.

I'm also trying to use the van der Corput sequence to generate
pseudo-random samples which are distributed more evenly. I have used a
definition found on the web:

vanderCorput[n_, b_] := IntegerDigits[n, b].(b^
    Range[-Floor[Log[b, n] + 1], -1]);
Attributes[vanderCorput] = Listable;

and then set up a sampling function as:

PseudoRandomMonteCarloSample[distfn_, distmin_, distmax_, 
    sequencenumber_] := Module[{a, b},
    a = distmin + (distmax - distmin)vanderCorput[sequencenumber, 2]; b
= vanderCorput[sequencenumber, 2];
    If[b > distfn[a], {}, a]]

You can then generate a Table of numbers by scanning over the sequence
number and Flatten-ing the result. Again, this works fine but you end up
with a series of samples whose length is of course much less than the
sequence numbers (you throw away most of the edges of the distribution).
Can anyone think of a better method?

Thanks!

Hywel


  • Prev by Date: Re: Nested Lists, Definition and Evaluation.
  • Next by Date: Re: Nested Lists, Definition and Evaluation.
  • Previous by thread: Re: Weird Plot problem
  • Next by thread: Re: Random sampling of an arbitrary distribution