[Jprogramming] generating standard normal variates

Viktor Cerovski viktor.cerovski at gmail.com
Fri Aug 15 05:01:15 HKT 2008



Henry Rich wrote:
> 
> I'm not following this thread closely, but Algorithm M in section
> 3.4.1 of TAOCP is a very fast way of generating
> normal deviates.  It can be modified to support generating
> them in batches.
> 
> Knuth says (p. 113 of my 1969 edition) "a general-purpose
> subroutine based on Algorithm M will be a valuable part of
> any subroutine library".
> 
> Henry Rich
> 
Presumably it is about the code that avoids sin and cos of
the Box-Mueller code by picking a random point within the unit 
circle and then doing a transformation involving only ln 
and square root.

It can be done like this:

F=:(1-~2*(?,?)@0:)^:(1<:+&*:/)^:_
Nrnd=:({.,)(*([:%:@(- at +:@^. % ])+&*:/))@F"0@($1:)@>. at -:

F picks the point, Nrnd does the rest.  There is doubling of 
computation of +&*:/ for every found point.

The following mathematically equivalent routine done via 
complex numbers is a bit faster:

ReIm=:9 11&o.
G=:(1j1-~2*(?j.?)@0:)^:(1<:|)^:_
Nrnd1=:({.,)(((%:@-@^. % ])@| * ReIm)"1 at G"0@($1:))@>. at -:

but both are much slower than other tacit routines from this thread.

-- 
View this message in context: http://www.nabble.com/generating-standard-normal-variates-tp18898408s24193p18989673.html
Sent from the J Programming mailing list archive at Nabble.com.



More information about the Programming mailing list