commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex D Herbert (JIRA)" <>
Subject [jira] [Commented] (RNG-96) AhrensDieterMarsagliaTsangGammaSampler incorrectly names parameters
Date Thu, 25 Apr 2019 13:22:00 GMT


Alex D Herbert commented on RNG-96:

{quote}I'd favour the cleaner fix (i.e. change parameter order and name in order to match
the reference).
OK. So update the sampler so that the parameter order and meaning is the same as Commons Math

alpha = shape

theta = scale

I will maintain alpha and theta but note the alternative names in the Javadoc. FYI. I already
added the alternative names to the javadoc when I split the algorithms for RNG-68. I just
did not notice the sampler functionality was reversed until I started using the sampler for
{quote}Class GammaDistribution in "Commons Statistics" should also be fixed.
IIUC that would be just be a parameter swap in the following method:
public ContinuousDistribution.Sampler createSampler
The javadoc about the algorithm appears to be correct, i.e. AhrensDieter when shape <
1 or else MarsagliaTsang.

The change to this class should be made when Commons RNG 1.3 is released. Should I add a Jira
ticket to do this to Commons Statistics and link this?

> AhrensDieterMarsagliaTsangGammaSampler incorrectly names parameters
> -------------------------------------------------------------------
>                 Key: RNG-96
>                 URL:
>             Project: Commons RNG
>          Issue Type: Bug
>          Components: sampling
>    Affects Versions: 1.3
>            Reporter: Alex D Herbert
>            Assignee: Alex D Herbert
>            Priority: Minor
>             Fix For: 1.3
> The AhrensDieterMarsagliaTsangGammaSampler has parameters alpha and theta.
> Using the naming conventions on [Wikipedia Gamma distribution|]
the alpha parameter is also known as the shape and the theta parameter is the scale:
> {noformat}
> // Wikipedia
> alpha = shape
> theta = scale
> {noformat}
> However if the sampler is run with the same parameters as the Wikipedia article histograms
of the output sample distribution does not match. They need to be swapped indicating a naming
> Studying the same algorithm in o.a.c.math3.distribution.GammaDistribution it appears
that the theta parameter is being used by Commons RNG as the shape and the alpha parameter
is being used as the scale. So the names are incorrect and have been swapped.
> {noformat}
> // Commons RNG
> alpha = scale (wrong)
> theta = shape (wrong)
> {noformat}
> The unit tests for this sampler does this:
> {code:java}
> // Gamma (theta < 1).
> add(LIST, new org.apache.commons.math3.distribution.GammaDistribution(unusedRng,
>     thetaGammaSmallerThanOne, alphaGamma),
>     new AhrensDieterMarsagliaTsangGammaSampler(
>             RandomSource.create(RandomSource.XOR_SHIFT_1024_S),
>             alphaGamma, thetaGammaSmallerThanOne));
> // Gamma (theta > 1).
> add(LIST, new org.apache.commons.math3.distribution.GammaDistribution(unusedRng, 
>     thetaGammaLargerThanOne, alphaGamma),
>     new AhrensDieterMarsagliaTsangGammaSampler(
>               RandomSource.create(RandomSource.WELL_44497_B),
>               alphaGamma, thetaGammaLargerThanOne));
> {code}
> This is a different parameter order for the two samplers.
>  So the tests enforce the fact that the parameters are swapped between Commons Math3
and Commons RNG.
> Changing the actual parameter order would be a change of functionality. So this can be
fixed by updating the Javadoc and parameter names for the sampler.
> {noformat}
> // Commons RNG
> alpha renamed to theta (scale)
> theta renamed to alpha (shape)
> {noformat}

This message was sent by Atlassian JIRA

View raw message