Re: Random Normal deviates within compiled function?
- To: mathgroup at smc.vnet.net
- Subject: [mg62345] Re: Random Normal deviates within compiled function?
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Mon, 21 Nov 2005 03:54:36 -0500 (EST)
- References: <dln17e$gf4$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Gareth Russell wrote: > Hi All, > > I have a function which needs to be quick as it's used in simulations, > and it requires the internal generation of a large vector of random > normal deviates (up to 50,000). It appears that a function like > Random[NormalDistribution[0,s]] cannot be compiled. Can anyone suggest > an algorithm for getting such numbers that would work within a Compile > statement and still be quicker than using the non-compiled function? > > The non-compiled function would look as follows: > > f[v_,r_,k_,s_,q_]:=Select[v*Exp[r*(1 - v/k) + > RandomArray[NormalDistribution[0, s], > Length[v]]], # > q &] > > where v is a vector of 50,000 reals, and r, k, s and q are scalar reals. > > (If anyone is interested, this is for population projection in > population viability analysis.) > > Thanks, > > Gareth Russell > NJIT There are problems with Random[]. I do not use it for anything in which the lack of independence of successive values might conceivably matter. For much more on this, see the thread "normal distribution random number generation" that started Oct 4, 2004.