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 2017/08/16 12:46:30 UTC
[math] MATH-1429: "UnitSphereRandomVectorGenerator" replaced by
"UnitSphereSampler".
Repository: commons-math
Updated Branches:
refs/heads/master eed46beef -> 2c6e3404b
MATH-1429: "UnitSphereRandomVectorGenerator" replaced by "UnitSphereSampler".
Functionality moved to "Commons RNG":
https://issues.apache.org/jira/browse/RNG-39
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/2c6e3404
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/2c6e3404
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/2c6e3404
Branch: refs/heads/master
Commit: 2c6e3404bc72e76b2e9d308121368f09b723c8df
Parents: eed46be
Author: Gilles <er...@apache.org>
Authored: Wed Aug 16 14:42:19 2017 +0200
Committer: Gilles <er...@apache.org>
Committed: Wed Aug 16 14:42:19 2017 +0200
----------------------------------------------------------------------
.../interpolation/InterpolatingMicrosphere.java | 4 +-
.../MicrosphereProjectionInterpolator.java | 6 +-
.../random/UnitSphereRandomVectorGenerator.java | 84 --------------------
.../geometry/enclosing/WelzlEncloser3DTest.java | 12 +--
.../euclidean/threed/FieldRotationDSTest.java | 14 ++--
.../euclidean/threed/FieldRotationDfpTest.java | 16 ++--
.../euclidean/threed/SphereGeneratorTest.java | 14 ++--
.../euclidean/twod/DiskGeneratorTest.java | 13 ++-
.../geometry/spherical/twod/CircleTest.java | 16 ++--
.../twod/SphericalPolygonsSetTest.java | 52 ++++++------
.../UnitSphereRandomVectorGeneratorTest.java | 70 ----------------
11 files changed, 73 insertions(+), 228 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/main/java/org/apache/commons/math4/analysis/interpolation/InterpolatingMicrosphere.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/InterpolatingMicrosphere.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/InterpolatingMicrosphere.java
index 893a760..e40d202 100644
--- a/src/main/java/org/apache/commons/math4/analysis/interpolation/InterpolatingMicrosphere.java
+++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/InterpolatingMicrosphere.java
@@ -20,7 +20,7 @@ import java.util.List;
import java.util.ArrayList;
import org.apache.commons.numbers.arrays.CosAngle;
import org.apache.commons.numbers.arrays.SafeNorm;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.NotPositiveException;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
@@ -126,7 +126,7 @@ public class InterpolatingMicrosphere {
double maxDarkFraction,
double darkThreshold,
double background,
- UnitSphereRandomVectorGenerator rand) {
+ UnitSphereSampler rand) {
this(dimension, size, maxDarkFraction, darkThreshold, background);
// Generate the microsphere normals, assuming that a number of
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/main/java/org/apache/commons/math4/analysis/interpolation/MicrosphereProjectionInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/MicrosphereProjectionInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/MicrosphereProjectionInterpolator.java
index ebe3c71..49cbf2e 100644
--- a/src/main/java/org/apache/commons/math4/analysis/interpolation/MicrosphereProjectionInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/MicrosphereProjectionInterpolator.java
@@ -16,12 +16,13 @@
*/
package org.apache.commons.math4.analysis.interpolation;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.math4.analysis.MultivariateFunction;
import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.NoDataException;
import org.apache.commons.math4.exception.NotPositiveException;
import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
/**
* Interpolator that implements the algorithm described in
@@ -82,7 +83,8 @@ public class MicrosphereProjectionInterpolator
maxDarkFraction,
darkThreshold,
background,
- new UnitSphereRandomVectorGenerator(dimension)),
+ new UnitSphereSampler(dimension,
+ RandomSource.create(RandomSource.MT_64))),
exponent,
sharedSphere,
noInterpolationTolerance);
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/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
deleted file mode 100644
index 304ad24..0000000
--- a/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.random;
-
-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;
-import org.apache.commons.math4.util.FastMath;
-
-
-/**
- * Generate random vectors isotropically located on the surface of a sphere.
- *
- * @since 2.1
- */
-public class UnitSphereRandomVectorGenerator
- implements RandomVectorGenerator {
- /**
- * Sampler used for generating the individual components of the vectors.
- */
- private final RealDistribution.Sampler rand;
- /**
- * Space dimension.
- */
- private final int dimension;
-
- /**
- * @param dimension Space dimension.
- * @param rng RNG for the individual components of the vectors.
- */
- public UnitSphereRandomVectorGenerator(final int dimension,
- final UniformRandomProvider rng) {
- this.dimension = dimension;
- this.rand = new NormalDistribution().createSampler(rng);
- }
- /**
- * Create an object that will use a {@link RandomSource#MT_64 default RNG},
- * in order to generate the individual components.
- *
- * @param dimension Space dimension.
- */
- public UnitSphereRandomVectorGenerator(final int dimension) {
- this(dimension, RandomSource.create(RandomSource.MT_64));
- }
-
- /** {@inheritDoc} */
- @Override
- public double[] nextVector() {
- final double[] v = new double[dimension];
-
- // See http://mathworld.wolfram.com/SpherePointPicking.html for example.
- // Pick a point by choosing a standard Gaussian for each element, and then
- // normalizing to unit length.
- double normSq = 0;
- for (int i = 0; i < dimension; i++) {
- final double comp = rand.sample();
- v[i] = comp;
- normSq += comp * comp;
- }
-
- final double f = 1 / FastMath.sqrt(normSq);
- for (int i = 0; i < dimension; i++) {
- v[i] *= f;
- }
-
- return v;
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java b/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java
index 4bd3d04..5f585b4 100644
--- a/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java
@@ -21,16 +21,16 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.math4.geometry.enclosing.EnclosingBall;
import org.apache.commons.math4.geometry.enclosing.WelzlEncloser;
import org.apache.commons.math4.geometry.euclidean.threed.Euclidean3D;
import org.apache.commons.math4.geometry.euclidean.threed.SphereGenerator;
import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
-import org.junit.Test;
public class WelzlEncloser3DTest {
@@ -106,7 +106,7 @@ public class WelzlEncloser3DTest {
public void testLargeSamples() throws IOException {
final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
0x35ddecfc78131e1dl);
- final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
+ final UnitSphereSampler sr = new UnitSphereSampler(3, random);
for (int k = 0; k < 50; ++k) {
// define the reference sphere we want to compute
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
index 873a80a..83351b6 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
@@ -17,7 +17,12 @@
package org.apache.commons.math4.geometry.euclidean.threed;
+import org.junit.Assert;
+import org.junit.Test;
import org.apache.commons.numbers.angle.PlaneAngleRadians;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.exception.MathArithmeticException;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
@@ -30,12 +35,7 @@ import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder;
import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D;
import org.apache.commons.math4.linear.MatrixUtils;
import org.apache.commons.math4.linear.RealMatrix;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
-import org.junit.Assert;
-import org.junit.Test;
public class FieldRotationDSTest {
@@ -962,7 +962,7 @@ public class FieldRotationDSTest {
public void testDoubleVectors() throws MathIllegalArgumentException {
UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
0x180b41cfeeffaf67l);
- UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
+ UnitSphereSampler g = new UnitSphereSampler(3, random);
for (int i = 0; i < 10; ++i) {
double[] unit = g.nextVector();
FieldRotation<DerivativeStructure> r = new FieldRotation<>(createVector(unit[0], unit[1], unit[2]),
@@ -997,7 +997,7 @@ public class FieldRotationDSTest {
public void testDoubleRotations() throws MathIllegalArgumentException {
UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
0x180b41cfeeffaf67l);
- UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
+ UnitSphereSampler g = new UnitSphereSampler(3, random);
for (int i = 0; i < 10; ++i) {
double[] unit1 = g.nextVector();
Rotation r1 = new Rotation(new Cartesian3D(unit1[0], unit1[1], unit1[2]),
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
index 4586bad..a835b77 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
@@ -17,6 +17,12 @@
package org.apache.commons.math4.geometry.euclidean.threed;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.commons.numbers.angle.PlaneAngleRadians;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.numbers.angle.PlaneAngleRadians;
import org.apache.commons.math4.dfp.Dfp;
import org.apache.commons.math4.dfp.DfpField;
@@ -29,13 +35,7 @@ import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixExce
import org.apache.commons.math4.geometry.euclidean.threed.Rotation;
import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder;
import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
-import org.junit.Assert;
-import org.junit.Test;
-
public class FieldRotationDfpTest {
@@ -803,7 +803,7 @@ public class FieldRotationDfpTest {
public void testDoubleVectors() throws MathIllegalArgumentException {
UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
0x180b41cfeeffaf67l);
- UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
+ UnitSphereSampler g = new UnitSphereSampler(3, random);
for (int i = 0; i < 10; ++i) {
double[] unit = g.nextVector();
FieldRotation<Dfp> r = new FieldRotation<>(createVector(unit[0], unit[1], unit[2]),
@@ -839,7 +839,7 @@ public class FieldRotationDfpTest {
UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
0x180b41cfeeffaf67l);
DfpField field = new DfpField(20);
- UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
+ UnitSphereSampler g = new UnitSphereSampler(3, random);
for (int i = 0; i < 10; ++i) {
double[] unit1 = g.nextVector();
Rotation r1 = new Rotation(new Cartesian3D(unit1[0], unit1[1], unit1[2]),
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java
index ec920b3..1d0a913 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java
@@ -19,18 +19,16 @@ package org.apache.commons.math4.geometry.euclidean.threed;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.math4.geometry.enclosing.EnclosingBall;
import org.apache.commons.math4.geometry.euclidean.threed.Euclidean3D;
import org.apache.commons.math4.geometry.euclidean.threed.SphereGenerator;
import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
-import org.junit.Assert;
-import org.junit.Test;
-
public class SphereGeneratorTest {
@@ -139,7 +137,7 @@ public class SphereGeneratorTest {
public void testRandom() {
final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
0xd015982e9f31ee04l);
- final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
+ final UnitSphereSampler sr = new UnitSphereSampler(3, random);
for (int i = 0; i < 100; ++i) {
double d = 25 * random.nextDouble();
double refRadius = 10 * random.nextDouble();
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
index 727bdfa..2da1191 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
@@ -19,16 +19,15 @@ package org.apache.commons.math4.geometry.euclidean.twod;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.math4.geometry.enclosing.EnclosingBall;
import org.apache.commons.math4.geometry.euclidean.twod.DiskGenerator;
import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
import org.apache.commons.math4.geometry.euclidean.twod.Cartesian2D;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
-import org.junit.Test;
public class DiskGeneratorTest {
@@ -104,7 +103,7 @@ public class DiskGeneratorTest {
public void testRandom() {
final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
0x12faa818373ffe90l);
- final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(2, random);
+ final UnitSphereSampler sr = new UnitSphereSampler(2, random);
for (int i = 0; i < 500; ++i) {
double d = 25 * random.nextDouble();
double refRadius = 10 * random.nextDouble();
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
index f45c22d..0cc3d70 100644
--- a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
@@ -16,6 +16,11 @@
*/
package org.apache.commons.math4.geometry.spherical.twod;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.math4.geometry.euclidean.threed.Rotation;
import org.apache.commons.math4.geometry.euclidean.threed.RotationConvention;
import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D;
@@ -28,13 +33,8 @@ import org.apache.commons.math4.geometry.spherical.oned.SubLimitAngle;
import org.apache.commons.math4.geometry.spherical.twod.Circle;
import org.apache.commons.math4.geometry.spherical.twod.S2Point;
import org.apache.commons.math4.geometry.spherical.twod.Sphere2D;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathUtils;
-import org.junit.Assert;
-import org.junit.Test;
public class CircleTest {
@@ -135,8 +135,8 @@ public class CircleTest {
@Test
public void testInsideArc() {
- UnitSphereRandomVectorGenerator sphRandom = new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
- 0xbfd34e92231bbcfel));
+ UnitSphereSampler sphRandom = new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A,
+ 0xbfd34e92231bbcfel));
for (int i = 0; i < 100; ++i) {
Circle c1 = new Circle(new Cartesian3D(sphRandom.nextVector()), 1.0e-10);
Circle c2 = new Circle(new Cartesian3D(sphRandom.nextVector()), 1.0e-10);
@@ -160,7 +160,7 @@ public class CircleTest {
public void testTransform() {
UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
0x16992fc4294bf2f1l);
- UnitSphereRandomVectorGenerator sphRandom = new UnitSphereRandomVectorGenerator(3, random);
+ UnitSphereSampler sphRandom = new UnitSphereSampler(3, random);
for (int i = 0; i < 100; ++i) {
Rotation r = new Rotation(new Cartesian3D(sphRandom.nextVector()),
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java
index 4096a59..74bcf6f 100644
--- a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java
@@ -18,7 +18,11 @@ package org.apache.commons.math4.geometry.spherical.twod;
import java.util.ArrayList;
import java.util.List;
-
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.UnitSphereSampler;
import org.apache.commons.math4.geometry.enclosing.EnclosingBall;
import org.apache.commons.math4.geometry.euclidean.threed.Rotation;
import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D;
@@ -34,21 +38,17 @@ import org.apache.commons.math4.geometry.spherical.twod.Sphere2D;
import org.apache.commons.math4.geometry.spherical.twod.SphericalPolygonsSet;
import org.apache.commons.math4.geometry.spherical.twod.SubCircle;
import org.apache.commons.math4.geometry.spherical.twod.Vertex;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathUtils;
-import org.junit.Assert;
-import org.junit.Test;
public class SphericalPolygonsSetTest {
@Test
public void testFullSphere() {
SphericalPolygonsSet full = new SphericalPolygonsSet(1.0e-10);
- UnitSphereRandomVectorGenerator random =
- new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
- 0x852fd2a0ed8d2f6dl));
+ UnitSphereSampler random =
+ new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A,
+ 0x852fd2a0ed8d2f6dl));
for (int i = 0; i < 1000; ++i) {
Cartesian3D v = new Cartesian3D(random.nextVector());
Assert.assertEquals(Location.INSIDE, full.checkPoint(new S2Point(v)));
@@ -64,9 +64,9 @@ public class SphericalPolygonsSetTest {
public void testEmpty() {
SphericalPolygonsSet empty =
(SphericalPolygonsSet) new RegionFactory<Sphere2D>().getComplement(new SphericalPolygonsSet(1.0e-10));
- UnitSphereRandomVectorGenerator random =
- new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
- 0x76d9205d6167b6ddl));
+ UnitSphereSampler random =
+ new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A,
+ 0x76d9205d6167b6ddl));
for (int i = 0; i < 1000; ++i) {
Cartesian3D v = new Cartesian3D(random.nextVector());
Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(new S2Point(v)));
@@ -83,9 +83,9 @@ public class SphericalPolygonsSetTest {
double tol = 0.01;
double sinTol = FastMath.sin(tol);
SphericalPolygonsSet south = new SphericalPolygonsSet(Cartesian3D.MINUS_K, tol);
- UnitSphereRandomVectorGenerator random =
- new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
- 0x6b9d4a6ad90d7b0bl));
+ UnitSphereSampler random =
+ new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A,
+ 0x6b9d4a6ad90d7b0bl));
for (int i = 0; i < 1000; ++i) {
Cartesian3D v = new Cartesian3D(random.nextVector());
if (v.getZ() < -sinTol) {
@@ -119,9 +119,9 @@ public class SphericalPolygonsSetTest {
SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Cartesian3D.PLUS_K, tol);
SphericalPolygonsSet octant =
(SphericalPolygonsSet) factory.intersection(factory.intersection(plusX, plusY), plusZ);
- UnitSphereRandomVectorGenerator random =
- new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
- 0x9c9802fde3cbcf25l));
+ UnitSphereSampler random =
+ new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A,
+ 0x9c9802fde3cbcf25l));
for (int i = 0; i < 1000; ++i) {
Cartesian3D v = new Cartesian3D(random.nextVector());
if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
@@ -184,9 +184,9 @@ public class SphericalPolygonsSetTest {
double tol = 0.01;
double sinTol = FastMath.sin(tol);
SphericalPolygonsSet octant = new SphericalPolygonsSet(tol, S2Point.PLUS_I, S2Point.PLUS_J, S2Point.PLUS_K);
- UnitSphereRandomVectorGenerator random =
- new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
- 0xb8fc5acc91044308l));
+ UnitSphereSampler random =
+ new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A,
+ 0xb8fc5acc91044308l));
for (int i = 0; i < 1000; ++i) {
Cartesian3D v = new Cartesian3D(random.nextVector());
if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
@@ -210,9 +210,9 @@ public class SphericalPolygonsSetTest {
SphericalPolygonsSet threeOctants =
(SphericalPolygonsSet) factory.difference(plusZ, factory.intersection(plusX, plusY));
- UnitSphereRandomVectorGenerator random =
- new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
- 0x9c9802fde3cbcf25l));
+ UnitSphereSampler random =
+ new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A,
+ 0x9c9802fde3cbcf25l));
for (int i = 0; i < 1000; ++i) {
Cartesian3D v = new Cartesian3D(random.nextVector());
if (((v.getX() < -sinTol) || (v.getY() < -sinTol)) && (v.getZ() > sinTol)) {
@@ -344,9 +344,9 @@ public class SphericalPolygonsSetTest {
SphericalPolygonsSet polygon = new SphericalPolygonsSet(boundary, tol);
- UnitSphereRandomVectorGenerator random =
- new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
- 0xcc5ce49949e0d3ecl));
+ UnitSphereSampler random =
+ new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A,
+ 0xcc5ce49949e0d3ecl));
for (int i = 0; i < 1000; ++i) {
Cartesian3D v = new Cartesian3D(random.nextVector());
if ((v.getX() < -sinTol) && (v.getY() < -sinTol) && (v.getZ() < -sinTol)) {
http://git-wip-us.apache.org/repos/asf/commons-math/blob/2c6e3404/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java
deleted file mode 100644
index 11311f0..0000000
--- a/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.random;
-
-import org.apache.commons.rng.simple.RandomSource;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.math4.util.FastMath;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class UnitSphereRandomVectorGeneratorTest {
- /**
- * Test the distribution of points from {@link UnitSphereRandomVectorGenerator#nextVector()}
- * in two dimensions.
- */
- @Test
- public void test2DDistribution() {
-
- UniformRandomProvider rg = RandomSource.create(RandomSource.XOR_SHIFT_1024_S, 17399225432L);
- UnitSphereRandomVectorGenerator generator = new UnitSphereRandomVectorGenerator(2, rg);
-
- // In 2D, angles with a given vector should be uniformly distributed
- int[] angleBuckets = new int[100];
- int steps = 1000000;
- for (int i = 0; i < steps; ++i) {
- final double[] v = generator.nextVector();
- Assert.assertEquals(2, v.length);
- Assert.assertEquals(1, length(v), 1e-10);
- // Compute angle formed with vector (1,0)
- // Cosine of angle is their dot product, because both are unit length
- // Dot product here is just the first element of the vector by construction
- final double angle = FastMath.acos(v[0]);
- final int bucket = (int) (angleBuckets.length * (angle / FastMath.PI));
- ++angleBuckets[bucket];
- }
-
- // Simplistic test for roughly even distribution
- final int expectedBucketSize = steps / angleBuckets.length;
- for (int bucket : angleBuckets) {
- Assert.assertTrue("Bucket count " + bucket + " vs expected " + expectedBucketSize,
- FastMath.abs(expectedBucketSize - bucket) < 350);
- }
- }
-
- /**
- * @return length (L2 norm) of given vector
- */
- private static double length(double[] vector) {
- double total = 0;
- for (double d : vector) {
- total += d * d;
- }
- return FastMath.sqrt(total);
- }
-}