You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gilles (JIRA)" <ji...@apache.org> on 2019/01/25 15:09:00 UTC

[jira] [Commented] (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:comment-tabpanel&focusedCommentId=16752341#comment-16752341 ] 

Gilles commented on RNG-68:
---------------------------

bq. split the two algorithms into two classes

+1
Private inner classes (?).

> 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 D Herbert
>            Priority: Trivial
>
> 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
(v7.6.3#76005)