org.apache.commons.math3.random.Well1024a Java Examples

The following examples show how to use org.apache.commons.math3.random.Well1024a. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testShuffleHead() {
    final int[] orig = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    final int[] list = orig.clone();
    final int start = 4;
    MathArrays.shuffle(list, start, MathArrays.Position.HEAD, new Well1024a(1234567L));

    // Ensure that all entries above index "start" did not move.
    for (int i = start + 1; i < orig.length; i++) {
        Assert.assertEquals(orig[i], list[i]);
    }

    // Ensure that at least one entry has moved.
    boolean ok = false;
    for (int i = 0; i <= start; i++) {
        if (orig[i] != list[i]) {
            ok = true;
            break;
        }
    }
    Assert.assertTrue(ok);
}
 
Example #2
Source File: SphereGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRandom() {
    final RandomGenerator random = new Well1024a(0xd015982e9f31ee04l);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
    for (int i = 0; i < 100; ++i) {
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector3D refCenter = new Vector3D(d, new Vector3D(sr.nextVector()));
        List<Vector3D> support = new ArrayList<Vector3D>();
        for (int j = 0; j < 5; ++j) {
            support.add(new Vector3D(1.0, refCenter, refRadius, new Vector3D(sr.nextVector())));
        }
        EnclosingBall<Euclidean3D, Vector3D> sphere = new SphereGenerator().ballOnSupport(support);
        Assert.assertEquals(0.0, refCenter.distance(sphere.getCenter()), 4e-7 * refRadius);
        Assert.assertEquals(refRadius, sphere.getRadius(), 1e-7 * refRadius);
    }
    
}
 
Example #3
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLinearCombination2() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);

    for (int i = 0; i < 10000; ++i) {
        final double ux = 1e17 * random.nextDouble();
        final double uy = 1e17 * random.nextDouble();
        final double uz = 1e17 * random.nextDouble();
        final double vx = 1e17 * random.nextDouble();
        final double vy = 1e17 * random.nextDouble();
        final double vz = 1e17 * random.nextDouble();
        final double sInline = MathArrays.linearCombination(ux, vx,
                                                            uy, vy,
                                                            uz, vz);
        final double sArray = MathArrays.linearCombination(new double[] {ux, uy, uz},
                                                           new double[] {vx, vy, vz});
        Assert.assertEquals(sInline, sArray, 0);
    }
}
 
Example #4
Source File: Vector3DTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDotProduct() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);
    for (int i = 0; i < 10000; ++i) {
        double ux = 10000 * random.nextDouble();
        double uy = 10000 * random.nextDouble();
        double uz = 10000 * random.nextDouble();
        double vx = 10000 * random.nextDouble();
        double vy = 10000 * random.nextDouble();
        double vz = 10000 * random.nextDouble();
        double sNaive = ux * vx + uy * vy + uz * vz;
        double sAccurate = new Vector3D(ux, uy, uz).dotProduct(new Vector3D(vx, vy, vz));
        Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate);
    }
}
 
Example #5
Source File: LogitTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testValueWithInverseFunction() {
    final double lo = 2;
    final double hi = 3;
    final Logit f = new Logit(lo, hi);
    final Sigmoid g = new Sigmoid(lo, hi);
    RandomGenerator random = new Well1024a(0x49914cdd9f0b8db5l);
    final UnivariateDifferentiableFunction id = FunctionUtils.compose((UnivariateDifferentiableFunction) g,
                                                            (UnivariateDifferentiableFunction) f);

    for (int i = 0; i < 10; i++) {
        final double x = lo + random.nextDouble() * (hi - lo);
        Assert.assertEquals(x, id.value(new DerivativeStructure(1, 1, 0, x)).getValue(), EPS);
    }

    Assert.assertEquals(lo, id.value(new DerivativeStructure(1, 1, 0, lo)).getValue(), EPS);
    Assert.assertEquals(hi, id.value(new DerivativeStructure(1, 1, 0, hi)).getValue(), EPS);
}
 
Example #6
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLinearCombination2() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);

    for (int i = 0; i < 10000; ++i) {
        final double ux = 1e17 * random.nextDouble();
        final double uy = 1e17 * random.nextDouble();
        final double uz = 1e17 * random.nextDouble();
        final double vx = 1e17 * random.nextDouble();
        final double vy = 1e17 * random.nextDouble();
        final double vz = 1e17 * random.nextDouble();
        final double sInline = MathArrays.linearCombination(ux, vx,
                                                            uy, vy,
                                                            uz, vz);
        final double sArray = MathArrays.linearCombination(new double[] {ux, uy, uz},
                                                           new double[] {vx, vy, vz});
        Assert.assertEquals(sInline, sArray, 0);
    }
}
 
