You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2016/12/13 08:04:09 UTC
[2/2] [math] Depend on Commons RNG v1.0 official release.
Depend on Commons RNG v1.0 official release.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/b1d38d9b
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/b1d38d9b
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/b1d38d9b
Branch: refs/heads/master
Commit: b1d38d9bf25d715d2eca86876baa360a2df356d3
Parents: af1b587
Author: Gilles <er...@apache.org>
Authored: Tue Dec 13 09:02:24 2016 +0100
Committer: Gilles <er...@apache.org>
Committed: Tue Dec 13 09:02:24 2016 +0100
----------------------------------------------------------------------
pom.xml | 16 +-
.../AbstractIntegerDistribution.java | 21 +-
.../distribution/AbstractRealDistribution.java | 21 +-
.../math4/distribution/BetaDistribution.java | 158 ++------------
.../distribution/ExponentialDistribution.java | 91 +-------
.../math4/distribution/GammaDistribution.java | 74 +------
.../distribution/LogNormalDistribution.java | 13 +-
.../math4/distribution/NormalDistribution.java | 35 +--
.../math4/distribution/ParetoDistribution.java | 12 +-
.../math4/distribution/PoissonDistribution.java | 106 +---------
.../UniformIntegerDistribution.java | 24 +--
.../distribution/UniformRealDistribution.java | 10 +-
.../math4/distribution/ZipfDistribution.java | 212 +------------------
.../math4/genetics/GeneticAlgorithm.java | 2 +-
.../ml/clustering/FuzzyKMeansClusterer.java | 2 +-
.../ml/clustering/KMeansPlusPlusClusterer.java | 2 +-
.../ml/neuralnet/FeatureInitializerFactory.java | 2 +-
.../apache/commons/math4/random/RngAdaptor.java | 7 +-
.../random/UnitSphereRandomVectorGenerator.java | 2 +-
.../stat/inference/KolmogorovSmirnovTest.java | 2 +-
.../math4/stat/ranking/NaturalRanking.java | 2 +-
.../apache/commons/math4/util/MathArrays.java | 2 +-
.../math4/util/RandomPivotingStrategy.java | 7 +-
.../math4/ExtendedFieldElementAbstractTest.java | 2 +-
.../org/apache/commons/math4/PerfTestUtils.java | 2 +-
.../DerivativeStructureTest.java | 2 +-
.../differentiation/SparseGradientTest.java | 2 +-
.../math4/analysis/function/LogitTest.java | 2 +-
.../AkimaSplineInterpolatorTest.java | 2 +-
.../BicubicInterpolatingFunctionTest.java | 2 +-
.../interpolation/BicubicInterpolatorTest.java | 2 +-
...eBicubicSplineInterpolatingFunctionTest.java | 2 +-
.../PiecewiseBicubicSplineInterpolatorTest.java | 2 +-
.../TricubicInterpolatingFunctionTest.java | 2 +-
.../distribution/BetaDistributionTest.java | 2 +-
.../distribution/EmpiricalDistributionTest.java | 2 +-
.../EnumeratedIntegerDistributionTest.java | 2 +-
.../EnumeratedRealDistributionTest.java | 2 +-
.../HypergeometricDistributionTest.java | 2 +-
.../IntegerDistributionAbstractTest.java | 2 +-
...xtureMultivariateNormalDistributionTest.java | 2 +-
.../MultivariateNormalDistributionTest.java | 2 +-
.../RealDistributionAbstractTest.java | 2 +-
.../distribution/ZipfDistributionTest.java | 38 +---
.../commons/math4/filter/KalmanFilterTest.java | 2 +-
.../fitting/PolynomialCurveFitterTest.java | 2 +-
.../math4/fitting/SimpleCurveFitterTest.java | 2 +-
.../RandomCirclePointGenerator.java | 2 +-
.../RandomStraightLinePointGenerator.java | 2 +-
.../geometry/enclosing/WelzlEncloser2DTest.java | 2 +-
.../geometry/enclosing/WelzlEncloser3DTest.java | 2 +-
.../euclidean/threed/FieldRotationDSTest.java | 2 +-
.../euclidean/threed/FieldRotationDfpTest.java | 2 +-
.../euclidean/threed/FieldVector3DTest.java | 2 +-
.../euclidean/threed/PolyhedronsSetTest.java | 2 +-
.../euclidean/threed/SphereGeneratorTest.java | 2 +-
.../geometry/euclidean/threed/Vector3DTest.java | 2 +-
.../euclidean/twod/DiskGeneratorTest.java | 2 +-
.../hull/ConvexHullGenerator2DAbstractTest.java | 2 +-
.../geometry/spherical/twod/CircleTest.java | 2 +-
.../twod/SphericalPolygonsSetTest.java | 2 +-
.../math4/linear/EigenDecompositionTest.java | 2 +-
.../math4/linear/HessenbergTransformerTest.java | 2 +-
.../math4/linear/SchurTransformerTest.java | 2 +-
.../ml/clustering/FuzzyKMeansClustererTest.java | 2 +-
.../clustering/KMeansPlusPlusClustererTest.java | 2 +-
.../sofm/TravellingSalesmanSolver.java | 2 +-
.../math4/ode/events/EventFilterTest.java | 2 +-
.../MultiStartMultivariateOptimizerTest.java | 2 +-
.../scalar/noderiv/CMAESOptimizerTest.java | 2 +-
.../MultiStartUnivariateOptimizerTest.java | 4 +-
.../CorrelatedRandomVectorGeneratorTest.java | 2 +-
.../random/GaussianRandomGeneratorTest.java | 2 +-
.../math4/random/JDKRandomAdaptorTest.java | 2 +-
.../math4/random/StableRandomGeneratorTest.java | 2 +-
.../random/SynchronizedRandomGeneratorTest.java | 2 +-
.../UncorrelatedRandomVectorGeneratorTest.java | 2 +-
.../random/UniformRandomGeneratorTest.java | 2 +-
.../UnitSphereRandomVectorGeneratorTest.java | 2 +-
.../correlation/KendallsCorrelationTest.java | 2 +-
.../correlation/StorelessCovarianceTest.java | 2 +-
.../AggregateSummaryStatisticsTest.java | 2 +-
.../UnivariateStatisticAbstractTest.java | 2 +-
.../descriptive/rank/PSquarePercentileTest.java | 2 +-
.../stat/descriptive/rank/PercentileTest.java | 2 +-
.../inference/KolmogorovSmirnovTestTest.java | 2 +-
.../math4/stat/ranking/NaturalRankingTest.java | 5 +-
.../GLSMultipleLinearRegressionTest.java | 2 +-
.../stat/regression/SimpleRegressionTest.java | 2 +-
.../apache/commons/math4/util/FastMathTest.java | 2 +-
.../commons/math4/util/MathArraysTest.java | 2 +-
.../commons/math4/util/MathUtilsTest.java | 2 +-
.../math4/util/ResizableDoubleArrayTest.java | 2 +-
93 files changed, 219 insertions(+), 785 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b3a649b..5263413 100644
--- a/pom.xml
+++ b/pom.xml
@@ -362,8 +362,20 @@
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-rng</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <artifactId>commons-rng-client-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-rng-simple</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-rng-sampling</artifactId>
+ <version>1.0</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/AbstractIntegerDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/AbstractIntegerDistribution.java b/src/main/java/org/apache/commons/math4/distribution/AbstractIntegerDistribution.java
index f502e0c..df0bee5 100644
--- a/src/main/java/org/apache/commons/math4/distribution/AbstractIntegerDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/AbstractIntegerDistribution.java
@@ -23,6 +23,9 @@ import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.OutOfRangeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.InverseTransformDiscreteSampler;
+import org.apache.commons.rng.sampling.distribution.DiscreteInverseCumulativeProbabilityFunction;
+import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
import org.apache.commons.math4.util.FastMath;
/**
@@ -195,10 +198,26 @@ public abstract class AbstractIntegerDistribution implements IntegerDistribution
@Override
public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new IntegerDistribution.Sampler() {
+ private final DiscreteSampler sampler =
+ new InverseTransformDiscreteSampler(rng, createICPF());
+
/** {@inheritDoc} */
@Override
public int sample() {
- return inverseCumulativeProbability(rng.nextDouble());
+ return sampler.sample();
+ }
+ };
+ }
+
+ /**
+ * @return an instance for use by {@link #createSampler(UniformRandomProvider)}
+ */
+ private DiscreteInverseCumulativeProbabilityFunction createICPF() {
+ return new DiscreteInverseCumulativeProbabilityFunction() {
+ /** {@inheritDoc} */
+ @Override
+ public int inverseCumulativeProbability(double p) {
+ return AbstractIntegerDistribution.this.inverseCumulativeProbability(p);
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java b/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
index f874f16..b2a0956 100644
--- a/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
@@ -24,6 +24,9 @@ import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.OutOfRangeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.InverseTransformContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.ContinuousInverseCumulativeProbabilityFunction;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
import org.apache.commons.math4.util.FastMath;
/**
@@ -243,10 +246,26 @@ public abstract class AbstractRealDistribution
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
+ private final ContinuousSampler sampler =
+ new InverseTransformContinuousSampler(rng, createICPF());
+
/** {@inheritDoc} */
@Override
public double sample() {
- return inverseCumulativeProbability(rng.nextDouble());
+ return sampler.sample();
+ }
+ };
+ }
+
+ /**
+ * @return an instance for use by {@link #createSampler(UniformRandomProvider)}
+ */
+ private ContinuousInverseCumulativeProbabilityFunction createICPF() {
+ return new ContinuousInverseCumulativeProbabilityFunction() {
+ /** {@inheritDoc} */
+ @Override
+ public double inverseCumulativeProbability(double p) {
+ return AbstractRealDistribution.this.inverseCumulativeProbability(p);
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java b/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java
index 31a1d30..025d655 100644
--- a/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java
@@ -18,11 +18,12 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.exception.NumberIsTooSmallException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.special.Beta;
import org.apache.commons.math4.special.Gamma;
import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.Precision;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.ChengBetaSampler;
/**
* Implements the Beta distribution.
@@ -227,150 +228,15 @@ public class BetaDistribution extends AbstractRealDistribution {
*/
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
- return new ChengBetaSampler(rng, alpha, beta);
- }
-
- /**
- * Utility class implementing Cheng's algorithms for beta distribution sampling.
- *
- * <blockquote>
- * <pre>
- * R. C. H. Cheng,
- * "Generating beta variates with nonintegral shape parameters",
- * Communications of the ACM, 21, 317-322, 1978.
- * </pre>
- * </blockquote>
- *
- * @since 3.6
- */
- private static class ChengBetaSampler implements RealDistribution.Sampler {
- /** RNG (uniform distribution). */
- private final UniformRandomProvider rng;
- /** First shape parameter. */
- private final double alphaShape;
- /** Second shape parameter. */
- private final double betaShape;
-
- /**
- * Creates a sampler instance.
- *
- * @param generator RNG.
- * @param alpha Distribution first shape parameter.
- * @param beta Distribution second shape parameter.
- */
- ChengBetaSampler(UniformRandomProvider generator,
- double alpha,
- double beta) {
- rng = generator;
- alphaShape = alpha;
- betaShape = beta;
- }
-
- /** {@inheritDoc} */
- @Override
- public double sample() {
- final double a = FastMath.min(alphaShape, betaShape);
- final double b = FastMath.max(alphaShape, betaShape);
-
- if (a > 1) {
- return algorithmBB(alphaShape, a, b);
- } else {
- return algorithmBC(alphaShape, b, a);
+ return new RealDistribution.Sampler() {
+ private final ContinuousSampler sampler =
+ new ChengBetaSampler(rng, alpha, beta);
+
+ /**{@inheritDoc} */
+ @Override
+ public double sample() {
+ return sampler.sample();
}
- }
-
- /**
- * Computes one sample using Cheng's BB algorithm, when α and
- * β are both larger than 1.
- *
- * @param a0 First shape parameter (α).
- * @param a Min(α, β) where α, β are the shape parameters.
- * @param b Max(α, β) where α, β are the shape parameters.
- * @return a random sample.
- */
- private double algorithmBB(double a0,
- double a,
- double b) {
- final double alpha = a + b;
- final double beta = FastMath.sqrt((alpha - 2) / (2 * a * b - alpha));
- final double gamma = a + 1 / beta;
-
- double r;
- double w;
- double t;
- do {
- final double u1 = rng.nextDouble();
- final double u2 = rng.nextDouble();
- final double v = beta * (FastMath.log(u1) - FastMath.log1p(-u1));
- w = a * FastMath.exp(v);
- final double z = u1 * u1 * u2;
- r = gamma * v - 1.3862944;
- final double s = a + r - w;
- if (s + 2.609438 >= 5 * z) {
- break;
- }
-
- t = FastMath.log(z);
- if (s >= t) {
- break;
- }
- } while (r + alpha * (FastMath.log(alpha) - FastMath.log(b + w)) < t);
-
- w = FastMath.min(w, Double.MAX_VALUE);
-
- return Precision.equals(a, a0) ? w / (b + w) : b / (b + w);
- }
-
- /**
- * Computes one sample using Cheng's BC algorithm, when at least one
- * of α and β is smaller than 1.
- *
- * @param a0 First shape parameter (α).
- * @param a Max(α, β) where α, β are the shape parameters.
- * @param b min(α, β) where α, β are the shape parameters.
- * @return a random sample.
- */
- private double algorithmBC(double a0,
- double a,
- double b) {
- final double alpha = a + b;
- final double beta = 1 / b;
- final double delta = 1 + a - b;
- final double k1 = delta * (0.0138889 + 0.0416667 * b) / (a * beta - 0.777778);
- final double k2 = 0.25 + (0.5 + 0.25 / delta) * b;
-
- double w;
- while (true) {
- final double u1 = rng.nextDouble();
- final double u2 = rng.nextDouble();
- final double y = u1 * u2;
- final double z = u1 * y;
- if (u1 < 0.5) {
- if (0.25 * u2 + z - y >= k1) {
- continue;
- }
- } else {
- if (z <= 0.25) {
- final double v = beta * (FastMath.log(u1) - FastMath.log1p(-u1));
- w = a * FastMath.exp(v);
- break;
- }
-
- if (z >= k2) {
- continue;
- }
- }
-
- final double v = beta * (FastMath.log(u1) - FastMath.log1p(-u1));
- w = a * FastMath.exp(v);
- if (alpha * (FastMath.log(alpha) - FastMath.log(b + w) + v) - 1.3862944 >= FastMath.log(z)) {
- break;
- }
- }
-
- w = FastMath.min(w, Double.MAX_VALUE);
-
- return Precision.equals(a, a0) ? w / (b + w) : b / (b + w);
- }
+ };
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java b/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java
index fb44536..449fb5b 100644
--- a/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java
@@ -19,10 +19,10 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.OutOfRangeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.math4.util.CombinatoricsUtils;
import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.ResizableDoubleArray;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.AhrensDieterExponentialSampler;
/**
* Implementation of the exponential distribution.
@@ -38,20 +38,6 @@ public class ExponentialDistribution extends AbstractRealDistribution {
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
/** Serializable version identifier */
private static final long serialVersionUID = 20160311L;
- /**
- * Used when generating Exponential samples.
- * Table containing the constants
- * q_i = sum_{j=1}^i (ln 2)^j/j! = ln 2 + (ln 2)^2/2 + ... + (ln 2)^i/i!
- * until the largest representable fraction below 1 is exceeded.
- *
- * Note that
- * 1 = 2 - 1 = exp(ln 2) - 1 = sum_{n=1}^infty (ln 2)^n / n!
- * thus q_i -> 1 as i -> +inf,
- * so the higher i, the closer to one we get (the series is not alternating).
- *
- * By trying, n = 16 in Java is enough to reach 1.0.
- */
- private static final double[] EXPONENTIAL_SA_QI;
/** The mean of this distribution. */
private final double mean;
/** The logarithm of the mean, stored to reduce computing time. **/
@@ -60,35 +46,6 @@ public class ExponentialDistribution extends AbstractRealDistribution {
private final double solverAbsoluteAccuracy;
/**
- * Initialize tables.
- */
- static {
- /**
- * Filling EXPONENTIAL_SA_QI table.
- * Note that we don't want qi = 0 in the table.
- */
- final double LN2 = FastMath.log(2);
- double qi = 0;
- int i = 1;
-
- /**
- * ArithmeticUtils provides factorials up to 20, so let's use that
- * limit together with Precision.EPSILON to generate the following
- * code (a priori, we know that there will be 16 elements, but it is
- * better to not hardcode it).
- */
- final ResizableDoubleArray ra = new ResizableDoubleArray(20);
-
- while (qi < 1) {
- qi += FastMath.pow(LN2, i) / CombinatoricsUtils.factorial(i);
- ra.addElement(qi);
- ++i;
- }
-
- EXPONENTIAL_SA_QI = ra.getElements();
- }
-
- /**
* Creates a distribution.
*
* @param mean mean of this distribution.
@@ -262,45 +219,13 @@ public class ExponentialDistribution extends AbstractRealDistribution {
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
- /** {@inheritDoc} */
+ private final ContinuousSampler sampler =
+ new AhrensDieterExponentialSampler(rng, mean);
+
+ /**{@inheritDoc} */
@Override
public double sample() {
- // Step 1:
- double a = 0;
- double u = rng.nextDouble();
-
- // Step 2 and 3:
- while (u < 0.5) {
- a += EXPONENTIAL_SA_QI[0];
- u *= 2;
- }
-
- // Step 4 (now u >= 0.5):
- u += u - 1;
-
- // Step 5:
- if (u <= EXPONENTIAL_SA_QI[0]) {
- return mean * (a + u);
- }
-
- // Step 6:
- int i = 0; // Should be 1, be we iterate before it in while using 0
- double u2 = rng.nextDouble();
- double umin = u2;
-
- // Step 7 and 8:
- do {
- ++i;
- u2 = rng.nextDouble();
-
- if (u2 < umin) {
- umin = u2;
- }
-
- // Step 8:
- } while (u > EXPONENTIAL_SA_QI[i]); // Ensured to exit since EXPONENTIAL_SA_QI[MAX] = 1
-
- return mean * (a + umin * EXPONENTIAL_SA_QI[0]);
+ return sampler.sample();
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java b/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java
index a1d2d87..db6feb6 100644
--- a/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java
@@ -18,9 +18,11 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.special.Gamma;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler;
/**
* Implementation of the Gamma distribution.
@@ -378,75 +380,15 @@ public class GammaDistribution extends AbstractRealDistribution {
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
- /** Gaussian sampling. */
- private final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
+ private final ContinuousSampler sampler =
+ new AhrensDieterMarsagliaTsangGammaSampler(rng, scale, shape);
- /** {@inheritDoc} */
+ /**{@inheritDoc} */
@Override
public double sample() {
- if (shape < 1) {
- // [1]: p. 228, Algorithm GS
-
- while (true) {
- // Step 1:
- final double u = rng.nextDouble();
- final double bGS = 1 + shape / FastMath.E;
- final double p = bGS * u;
-
- if (p <= 1) {
- // Step 2:
-
- final double x = FastMath.pow(p, 1 / shape);
- final double u2 = rng.nextDouble();
-
- if (u2 > FastMath.exp(-x)) {
- // Reject
- continue;
- } else {
- return scale * x;
- }
- } else {
- // Step 3:
-
- final double x = -1 * FastMath.log((bGS - p) / shape);
- final double u2 = rng.nextDouble();
-
- if (u2 > FastMath.pow(x, shape - 1)) {
- // Reject
- continue;
- } else {
- return scale * x;
- }
- }
- }
- }
-
- // Now shape >= 1
-
- final double d = shape - 0.333333333333333333;
- final double c = 1 / (3 * FastMath.sqrt(d));
-
- while (true) {
- final double x = gaussian.sample();
- final double v = (1 + c * x) * (1 + c * x) * (1 + c * x);
-
- if (v <= 0) {
- continue;
- }
-
- final double x2 = x * x;
- final double u = rng.nextDouble();
-
- // Squeeze
- if (u < 1 - 0.0331 * x2 * x2) {
- return scale * d * v;
- }
-
- if (FastMath.log(u) < 0.5 * x2 + d * (1 - v + FastMath.log(v))) {
- return scale * d * v;
- }
- }
+ return sampler.sample();
}
};
+
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java b/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
index d8a0229..575466d 100644
--- a/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
@@ -20,9 +20,11 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.special.Erf;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.BoxMullerLogNormalSampler;
/**
* Implementation of the log-normal (gaussian) distribution.
@@ -292,14 +294,13 @@ public class LogNormalDistribution extends AbstractRealDistribution {
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
- /** Gaussian sampling. */
- private final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
+ private final ContinuousSampler sampler =
+ new BoxMullerLogNormalSampler(rng, scale, shape);
- /** {@inheritDoc} */
+ /**{@inheritDoc} */
@Override
public double sample() {
- final double n = gaussian.sample();
- return FastMath.exp(scale + shape * n);
+ return sampler.sample();
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java b/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java
index d971eb6..71eee15 100644
--- a/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java
@@ -21,9 +21,11 @@ import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.OutOfRangeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.special.Erf;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.BoxMullerGaussianSampler;
/**
* Implementation of the normal (gaussian) distribution.
@@ -239,36 +241,13 @@ public class NormalDistribution extends AbstractRealDistribution {
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
- /** Next gaussian. */
- private double nextGaussian = Double.NaN;
+ private final ContinuousSampler sampler =
+ new BoxMullerGaussianSampler(rng, mean, standardDeviation);
- /** {@inheritDoc} */
+ /**{@inheritDoc} */
@Override
public double sample() {
- final double random;
- if (Double.isNaN(nextGaussian)) {
- // Generate a pair of Gaussian numbers.
-
- final double x = rng.nextDouble();
- final double y = rng.nextDouble();
- final double alpha = 2 * FastMath.PI * x;
- final double r = FastMath.sqrt(-2 * FastMath.log(y));
-
- // Return the first element of the generated pair.
- random = r * FastMath.cos(alpha);
-
- // Keep second element of the pair for next invocation.
- nextGaussian = r * FastMath.sin(alpha);
- } else {
- // Use the second element of the pair (generated at the
- // previous invocation).
- random = nextGaussian;
-
- // Both elements of the pair have been used.
- nextGaussian = Double.NaN;
- }
-
- return standardDeviation * random + mean;
+ return sampler.sample();
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java b/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java
index b7c405f..10fbaad 100644
--- a/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java
@@ -19,8 +19,10 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.InverseTransformParetoSampler;
/**
* Implementation of the Pareto distribution.
@@ -252,11 +254,13 @@ public class ParetoDistribution extends AbstractRealDistribution {
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
- /** {@inheritDoc} */
+ private final ContinuousSampler sampler =
+ new InverseTransformParetoSampler(rng, scale, shape);
+
+ /**{@inheritDoc} */
@Override
public double sample() {
- final double n = rng.nextDouble();
- return scale / FastMath.pow(n, 1 / shape);
+ return sampler.sample();
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/PoissonDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/PoissonDistribution.java b/src/main/java/org/apache/commons/math4/distribution/PoissonDistribution.java
index 1c7b8db..a39a73f 100644
--- a/src/main/java/org/apache/commons/math4/distribution/PoissonDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/PoissonDistribution.java
@@ -19,10 +19,11 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.special.Gamma;
-import org.apache.commons.math4.util.CombinatoricsUtils;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathUtils;
import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
+import org.apache.commons.rng.sampling.distribution.PoissonSampler;
/**
* Implementation of the Poisson distribution.
@@ -248,108 +249,13 @@ public class PoissonDistribution extends AbstractIntegerDistribution {
@Override
public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new IntegerDistribution.Sampler() {
- /** Exponential distribution. */
- private final RealDistribution.Sampler exponentialSampler
- = new ExponentialDistribution(1).createSampler(rng);
- /** Gaussian distribution. */
- private final RealDistribution.Sampler gaussianSampler
- = new NormalDistribution().createSampler(rng);
+ private final DiscreteSampler sampler =
+ new PoissonSampler(rng, mean);
- /** {@inheritDoc} */
+ /**{@inheritDoc} */
@Override
public int sample() {
- return (int) FastMath.min(nextPoisson(mean),
- Integer.MAX_VALUE);
- }
-
- /**
- * @param meanPoisson Mean of the Poisson distribution.
- * @return the next sample.
- */
- private long nextPoisson(double meanPoisson) {
- final double pivot = 40.0d;
- if (meanPoisson < pivot) {
- double p = FastMath.exp(-meanPoisson);
- long n = 0;
- double r = 1.0d;
- double rnd = 1.0d;
-
- while (n < 1000 * meanPoisson) {
- rnd = rng.nextDouble();
- r *= rnd;
- if (r >= p) {
- n++;
- } else {
- return n;
- }
- }
- return n;
- } else {
- final double lambda = FastMath.floor(meanPoisson);
- final double lambdaFractional = meanPoisson - lambda;
- final double logLambda = FastMath.log(lambda);
- final double logLambdaFactorial = CombinatoricsUtils.factorialLog((int) lambda);
- final long y2 = lambdaFractional < Double.MIN_VALUE ? 0 : nextPoisson(lambdaFractional);
- final double delta = FastMath.sqrt(lambda * FastMath.log(32 * lambda / FastMath.PI + 1));
- final double halfDelta = delta / 2;
- final double twolpd = 2 * lambda + delta;
- final double a1 = FastMath.sqrt(FastMath.PI * twolpd) * FastMath.exp(1 / (8 * lambda));
- final double a2 = (twolpd / delta) * FastMath.exp(-delta * (1 + delta) / twolpd);
- final double aSum = a1 + a2 + 1;
- final double p1 = a1 / aSum;
- final double p2 = a2 / aSum;
- final double c1 = 1 / (8 * lambda);
-
- double x = 0;
- double y = 0;
- double v = 0;
- int a = 0;
- double t = 0;
- double qr = 0;
- double qa = 0;
- while (true) {
- final double u = rng.nextDouble();
- if (u <= p1) {
- final double n = gaussianSampler.sample();
- x = n * FastMath.sqrt(lambda + halfDelta) - 0.5d;
- if (x > delta || x < -lambda) {
- continue;
- }
- y = x < 0 ? FastMath.floor(x) : FastMath.ceil(x);
- final double e = exponentialSampler.sample();
- v = -e - (n * n / 2) + c1;
- } else {
- if (u > p1 + p2) {
- y = lambda;
- break;
- } else {
- x = delta + (twolpd / delta) * exponentialSampler.sample();
- y = FastMath.ceil(x);
- v = -exponentialSampler.sample() - delta * (x + 1) / twolpd;
- }
- }
- a = x < 0 ? 1 : 0;
- t = y * (y + 1) / (2 * lambda);
- if (v < -t && a == 0) {
- y = lambda + y;
- break;
- }
- qr = t * ((2 * y + 1) / (6 * lambda) - 1);
- qa = qr - (t * t) / (3 * (lambda + a * (y + 1)));
- if (v < qa) {
- y = lambda + y;
- break;
- }
- if (v > qr) {
- continue;
- }
- if (v < y * logLambda - CombinatoricsUtils.factorialLog((int) (y + lambda)) + logLambdaFactorial) {
- y = lambda + y;
- break;
- }
- }
- return y2 + (long) y;
- }
+ return sampler.sample();
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/UniformIntegerDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/UniformIntegerDistribution.java b/src/main/java/org/apache/commons/math4/distribution/UniformIntegerDistribution.java
index 2909cc8..cf2a72c 100644
--- a/src/main/java/org/apache/commons/math4/distribution/UniformIntegerDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/UniformIntegerDistribution.java
@@ -20,6 +20,8 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
+import org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler;
/**
* Implementation of the <a href="http://en.wikipedia.org/wiki/Uniform_distribution_(discrete)">
@@ -147,25 +149,13 @@ public class UniformIntegerDistribution extends AbstractIntegerDistribution {
@Override
public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new IntegerDistribution.Sampler() {
- /** {@inheritDoc} */
+ private final DiscreteSampler sampler =
+ new DiscreteUniformSampler(rng, lower, upper);
+
+ /**{@inheritDoc} */
@Override
public int sample() {
- final int max = (upper - lower) + 1;
- if (max <= 0) {
- // The range is too wide to fit in a positive int (larger
- // than 2^31); as it covers more than half the integer range,
- // we use a simple rejection method.
- while (true) {
- final int r = rng.nextInt();
- if (r >= lower &&
- r <= upper) {
- return r;
- }
- }
- } else {
- // We can shift the range and directly generate a positive int.
- return lower + rng.nextInt(max);
- }
+ return sampler.sample();
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java b/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java
index 343bee0..ce1b1e0 100644
--- a/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java
@@ -21,6 +21,8 @@ import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.OutOfRangeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler;
/**
* Implementation of the uniform real distribution.
@@ -162,11 +164,13 @@ public class UniformRealDistribution extends AbstractRealDistribution {
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
- /** {@inheritDoc} */
+ private final ContinuousSampler sampler =
+ new ContinuousUniformSampler(rng, lower, upper);
+
+ /**{@inheritDoc} */
@Override
public double sample() {
- final double u = rng.nextDouble();
- return u * upper + (1 - u) * lower;
+ return sampler.sample();
}
};
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/distribution/ZipfDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/ZipfDistribution.java b/src/main/java/org/apache/commons/math4/distribution/ZipfDistribution.java
index 3ea152c..69e7674 100644
--- a/src/main/java/org/apache/commons/math4/distribution/ZipfDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/ZipfDistribution.java
@@ -19,8 +19,10 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
+import org.apache.commons.rng.sampling.distribution.RejectionInversionZipfSampler;
/**
* Implementation of the Zipf distribution.
@@ -261,214 +263,14 @@ public class ZipfDistribution extends AbstractIntegerDistribution {
@Override
public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new IntegerDistribution.Sampler() {
- /** Helper. */
- private final ZipfRejectionInversionSampler sampler =
- new ZipfRejectionInversionSampler(numberOfElements, exponent);
+ private final DiscreteSampler sampler =
+ new RejectionInversionZipfSampler(rng, numberOfElements, exponent);
- /** {@inheritDoc} */
+ /**{@inheritDoc} */
@Override
public int sample() {
- return sampler.sample(rng);
+ return sampler.sample();
}
};
}
-
- /**
- * Utility class implementing a rejection inversion sampling method for a discrete,
- * bounded Zipf distribution that is based on the method described in
- * <p>
- * Wolfgang H�rmann and Gerhard Derflinger
- * "Rejection-inversion to generate variates from monotone discrete distributions."
- * ACM Transactions on Modeling and Computer Simulation (TOMACS) 6.3 (1996): 169-184.
- * <p>
- * The paper describes an algorithm for exponents larger than 1 (Algorithm ZRI).
- * The original method uses {@code H(x) := (v + x)^(1 - q) / (1 - q)}
- * as the integral of the hat function. This function is undefined for
- * q = 1, which is the reason for the limitation of the exponent.
- * If instead the integral function
- * {@code H(x) := ((v + x)^(1 - q) - 1) / (1 - q)} is used,
- * for which a meaningful limit exists for q = 1,
- * the method works for all positive exponents.
- * <p>
- * The following implementation uses v := 0 and generates integral numbers
- * in the range [1, numberOfElements]. This is different to the original method
- * where v is defined to be positive and numbers are taken from [0, i_max].
- * This explains why the implementation looks slightly different.
- *
- * @since 3.6
- */
- static class ZipfRejectionInversionSampler {
- /** Exponent parameter of the distribution. */
- private final double exponent;
- /** Number of elements. */
- private final int numberOfElements;
- /** Constant equal to {@code hIntegral(1.5) - 1}. */
- private final double hIntegralX1;
- /** Constant equal to {@code hIntegral(numberOfElements + 0.5)}. */
- private final double hIntegralNumberOfElements;
- /** Constant equal to {@code 2 - hIntegralInverse(hIntegral(2.5) - h(2)}. */
- private final double s;
-
- /**
- * @param numberOfElements number of elements
- * @param exponent exponent parameter of the distribution
- */
- ZipfRejectionInversionSampler(final int numberOfElements, final double exponent) {
- this.exponent = exponent;
- this.numberOfElements = numberOfElements;
- this.hIntegralX1 = hIntegral(1.5) - 1d;
- this.hIntegralNumberOfElements = hIntegral(numberOfElements + 0.5);
- this.s = 2d - hIntegralInverse(hIntegral(2.5) - h(2));
- }
-
- /**
- * Generates one integer in the range [1, numberOfElements].
- *
- * @param random random generator to use
- * @return generated integral number in the range [1, numberOfElements]
- */
- int sample(final UniformRandomProvider random) {
- while(true) {
- final double u = hIntegralNumberOfElements + random.nextDouble() * (hIntegralX1 - hIntegralNumberOfElements);
- // u is uniformly distributed in (hIntegralX1, hIntegralNumberOfElements]
-
- double x = hIntegralInverse(u);
- int k = (int)(x + 0.5);
-
- // Limit k to the range [1, numberOfElements]
- // (k could be outside due to numerical inaccuracies)
- if (k < 1) {
- k = 1;
- }
- else if (k > numberOfElements) {
- k = numberOfElements;
- }
-
- // Here, the distribution of k is given by:
- //
- // P(k = 1) = C * (hIntegral(1.5) - hIntegralX1) = C
- // P(k = m) = C * (hIntegral(m + 1/2) - hIntegral(m - 1/2)) for m >= 2
- //
- // where C := 1 / (hIntegralNumberOfElements - hIntegralX1)
-
- if (k - x <= s || u >= hIntegral(k + 0.5) - h(k)) {
-
- // Case k = 1:
- //
- // The right inequality is always true, because replacing k by 1 gives
- // u >= hIntegral(1.5) - h(1) = hIntegralX1 and u is taken from
- // (hIntegralX1, hIntegralNumberOfElements].
- //
- // Therefore, the acceptance rate for k = 1 is P(accepted | k = 1) = 1
- // and the probability that 1 is returned as random value is
- // P(k = 1 and accepted) = P(accepted | k = 1) * P(k = 1) = C = C / 1^exponent
- //
- // Case k >= 2:
- //
- // The left inequality (k - x <= s) is just a short cut
- // to avoid the more expensive evaluation of the right inequality
- // (u >= hIntegral(k + 0.5) - h(k)) in many cases.
- //
- // If the left inequality is true, the right inequality is also true:
- // Theorem 2 in the paper is valid for all positive exponents, because
- // the requirements h'(x) = -exponent/x^(exponent + 1) < 0 and
- // (-1/hInverse'(x))'' = (1+1/exponent) * x^(1/exponent-1) >= 0
- // are both fulfilled.
- // Therefore, f(x) := x - hIntegralInverse(hIntegral(x + 0.5) - h(x))
- // is a non-decreasing function. If k - x <= s holds,
- // k - x <= s + f(k) - f(2) is obviously also true which is equivalent to
- // -x <= -hIntegralInverse(hIntegral(k + 0.5) - h(k)),
- // -hIntegralInverse(u) <= -hIntegralInverse(hIntegral(k + 0.5) - h(k)),
- // and finally u >= hIntegral(k + 0.5) - h(k).
- //
- // Hence, the right inequality determines the acceptance rate:
- // P(accepted | k = m) = h(m) / (hIntegrated(m+1/2) - hIntegrated(m-1/2))
- // The probability that m is returned is given by
- // P(k = m and accepted) = P(accepted | k = m) * P(k = m) = C * h(m) = C / m^exponent.
- //
- // In both cases the probabilities are proportional to the probability mass function
- // of the Zipf distribution.
-
- return k;
- }
- }
- }
-
- /**
- * {@code H(x) :=}
- * <ul>
- * <li>{@code (x^(1-exponent) - 1)/(1 - exponent)}, if {@code exponent != 1}</li>
- * <li>{@code log(x)}, if {@code exponent == 1}</li>
- * </ul>
- * H(x) is an integral function of h(x),
- * the derivative of H(x) is h(x).
- *
- * @param x free parameter
- * @return {@code H(x)}
- */
- private double hIntegral(final double x) {
- final double logX = FastMath.log(x);
- return helper2((1d-exponent)*logX)*logX;
- }
-
- /**
- * {@code h(x) := 1/x^exponent}
- *
- * @param x free parameter
- * @return h(x)
- */
- private double h(final double x) {
- return FastMath.exp(-exponent * FastMath.log(x));
- }
-
- /**
- * The inverse function of H(x).
- *
- * @param x free parameter
- * @return y for which {@code H(y) = x}
- */
- private double hIntegralInverse(final double x) {
- double t = x*(1d-exponent);
- if (t < -1d) {
- // Limit value to the range [-1, +inf).
- // t could be smaller than -1 in some rare cases due to numerical errors.
- t = -1;
- }
- return FastMath.exp(helper1(t)*x);
- }
-
- /**
- * Helper function that calculates {@code log(1+x)/x}.
- * <p>
- * A Taylor series expansion is used, if x is close to 0.
- *
- * @param x a value larger than or equal to -1
- * @return {@code log(1+x)/x}
- */
- static double helper1(final double x) {
- if (FastMath.abs(x)>1e-8) {
- return FastMath.log1p(x)/x;
- }
- else {
- return 1.-x*((1./2.)-x*((1./3.)-x*(1./4.)));
- }
- }
-
- /**
- * Helper function to calculate {@code (exp(x)-1)/x}.
- * <p>
- * A Taylor series expansion is used, if x is close to 0.
- *
- * @param x free parameter
- * @return {@code (exp(x)-1)/x} if x is non-zero, or 1 if x=0
- */
- static double helper2(final double x) {
- if (FastMath.abs(x)>1e-8) {
- return FastMath.expm1(x)/x;
- }
- else {
- return 1.+x*(1./2.)*(1.+x*(1./3.)*(1.+x*(1./4.)));
- }
- }
- }
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java b/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java
index b43bf52..e4fcf4c 100644
--- a/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java
+++ b/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java
@@ -18,7 +18,7 @@ package org.apache.commons.math4.genetics;
import org.apache.commons.math4.exception.OutOfRangeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
/**
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java b/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java
index e9e669c..ee3d590 100644
--- a/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java
@@ -28,7 +28,7 @@ import org.apache.commons.math4.linear.MatrixUtils;
import org.apache.commons.math4.linear.RealMatrix;
import org.apache.commons.math4.ml.distance.DistanceMeasure;
import org.apache.commons.math4.ml.distance.EuclideanDistance;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathArrays;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java b/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java
index 6ab9058..74699ff 100644
--- a/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java
@@ -28,7 +28,7 @@ import org.apache.commons.math4.exception.NumberIsTooSmallException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.ml.distance.DistanceMeasure;
import org.apache.commons.math4.ml.distance.EuclideanDistance;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.stat.descriptive.moment.Variance;
import org.apache.commons.math4.util.MathUtils;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/ml/neuralnet/FeatureInitializerFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ml/neuralnet/FeatureInitializerFactory.java b/src/main/java/org/apache/commons/math4/ml/neuralnet/FeatureInitializerFactory.java
index 9ab532c..8aa6bb8 100644
--- a/src/main/java/org/apache/commons/math4/ml/neuralnet/FeatureInitializerFactory.java
+++ b/src/main/java/org/apache/commons/math4/ml/neuralnet/FeatureInitializerFactory.java
@@ -21,7 +21,7 @@ import org.apache.commons.math4.analysis.UnivariateFunction;
import org.apache.commons.math4.analysis.function.Constant;
import org.apache.commons.math4.distribution.RealDistribution;
import org.apache.commons.math4.distribution.UniformRealDistribution;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
/**
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/random/RngAdaptor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/RngAdaptor.java b/src/main/java/org/apache/commons/math4/random/RngAdaptor.java
index 3c365af..c4613a4 100644
--- a/src/main/java/org/apache/commons/math4/random/RngAdaptor.java
+++ b/src/main/java/org/apache/commons/math4/random/RngAdaptor.java
@@ -22,7 +22,8 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.rng.RestorableUniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.core.RandomProviderDefaultState;
/**
* Adaptor that delegates to a {@link UniformRandomProvider} instance.
@@ -206,7 +207,7 @@ public final class RngAdaptor
out.defaultWriteObject();
// Save current state.
- out.writeObject(((RandomSource.State) delegate.saveState()).getState());
+ out.writeObject(((RandomProviderDefaultState) delegate.saveState()).getState());
}
/**
@@ -223,7 +224,7 @@ public final class RngAdaptor
// Recreate the "delegate" from serialized info.
delegate = RandomSource.create(source);
// And restore its state.
- final RandomSource.State state = new RandomSource.State((byte[]) in.readObject());
+ final RandomProviderDefaultState state = new RandomProviderDefaultState((byte[]) in.readObject());
delegate.restoreState(state);
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java b/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
index 19a64d6..304ad24 100644
--- a/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
@@ -17,7 +17,7 @@
package org.apache.commons.math4.random;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.distribution.RealDistribution;
import org.apache.commons.math4.distribution.NormalDistribution;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
index c3d69bb..9757b73 100644
--- a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
+++ b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
@@ -40,7 +40,7 @@ import org.apache.commons.math4.linear.Array2DRowFieldMatrix;
import org.apache.commons.math4.linear.FieldMatrix;
import org.apache.commons.math4.linear.MatrixUtils;
import org.apache.commons.math4.linear.RealMatrix;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.util.CombinatoricsUtils;
import org.apache.commons.math4.util.FastMath;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/stat/ranking/NaturalRanking.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/ranking/NaturalRanking.java b/src/main/java/org/apache/commons/math4/stat/ranking/NaturalRanking.java
index b0cec69..ad15725 100644
--- a/src/main/java/org/apache/commons/math4/stat/ranking/NaturalRanking.java
+++ b/src/main/java/org/apache/commons/math4/stat/ranking/NaturalRanking.java
@@ -25,7 +25,7 @@ import java.util.List;
import org.apache.commons.math4.exception.MathInternalError;
import org.apache.commons.math4.exception.NotANumberException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.random.RandomUtils;
import org.apache.commons.math4.util.FastMath;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/util/MathArrays.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/util/MathArrays.java b/src/main/java/org/apache/commons/math4/util/MathArrays.java
index 0c6f26d..b56196f 100644
--- a/src/main/java/org/apache/commons/math4/util/MathArrays.java
+++ b/src/main/java/org/apache/commons/math4/util/MathArrays.java
@@ -39,7 +39,7 @@ import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
/**
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java b/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java
index ddcaf28..f8b0ac7 100644
--- a/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java
+++ b/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java
@@ -22,7 +22,8 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.rng.RestorableUniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.core.RandomProviderDefaultState;
/**
* A strategy of selecting random index between begin and end indices.
@@ -77,7 +78,7 @@ public class RandomPivotingStrategy implements PivotingStrategyInterface, Serial
out.defaultWriteObject();
// Save current state.
- out.writeObject(((RandomSource.State) random.saveState()).getState());
+ out.writeObject(((RandomProviderDefaultState) random.saveState()).getState());
}
/**
@@ -94,7 +95,7 @@ public class RandomPivotingStrategy implements PivotingStrategyInterface, Serial
// Recreate the "delegate" from serialized info.
random = RandomSource.create(randomSource);
// And restore its state.
- final RandomSource.State state = new RandomSource.State((byte[]) in.readObject());
+ final RandomProviderDefaultState state = new RandomProviderDefaultState((byte[]) in.readObject());
random.restoreState(state);
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java b/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java
index 240fea4..7f24b7b 100644
--- a/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.math4;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathArrays;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/PerfTestUtils.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/PerfTestUtils.java b/src/test/java/org/apache/commons/math4/PerfTestUtils.java
index dfeed00..eb965ba 100644
--- a/src/test/java/org/apache/commons/math4/PerfTestUtils.java
+++ b/src/test/java/org/apache/commons/math4/PerfTestUtils.java
@@ -23,7 +23,7 @@ import java.util.concurrent.Callable;
import org.apache.commons.math4.util.MathArrays;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.exception.MathIllegalStateException;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java b/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
index 7c64d1a..1e82465 100644
--- a/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
@@ -27,7 +27,7 @@ import org.apache.commons.math4.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.ArithmeticUtils;
import org.apache.commons.math4.util.CombinatoricsUtils;
import org.apache.commons.math4.util.FastMath;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java b/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java
index 2f2b347..5f417a8 100644
--- a/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java
@@ -23,7 +23,7 @@ import org.apache.commons.math4.ExtendedFieldElementAbstractTest;
import org.apache.commons.math4.TestUtils;
import org.apache.commons.math4.analysis.polynomials.PolynomialFunction;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java b/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java
index 1bb7fe0..9eb1b0a 100644
--- a/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.analysis.function.Sigmoid;
import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.util.FastMath;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java b/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java
index 2fa667e..85a3e09 100644
--- a/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java
@@ -27,7 +27,7 @@ import org.apache.commons.math4.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.exception.NumberIsTooSmallException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.Precision;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunctionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunctionTest.java b/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunctionTest.java
index e65a9dd..dc53e40 100644
--- a/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunctionTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunctionTest.java
@@ -23,7 +23,7 @@ import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.OutOfRangeException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.Precision;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatorTest.java b/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatorTest.java
index bc3b7d2..8c29778 100644
--- a/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.distribution.UniformRealDistribution;
import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.junit.Assert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunctionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunctionTest.java b/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunctionTest.java
index c4cfcb2..fc38867 100644
--- a/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunctionTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunctionTest.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.exception.InsufficientDataException;
import org.apache.commons.math4.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.Precision;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java b/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java
index e7d6c6e..1c0a070 100644
--- a/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.exception.InsufficientDataException;
import org.apache.commons.math4.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.junit.Assert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunctionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunctionTest.java b/src/test/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunctionTest.java
index 0277a00..79777fa 100644
--- a/src/test/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunctionTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunctionTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.distribution.UniformRealDistribution;
import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.Precision;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/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 2b9b23b..d414db4 100644
--- a/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
@@ -18,7 +18,7 @@ package org.apache.commons.math4.distribution;
import java.util.Arrays;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.math4.stat.StatUtils;
import org.apache.commons.math4.stat.inference.KolmogorovSmirnovTest;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/distribution/EmpiricalDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/EmpiricalDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/EmpiricalDistributionTest.java
index a876829..e0a7839 100644
--- a/src/test/java/org/apache/commons/math4/distribution/EmpiricalDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/EmpiricalDistributionTest.java
@@ -31,7 +31,7 @@ import org.apache.commons.math4.analysis.integration.IterativeLegendreGaussInteg
import org.apache.commons.math4.exception.MathIllegalStateException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
import org.apache.commons.math4.util.FastMath;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/distribution/EnumeratedIntegerDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/EnumeratedIntegerDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/EnumeratedIntegerDistributionTest.java
index 3e32934..439764a 100644
--- a/src/test/java/org/apache/commons/math4/distribution/EnumeratedIntegerDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/EnumeratedIntegerDistributionTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.exception.NotANumberException;
import org.apache.commons.math4.exception.NotFiniteNumberException;
import org.apache.commons.math4.exception.NotPositiveException;
import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.junit.Assert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/distribution/EnumeratedRealDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/EnumeratedRealDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/EnumeratedRealDistributionTest.java
index 18d71e5..77abceb 100644
--- a/src/test/java/org/apache/commons/math4/distribution/EnumeratedRealDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/EnumeratedRealDistributionTest.java
@@ -31,7 +31,7 @@ import org.apache.commons.math4.exception.NotPositiveException;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.Pair;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.junit.Assert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/distribution/HypergeometricDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/HypergeometricDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/HypergeometricDistributionTest.java
index 6bfe8d6..31f04ba 100644
--- a/src/test/java/org/apache/commons/math4/distribution/HypergeometricDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/HypergeometricDistributionTest.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.exception.NotPositiveException;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.util.Precision;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.junit.Assert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/distribution/IntegerDistributionAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/IntegerDistributionAbstractTest.java b/src/test/java/org/apache/commons/math4/distribution/IntegerDistributionAbstractTest.java
index 34cceb7..bb99df8 100644
--- a/src/test/java/org/apache/commons/math4/distribution/IntegerDistributionAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/IntegerDistributionAbstractTest.java
@@ -20,7 +20,7 @@ import org.apache.commons.math4.TestUtils;
import org.apache.commons.math4.distribution.AbstractIntegerDistribution;
import org.apache.commons.math4.distribution.IntegerDistribution;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.junit.After;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/distribution/MixtureMultivariateNormalDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/MixtureMultivariateNormalDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/MixtureMultivariateNormalDistributionTest.java
index e6c646f..54c2483 100644
--- a/src/test/java/org/apache/commons/math4/distribution/MixtureMultivariateNormalDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/MixtureMultivariateNormalDistributionTest.java
@@ -23,7 +23,7 @@ import org.apache.commons.math4.distribution.MixtureMultivariateRealDistribution
import org.apache.commons.math4.distribution.MultivariateNormalDistribution;
import org.apache.commons.math4.exception.MathArithmeticException;
import org.apache.commons.math4.exception.NotPositiveException;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.Pair;
import org.junit.Assert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b1d38d9b/src/test/java/org/apache/commons/math4/distribution/MultivariateNormalDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/MultivariateNormalDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/MultivariateNormalDistributionTest.java
index 70d7e02..0f6f33e 100644
--- a/src/test/java/org/apache/commons/math4/distribution/MultivariateNormalDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/MultivariateNormalDistributionTest.java
@@ -20,7 +20,7 @@ package org.apache.commons.math4.distribution;
import org.apache.commons.math4.distribution.MultivariateNormalDistribution;
import org.apache.commons.math4.distribution.NormalDistribution;
import org.apache.commons.math4.linear.RealMatrix;
-import org.apache.commons.rng.RandomSource;
+import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.stat.correlation.Covariance;
import java.util.Random;