MathGroup Archive 2004

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49987] Re: populate a list with random numbers from normal distribution?
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Mon, 9 Aug 2004 04:29:26 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 8/8/04 at 10:54 AM, drbob at bigfoot.com (DrBob) wrote:

>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]]]])

You could simplify this some what and achieve the same effect as follows:

myNormal[]:=
    Module[{k = Random[Integer, Length@sampler],x},
        x=sampler[[k]];
        sampler[[k]]=Random[NormalDistribution[0,1]];
        Return[x]]


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

This procedure should definitely break up any serial correlations that existed. I don't recall exactly what problems were reported for Random. If serial correlation was the only problem, then this should fix things.

>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.

If you modify the procedure as I outlined, then the cost difference over using Random is simply generating one extra random integer each time Random is called. Of course, there will be the additional loss whenever RandomArray is more efficient than repeated calls to Random. But for several distributions (such as the exponential or uniform distributions) RandomArray offers no gain in speed over repeated calls to Random

>Anyway, isn't it true that RandomArray doesn't have the problems
>Random has displayed? 

No.  From ContinuousDistributions.m

(* NOTE: For UniformDistribution, RandomArray provides no speedup over Random. *)
UniformDistribution/: RandomArray[UniformDistribution[min_:0, max_:1], dim_] :=
  Module[{n, array},
    n = If[VectorQ[dim], Apply[Times, dim], dim];
    array = Table[Random[Real, {min, max}], {n}];
    If[VectorQ[dim] && Length[dim] > 1,
       Fold[Partition[#1, #2]&, array, Reverse[Drop[dim, 1]] ],
       array  ]
  ] /; (IntegerQ[dim] && dim > 0) || VectorQ[dim, (IntegerQ[#] && # > 0)&]

As you can see RandomArray simply calls Random to generate the uniform deviates. So, it must suffer from the same problems as Random.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: button to emulate Shift-Enter
  • Next by Date: Re: Binomial ratio expectation
  • Previous by thread: Re: Re: populate a list with random numbers from normal distribution?
  • Next by thread: Re: Re: populate a list with random numbers from normal distribution?