Example #7
Source File: LibMatrixDatagen.java    From systemds with Apache License 2.0 6 votes vote down vote up
/**
 * A matrix of random numbers is generated by using multiple seeds, one for each 
 * block. Such block-level seeds are produced via Well equidistributed long-period linear 
 * generator (Well1024a). For a given seed, this function sets up the block-level seeds.
 * 
 * This function is invoked from both CP (RandCPInstruction.processInstruction()) 
 * as well as MR (RandMR.java while setting up the Rand job).
 * 
 * @param seed seed for random generator
 * @return Well1024a pseudo-random number generator
 */
public static Well1024a setupSeedsForRand(long seed) 
{
	long lSeed = (seed == DataGenOp.UNSPECIFIED_SEED ? DataGenOp.generateRandomSeed() : seed);
	LOG.trace("Setting up RandSeeds with initial seed = "+lSeed+".");

	Random random=new Random(lSeed);
	Well1024a bigrand=new Well1024a();
	//random.setSeed(lSeed);
	int[] seeds=new int[32];
	for(int s=0; s<seeds.length; s++)
		seeds[s]=random.nextInt();
	bigrand.setSeed(seeds);
	
	return bigrand;
}
 
Example #8
Source File: Vector3DTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDotProduct() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);
    for (int i = 0; i < 10000; ++i) {
        double ux = 10000 * random.nextDouble();
        double uy = 10000 * random.nextDouble();
        double uz = 10000 * random.nextDouble();
        double vx = 10000 * random.nextDouble();
        double vy = 10000 * random.nextDouble();
        double vz = 10000 * random.nextDouble();
        double sNaive = ux * vx + uy * vy + uz * vz;
        double sAccurate = new Vector3D(ux, uy, uz).dotProduct(new Vector3D(vx, vy, vz));
        Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate);
    }
}
 
Example #9
Source File: LogitTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testValueWithInverseFunction() {
    final double lo = 2;
    final double hi = 3;
    final Logit f = new Logit(lo, hi);
    final Sigmoid g = new Sigmoid(lo, hi);
    RandomGenerator random = new Well1024a(0x49914cdd9f0b8db5l);
    final UnivariateDifferentiableFunction id = FunctionUtils.compose((UnivariateDifferentiableFunction) g,
                                                            (UnivariateDifferentiableFunction) f);

    for (int i = 0; i < 10; i++) {
        final double x = lo + random.nextDouble() * (hi - lo);
        Assert.assertEquals(x, id.value(new DerivativeStructure(1, 1, 0, x)).getValue(), EPS);
    }

    Assert.assertEquals(lo, id.value(new DerivativeStructure(1, 1, 0, lo)).getValue(), EPS);
    Assert.assertEquals(hi, id.value(new DerivativeStructure(1, 1, 0, hi)).getValue(), EPS);
}
 
Example #10
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testShuffleHead() {
    final int[] orig = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    final int[] list = orig.clone();
    final int start = 4;
    MathArrays.shuffle(list, start, MathArrays.Position.HEAD, new Well1024a(1234567L));

    // Ensure that all entries above index "start" did not move.
    for (int i = start + 1; i < orig.length; i++) {
        Assert.assertEquals(orig[i], list[i]);
    }

    // Ensure that at least one entry has moved.
    boolean ok = false;
    for (int i = 0; i <= start; i++) {
        if (orig[i] != list[i]) {
            ok = true;
            break;
        }
    }
    Assert.assertTrue(ok);
}
 
Example #11
Source File: Vector3DTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDotProduct() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);
    for (int i = 0; i < 10000; ++i) {
        double ux = 10000 * random.nextDouble();
        double uy = 10000 * random.nextDouble();
        double uz = 10000 * random.nextDouble();
        double vx = 10000 * random.nextDouble();
        double vy = 10000 * random.nextDouble();
        double vz = 10000 * random.nextDouble();
        double sNaive = ux * vx + uy * vy + uz * vz;
        double sAccurate = new Vector3D(ux, uy, uz).dotProduct(new Vector3D(vx, vy, vz));
        Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate);
    }
}
 
Example #12
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testShuffleHead() {
    final int[] orig = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    final int[] list = orig.clone();
    final int start = 4;
    MathArrays.shuffle(list, start, MathArrays.Position.HEAD, new Well1024a(1234567L));

    // Ensure that all entries above index "start" did not move.
    for (int i = start + 1; i < orig.length; i++) {
        Assert.assertEquals(orig[i], list[i]);
    }

    // Ensure that at least one entry has moved.
    boolean ok = false;
    for (int i = 0; i <= start; i++) {
        if (orig[i] != list[i]) {
            ok = true;
            break;
        }
    }
    Assert.assertTrue(ok);
}
 
