MathGroup Archive 1992

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

Search the Archive

Re: excessive LogNormalDistribution timing

  • To: mathgroup at
  • Subject: Re: excessive LogNormalDistribution timing
  • From: withoff
  • Date: Mon, 5 Oct 92 10:35:04 CDT

> Dear Mathgroupers,
>   We need to draw random numbers from some of the continuous distributions
> provided in the package Statistics`ContinuousDistributions` in Mma 2.0, but
> we discovered a gross disparity in the timing for the LogNormalDistribution
> which makes it almost impossible to use for real applications.  Here is an
> example (on a MacIIfx):
> ran1=Table[Random[ExponentialDistribution[1]], {100} ]//Timing
>   {1.  Second,...}
> ran2=Table[Random[NormalDistribution[0,1]], {100} ]//Timing
>   {1.61667  Second,...}
> ran3=Table[Random[LogNormalDistribution[0,1]], {100} ]//Timing
>   {110.7  Second,...}
> There is a factor of 50-100 disparity.  Yet LogNormalDistribution only
> involves one extra Log evaluation compared to ExponentialDistribution or
> NormalDistribution.  What can possibly be wrong here?
> -------------------------------------------
> Dr. Warren J. Wiscombe
> NASA Goddard, Code 913, Greenbelt, MD 20771
> (301) 286-8499

The formula in Statistics`ContinuousDistributions` for random
numbers with a LogNormalDistribution computes quantiles of
uniformly distributed random numbers, while the formula for
random numbers with a NormalDistribution uses a much faster
formula.  The faster formula can be used for both distributions.

In[4]:= Do[Random[LogNormalDistribution[0, 1]], {100}] //Timing

Out[4]= {60.9333 Second, Null} 

In[13]:= LogNormalDistribution/: Random[LogNormalDistribution[mu_, sigma_]] := 
            Exp[mu + sigma Sqrt[-2 Log[Random[]]] Cos[2Pi Random[]]] 
In[14]:= Do[Random[LogNormalDistribution[0, 1]], {100}] //Timing 

Out[14]= {0.566667 Second, Null}

In many cases a number of other things can be done for further speed
improvements, (use low-precision formulas for quantiles, generate numbers
in pairs, etc.), but I am not an expert on the subject.  Perhaps someone
who is could help out.

  • Prev by Date: Re: A Simplify that really simplifies? Summary
  • Next by Date: Mathematica Problem
  • Previous by thread: excessive LogNormalDistribution timing
  • Next by thread: EditIn