MathGroup Archive 2005

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

Search the Archive

Re: Random sampling of an arbitrary distribution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59991] Re: Random sampling of an arbitrary distribution
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sat, 27 Aug 2005 04:11:31 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 8/26/05 at 4:53 AM, h.l.owen at dl.ac.uk (Owen, HL (Hywel)) wrote:

>Thanks for the reply. First off, I should point out that I am a
>physicist (i.e. small maths brain!) rather than a mathematician
>(big maths brain).

I too, am a physicist by training not a mathematician. Currently, I am often trying to extract some meaningful information from data. And for this purpose, I've found a solid understanding of statistics to be essential.
 
>>Using mathStatica,

>>f = (1/(\[Sigma]*Sqrt[2*Pi]))*Exp[-((x - \[Mu])^2/
>>(2*\[Sigma]^2))]; domain[f] = {x, -Infinity, Infinity} && {\[Mu]
>>\[Element] Reals, \[Sigma] > 0};
>>
>>Expect[a*Sin[2*Pi*x], f]

>>(a*Sin[2*Pi*\[Mu]])/ E^(2*Pi^2*\[Sigma]^2)

>>That is the integral over the domain does not evaluate to 1.

>I get 1, e.g.

>1 + (modamp*Sin[modphase + (2*mu*Pi)/modlambda])/E^((
>2*Pi^2*sigma^2)/modlambda^2) /. {modlambda -> 1, modphase -> 0, mu
>-> 1, sigma -> 1}

This is not different than what I got using mathStatica. The difference is you set mu to zero which causes the sin term to vanish. But mu may be any positive real number. And certainly the sin term only vanishes for particular values of mu. Hence, the integral is not unity in general and cannot be a density function.

>>Normally, when someone speaks of getting random numbers from a
>>specified density function they mean the the probability of
>>getting a number less than a specified value is equal to the
>>cumulative distribution function evaluated at that specified
>>value. What you are doing above is distinctly different. You are
>>selecting random points conditioned on having the value of a
>>expression (intended to be the density function?) at that point
>>less than the random another random point. This is not equivalent
>>to generating random numbers with a specified density function.

>Yes, but I thought that since the sampled points match the density
>function that it was a valid method. 

No. The value of the density function is unimportant. It is the value of the cumulative distribution function that gives the probability of finding values less than or equal to the given value. But of course if you know the cumulative distribution function and it is invertible, then simply using the inverse function gives you what you want when the input is a uniform deviate.

>>OTOH, if you do want random numbers from a specified density
>>function it is possible to achieve this when the cumulative
>>distribution function cannot be easily evaluated. But rather than
>>attempt to explain the possibilities here I stongly suggest you
>>consult established texts. An excellent starting point is Knuth's
>>Seminumerical Algorithms Vol 2. 
>
>Yes, I have it front of me now!

>My sampling method above appears to me to be a form of von
>Neumann's rejection method, so I can't see why it isn't valid
>statistically. 

If you were using the cumulative distribution function (not the density function) then it does look to me like this is a form of the rejetion method. In fact, when I looked at your first post that is what I thought you were doing. It was only on later posts I noticed you were using the density function rather than the cumulative distribution function.

>>A couple of final thoughts. Creating a psuedo random number
>>generator with the desired properties is anything but a trivial
>>task. It is extremely easy to create a very bad generator. Bad
>>meaning the numbers do generated have few if any of the desired
>>properties. Knuth discusses several examples of bad generators.

>Absolutely! It's a good book.

If you are going to do a lot of statistical analysis or random number generation using Mathematica, then the other text I menitioned is also very useful particularly if you purchase a license for mathStatica. Using mathStatica greatly simplifies the process of generating pseudo random numbers from arbitrary distributions.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: ListDensityPlot and transparency
  • Next by Date: Re: help working with functions
  • Previous by thread: Re: Re: Random sampling of an arbitrary distribution
  • Next by thread: SuDoku Deduction Rules