commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex D Herbert (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (RNG-68) AhrensDieterMarsagliaTsangGammaSampler constructor can be optimised for the theta parameter
Date Thu, 11 Apr 2019 11:34:00 GMT

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

Alex D Herbert resolved RNG-68.
-------------------------------
    Resolution: Implemented
      Assignee: Alex D Herbert

In master.

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

Mime
View raw message