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] [Commented] (RNG-96) AhrensDieterMarsagliaTsangGammaSampler incorrectly names parameters
Date Thu, 25 Apr 2019 14:06:01 GMT

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

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

{quote}As per the above, it would be clearer (IMHO) to only refer to names used on the Wikipedia
and MathWorld pages (i.e. α and θ).
{quote}
Wikipedia uses [shape|https://en.wikipedia.org/wiki/Shape_parameter]:
{noformat}
In probability theory and statistics, a shape parameter is a kind of numerical parameter of
a parametric family of probability distributions.[1]

Specifically, a shape parameter is any parameter of a probability distribution that is neither
a location parameter nor a scale parameter (nor a function of either or both of these only,
such as a rate parameter). Such a parameter must affect the shape of a distribution rather
than simply shifting it (as a location parameter does) or stretching/shrinking it (as a scale
parameter does).
{noformat}
and [scale|https://en.wikipedia.org/wiki/Scale_parameter]:
{noformat}
In probability theory and statistics, a scale parameter is a special kind of numerical parameter
of a parametric family of probability distributions. The larger the scale parameter, the more
spread out the distribution.
{noformat}
Given these definitions I think they are useful.

It could be made more explicit by changing the constructor to:
{code:java}
/**
 * @param rng Generator of uniformly distributed random numbers.
 * @param alpha Alpha parameter of the distribution (this is a shape parameter).
 * @param theta Theta parameter of the distribution (this is a scale parameter).
 * @throws IllegalArgumentException if {@code alpha <= 0} or {@code theta <= 0}
 */
public AhrensDieterMarsagliaTsangGammaSampler(UniformRandomProvider rng,
                                              double alpha,
                                              double theta) {

{code}
Thus a user converting from CM3 which uses shape and scale as the parameter names will know
this is equivalent.

 

> AhrensDieterMarsagliaTsangGammaSampler incorrectly names parameters
> -------------------------------------------------------------------
>
>                 Key: RNG-96
>                 URL: https://issues.apache.org/jira/browse/RNG-96
>             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|https://en.wikipedia.org/wiki/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
mismatch.
> 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
(v7.6.3#76005)

Mime
View raw message