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

Alex Herbert commented on RNG-148:
----------------------------------

This issue is due to the possible generation of infinite samples by the 
underlying Gaussian sampler. This has been fixed in [RNG-154]. The extreme tail 
of the ZigguratNormalizedGaussianSampler is now approximately 12.01. To create 
an infinite sum would require a summation of 12.01^2 to overflow to infinity. 
This is not possible due to the precision of a double value:

{code:java}
@Test
public void test() {
    double big = 0x1.0p1023;
    double x = big + Math.pow(13, 2);
    Assert.assertEquals(big, x, 0.0);
}
{code}

The exponent of 13^2 is 7. Once the summation exceeds a value with an exponent 
of 7+53 = 60 then no further additions can be made due to the 53-bit precision 
of the mantissa of the double.

Also note that maximum summation is limited by the length of an array. The sum 
2^31 * 13^2 is easily within the range of a double and not even close to 
infinity.

If the tail of the normalized Gaussian is within a reasonable range, of even an 
unreasonable range up to a few thousand, then it is not possible to create an 
infinite sum. The infinite sum was due to a bug in the tail of the Gaussian and 
does not require detection in the UnitSphereSampler.



> UnitSphereSampler does not check for infinite length dimension
> --------------------------------------------------------------
>
>                 Key: RNG-148
>                 URL: https://issues.apache.org/jira/browse/RNG-148
>             Project: Commons RNG
>          Issue Type: Bug
>          Components: sampling
>    Affects Versions: 1.3
>            Reporter: Alex Herbert
>            Priority: Trivial
>
> The UnitSphereSampler does not check the vector to be normalised has infinite 
> length.
> A check is already made for zero length (see RNG-55) since the underlying 
> Gaussian sampler can return zero values. A check should also be made for 
> infinite length. The normalisation is only valid if the sum is a finite 
> positive value.
> The code can be fixed by changing:
> {code:java}
> if (sum == 0) {
>     // Zero-norm vector is discarded.
>     return sample();
> }
> {code}
> to:
> {code:java}
> if (sum == 0 || sum == Double.POSITIVE_INFINITY) {
>     // Invalid vector is discarded.
>     return sample();
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to