Example #13
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testShuffleHead() {
    final int[] orig = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    final int[] list = orig.clone();
    final int start = 4;
    MathArrays.shuffle(list, start, MathArrays.Position.HEAD, new Well1024a(1234567L));

    // Ensure that all entries above index "start" did not move.
    for (int i = start + 1; i < orig.length; i++) {
        Assert.assertEquals(orig[i], list[i]);
    }

    // Ensure that at least one entry has moved.
    boolean ok = false;
    for (int i = 0; i <= start; i++) {
        if (orig[i] != list[i]) {
            ok = true;
            break;
        }
    }
    Assert.assertTrue(ok);
}
 
Example #14
Source File: Vector3DTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDotProduct() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);
    for (int i = 0; i < 10000; ++i) {
        double ux = 10000 * random.nextDouble();
        double uy = 10000 * random.nextDouble();
        double uz = 10000 * random.nextDouble();
        double vx = 10000 * random.nextDouble();
        double vy = 10000 * random.nextDouble();
        double vz = 10000 * random.nextDouble();
        double sNaive = ux * vx + uy * vy + uz * vz;
        double sAccurate = new Vector3D(ux, uy, uz).dotProduct(new Vector3D(vx, vy, vz));
        Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate);
    }
}
 
Example #15
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testShuffleTail() {
    final int[] orig = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    final int[] list = orig.clone();
    final int start = 4;
    MathArrays.shuffle(list, start, MathArrays.Position.TAIL, new Well1024a(7654321L));

    // Ensure that all entries below index "start" did not move.
    for (int i = 0; i < start; i++) {
        Assert.assertEquals(orig[i], list[i]);
    }

    // Ensure that at least one entry has moved.
    boolean ok = false;
    for (int i = start; i < orig.length - 1; i++) {
        if (orig[i] != list[i]) {
            ok = true;
            break;
        }
    }
    Assert.assertTrue(ok);
}
 
Example #16
Source File: WelzlEncloser3DTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLargeSamples() throws IOException {
    RandomGenerator random = new Well1024a(0x35ddecfc78131e1dl);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
    for (int k = 0; k < 50; ++k) {

        // define the reference sphere we want to compute
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector3D refCenter = new Vector3D(d, new Vector3D(sr.nextVector()));
        // set up a large sample inside the reference sphere
        int nbPoints = random.nextInt(1000);
        List<Vector3D> points = new ArrayList<Vector3D>();
        for (int i = 0; i < nbPoints; ++i) {
            double r = refRadius * random.nextDouble();
            points.add(new Vector3D(1.0, refCenter, r, new Vector3D(sr.nextVector())));
        }

        // test we find a sphere at most as large as the one used for random drawings
        checkSphere(points, refRadius);

    }
}
 
Example #17
Source File: DiskGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRandom() {
    final RandomGenerator random = new Well1024a(0x12faa818373ffe90l);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(2, random);
    for (int i = 0; i < 500; ++i) {
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector2D refCenter = new Vector2D(d, new Vector2D(sr.nextVector()));
        List<Vector2D> support = new ArrayList<Vector2D>();
        for (int j = 0; j < 3; ++j) {
            support.add(new Vector2D(1.0, refCenter, refRadius, new Vector2D(sr.nextVector())));
        }
        EnclosingBall<Euclidean2D, Vector2D> disk = new DiskGenerator().ballOnSupport(support);
        Assert.assertEquals(0.0, refCenter.distance(disk.getCenter()), 3e-9 * refRadius);
        Assert.assertEquals(refRadius, disk.getRadius(), 7e-10 * refRadius);
    }
    
}
 
Example #18
Source File: Vector3DTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDotProduct() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);
    for (int i = 0; i < 10000; ++i) {
        double ux = 10000 * random.nextDouble();
        double uy = 10000 * random.nextDouble();
        double uz = 10000 * random.nextDouble();
        double vx = 10000 * random.nextDouble();
        double vy = 10000 * random.nextDouble();
        double vz = 10000 * random.nextDouble();
        double sNaive = ux * vx + uy * vy + uz * vz;
        double sAccurate = new Vector3D(ux, uy, uz).dotProduct(new Vector3D(vx, vy, vz));
        Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate);
    }
}
 
