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 Herbert (Jira)" <ji...@apache.org> on 2021/04/15 22:05:00 UTC

[jira] [Resolved] (RNG-130) UnitSphereSampler for 1 dimension can return invalid length samples

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

Alex Herbert resolved RNG-130.
------------------------------
    Fix Version/s: 1.4
         Assignee: Alex Herbert
       Resolution: Fixed

In git master.

Commit: 5692fe119d9f5866e4448a47472ba20a4ea7a813

Note: The changes to improve the performance of the UnitSphereSampler in [RNG-129] add a dedicated 1D sampler that resolves this issue.


> UnitSphereSampler for 1 dimension can return invalid length samples
> -------------------------------------------------------------------
>
>                 Key: RNG-130
>                 URL: https://issues.apache.org/jira/browse/RNG-130
>             Project: Commons RNG
>          Issue Type: Bug
>          Components: sampling
>    Affects Versions: 1.3
>            Reporter: Alex Herbert
>            Assignee: Alex Herbert
>            Priority: Minor
>             Fix For: 1.4
>
>
> The UnitSphereSampler for 1 dimension currently creates a sample from a standard normal distribution and then normalises it to unit length. This can create values that are not 1 or -1.
> The following code shows this occurs approximately 14% of the time:
> {code:java}
> final UniformRandomProvider rng =
>     RandomSource.create(RandomSource.XO_RO_SHI_RO_128_PP, 0x1a2b3cL);
> final UnitSphereSampler generator = new UnitSphereSampler(1, rng);
> int count = 0;
> int size = 1000000;
> for (int i = size; i-- > 0; ) {
>     final double[] v = generator.nextVector();
>     if (Math.abs(v[0]) != 1.0) {
>         count++;
>     }
> }
> System.out.printf("%d / %d (%.3f)%n", count, size, 100.0 * count / size);
> {code}
> Outputs:
> {noformat}
> 139977 / 1000000 (13.998)
> {noformat}
> This can be fixed by switching the sampling algorithm to use a bit from the random generator to pick either a 1 or -1 for the return value. This can be fixed as part of [RNG-129] which is creating specialisations for sampling for lower order dimensions.



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