use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class OffsetFunctionTest method offsetValueFunctionWrapsPrecomputedValues.
@SeededTest
void offsetValueFunctionWrapsPrecomputedValues(RandomSeed seed) {
final int n = 3;
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
final ValueFunction f0 = new FakeGradientFunction(3, n);
final int size = f0.size();
final double[] b1 = GdscSmlmTestUtils.generateDoubles(size, r);
final double[] b2 = GdscSmlmTestUtils.generateDoubles(size, r);
final ValueFunction f1 = OffsetValueFunction.wrapValueFunction(f0, b1);
final ValueFunction f2 = OffsetValueFunction.wrapValueFunction(f1, b2);
final double[] p = new double[n];
for (int i = 0; i < n; i++) {
p[i] = r.nextDouble();
}
final double[] v0 = evaluateValueFunction(f0, p);
final double[] v1 = evaluateValueFunction(f1, p);
final double[] v2 = evaluateValueFunction(f2, p);
for (int i = 0; i < v0.length; i++) {
final double e = v0[i] + b1[i] + b2[i];
final double o1 = v1[i] + b2[i];
final double o2 = v2[i];
Assertions.assertEquals(e, o1, "o1");
Assertions.assertEquals(e, o2, 1e-6, "o2");
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class OffsetFunctionTest method offsetGradient2FunctionWrapsPrecomputedValues.
@SeededTest
void offsetGradient2FunctionWrapsPrecomputedValues(RandomSeed seed) {
final int n = 3;
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
final Gradient2Function f0 = new FakeGradientFunction(3, n);
final int size = f0.size();
final double[] b1 = GdscSmlmTestUtils.generateDoubles(size, r);
final double[] b2 = GdscSmlmTestUtils.generateDoubles(size, r);
final Gradient2Function f1 = OffsetGradient2Function.wrapGradient2Function(f0, b1);
final Gradient2Function f2 = OffsetGradient2Function.wrapGradient2Function(f1, b2);
final double[] p = new double[n];
for (int i = 0; i < n; i++) {
p[i] = r.nextDouble();
}
final double[] d0 = new double[n];
final double[] d1 = new double[n];
final double[] d2 = new double[n];
final double[] d20 = new double[n];
final double[] d21 = new double[n];
final double[] d22 = new double[n];
final double[] v0 = evaluateGradient2Function(f0, p, d0, d20);
final double[] v1 = evaluateGradient2Function(f1, p, d1, d21);
final double[] v2 = evaluateGradient2Function(f2, p, d2, d22);
for (int i = 0; i < v0.length; i++) {
final double e = v0[i] + b1[i] + b2[i];
final double o1 = v1[i] + b2[i];
final double o2 = v2[i];
Assertions.assertEquals(e, o1, "o1");
Assertions.assertEquals(e, o2, 1e-6, "o2");
}
Assertions.assertArrayEquals(d0, d1, "d1");
Assertions.assertArrayEquals(d0, d2, "d2");
Assertions.assertArrayEquals(d20, d21, "d21");
Assertions.assertArrayEquals(d20, d22, "d22");
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class ScmosLikelihoodWrapperTest method fitEllipticalComputesGradient.
@SeededTest
void fitEllipticalComputesGradient(RandomSeed seed) {
// The elliptical function gradient evaluation is worse
final DoubleEquality tmp = eq;
eq = eqPerDatum;
functionComputesGradient(seed, GaussianFunctionFactory.FIT_ELLIPTICAL);
eq = tmp;
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class PrecomputedFunctionTest method precomputedValueFunctionWrapsPrecomputedValues.
@SeededTest
void precomputedValueFunctionWrapsPrecomputedValues(RandomSeed seed) {
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
final int size = 100;
final double[] v = GdscSmlmTestUtils.generateDoubles(size, r);
final ValueFunction func = new PrecomputedValueFunction(v);
final double[] vo = evaluateValueFunction(func);
Assertions.assertArrayEquals(v, vo, "values");
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class PrecomputedFunctionTest method precomputedGradient2FunctionWrapsPrecomputedValues.
@SeededTest
void precomputedGradient2FunctionWrapsPrecomputedValues(RandomSeed seed) {
final int n = 3;
final UniformRandomProvider r = RngUtils.create(seed.getSeed());
final int size = 100;
final double[] v = GdscSmlmTestUtils.generateDoubles(size, r);
final double[][] g1 = new double[size][];
final double[][] g2 = new double[size][];
for (int i = 0; i < g1.length; i++) {
g1[i] = GdscSmlmTestUtils.generateDoubles(n, r);
g2[i] = GdscSmlmTestUtils.generateDoubles(n, r);
}
final Gradient2Function func = new PrecomputedGradient2Function(v, g1, g2);
final double[][] g1o = new double[size][];
final double[][] g2o = new double[size][];
final double[] vo = evaluateGradient2Function(func, g1o, g2o);
Assertions.assertArrayEquals(v, vo, "values");
Assertions.assertArrayEquals(g1, g1o, "g1");
Assertions.assertArrayEquals(g2, g2o, "g2");
}
Aggregations