You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/09/16 18:58:56 UTC

[commons-rng] branch master updated (7ceb042 -> 188f15d)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git.


    from 7ceb042  Create the exponent to Math.pow explicitly as a double.
     new 188deb4  Extract assignment out of expression.
     new 4fe4e37  Extract assignment out of expression.
     new 64d0c35  Extract assignment out of expression.
     new 9574c0c  Comment reversal of parameters
     new 3cd484a  Removed TODO comment.
     new e803c8d  Removed commented out sections of pom.xml.
     new 96c4368  Updated comment about the examples modules.
     new d23acfd  Add an assertion to tests without full length seeds.
     new 37d20a4  Comment tests with no assertions.
     new 01792b7  Improved comments for tests with no assertions.
     new 5f595c2  Reinstate ignored tests for all zero seeds.
     new bfd5e97  Assert the self-seeded generator output.
     new 188f15d  MiddleSquareWeylSequence to generate valid output when self-seeded.

The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../core/source32/MiddleSquareWeylSequence.java    | 17 +++++++--
 .../rng/core/source64/XorShift1024Star.java        |  3 +-
 .../source32/MiddleSquareWeylSequenceTest.java     | 18 +++++-----
 .../rng/core/source32/XoRoShiRo64StarStarTest.java |  3 +-
 .../rng/core/source32/XoRoShiRo64StarTest.java     |  3 +-
 .../rng/core/source32/XoShiRo128PlusTest.java      |  3 +-
 .../rng/core/source32/XoShiRo128StarStarTest.java  |  3 +-
 .../rng/core/source64/XoRoShiRo128PlusTest.java    |  3 +-
 .../core/source64/XoRoShiRo128StarStarTest.java    |  3 +-
 .../rng/core/source64/XoShiRo256PlusTest.java      |  3 +-
 .../rng/core/source64/XoShiRo256StarStarTest.java  |  3 +-
 .../rng/core/source64/XoShiRo512PlusTest.java      |  3 +-
 .../rng/core/source64/XoShiRo512StarStarTest.java  |  3 +-
 .../sampling/distribution/ChengBetaSampler.java    |  5 +--
 .../rng/sampling/distribution/InternalGamma.java   |  2 --
 .../MarsagliaTsangWangDiscreteSampler.java         | 42 ++++++++++++----------
 .../MarsagliaTsangWangDiscreteSamplerTest.java     | 20 +++++++----
 .../rng/simple/ProvidersCommonParametricTest.java  | 28 +++++++++++++--
 .../rng/simple/internal/SeedFactoryTest.java       |  4 +++
 pom.xml                                            |  8 ++---
 20 files changed, 117 insertions(+), 60 deletions(-)


[commons-rng] 13/13: MiddleSquareWeylSequence to generate valid output when self-seeded.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 188f15dad6754f2db164d08c798f4a624810d42f
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Sep 16 19:50:29 2019 +0100

    MiddleSquareWeylSequence to generate valid output when self-seeded.
---
 .../core/source32/MiddleSquareWeylSequence.java    | 14 ++++++++++++--
 .../source32/MiddleSquareWeylSequenceTest.java     | 22 +++++++++-------------
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java
index 065ea47..c0495f2 100644
--- a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java
+++ b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java
@@ -19,6 +19,8 @@ package org.apache.commons.rng.core.source32;
 
 import org.apache.commons.rng.core.util.NumberFactory;
 
+import java.util.Arrays;
+
 /**
  * Middle Square Weyl Sequence Random Number Generator.
  *
@@ -35,6 +37,12 @@ import org.apache.commons.rng.core.util.NumberFactory;
 public class MiddleSquareWeylSequence extends IntProvider {
     /** Size of the seed array. */
     private static final int SEED_SIZE = 3;
+    /**
+     * The default seed.
+     * This has a high quality Weyl increment (containing many bit state transitions).
+     */
+    private static final long[] DEFAULT_SEED =
+        {0x012de1babb3c4104L, 0xc8161b4202294965L, 0xb5ad4eceda1ce2a9L};
 
     /** State of the generator. */
     private long x;
