commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikkel Meyer Andersen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MATH-585) Very slow generation of gamma random variates
Date Fri, 10 Jun 2011 16:06:58 GMT

    [ https://issues.apache.org/jira/browse/MATH-585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13047265#comment-13047265
] 

Mikkel Meyer Andersen commented on MATH-585:
--------------------------------------------

Darren, exactly. I'm also thinking about an inner class, but it's quite easy to change so
I'll wait to raise that question until I have written some tests and get closer to committing.
Yes, it indeed took some time - but as you might imagine, it was good fun :-).

Brent, thanks for the proposals. They actually improved the algorithm slightly - around 7%
in the (too) small tests I made (5 samples on each with one choice of parameters). Tests from
before the change was made:
{quote}
Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 502.0 ms. with mean 104.88707585478387 and var 471.92840503136534

Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 483.0 ms. with mean 104.82077923605411 and var 470.1964562913125

Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 542.0 ms. with mean 104.85678418999862 and var 471.6356319869918

Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 471.0 ms. with mean 104.86904621863894 and var 472.21151252978103

Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 491.0 ms. with mean 104.83920614619137 and var 473.1249434489607
{quote}
and afterwards
{quote}
Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 447.0 ms. with mean 104.87373894447317 and var 471.39010480694253

Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 455.0 ms. with mean 104.85845231810445 and var 472.42913996929894

Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 482.0 ms. with mean 104.8721506023297 and var 471.1563267884988

Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 460.0 ms. with mean 104.90256013379438 and var 472.7495176399378

Generating 1000000 random gamma(23.3, 4.5) with mean 104.85000000000001 and var 471.82500000000005
nextGamma took 461.0 ms. with mean 104.82129306938253 and var 470.8630399950795
{quote}

{code}
> x1 <- c(502, 483, 542, 471, 491)
> x2 <- c(447, 455, 482, 460, 461)
> mean(x1)-mean(x2)
[1] 36.8
> (mean(x2)-mean(x1))/mean(x1)
[1] -0.07392527
{code}

> Very slow generation of gamma random variates
> ---------------------------------------------
>
>                 Key: MATH-585
>                 URL: https://issues.apache.org/jira/browse/MATH-585
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.2, 3.0
>         Environment: All
>            Reporter: Darren Wilkinson
>            Assignee: Mikkel Meyer Andersen
>              Labels: Gamma, Random
>         Attachments: MATH585-1.patch
>
>   Original Estimate: 6h
>  Remaining Estimate: 6h
>
> The current implementation of gamma random variate generation works, but uses an inversion
method. This is well-known to be a bad idea. Usually a carefully constructed rejection procedure
is used. To give an idea of the magnitude of the problem, the Gamma variate generation in
Parallel COLT is roughly 50 times faster than in Commons Math. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message