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/05/17 15:49:47 UTC

[14/25] [math] MATH-1335

MATH-1335

Use new RNG API.


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

Branch: refs/heads/develop
Commit: f9f632e7056cd9d2b3c88bad50fe0597610e2eca
Parents: 0484bdb
Author: Gilles <er...@apache.org>
Authored: Thu May 12 12:43:04 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/filter/KalmanFilterTest.java   | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/f9f632e7/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java b/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java
index 2db564d..131da51 100644
--- a/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java
+++ b/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java
@@ -27,9 +27,6 @@ import org.apache.commons.math4.linear.MatrixDimensionMismatchException;
 import org.apache.commons.math4.linear.MatrixUtils;
 import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.linear.RealVector;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.Precision;
@@ -129,19 +126,20 @@ public class KalmanFilterTest {
         RealVector pNoise = new ArrayRealVector(1);
         RealVector mNoise = new ArrayRealVector(1);
 
-        RandomGenerator rand = new JDKRandomGenerator();
+        final RealDistribution.Sampler rand = new NormalDistribution().createSampler(RandomSource.create(RandomSource.WELL_19937_C));
+
         // iterate 60 steps
         for (int i = 0; i < 60; i++) {
             filter.predict();
 
             // Simulate the process
-            pNoise.setEntry(0, processNoise * rand.nextGaussian());
+            pNoise.setEntry(0, processNoise * rand.sample());
 
             // x = A * x + p_noise
             x = A.operate(x).add(pNoise);
 
             // Simulate the measurement
-            mNoise.setEntry(0, measurementNoise * rand.nextGaussian());
+            mNoise.setEntry(0, measurementNoise * rand.sample());
 
             // z = H * x + m_noise
             RealVector z = H.operate(x).add(mNoise);
@@ -217,7 +215,7 @@ public class KalmanFilterTest {
         double[] expectedInitialState = new double[] { 0.0, 0.0 };
         assertVectorEquals(expectedInitialState, filter.getStateEstimation());
 
-        RandomGenerator rand = new JDKRandomGenerator();
+        final RealDistribution.Sampler rand = new NormalDistribution().createSampler(RandomSource.create(RandomSource.WELL_19937_C));
 
         RealVector tmpPNoise = new ArrayRealVector(
                 new double[] { FastMath.pow(dt, 2d) / 2d, dt });
@@ -227,13 +225,13 @@ public class KalmanFilterTest {
             filter.predict(u);
 
             // Simulate the process
-            RealVector pNoise = tmpPNoise.mapMultiply(accelNoise * rand.nextGaussian());
+            RealVector pNoise = tmpPNoise.mapMultiply(accelNoise * rand.sample());
 
             // x = A * x + B * u + pNoise
             x = A.operate(x).add(B.operate(u)).add(pNoise);
 
             // Simulate the measurement
-            double mNoise = measurementNoise * rand.nextGaussian();
+            double mNoise = measurementNoise * rand.sample();
 
             // z = H * x + m_noise
             RealVector z = H.operate(x).mapAdd(mNoise);
@@ -394,8 +392,7 @@ public class KalmanFilterTest {
         final MeasurementModel mm = new DefaultMeasurementModel(H, R);
         final KalmanFilter filter = new KalmanFilter(pm, mm);
 
-        final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1000);
-        final RealDistribution.Sampler dist = new NormalDistribution(0, measurementNoise).createSampler(rng);
+        final RealDistribution.Sampler dist = new NormalDistribution(0, measurementNoise).createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
 
         for (int i = 0; i < iterations; i++) {
             // get the "real" cannonball position