use of org.nd4j.linalg.api.rng.Random in project nd4j by deeplearning4j.
the class RandomTests method testJavaSide1.
@Test
public void testJavaSide1() throws Exception {
Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);
float[] array1 = new float[1000];
float[] array2 = new float[1000];
for (int e = 0; e < array1.length; e++) {
array1[e] = random1.nextFloat();
array2[e] = random2.nextFloat();
assertTrue(array1[e] <= 1.0f);
}
assertArrayEquals(array1, array2, 1e-5f);
}
use of org.nd4j.linalg.api.rng.Random in project nd4j by deeplearning4j.
the class RandomTests method testStepOver3.
@Test
public void testStepOver3() throws Exception {
Random random = Nd4j.getRandomFactory().getNewRandomInstance(119);
if (random instanceof NativeRandom) {
NativeRandom rng = (NativeRandom) random;
assertTrue(rng.getBufferSize() > 1000000L);
int someInt = rng.nextInt();
for (int e = 0; e < 10000; e++) rng.nextInt();
random.setSeed(119);
int sameInt = rng.nextInt();
assertEquals(someInt, sameInt);
random.setSeed(120);
int otherInt = rng.nextInt();
assertNotEquals(someInt, otherInt);
} else
log.warn("Not a NativeRandom object received, skipping test");
}
use of org.nd4j.linalg.api.rng.Random in project nd4j by deeplearning4j.
the class RandomTests method testBernoulliDistribution2.
@Test
public void testBernoulliDistribution2() throws Exception {
Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);
INDArray z1 = Nd4j.zeros(20);
INDArray z2 = Nd4j.zeros(20);
INDArray z1Dup = Nd4j.zeros(20);
INDArray exp = Nd4j.create(new double[] { 1.00, 0.00, 1.00, 0.00, 1.00, 1.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.00, 1.00, 1.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00 });
BernoulliDistribution op1 = new BernoulliDistribution(z1, 0.50);
BernoulliDistribution op2 = new BernoulliDistribution(z2, 0.50);
Nd4j.getExecutioner().exec(op1, random1);
Nd4j.getExecutioner().exec(op2, random2);
assertNotEquals(z1Dup, z1);
assertEquals(z1, z2);
assertEquals(exp, z1);
}
use of org.nd4j.linalg.api.rng.Random in project nd4j by deeplearning4j.
the class RandomTests method testDistribution2.
@Test
public void testDistribution2() throws Exception {
Random random1 = Nd4j.getRandomFactory().getNewRandomInstance(119);
Random random2 = Nd4j.getRandomFactory().getNewRandomInstance(119);
INDArray z1 = Nd4j.create(32);
INDArray z2 = Nd4j.create(32);
UniformDistribution distribution = new UniformDistribution(z1, 1.0, 2.0);
Nd4j.getExecutioner().exec(distribution, random1);
UniformDistribution distribution2 = new UniformDistribution(z2, 1.0, 2.0);
Nd4j.getExecutioner().exec(distribution2, random2);
System.out.println("Data: " + z1);
System.out.println("Data: " + z2);
for (int e = 0; e < z1.length(); e++) {
double val = z1.getDouble(e);
assertTrue(val >= 1.0 && val <= 2.0);
}
assertEquals(z1, z2);
}
use of org.nd4j.linalg.api.rng.Random in project nd4j by deeplearning4j.
the class RandomTests method testJavaSide4.
/**
* 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);
}
}
Aggregations