@@ -77,8 +85,10 @@ public class MiddleSquareWeylSequence extends IntProvider {
      */
     public MiddleSquareWeylSequence(long[] seed) {
         if (seed.length < SEED_SIZE) {
-            final long[] tmp = new long[SEED_SIZE];
-            fillState(tmp, seed);
+            // Complete the seed with a default to avoid
+            // low complexity Weyl increments.
+            final long[] tmp = Arrays.copyOf(seed, SEED_SIZE);
+            System.arraycopy(DEFAULT_SEED, seed.length, tmp, seed.length, SEED_SIZE - seed.length);
             setSeedInternal(tmp);
         } else {
             setSeedInternal(seed);
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
index 8168c15..fcb4d81 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
@@ -68,23 +68,19 @@ public class MiddleSquareWeylSequenceTest {
     }
 
     /**
-     * Test the self-seeding functionality does not throw.
+     * Test the self-seeding functionality outputs non-zero output from the initial state.
      *
-     * <p><strong>Warning:</strong> The seeding of the generator requires a high complexity
-     * increment for the Weyl sequence. The standard test for the statistical quality of the
-     * generator uses a good increment. This test ensures the generator can be created with a seed
-     * smaller than the seed size without exception; the statistical quality of the output from
-     * low complexity Weyl increments is expected to be poor. In this case the output is
-     * non-functional for a large number of cycles.</p>
+     * <p>Note: The generator quality is dependent on a high complexity Weyl increment. This
+     * test passes a seed without the increment set and expects the generator to work. The
+     * statistical quality of the output is not tested.</p>
      */
     @Test
     public void testSelfSeeding() {
-        // This test has been verified to fail when cycles = 2^29 (i.e. 1 << 29).
-        // Here the cycles has been lowered to increase speed.
-        // This demonstrates the generator requires a good seed.
-        final int cycles = 100;
-        RandomAssert.assertNextLongZeroOutput(new MiddleSquareWeylSequence(new long[0]),
-                cycles);
+        final int warmupCycles = 0;
+        final int testCycles = 3;
+        // Do not pass the Weyl increment (the 3rd value in the seed array)
+        RandomAssert.assertNextLongNonZeroOutput(new MiddleSquareWeylSequence(new long[2]),
+                warmupCycles, testCycles);
     }
 
     /**


[commons-rng] 08/13: Add an assertion to tests without full length seeds.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit d23acfd4581ee750566ef198a7c3eff4ee6b91ad
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 20:12:58 2019 +0100

    Add an assertion to tests without full length seeds.
---
 .../org/apache/commons/rng/core/source32/XoRoShiRo64StarStarTest.java  | 3 ++-
 .../java/org/apache/commons/rng/core/source32/XoRoShiRo64StarTest.java | 3 ++-
 .../java/org/apache/commons/rng/core/source32/XoShiRo128PlusTest.java  | 3 ++-
 .../org/apache/commons/rng/core/source32/XoShiRo128StarStarTest.java   | 3 ++-
 .../org/apache/commons/rng/core/source64/XoRoShiRo128PlusTest.java     | 3 ++-
 .../org/apache/commons/rng/core/source64/XoRoShiRo128StarStarTest.java | 3 ++-
 .../java/org/apache/commons/rng/core/source64/XoShiRo256PlusTest.java  | 3 ++-
 .../org/apache/commons/rng/core/source64/XoShiRo256StarStarTest.java   | 3 ++-
 .../java/org/apache/commons/rng/core/source64/XoShiRo512PlusTest.java  | 3 ++-
 .../org/apache/commons/rng/core/source64/XoShiRo512StarStarTest.java   | 3 ++-
 10 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoRoShiRo64StarStarTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoRoShiRo64StarStarTest.java
index 388e784..0ede6a1 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoRoShiRo64StarStarTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoRoShiRo64StarStarTest.java
@@ -62,7 +62,8 @@ public class XoRoShiRo64StarStarTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoRoShiRo64StarStar(new int[] {0x012de1ba});
+        RandomAssert.assertNextLongNonZeroOutput(new XoRoShiRo64StarStar(new int[] {0x012de1ba}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoRoShiRo64StarTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoRoShiRo64StarTest.java
index 2861963..0bf4ea2 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoRoShiRo64StarTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoRoShiRo64StarTest.java
@@ -62,7 +62,8 @@ public class XoRoShiRo64StarTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoRoShiRo64Star(new int[] {0x012de1ba});
+        RandomAssert.assertNextLongNonZeroOutput(new XoRoShiRo64Star(new int[] {0x012de1ba}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoShiRo128PlusTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoShiRo128PlusTest.java
index 80dd21e..0a83ebf 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoShiRo128PlusTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoShiRo128PlusTest.java
@@ -76,7 +76,8 @@ public class XoShiRo128PlusTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoShiRo128Plus(new int[] {SEED[0]});
+        RandomAssert.assertNextLongNonZeroOutput(new XoShiRo128Plus(new int[] {SEED[0]}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoShiRo128StarStarTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoShiRo128StarStarTest.java
index 75fdbaa..eba120b 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoShiRo128StarStarTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/XoShiRo128StarStarTest.java
@@ -76,7 +76,8 @@ public class XoShiRo128StarStarTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoShiRo128StarStar(new int[] {SEED[0]});
+        RandomAssert.assertNextLongNonZeroOutput(new XoShiRo128StarStar(new int[] {SEED[0]}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoRoShiRo128PlusTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoRoShiRo128PlusTest.java
index 0439fb5..c16475c 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoRoShiRo128PlusTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoRoShiRo128PlusTest.java
@@ -89,7 +89,8 @@ public class XoRoShiRo128PlusTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoRoShiRo128Plus(new long[] {SEED[0]});
+        RandomAssert.assertNextLongNonZeroOutput(new XoRoShiRo128Plus(new long[] {SEED[0]}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoRoShiRo128StarStarTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoRoShiRo128StarStarTest.java
index 204ead2..ecadb5b 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoRoShiRo128StarStarTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoRoShiRo128StarStarTest.java
@@ -89,7 +89,8 @@ public class XoRoShiRo128StarStarTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoRoShiRo128StarStar(new long[] {SEED[0]});
+        RandomAssert.assertNextLongNonZeroOutput(new XoRoShiRo128StarStar(new long[] {SEED[0]}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo256PlusTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo256PlusTest.java
index ba47b8e..d9c3855 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo256PlusTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo256PlusTest.java
@@ -89,7 +89,8 @@ public class XoShiRo256PlusTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoShiRo256Plus(new long[] {SEED[0]});
+        RandomAssert.assertNextLongNonZeroOutput(new XoShiRo256Plus(new long[] {SEED[0]}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo256StarStarTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo256StarStarTest.java
index dd9d209..5c7abdf 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo256StarStarTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo256StarStarTest.java
@@ -89,7 +89,8 @@ public class XoShiRo256StarStarTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoShiRo256StarStar(new long[] {SEED[0]});
+        RandomAssert.assertNextLongNonZeroOutput(new XoShiRo256StarStar(new long[] {SEED[0]}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo512PlusTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo512PlusTest.java
index 448065d..ac679a6 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo512PlusTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo512PlusTest.java
@@ -77,7 +77,8 @@ public class XoShiRo512PlusTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoShiRo512Plus(new long[] {SEED[0]});
+        RandomAssert.assertNextLongNonZeroOutput(new XoShiRo512Plus(new long[] {SEED[0]}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test
diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo512StarStarTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo512StarStarTest.java
index d472312..dcf1fcb 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo512StarStarTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source64/XoShiRo512StarStarTest.java
@@ -77,7 +77,8 @@ public class XoShiRo512StarStarTest {
     @Test
     public void testConstructorWithoutFullLengthSeed() {
         // Hit the case when the input seed is self-seeded when not full length
-        new XoShiRo512StarStar(new long[] {SEED[0]});
+        RandomAssert.assertNextLongNonZeroOutput(new XoShiRo512StarStar(new long[] {SEED[0]}),
+                SEED_SIZE, SEED_SIZE);
     }
 
     @Test


[commons-rng] 01/13: Extract assignment out of expression.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 188deb4ddb2f911750ecdfe9d9926ddd0c0f744e
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 12:11:46 2019 +0100

    Extract assignment out of expression.
---
 .../java/org/apache/commons/rng/core/source64/XorShift1024Star.java    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/XorShift1024Star.java b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/XorShift1024Star.java
index 0b732c2..7525129 100644
--- a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/XorShift1024Star.java
+++ b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source64/XorShift1024Star.java
@@ -126,7 +126,8 @@ public class XorShift1024Star extends LongProvider implements JumpableUniformRan
     @Override
     public long next() {
         final long s0 = state[index];
-        long s1 = state[index = (index + 1) & 15];
+        index = (index + 1) & 15;
+        long s1 = state[index];
         s1 ^= s1 << 31; // a
         state[index] = s1 ^ s0 ^ (s1 >>> 11) ^ (s0 >>> 30); // b,c
         return state[index] * multiplier;


[commons-rng] 12/13: Assert the self-seeded generator output.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit bfd5e97dfa5ac0b6a0ddc788990e80a32c7136bd
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 20:13:38 2019 +0100

    Assert the self-seeded generator output.
---
 .../core/source32/MiddleSquareWeylSequenceTest.java    | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
index e9cde90..8168c15 100644
--- a/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
+++ b/commons-rng-core/src/test/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequenceTest.java
@@ -68,17 +68,23 @@ public class MiddleSquareWeylSequenceTest {
     }
 
     /**
-     * Test the self-seeding functionality. The seeding of the generator requires a high complexity
+     * Test the self-seeding functionality does not throw.
+     *
+     * <p><strong>Warning:</strong> The seeding of the generator requires a high complexity
      * increment for the Weyl sequence. The standard test for the statistical quality of the
      * generator uses a good increment. This test ensures the generator can be created with a seed
-     * smaller than the seed size without exception; the statistical quality of the output is not
-     * assessed and expected to be poor.
+     * smaller than the seed size without exception; the statistical quality of the output from
+     * low complexity Weyl increments is expected to be poor. In this case the output is
+     * non-functional for a large number of cycles.</p>
      */
     @Test
     public void testSelfSeeding() {
-        // Ensure this does not throw. The output quality will be poor.
-        final MiddleSquareWeylSequence rng = new MiddleSquareWeylSequence(new long[0]);
-        rng.nextInt();
+        // This test has been verified to fail when cycles = 2^29 (i.e. 1 << 29).
+        // Here the cycles has been lowered to increase speed.
+        // This demonstrates the generator requires a good seed.
+        final int cycles = 100;
+        RandomAssert.assertNextLongZeroOutput(new MiddleSquareWeylSequence(new long[0]),
+                cycles);
     }
 
     /**


[commons-rng] 05/13: Removed TODO comment.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 3cd484ab8267efefb8af4c8d3c8605c9aba4c4d5
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 12:22:53 2019 +0100

    Removed TODO comment.
    
    There is no current requirement for this class to be a separate
    component.
---
 .../org/apache/commons/rng/sampling/distribution/InternalGamma.java     | 2 --
 1 file changed, 2 deletions(-)

diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/InternalGamma.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/InternalGamma.java
index 0e27be5..97c8dee 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/InternalGamma.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/InternalGamma.java
@@ -20,8 +20,6 @@ package org.apache.commons.rng.sampling.distribution;
  * <h3>
  *  Adapted and stripped down copy of class
  *  {@code "org.apache.commons.math4.special.Gamma"}.
- *  TODO: Include it in a "core" component upon which high-level functionality
- *  such as sampling can depend.
  * </h3>
  *
  * <p>


[commons-rng] 07/13: Updated comment about the examples modules.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 96c43682d3d26564cfe24e64d8012e50258af186
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 12:33:14 2019 +0100

    Updated comment about the examples modules.
---
 pom.xml | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index ed905ff..7c272e2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -102,10 +102,9 @@
     <module>commons-rng-simple</module>
     <module>commons-rng-sampling</module>
     <!--
-        Built only upon explicit request (requires Java 1.7+).
-        See profile "commons-rng-examples".
+        The examples are built only upon explicit request (requires Java 1.7+).
+        See profiles: "commons-rng-examples"; "release"
     -->
-    <!-- <module>commons-rng-examples</module> -->
   </modules>
 
   <scm>


[commons-rng] 10/13: Improved comments for tests with no assertions.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 01792b75d884ebf8854823fc4648f24028b94b26
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 20:26:57 2019 +0100

    Improved comments for tests with no assertions.
---
 .../MarsagliaTsangWangDiscreteSamplerTest.java       | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSamplerTest.java
index 4b05b1e..cebd47b 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSamplerTest.java
@@ -293,7 +293,7 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
     }
 
     /**
-     * Test the constructor with a bad mean.
+     * Test the Poisson distribution with a bad mean that is above the supported range.
      */
     @Test(expected = IllegalArgumentException.class)
     public void testCreatePoissonDistributionThrowsWithMeanLargerThanUpperBound() {
@@ -304,7 +304,7 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
     }
 
     /**
-     * Test the Poisson distribution with a bad mean.
+     * Test the Poisson distribution with a bad mean that is below the supported range.
      */
     @Test(expected = IllegalArgumentException.class)
     public void testCreatePoissonDistributionThrowsWithZeroMean() {
@@ -321,8 +321,10 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
     public void testCreatePoissonDistributionWithMaximumMean() {
         final UniformRandomProvider rng = new FixedRNG();
         final double mean = 1024;
-        @SuppressWarnings("unused")
         final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Poisson.of(rng, mean);
+        // Note: No assertions. This will throw if the table does not sum to 2^30
+        // as the RNG outputs the maximum index into the look-up tables.
+        sampler.sample();
     }
 
     /**
@@ -334,7 +336,8 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
         final UniformRandomProvider rng = new FixedRNG();
         final double mean = 0.25;
         final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Poisson.of(rng, mean);
-        // This will throw if the table does not sum to 2^30
+        // Note: No assertions. This will throw if the table does not sum to 2^30
+        // as the RNG outputs the maximum index into the look-up tables.
         sampler.sample();
     }
 
@@ -348,7 +351,8 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
         final UniformRandomProvider rng = new FixedRNG();
         final double mean = 21.4;
         final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Poisson.of(rng, mean);
-        // This will throw if the table does not sum to 2^30
+        // Note: No assertions. This will throw if the table does not sum to 2^30
+        // as the RNG outputs the maximum index into the look-up tables.
         sampler.sample();
     }
 
@@ -542,7 +546,8 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
         final int trials = 65000;
         final double p = 0.01;
         final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p);
-        // This will throw if the table does not sum to 2^30
+        // Note: No assertions. This will throw if the table does not sum to 2^30
+        // as the RNG outputs the maximum index into the look-up tables.
         sampler.sample();
     }
 
@@ -556,7 +561,8 @@ public class MarsagliaTsangWangDiscreteSamplerTest {
         final int trials = 10;
         final double p = 0.5;
         final DiscreteSampler sampler = MarsagliaTsangWangDiscreteSampler.Binomial.of(rng, trials, p);
-        // This will throw if the table does not sum to 2^30
+        // Note: No assertions. This will throw if the table does not sum to 2^30
+        // as the RNG outputs the maximum index into the look-up tables.
         sampler.sample();
     }
 


[commons-rng] 09/13: Comment tests with no assertions.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 37d20a407130a77b715ea82a16636642e918cb2c
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 20:18:23 2019 +0100

    Comment tests with no assertions.
    
    These tests pass if an exception is not thrown with zero length arrays.
---
 .../java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java  | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java
index cd0d1f0..842bdaa 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/internal/SeedFactoryTest.java
@@ -209,6 +209,8 @@ public class SeedFactoryTest {
     public void testEnsureNonZeroIntArrayIgnoresEmptySeed() {
         final int[] seed = new int[0];
         SeedFactory.ensureNonZero(seed);
+        // Note: Nothing to assert.
+        // This tests an ArrayIndexOutOfBoundsException does not occur.
     }
 
     @Test
@@ -239,6 +241,8 @@ public class SeedFactoryTest {
     public void testEnsureNonZeroLongArrayIgnoresEmptySeed() {
         final long[] seed = new long[0];
         SeedFactory.ensureNonZero(seed);
+        // Note: Nothing to assert.
+        // This tests an ArrayIndexOutOfBoundsException does not occur.
     }
 
     @Test


[commons-rng] 03/13: Extract assignment out of expression.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 64d0c35c2a52a0fc7ea257474525a90fd598fc0a
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 12:17:50 2019 +0100

    Extract assignment out of expression.
---
 .../MarsagliaTsangWangDiscreteSampler.java         | 42 ++++++++++++----------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSampler.java
index 8c04309..badd6a7 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSampler.java
@@ -196,11 +196,11 @@ public final class MarsagliaTsangWangDiscreteSampler {
                 final int m = prob[i];
                 // Primitive type conversion will extract lower 8 bits
                 final byte k = (byte) (i + offset);
-                fill(table1, n1, n1 += getBase64Digit(m, 1), k);
-                fill(table2, n2, n2 += getBase64Digit(m, 2), k);
-                fill(table3, n3, n3 += getBase64Digit(m, 3), k);
-                fill(table4, n4, n4 += getBase64Digit(m, 4), k);
-                fill(table5, n5, n5 += getBase64Digit(m, 5), k);
+                n1 = fill(table1, n1, n1 + getBase64Digit(m, 1), k);
+                n2 = fill(table2, n2, n2 + getBase64Digit(m, 2), k);
+                n3 = fill(table3, n3, n3 + getBase64Digit(m, 3), k);
+                n4 = fill(table4, n4, n4 + getBase64Digit(m, 4), k);
+                n5 = fill(table5, n5, n5 + getBase64Digit(m, 5), k);
             }
         }
 
@@ -229,11 +229,13 @@ public final class MarsagliaTsangWangDiscreteSampler {
          * @param from Lower bound index (inclusive)
          * @param to Upper bound index (exclusive)
          * @param value Value.
+         * @return the upper bound index
          */
-        private static void fill(byte[] table, int from, int to, byte value) {
+        private static int fill(byte[] table, int from, int to, byte value) {
             for (int i = from; i < to; i++) {
                 table[i] = value;
             }
+            return to;
         }
 
         @Override
@@ -336,11 +338,11 @@ public final class MarsagliaTsangWangDiscreteSampler {
                 final int m = prob[i];
                 // Primitive type conversion will extract lower 16 bits
                 final short k = (short) (i + offset);
-                fill(table1, n1, n1 += getBase64Digit(m, 1), k);
-                fill(table2, n2, n2 += getBase64Digit(m, 2), k);
-                fill(table3, n3, n3 += getBase64Digit(m, 3), k);
-                fill(table4, n4, n4 += getBase64Digit(m, 4), k);
-                fill(table5, n5, n5 += getBase64Digit(m, 5), k);
+                n1 = fill(table1, n1, n1 + getBase64Digit(m, 1), k);
+                n2 = fill(table2, n2, n2 + getBase64Digit(m, 2), k);
+                n3 = fill(table3, n3, n3 + getBase64Digit(m, 3), k);
+                n4 = fill(table4, n4, n4 + getBase64Digit(m, 4), k);
+                n5 = fill(table5, n5, n5 + getBase64Digit(m, 5), k);
             }
         }
 
@@ -369,11 +371,13 @@ public final class MarsagliaTsangWangDiscreteSampler {
          * @param from Lower bound index (inclusive)
          * @param to Upper bound index (exclusive)
          * @param value Value.
+         * @return the upper bound index
          */
-        private static void fill(short[] table, int from, int to, short value) {
+        private static int fill(short[] table, int from, int to, short value) {
             for (int i = from; i < to; i++) {
                 table[i] = value;
             }
+            return to;
         }
 
         @Override
@@ -472,11 +476,11 @@ public final class MarsagliaTsangWangDiscreteSampler {
             for (int i = 0; i < prob.length; i++) {
                 final int m = prob[i];
                 final int k = i + offset;
-                fill(table1, n1, n1 += getBase64Digit(m, 1), k);
-                fill(table2, n2, n2 += getBase64Digit(m, 2), k);
-                fill(table3, n3, n3 += getBase64Digit(m, 3), k);
-                fill(table4, n4, n4 += getBase64Digit(m, 4), k);
-                fill(table5, n5, n5 += getBase64Digit(m, 5), k);
+                n1 = fill(table1, n1, n1 + getBase64Digit(m, 1), k);
+                n2 = fill(table2, n2, n2 + getBase64Digit(m, 2), k);
+                n3 = fill(table3, n3, n3 + getBase64Digit(m, 3), k);
+                n4 = fill(table4, n4, n4 + getBase64Digit(m, 4), k);
+                n5 = fill(table5, n5, n5 + getBase64Digit(m, 5), k);
             }
         }
 
@@ -505,11 +509,13 @@ public final class MarsagliaTsangWangDiscreteSampler {
          * @param from Lower bound index (inclusive)
          * @param to Upper bound index (exclusive)
          * @param value Value.
+         * @return the upper bound index
          */
-        private static void fill(int[] table, int from, int to, int value) {
+        private static int fill(int[] table, int from, int to, int value) {
             for (int i = from; i < to; i++) {
                 table[i] = value;
             }
+            return to;
         }
 
         @Override


[commons-rng] 04/13: Comment reversal of parameters

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 9574c0c12b8489b09a1790ad334e030fc72134a3
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 12:21:25 2019 +0100

    Comment reversal of parameters
---
 .../apache/commons/rng/sampling/distribution/ChengBetaSampler.java   | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/ChengBetaSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/ChengBetaSampler.java
index 1a01e1f..c85278a 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/ChengBetaSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/ChengBetaSampler.java
@@ -91,9 +91,10 @@ public class ChengBetaSampler
 
         if (a > 1) {
             return algorithmBB(a, b);
-        } else {
-            return algorithmBC(b, a);
         }
+        // This method declares parameters (a, b).
+        // The algorithm is deliberately invoked with reversed parameters.
+        return algorithmBC(b, a);
     }
 
     /** {@inheritDoc} */


[commons-rng] 02/13: Extract assignment out of expression.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 4fe4e3777d9eaf346768e5a289fa56e8d07adae7
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 12:12:24 2019 +0100

    Extract assignment out of expression.
---
 .../org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java
index 1df971e..065ea47 100644
--- a/commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java
+++ b/commons-rng-core/src/main/java/org/apache/commons/rng/core/source32/MiddleSquareWeylSequence.java
@@ -117,7 +117,8 @@ public class MiddleSquareWeylSequence extends IntProvider {
     public int next() {
         x *= x;
         x += w += s;
-        return (int) (x = (x >>> 32) | (x << 32));
+        x = (x >>> 32) | (x << 32);
+        return (int) x;
     }
 
     /** {@inheritDoc} */


[commons-rng] 06/13: Removed commented out sections of pom.xml.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit e803c8db4e14de2a976282c36ac38092b47fd75b
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 12:32:54 2019 +0100

    Removed commented out sections of pom.xml.
    
    <aggregate> tag from javadoc plugin.
    
    -verbose argument from compiler-plugin.
---
 pom.xml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 255a95b..ed905ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -157,7 +157,6 @@
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
           <compilerArgs>
-            <!-- <arg>-verbose</arg> -->
             <arg>-Xlint:all,-options,-path</arg>
           </compilerArgs>
         </configuration>
@@ -255,7 +254,6 @@
         <configuration>
           <!-- Enable MathJax -->
           <additionalOptions>${doclint.javadoc.qualifier} ${allowscript.javadoc.qualifier} -header '&lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/${rng.mathjax.version}/MathJax.js?config=TeX-AMS-MML_HTMLorMML"&gt;&lt;/script&gt;'</additionalOptions>
-          <!-- <aggregate>true</aggregate> -->
         </configuration>
       </plugin>
       <plugin>
@@ -357,7 +355,6 @@
         <configuration>
           <!-- Enable MathJax -->
           <additionalOptions>${doclint.javadoc.qualifier} ${allowscript.javadoc.qualifier} -header '&lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/${rng.mathjax.version}/MathJax.js?config=TeX-AMS-MML_HTMLorMML"&gt;&lt;/script&gt;'</additionalOptions>
-          <!-- <aggregate>true</aggregate> -->
         </configuration>
       </plugin>
 


[commons-rng] 11/13: Reinstate ignored tests for all zero seeds.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 5f595c2efba368f5da74215628cf065f1742c3ea
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Sep 14 20:50:13 2019 +0100

    Reinstate ignored tests for all zero seeds.
    
    The test now checks the generator is functional (produces non-zero
    output). If true it is tested statistically. If false the generator is
    assumed to be non-functional and the test is skipped.
    
    This allows the test to ignore xor-shift based generators that require
    some bits in the state pool.
---
 .../rng/simple/ProvidersCommonParametricTest.java  | 28 +++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java
index ff12153..882f0b0 100644
--- a/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java
+++ b/commons-rng-simple/src/test/java/org/apache/commons/rng/simple/ProvidersCommonParametricTest.java
@@ -29,7 +29,6 @@ import java.io.ByteArrayInputStream;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.Assume;
-import org.junit.Ignore;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
@@ -134,19 +133,23 @@ public class ProvidersCommonParametricTest {
         checkNextIntegerInRange(rng, 10, 10000);
     }
 
-    @Ignore@Test
+    @Test
     public void testZeroIntArraySeed() {
         // Exercise capacity to escape all "zero" state.
         final int[] zero = new int[2000]; // Large enough to fill the entire state with zeroes.
         final UniformRandomProvider rng = RandomSource.create(originalSource, zero, originalArgs);
+        Assume.assumeTrue("RNG is non-functional with an all zero seed: " + originalSource,
+                createsNonZeroLongOutput(rng, 2000));
         checkNextIntegerInRange(rng, 10, 10000);
     }
 
-    @Ignore@Test
+    @Test
     public void testZeroLongArraySeed() {
         // Exercise capacity to escape all "zero" state.
         final long[] zero = new long[2000]; // Large enough to fill the entire state with zeroes.
         final UniformRandomProvider rng = RandomSource.create(originalSource, zero, originalArgs);
+        Assume.assumeTrue("RNG is non-functional with an all zero seed: " + originalSource,
+                createsNonZeroLongOutput(rng, 2000));
         checkNextIntegerInRange(rng, 10, 10000);
     }
 
@@ -359,4 +362,23 @@ public class ProvidersCommonParametricTest {
                         " (" + numFailures + " out of " + numTests + " tests failed)");
         }
     }
+
+    /**
+     * Return true if the generator creates non-zero output from
+     * {@link UniformRandomProvider#nextLong()} within the given number of cycles.
+     *
+     * @param rng Random generator.
+     * @param cycles Number of cycles.
+     * @return true if non-zero output
+     */
+    private static boolean createsNonZeroLongOutput(UniformRandomProvider rng,
+                                                    int cycles) {
+        boolean nonZero = false;
+        for (int i = 0; i < cycles; i++) {
+            if (rng.nextLong() != 0) {
+                nonZero = true;
+            }
+        }
+        return nonZero;
+    }
 }