[Date Index]
[Thread Index]
[Author Index]
Re: Re: populate a list with random numbers from normal distribution?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg49996] Re: [mg49987] Re: populate a list with random numbers from normal distribution?
*From*: DrBob <drbob at bigfoot.com>
*Date*: Tue, 10 Aug 2004 06:02:52 -0400 (EDT)
*References*: <200408090829.EAA03561@smc.vnet.net>
*Reply-to*: drbob at bigfoot.com
*Sender*: owner-wri-mathgroup at wolfram.com
Your modification of myNormal[] has the nice feature that it prevents repeating the same variate. The same could be achieved by using Delete to remove each variate as it is used, but that can be slow, and any speedup from RandomArray probably won't be enough to counter it.
RandomArray is (potentially) different for every distribution, and I seem to recall it behaved better than Random for SOME distribution, possibly the Normal?
Here's a related post on the problem with Random for the Geometric distribution. In that case, RandomArray still has the problem.
http://groups.google.com/groups?q=random+geometric+group:comp.soft-sys.math.mathematica&hl=en&lr=&ie=UTF-8&group=comp.soft-sys.math.mathematica&selm=8etpva%24n40%40smc.vnet.net&rnum=1
Bobby
On Mon, 9 Aug 2004 04:29:26 -0400 (EDT), Bill Rowe <readnewsciv at earthlink.net> wrote:
> 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
>
>
>
--
DrBob at bigfoot.com
www.eclecticdreams.net
Prev by Date:
**Re: Re: button to emulate Shift-Enter**
Next by Date:
**Re: How to set linewidth in 3-D graphics?**
Previous by thread:
**Re: populate a list with random numbers from normal distribution?**
Next by thread:
**Re: populate a list with random numbers from normal distribution?**
| |