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

Alex D Herbert commented on RNG-68:
-----------------------------------

Here is the PR:

[Pull Request 17|https://github.com/apache/commons-rng/pull/17]

> 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
>          Time Spent: 0.5h
>  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
(v7.6.3#76005)

Reply via email to