You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2019/11/05 12:33:00 UTC

[jira] [Updated] (RNG-68) AhrensDieterMarsagliaTsangGammaSampler constructor can be optimised for the theta parameter

     [ https://issues.apache.org/jira/browse/RNG-68?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Herbert updated RNG-68:
----------------------------
    Fix Version/s: 1.3

> AhrensDieterMarsagliaTsangGammaSampler constructor can be optimised for the theta parameter
> -------------------------------------------------------------------------------------------
>
>                 Key: RNG-68
>                 URL: https://issues.apache.org/jira/browse/RNG-68
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: sampling
>    Affects Versions: 1.2
>            Reporter: Alex Herbert
>            Assignee: Alex Herbert
>            Priority: Trivial
>             Fix For: 1.3
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> The AhrensDieterExponentialSampler has two algorithms based on the {{theta}} parameter. The constructor precomputes factors for both algorithms even though only one algorithm will even be called.
> I suggest optimising the constructor using:
> {code:java}
> public AhrensDieterMarsagliaTsangGammaSampler(UniformRandomProvider rng,
>                                               double alpha,
>                                               double theta) {
>     super(null);
>     this.rng = rng;
>     this.alpha = alpha;
>     this.theta = theta;
>     gaussian = new ZigguratNormalizedGaussianSampler(rng);
>     if (theta < 1) {
>         oneOverTheta = 1 / theta;
>         bGSOptim = 1 + theta / Math.E;
>         // Unused
>         dOptim = cOptim = 0;
>     } else {
>         dOptim = theta - ONE_THIRD;
>         cOptim = ONE_THIRD / Math.sqrt(dOptim);
>         // Unused
>         oneOverTheta = bGSOptim = 0;
>     }
> }
> {code}
> An alternative is to split the two algorithms into two classes as was done for the {{PoissonSampler}} for small and large mean.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)