MathGroup Archive 2004

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

Search the Archive

Re: Re: populate a list with random numbers from normal distribution?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49982] Re: [mg49974] Re: populate a list with random numbers from normal distribution?
  • From: DrBob <drbob at bigfoot.com>
  • Date: Mon, 9 Aug 2004 04:29:20 -0400 (EDT)
  • References: <200408080938.FAA21931@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

>> Writing a good algorithm for generating psuedo-random values and validtating it is definitely a non-trivial exercise.

Writing a better one than Mathematica contains will be MORE than a non-trivial exercise.

If serial correlation in the built-in algorithms is an issue (but it probably isn't in the OP's application, whatever that is), I think I'd try one or more of these simple strategies:

1) Use RandomArray to pre-sample for a problem, and use Random[Integer,...] to index into that array to get individual variates.

2) Randomly throw away a fraction of the variates.

3) If using the first strategy, refresh the pre-sample occasionally (at random).

For instance, using the first and third strategies:

count = 0;
preSample[] :=
   (sampler = RandomArray[NormalDistribution[0, 1], {10000}];
    count = Random[Integer, {500, 1000}])
myNormal[] := (If[count <= 0, preSample[]]; count--; sampler[[Random[Integer, Length[sampler]]]])

I seriously doubt myNormal will exhibit any of the problems previouly detected for Random itself.

It will be slower than using the built-in alone, but the price can be greatly reduced by shrinking the size of the pre-sample and/or increasing the number of variates used before resampling.

Anyway, isn't it true that RandomArray doesn't have the problems Random has displayed? If so, this may work just as well, with much less overhead:

count = 0;
preSample[] := (sampler = RandomArray[NormalDistribution[0,1], {1000}]; count = Length[sampler])
myNormal[] := (If[count <= 0, preSample[]]; sampler[[count--]])

Bobby

On Sun, 8 Aug 2004 05:38:03 -0400 (EDT), Bill Rowe <readnewsciv at earthlink.net> wrote:

> On 8/7/04 at 3:52 AM, sean_incali01 at yahoo.com (sean_incali) wrote:
>
>> Only reason I wanted to use the integers is because of the issues
>> raised previously, and because i didn't understand them fully.
>
>> I wanted to pick the integers from a distribution in a range and
>> then scale the integers  to make real numbers.
>
> While there are some technical issues with the subtract with borrow algorithm used by Mathematica for reals, these issues don't have any impact on many applications of pseudo-random numbers. Quite possibly by using Mathematica to generate psuedo-random integers then converting these to reals, you are going to a lot of trouble without having any significant effect on your application. Obviously, for me or someone else to determine whether this is the case or not, details of your application are needed which you haven't yet supplied.
>
>> You said the discrete uniform distribution will pick intergers in
>> the range {10000,99999}, or any other distribution.
>
>> Will it do normal or poissonian distribution in that range?
>
> I take "it" here to mean Random[Integer,{10000, 99999}]. If this is correct, then the answer to your question is no. Integers uniformly selected in a given range cannot have either a Poisson distribution or a normal distribution. Each of these distributions has different statistical properties, different relationships between say the mean, standard deviation etc.
>
>> if so how do I implement that?
>
> If you need normal deviates then the simplest way to get them would be
>
> <<Statistics`
> Random[NormalDistribution[mean, stdDev]]
>
> or if it is Poisson deviates you need then try
>
> <<Statitistics`
> Random[PoissonDistribution[mu]]
>
> Also, do note the Poisson distribution is a discrete distribution, meaning the output of Random[PoissonDistribution[mu]] is an integer. So, starting with uniformly distributed integers and converting these to reals would be counterproductive if what you want are Poisson distributed integers.
>
> If for some reason the algorithms used by Mathematica to generate psuedo-random values are not adequate for your application, then it isn't difficult to implement your own algorithm in Mathematica. Knuth in Seminumerical Algorithms Vol 2 discusses a variety of algorithms for generating psuedo-random values from any desired distribution. But do note there are lot of very bad algorithms that have been used in the past. Writing a good algorithm for generating psuedo-random values and validtating it is definitely a non-trivial exercise.
> --
> To reply via email subtract one hundred and four
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Binomial ratio expectation
  • Next by Date: Re: Re: UnrankPermutation newbie problem .. Combinatorica Package
  • Previous by thread: Re: populate a list with random numbers from normal distribution?
  • Next by thread: Re: Re: populate a list with random numbers from normal distribution?