List of usage examples for org.apache.commons.math3.random Well19937a Well19937a
public Well19937a(long seed)
From source file:com.milaboratory.core.clustering.ClusteringTest.java
private static Cluster<TestObject> getRandomTestCluster(NucleotideSequence sequence, int color, int depth, int maxChildren, int maxCount, int delta, long seed) { assert delta * depth < maxCount; Cluster<TestObject> head = new Cluster<>(new TestObject(maxCount, sequence, color)); HashSet<NucleotideSequence> nucleotideSequences = new HashSet<>(); nucleotideSequences.add(sequence);/*w ww .j a va 2 s.c o m*/ addRandomTestCluster(head, color, nucleotideSequences, maxChildren, depth, delta, new Well19937a(seed)); return head; }
From source file:edu.cmu.tetrad.sem.LargeSemSimulator.java
public BoxDataSet simulateDataAcyclicConcurrent(int sampleSize) { int numVars = variableNodes.size(); setupModel(numVars);//from ww w . ja va 2s . c om System.out.println("Tier ordering"); final int[][] _parents = parents; final double[][] _coefs = coefs; // final double[][] _data = new double[sampleSize][numVars]; final double[][] _data = new double[numVars][sampleSize]; System.out.println("Starting simulation task"); // This random number generator is not thread safe, so we make a new one each time. RandomGenerator apacheGen = new Well19937a(new Date().getTime()); final RandomDataGenerator generator = new RandomDataGenerator(new SynchronizedRandomGenerator(apacheGen)); //Do the simulation. class SimulationTask extends RecursiveTask<Boolean> { private int chunk; private int from; private int to; public SimulationTask(int chunk, int from, int to) { this.chunk = chunk; this.from = from; this.to = to; } @Override protected Boolean compute() { RandomGenerator apacheGen = new Well44497b(generator.nextLong(0, Long.MAX_VALUE)); RandomDataGenerator generatorLocal = new RandomDataGenerator(apacheGen); if (to - from <= chunk) { for (int row = from; row < to; row++) { if (row % 100 == 0) out.println("Row " + row); for (int i = 0; i < tierIndices.length; i++) { int col = tierIndices[i]; double value = generatorLocal.nextGaussian(0, sqrt(errorVars[col])); for (int j = 0; j < _parents[col].length; j++) { int parent = _parents[col][j]; final double coef = _coefs[col][j]; final double v = _data[parent][row]; value += v * coef; if (Double.isNaN(value)) { throw new IllegalArgumentException(); } } value += means[col]; _data[col][row] = value; } } return true; } else { List<SimulationTask> simulationTasks = new ArrayList<SimulationTask>(); int mid = (to - from) / 2; simulationTasks.add(new SimulationTask(chunk, from, from + mid)); simulationTasks.add(new SimulationTask(chunk, from + mid, to)); invokeAll(simulationTasks); return true; } } } int chunk = 25; pool.invoke(new SimulationTask(chunk, 0, sampleSize)); return new BoxDataSet(new VerticalDoubleDataBox(_data), variableNodes); // return ColtDataSet.makeContinuousData(variableNodes, _data); }
From source file:org.orekit.bodies.EllipsoidTest.java
@Test public void testRandomNormalSections() throws IOException { RandomGenerator random = new Well19937a(0x573c54d152aeafe4l); for (int i = 0; i < 100; ++i) { double a = 10 * random.nextDouble(); double b = 10 * random.nextDouble(); double c = 10 * random.nextDouble(); double size = FastMath.max(FastMath.max(a, b), c); final Ellipsoid ellipsoid = new Ellipsoid(FramesFactory.getEME2000(), a, b, c); for (int j = 0; j < 50; ++j) { double phi = FastMath.PI * (random.nextDouble() - 0.5); double lambda = 2 * FastMath.PI * random.nextDouble(); double cPhi = FastMath.cos(phi); double sPhi = FastMath.sin(phi); double cLambda = FastMath.cos(lambda); double sLambda = FastMath.sin(lambda); Vector3D surfacePoint = new Vector3D(ellipsoid.getA() * cPhi * cLambda, ellipsoid.getB() * cPhi * sLambda, ellipsoid.getC() * sPhi); Vector3D t1 = new Vector3D(-ellipsoid.getA() * cPhi * sLambda, ellipsoid.getB() * cPhi * cLambda, 0) .normalize();//from w w w . ja v a 2 s. c o m Vector3D t2 = new Vector3D(-ellipsoid.getA() * sPhi * cLambda, -ellipsoid.getB() * sPhi * sLambda, ellipsoid.getC() * cPhi).normalize(); final double azimuth = 2 * FastMath.PI * random.nextDouble(); double cAzimuth = FastMath.cos(azimuth); double sAzimuth = FastMath.sin(azimuth); Vector3D tAz = new Vector3D(cAzimuth, t1, sAzimuth, t2); final Ellipse ps = ellipsoid.getPlaneSection(surfacePoint, tAz); Assert.assertEquals(0.0, errorOnEllipsoid(ps, ellipsoid), 1.0e-12 * size); Assert.assertEquals(0.0, errorOnPlane(ps, surfacePoint, tAz), 1.0e-10 * size); double cos = Vector3D.dotProduct(surfacePoint.subtract(ps.getCenter()), ps.getU()) / ps.getA(); double sin = Vector3D.dotProduct(surfacePoint.subtract(ps.getCenter()), ps.getV()) / ps.getB(); final Vector3D rebuilt = ps.pointAt(FastMath.atan2(sin, cos)); Assert.assertEquals(0, Vector3D.distance(surfacePoint, rebuilt), 1.0e-11 * size); } } }
From source file:org.orekit.frames.TransformTest.java
@Test public void testIdentityTranslation() { checkNoTransform(new Transform(AbsoluteDate.J2000_EPOCH, new Vector3D(0, 0, 0)), new Well19937a(0xfd118eac6b5ec136l)); }
From source file:org.orekit.frames.TransformTest.java
@Test public void testIdentityRotation() { checkNoTransform(new Transform(AbsoluteDate.J2000_EPOCH, new Rotation(1, 0, 0, 0, false)), new Well19937a(0xfd118eac6b5ec136l)); }
From source file:org.orekit.frames.TransformTest.java
@Test public void testAccelerationComposition() { RandomGenerator random = new Well19937a(0x41fdd07d6c9e9f65l); Vector3D p1 = randomVector(1.0e3, random); Vector3D v1 = randomVector(1.0, random); Vector3D a1 = randomVector(1.0e-3, random); Rotation r1 = randomRotation(random); Vector3D o1 = randomVector(0.1, random); Vector3D p2 = randomVector(1.0e3, random); Vector3D v2 = randomVector(1.0, random); Vector3D a2 = randomVector(1.0e-3, random); Rotation r2 = randomRotation(random); Vector3D o2 = randomVector(0.1, random); Transform t1 = new Transform(AbsoluteDate.J2000_EPOCH, new Transform(AbsoluteDate.J2000_EPOCH, p1, v1, a1), new Transform(AbsoluteDate.J2000_EPOCH, r1, o1)); Transform t2 = new Transform(AbsoluteDate.J2000_EPOCH, new Transform(AbsoluteDate.J2000_EPOCH, p2, v2, a2), new Transform(AbsoluteDate.J2000_EPOCH, r2, o2)); Transform t12 = new Transform(AbsoluteDate.J2000_EPOCH, t1, t2); Vector3D q = randomVector(1.0e3, random); Vector3D qDot = randomVector(1.0, random); Vector3D qDotDot = randomVector(1.0e-3, random); PVCoordinates pva0 = new PVCoordinates(q, qDot, qDotDot); PVCoordinates pva1 = t1.transformPVCoordinates(pva0); PVCoordinates pva2 = t2.transformPVCoordinates(pva1); PVCoordinates pvac = t12.transformPVCoordinates(pva0); checkVector(pva2.getPosition(), pvac.getPosition(), 1.0e-15); checkVector(pva2.getVelocity(), pvac.getVelocity(), 1.0e-15); checkVector(pva2.getAcceleration(), pvac.getAcceleration(), 1.0e-15); // despite neither raw transforms have angular acceleration, // the combination does have an angular acceleration, // it is due to the cross product ? Assert.assertEquals(0.0, t1.getAngular().getRotationAcceleration().getNorm(), 1.0e-15); Assert.assertEquals(0.0, t2.getAngular().getRotationAcceleration().getNorm(), 1.0e-15); Assert.assertTrue(t12.getAngular().getRotationAcceleration().getNorm() > 0.01); }
From source file:org.orekit.frames.TransformTest.java
@Test public void testRandomComposition() { RandomGenerator random = new Well19937a(0x171c79e323a1123l); for (int i = 0; i < 20; ++i) { // build a complex transform by composing primitive ones int n = random.nextInt(20); Transform[] transforms = new Transform[n]; Transform combined = Transform.IDENTITY; for (int k = 0; k < n; ++k) { transforms[k] = random.nextBoolean() ? new Transform(AbsoluteDate.J2000_EPOCH, randomVector(1.0e3, random), randomVector(1.0, random), randomVector(1.0e-3, random)) : new Transform(AbsoluteDate.J2000_EPOCH, randomRotation(random), randomVector(0.01, random), randomVector(1.0e-4, random)); combined = new Transform(AbsoluteDate.J2000_EPOCH, combined, transforms[k]); }/* w w w . jav a 2s. c o m*/ // check the composition for (int j = 0; j < 10; ++j) { Vector3D a = randomVector(1.0, random); Vector3D b = randomVector(1.0e3, random); PVCoordinates c = new PVCoordinates(randomVector(1.0e3, random), randomVector(1.0, random), randomVector(1.0e-3, random)); Vector3D aRef = a; Vector3D bRef = b; PVCoordinates cRef = c; for (int k = 0; k < n; ++k) { aRef = transforms[k].transformVector(aRef); bRef = transforms[k].transformPosition(bRef); cRef = transforms[k].transformPVCoordinates(cRef); } Vector3D aCombined = combined.transformVector(a); Vector3D bCombined = combined.transformPosition(b); PVCoordinates cCombined = combined.transformPVCoordinates(c); checkVector(aRef, aCombined, 3.0e-15); checkVector(bRef, bCombined, 5.0e-15); checkVector(cRef.getPosition(), cCombined.getPosition(), 1.0e-14); checkVector(cRef.getVelocity(), cCombined.getVelocity(), 1.0e-14); checkVector(cRef.getAcceleration(), cCombined.getAcceleration(), 1.0e-14); } } }
From source file:org.orekit.frames.TransformTest.java
@Test public void testReverse() { RandomGenerator random = new Well19937a(0x9f82ba2b2c98dac5l); for (int i = 0; i < 20; ++i) { Transform combined = randomTransform(random); checkNoTransform(new Transform(AbsoluteDate.J2000_EPOCH, combined, combined.getInverse()), random); }// w w w .j ava2s .c o m }
From source file:org.orekit.frames.TransformTest.java
@Test public void testDecomposeAndRebuild() { RandomGenerator random = new Well19937a(0xb8ee9da1b05198c9l); for (int i = 0; i < 20; ++i) { Transform combined = randomTransform(random); Transform rebuilt = new Transform(combined.getDate(), new Transform(combined.getDate(), combined.getTranslation(), combined.getVelocity(), combined.getAcceleration()), new Transform(combined.getDate(), combined.getRotation(), combined.getRotationRate(), combined.getRotationAcceleration())); checkNoTransform(new Transform(AbsoluteDate.J2000_EPOCH, combined, rebuilt.getInverse()), random); }/* w w w.j av a 2s . c o m*/ }
From source file:org.orekit.frames.TransformTest.java
@Test public void testTranslation() { RandomGenerator rnd = new Well19937a(0x7e9d737ba4147787l); for (int i = 0; i < 10; ++i) { Vector3D delta = randomVector(1.0e3, rnd); Transform transform = new Transform(AbsoluteDate.J2000_EPOCH, delta); for (int j = 0; j < 10; ++j) { Vector3D a = new Vector3D(rnd.nextDouble(), rnd.nextDouble(), rnd.nextDouble()); Vector3D b = transform.transformVector(a); Assert.assertEquals(0, b.subtract(a).getNorm(), 1.0e-15); Vector3D c = transform.transformPosition(a); Assert.assertEquals(0, c.subtract(a).subtract(delta).getNorm(), 1.0e-14); }/*from www .ja v a 2 s . c o m*/ } }