Java Code Examples for org.nd4j.linalg.api.rng.Random#reSeed()

The following examples show how to use org.nd4j.linalg.api.rng.Random#reSeed() . 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: RandomTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testGaussianDistribution2() throws Exception {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random3 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random4 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    INDArray z1 = Nd4j.create(100000);
    INDArray z2 = Nd4j.create(100000);
    INDArray z3 = Nd4j.create(100000);
    INDArray z4 = Nd4j.create(100000);

    random3.reSeed(8231);
    random4.reSeed(4453523);

    GaussianDistribution op1 = new GaussianDistribution(z1, 0.0, 1.0);
    Nd4j.getExecutioner().exec(op1, random1);

    GaussianDistribution op2 = new GaussianDistribution(z2, 0.0, 1.0);
    Nd4j.getExecutioner().exec(op2, random2);

    GaussianDistribution op3 = new GaussianDistribution(z3, 0.0, 1.0);
    Nd4j.getExecutioner().exec(op3, random3);

    GaussianDistribution op4 = new GaussianDistribution(z4, 0.0, 1.0);
    Nd4j.getExecutioner().exec(op4, random4);

    assertEquals(0.0, z1.meanNumber().doubleValue(), 0.01);
    assertEquals(1.0, z1.stdNumber().doubleValue(), 0.01);

    assertEquals(z1, z2);

    assertNotEquals(z1, z3);
    assertNotEquals(z2, z4);
    assertNotEquals(z3, z4);
}
 
Example 2
Source File: RandomTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks reSeed mechanics for native side
 *
 * @throws Exception
 */

@Test
public void testJavaSide4() throws Exception {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    int array1[] = new int[1000];
    int array2[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array1[e] = random1.nextInt();
        array2[e] = random2.nextInt();

        assertEquals(array1[e], array2[e]);
        assertTrue(array1[e] >= 0);
    }

    assertArrayEquals(array1, array2);

    random1.reSeed();
    random1.reSeed();

    int array3[] = new int[1000];
    int array4[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array3[e] = random1.nextInt();
        array4[e] = random2.nextInt();

        assertNotEquals(array3[e], array4[e]);
        assertTrue(array1[e] >= 0);
    }
}
 
Example 3
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testGaussianDistribution2() {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random3 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random4 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    INDArray z1 = Nd4j.create(100000);
    INDArray z2 = Nd4j.create(100000);
    INDArray z3 = Nd4j.create(100000);
    INDArray z4 = Nd4j.create(100000);

    random3.reSeed(8231);
    random4.reSeed(4453523);

    GaussianDistribution op1 = new GaussianDistribution(z1, 0.0, 1.0);
    Nd4j.getExecutioner().exec(op1, random1);

    GaussianDistribution op2 = new GaussianDistribution(z2, 0.0, 1.0);
    Nd4j.getExecutioner().exec(op2, random2);

    GaussianDistribution op3 = new GaussianDistribution(z3, 0.0, 1.0);
    Nd4j.getExecutioner().exec(op3, random3);

    GaussianDistribution op4 = new GaussianDistribution(z4, 0.0, 1.0);
    Nd4j.getExecutioner().exec(op4, random4);

    Nd4j.getExecutioner().commit();

    assertEquals(0.0, z1.meanNumber().doubleValue(), 0.01);
    assertEquals(1.0, z1.stdNumber().doubleValue(), 0.01);

    assertEquals(z1, z2);

    assertNotEquals(z1, z3);
    assertNotEquals(z2, z4);
    assertNotEquals(z3, z4);
}
 
Example 4
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks reSeed mechanics for native side
 *
 * @throws Exception
 */

@Test
public void testJavaSide4() {
    Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
    Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);

    int array1[] = new int[1000];
    int array2[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array1[e] = random1.nextInt();
        array2[e] = random2.nextInt();

        assertEquals(array1[e], array2[e]);
        assertTrue(array1[e] >= 0);
    }

    assertArrayEquals(array1, array2);

    random1.reSeed();
    random1.reSeed();

    int array3[] = new int[1000];
    int array4[] = new int[1000];

    for (int e = 0; e < array1.length; e++) {
        array3[e] = random1.nextInt();
        array4[e] = random2.nextInt();

        assertNotEquals(array3[e], array4[e]);
        assertTrue(array1[e] >= 0);
    }
}