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 D Herbert (JIRA)" <ji...@apache.org> on 2019/01/25 14:40:00 UTC
[jira] [Created] (RNG-68) AhrensDieterMarsagliaTsangGammaSampler
constructor can be optimised for the theta parameter
Alex D Herbert created RNG-68:
---------------------------------
Summary: 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
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)