commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [39/53] [math] MATH-1158.
Date Fri, 25 Mar 2016 15:19:24 GMT
MATH-1158.

Utility method instead of explicit loop.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a6eda3d8
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a6eda3d8
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a6eda3d8

Branch: refs/heads/feature-MATH-1158
Commit: a6eda3d8eff423ecb4901aa07339364732c02ddf
Parents: 7530b4b
Author: Gilles <erans@apache.org>
Authored: Fri Mar 11 04:38:30 2016 +0100
Committer: Gilles <erans@apache.org>
Committed: Fri Mar 11 04:38:30 2016 +0100

----------------------------------------------------------------------
 .../math4/distribution/BetaDistributionTest.java      | 14 ++++++--------
 .../distribution/RealDistributionAbstractTest.java    |  7 +------
 2 files changed, 7 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/a6eda3d8/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
b/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
index d3e167d..373271d 100644
--- a/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
@@ -321,12 +321,14 @@ public class BetaDistributionTest {
 
     @Test
     public void testMomentsSampling() {
-        RandomGenerator random = new Well1024a(0x7829862c82fec2dal);
+        final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_1024_A,
+                                                              123456789L);
         final int numSamples = 1000;
         for (final double alpha : alphaBetas) {
             for (final double beta : alphaBetas) {
-                final BetaDistribution betaDistribution = new BetaDistribution(random, alpha,
beta);
-                final double[] observed = new BetaDistribution(alpha, beta).sample(numSamples);
+                final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta);
+                final double[] observed = AbstractRealDistribution.sample(numSamples,
+                                                                          betaDistribution.createSampler(rng));
                 Arrays.sort(observed);
 
                 final String distribution = String.format("Beta(%.2f, %.2f)", alpha, beta);
@@ -353,11 +355,7 @@ public class BetaDistributionTest {
                 final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta);
 
                 final RealDistribution.Sampler sampler = betaDistribution.createSampler(rng);
-                final double[] observed = new double[numSamples];
-
-                for (int i = 0; i < numSamples; i++) {
-                    observed[i] = sampler.sample();
-                }
+                final double[] observed = AbstractRealDistribution.sample(numSamples, sampler);
 
                 Assert.assertFalse("G goodness-of-fit test rejected null at alpha = " + level,
                                    gTest(betaDistribution, observed) < level);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a6eda3d8/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java
b/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java
index fa1542f..61d01ff 100644
--- a/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java
@@ -347,12 +347,7 @@ public abstract class RealDistributionAbstractTest {
         final int sampleSize = 1000;
         final RealDistribution.Sampler sampler =
             distribution.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 123456789L));
-
-        final double[] sample = new double[sampleSize];
-        for (int i = 0; i < sampleSize; i++) {
-            sample[i] = sampler.sample();
-        }
-
+        final double[] sample = AbstractRealDistribution.sample(sampleSize, sampler);
         final double[] quartiles = TestUtils.getDistributionQuartiles(distribution);
         final double[] expected = {250, 250, 250, 250};
         final long[] counts = new long[4];


Mime
View raw message