[
https://issues.apache.org/jira/browse/RNG-130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Alex Herbert updated RNG-130:
-----------------------------
Description:
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.
was:
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-128] which is creating specialisations for sampling for
lower order dimensions.
> 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
> Priority: Minor
>
> 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)