Example #19
Source File: SphereGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRandom() {
    final RandomGenerator random = new Well1024a(0xd015982e9f31ee04l);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
    for (int i = 0; i < 100; ++i) {
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector3D refCenter = new Vector3D(d, new Vector3D(sr.nextVector()));
        List<Vector3D> support = new ArrayList<Vector3D>();
        for (int j = 0; j < 5; ++j) {
            support.add(new Vector3D(1.0, refCenter, refRadius, new Vector3D(sr.nextVector())));
        }
        EnclosingBall<Euclidean3D, Vector3D> sphere = new SphereGenerator().ballOnSupport(support);
        Assert.assertEquals(0.0, refCenter.distance(sphere.getCenter()), 4e-7 * refRadius);
        Assert.assertEquals(refRadius, sphere.getRadius(), 1e-7 * refRadius);
    }
    
}
 
Example #20
Source File: WelzlEncloser3DTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLargeSamples() throws IOException {
    RandomGenerator random = new Well1024a(0x35ddecfc78131e1dl);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
    for (int k = 0; k < 50; ++k) {

        // define the reference sphere we want to compute
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector3D refCenter = new Vector3D(d, new Vector3D(sr.nextVector()));
        // set up a large sample inside the reference sphere
        int nbPoints = random.nextInt(1000);
        List<Vector3D> points = new ArrayList<Vector3D>();
        for (int i = 0; i < nbPoints; ++i) {
            double r = refRadius * random.nextDouble();
            points.add(new Vector3D(1.0, refCenter, r, new Vector3D(sr.nextVector())));
        }

        // test we find a sphere at most as large as the one used for random drawings
        checkSphere(points, refRadius);

    }
}
 
Example #21
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLinearCombination2() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);

    for (int i = 0; i < 10000; ++i) {
        final double ux = 1e17 * random.nextDouble();
        final double uy = 1e17 * random.nextDouble();
        final double uz = 1e17 * random.nextDouble();
        final double vx = 1e17 * random.nextDouble();
        final double vy = 1e17 * random.nextDouble();
        final double vz = 1e17 * random.nextDouble();
        final double sInline = MathArrays.linearCombination(ux, vx,
                                                            uy, vy,
                                                            uz, vz);
        final double sArray = MathArrays.linearCombination(new double[] {ux, uy, uz},
                                                           new double[] {vx, vy, vz});
        Assert.assertEquals(sInline, sArray, 0);
    }
}
 
Example #22
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testPositiveOctantByVertices() {
    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, new Well1024a(0xb8fc5acc91044308l));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
            Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v)));
        } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) {
            Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v)));
        } else {
            Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v)));
        }
    }
}
 
Example #23
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testEmpty() {
    SphericalPolygonsSet empty =
        (SphericalPolygonsSet) new RegionFactory<Sphere2D>().getComplement(new SphericalPolygonsSet(1.0e-10));
    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0x76d9205d6167b6ddl));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(new S2Point(v)));
    }
    Assert.assertEquals(0, empty.getSize(), 1.0e-10);
    Assert.assertEquals(0, empty.getBoundarySize(), 1.0e-10);
    Assert.assertEquals(0, empty.getBoundaryLoops().size());
    Assert.assertTrue(empty.getEnclosingCap().getRadius() < 0);
    Assert.assertTrue(Double.isInfinite(empty.getEnclosingCap().getRadius()));
}
 
Example #24
Source File: MathArraysTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLinearCombination2() {
    // we compare accurate versus naive dot product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(553267312521321234l);

    for (int i = 0; i < 10000; ++i) {
        final double ux = 1e17 * random.nextDouble();
        final double uy = 1e17 * random.nextDouble();
        final double uz = 1e17 * random.nextDouble();
        final double vx = 1e17 * random.nextDouble();
        final double vy = 1e17 * random.nextDouble();
        final double vz = 1e17 * random.nextDouble();
        final double sInline = MathArrays.linearCombination(ux, vx,
                                                            uy, vy,
                                                            uz, vz);
        final double sArray = MathArrays.linearCombination(new double[] {ux, uy, uz},
                                                           new double[] {vx, vy, vz});
        Assert.assertEquals(sInline, sArray, 0);
    }
}
 
