use of gdsc.core.utils.PseudoRandomGenerator in project GDSC-SMLM by aherbert.
the class PrecomputedFunctionTest method precomputedGradient1FunctionWrapsPrecomputedValues.
@Test
public void precomputedGradient1FunctionWrapsPrecomputedValues() {
int n = 3;
RandomGenerator r = new Well19937c(30051977);
Gradient1Function f0 = new FakeGradientFunction(3, n);
int size = f0.size();
double[] b1 = new PseudoRandomGenerator(size, r).getSequence();
double[] b2 = new PseudoRandomGenerator(size, r).getSequence();
Gradient1Function f1 = PrecomputedGradient1Function.wrapGradient1Function(f0, b1);
Gradient1Function f2 = PrecomputedGradient1Function.wrapGradient1Function(f1, b2);
double[] p = new double[n];
for (int i = 0; i < n; i++) p[i] = r.nextDouble();
double[] d0 = new double[n];
double[] d1 = new double[n];
double[] d2 = new double[n];
double[] v0 = evaluateGradient1Function(f0, p, d0);
double[] v1 = evaluateGradient1Function(f1, p, d1);
double[] v2 = evaluateGradient1Function(f2, p, d2);
for (int i = 0; i < v0.length; i++) {
double e = v0[i] + b1[i] + b2[i];
double o1 = v1[i] + b2[i];
double o2 = v2[i];
Assert.assertEquals("o1", e, o1, 0);
Assert.assertEquals("o2", e, o2, 1e-6);
}
Assert.assertArrayEquals("d1", d0, d1, 0);
Assert.assertArrayEquals("d2", d0, d2, 0);
}
use of gdsc.core.utils.PseudoRandomGenerator in project GDSC-SMLM by aherbert.
the class PrecomputedFunctionTest method precomputedValueFunctionWrapsPrecomputedValues.
@Test
public void precomputedValueFunctionWrapsPrecomputedValues() {
int n = 3;
RandomGenerator r = new Well19937c(30051977);
ValueFunction f0 = new FakeGradientFunction(3, n);
int size = f0.size();
double[] b1 = new PseudoRandomGenerator(size, r).getSequence();
double[] b2 = new PseudoRandomGenerator(size, r).getSequence();
ValueFunction f1 = PrecomputedValueFunction.wrapValueFunction(f0, b1);
ValueFunction f2 = PrecomputedValueFunction.wrapValueFunction(f1, b2);
double[] p = new double[n];
for (int i = 0; i < n; i++) p[i] = r.nextDouble();
double[] v0 = evaluateValueFunction(f0, p);
double[] v1 = evaluateValueFunction(f1, p);
double[] v2 = evaluateValueFunction(f2, p);
for (int i = 0; i < v0.length; i++) {
double e = v0[i] + b1[i] + b2[i];
double o1 = v1[i] + b2[i];
double o2 = v2[i];
Assert.assertEquals("o1", e, o1, 0);
Assert.assertEquals("o2", e, o2, 1e-6);
}
}
use of gdsc.core.utils.PseudoRandomGenerator in project GDSC-SMLM by aherbert.
the class PrecomputedFunctionTest method precomputedGradient2FunctionWrapsPrecomputedValues.
@Test
public void precomputedGradient2FunctionWrapsPrecomputedValues() {
int n = 3;
RandomGenerator r = new Well19937c(30051977);
Gradient2Function f0 = new FakeGradientFunction(3, n);
int size = f0.size();
double[] b1 = new PseudoRandomGenerator(size, r).getSequence();
double[] b2 = new PseudoRandomGenerator(size, r).getSequence();
Gradient2Function f1 = PrecomputedGradient2Function.wrapGradient2Function(f0, b1);
Gradient2Function f2 = PrecomputedGradient2Function.wrapGradient2Function(f1, b2);
double[] p = new double[n];
for (int i = 0; i < n; i++) p[i] = r.nextDouble();
double[] d0 = new double[n];
double[] d1 = new double[n];
double[] d2 = new double[n];
double[] d20 = new double[n];
double[] d21 = new double[n];
double[] d22 = new double[n];
double[] v0 = evaluateGradient2Function(f0, p, d0, d20);
double[] v1 = evaluateGradient2Function(f1, p, d1, d21);
double[] v2 = evaluateGradient2Function(f2, p, d2, d22);
for (int i = 0; i < v0.length; i++) {
double e = v0[i] + b1[i] + b2[i];
double o1 = v1[i] + b2[i];
double o2 = v2[i];
Assert.assertEquals("o1", e, o1, 0);
Assert.assertEquals("o2", e, o2, 1e-6);
}
Assert.assertArrayEquals("d1", d0, d1, 0);
Assert.assertArrayEquals("d2", d0, d2, 0);
Assert.assertArrayEquals("d21", d20, d21, 0);
Assert.assertArrayEquals("d22", d20, d22, 0);
}
Aggregations