octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Low hanging fruit - Accelerated random distribution functions


From: Paul Kienzle
Subject: Re: Low hanging fruit - Accelerated random distribution functions
Date: Fri, 23 Feb 2007 08:05:37 -0500


On Feb 23, 2007, at 7:49 AM, Paul Kienzle wrote:


On Feb 23, 2007, at 5:27 AM, David Bateman wrote:

Paul Kienzle wrote:

On Feb 22, 2007, at 7:29 PM, Paul Kienzle wrote:


On Feb 22, 2007, at 11:46 AM, David Bateman wrote:

I haven't tried to convert the functions geornd,

Octave uses the following; it would be hard to beat:

   rnd(k) = floor (log (rand (size (k))) ./ log (1 - p(k)));

On second thought,

    rnd = floor(-rande(n)) ./ log(1-p)

Oops ... misplaced parenthesis...

It should be R = floor(-rande(n)./log(1-p))

I'm not sure why this would affect the speed.


is 2x faster.

Are you sure its not the reverse

octave:3> function rnd = geornd2(p,varargin), rnd =
floor(-rande(varargin{:})) ./ log(1-p); endfunction
octave:4> tic; b0 = geornd(3,1,1e7); toc
Elapsed time is 1.643173 seconds.
octave:5> tic; b1 = geornd2(3,1,1e7); toc
Elapsed time is 3.176453 seconds.

octave2.9:10> tic; y = floor(log(rand(400))./log(1-0.2)); toc
Elapsed time is 0.534271 seconds.
octave2.9:11> tic; x = floor(-rande(400)./log(1-0.2)); toc
Elapsed time is 0.348267 seconds.
octave2.9:12> [statistics(x(:)),statistics(y(:))]
ans =

    0.00000    0.00000
    1.00000    1.00000
    3.00000    3.00000
    6.00000    6.00000
   55.00000   54.00000
    4.00524    3.99577
    4.49588    4.46590
    2.02001    1.99510
    5.99429    5.90314




reply via email to

[Prev in Thread] Current Thread [Next in Thread]