Example #25
Source File: FieldVector3DTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testCrossProduct() {
    // we compare accurate versus naive cross product implementations
    // on regular vectors (i.e. not extreme cases like in the previous test)
    Well1024a random = new Well1024a(885362227452043214l);
    for (int i = 0; i < 10000; ++i) {
        double ux = random.nextDouble();
        double uy = random.nextDouble();
        double uz = random.nextDouble();
        double vx = random.nextDouble();
        double vy = random.nextDouble();
        double vz = random.nextDouble();
        Vector3D cNaive = new Vector3D(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx);

        FieldVector3D<DerivativeStructure> uds = createVector(ux, uy, uz, 3);
        FieldVector3D<DerivativeStructure> vds = createVector(vx, vy, vz, 3);
        Vector3D v = new Vector3D(vx, vy, vz);

        checkVector(FieldVector3D.crossProduct(uds, vds),
                    cNaive.getX(), cNaive.getY(), cNaive.getZ(),
                    0, vz - uz, uy - vy,
                    uz - vz, 0, vx - ux,
                    vy - uy, ux - vx, 0);

        checkVector(FieldVector3D.crossProduct(uds, v),
                    cNaive.getX(), cNaive.getY(), cNaive.getZ(),
                      0,  vz, -vy,
                    -vz,   0,  vx,
                     vy, -vx,   0);

    }
}
 
Example #26
Source File: ExtendedFieldElementAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testLinearCombinationFF3() {
    RandomGenerator r = new Well1024a(0xff3l);
    for (int i = 0; i < 50; ++i) {
        double[] aD = generateDouble(r, 3);
        double[] bD = generateDouble(r, 3);
        T[] aF      = toFieldArray(aD);
        T[] bF      = toFieldArray(bD);
        checkRelative(MathArrays.linearCombination(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2]),
                      aF[0].linearCombination(aF[0], bF[0], aF[1], bF[1], aF[2], bF[2]));
    }
}
 
Example #27
Source File: ExtendedFieldElementAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testLinearCombinationDF2() {
    RandomGenerator r = new Well1024a(0xdf2l);
    for (int i = 0; i < 50; ++i) {
        double[] aD = generateDouble(r, 2);
        double[] bD = generateDouble(r, 2);
        T[] bF      = toFieldArray(bD);
        checkRelative(MathArrays.linearCombination(aD[0], bD[0], aD[1], bD[1]),
                      bF[0].linearCombination(aD[0], bF[0], aD[1], bF[1]));
    }
}
 
Example #28
Source File: FieldRotationDSTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDoubleVectors() throws MathIllegalArgumentException {

    Well1024a random = new Well1024a(0x180b41cfeeffaf67l);
    UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
    for (int i = 0; i < 10; ++i) {
        double[] unit = g.nextVector();
        FieldRotation<DerivativeStructure> r = new FieldRotation<DerivativeStructure>(createVector(unit[0], unit[1], unit[2]),
                                      createAngle(random.nextDouble()));

        for (double x = -0.9; x < 0.9; x += 0.2) {
            for (double y = -0.9; y < 0.9; y += 0.2) {
                for (double z = -0.9; z < 0.9; z += 0.2) {
                    FieldVector3D<DerivativeStructure> uds   = createVector(x, y, z);
                    FieldVector3D<DerivativeStructure> ruds  = r.applyTo(uds);
                    FieldVector3D<DerivativeStructure> rIuds = r.applyInverseTo(uds);
                    Vector3D   u     = new Vector3D(x, y, z);
                    FieldVector3D<DerivativeStructure> ru    = r.applyTo(u);
                    FieldVector3D<DerivativeStructure> rIu   = r.applyInverseTo(u);
                    DerivativeStructure[] ruArray = new DerivativeStructure[3];
                    r.applyTo(new double[] { x, y, z}, ruArray);
                    DerivativeStructure[] rIuArray = new DerivativeStructure[3];
                    r.applyInverseTo(new double[] { x, y, z}, rIuArray);
                    checkVector(ruds, ru);
                    checkVector(ruds, new FieldVector3D<DerivativeStructure>(ruArray));
                    checkVector(rIuds, rIu);
                    checkVector(rIuds, new FieldVector3D<DerivativeStructure>(rIuArray));
                }
            }
        }
    }

}
 
Example #29
Source File: ExtendedFieldElementAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testLinearCombinationFaFa() {
    RandomGenerator r = new Well1024a(0xfafal);
    for (int i = 0; i < 50; ++i) {
        double[] aD = generateDouble(r, 10);
        double[] bD = generateDouble(r, 10);
        T[] aF      = toFieldArray(aD);
        T[] bF      = toFieldArray(bD);
        checkRelative(MathArrays.linearCombination(aD, bD),
                      aF[0].linearCombination(aF, bF));
    }
}
 
Example #30
Source File: PercentileTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testAllTechniquesPercentileUsingRandomPivoting() {
    kthSelector = new KthSelector(new RandomPivotingStrategy(new Well1024a(0x268a7fb4194240f6l)));
    Assert.assertEquals(RandomPivotingStrategy.class,
                        getUnivariateStatistic().getPivotingStrategy().getClass());
    checkAllTechniquesPercentile();
}