use of uk.ac.sussex.gdsc.test.utils.functions.IntArrayFormatSupplier in project GDSC-SMLM by aherbert.
the class LsqVarianceGradientProcedureTest method gradientProcedureUnrolledComputesSameAsGradientProcedure.
private void gradientProcedureUnrolledComputesSameAsGradientProcedure(RandomSeed seed, int nparams, boolean precomputed) {
final int iter = 10;
final ArrayList<double[]> paramsList = new ArrayList<>(iter);
createFakeParams(RngUtils.create(seed.getSeed()), nparams, iter, paramsList);
Gradient1Function func = new FakeGradientFunction(blockWidth, nparams);
if (precomputed) {
func = OffsetGradient1Function.wrapGradient1Function(func, SimpleArrayUtils.newArray(func.size(), 0.1, 1.3));
}
final IntArrayFormatSupplier msg = new IntArrayFormatSupplier("[%d] Observations: Not same variance @ %d", 2);
msg.set(0, nparams);
for (int i = 0; i < paramsList.size(); i++) {
final LsqVarianceGradientProcedure p1 = new LsqVarianceGradientProcedure(func);
p1.variance(paramsList.get(i));
final LsqVarianceGradientProcedure p2 = LsqVarianceGradientProcedureUtils.create(func);
p2.variance(paramsList.get(i));
// Exactly the same ...
Assertions.assertArrayEquals(p1.variance, p2.variance, msg.set(1, i));
}
}
use of uk.ac.sussex.gdsc.test.utils.functions.IntArrayFormatSupplier in project GDSC-SMLM by aherbert.
the class PoissonGradientProcedureTest method gradientProcedureComputesSameAsGradientCalculator.
private void gradientProcedureComputesSameAsGradientCalculator(RandomSeed seed, int nparams) {
final int iter = 10;
final ArrayList<double[]> paramsList = new ArrayList<>(iter);
createFakeParams(RngUtils.create(seed.getSeed()), nparams, iter, paramsList);
final int n = blockWidth * blockWidth;
final FakeGradientFunction func = new FakeGradientFunction(blockWidth, nparams);
final GradientCalculator calc = GradientCalculatorUtils.newCalculator(nparams, false);
// Create messages
final IntArrayFormatSupplier msgOal = getMessage(nparams, "[%d] Observations: Not same alpha linear @ %d");
final IntArrayFormatSupplier msgOam = getMessage(nparams, "[%d] Observations: Not same alpha matrix @ %d");
final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-10, 0);
for (int i = 0; i < paramsList.size(); i++) {
final PoissonGradientProcedure p = PoissonGradientProcedureUtils.create(func);
p.computeFisherInformation(paramsList.get(i));
final double[][] m = calc.fisherInformationMatrix(n, paramsList.get(i), func);
// Not exactly the same ...
final double[] al = p.getLinear();
TestAssertions.assertArrayTest(al, new DenseMatrix64F(m).data, predicate, msgOal.set(1, i));
final double[][] am = p.getMatrix();
TestAssertions.assertArrayTest(am, m, predicate, msgOam.set(1, i));
}
}
use of uk.ac.sussex.gdsc.test.utils.functions.IntArrayFormatSupplier in project GDSC-SMLM by aherbert.
the class PoissonGradientProcedureTest method gradientProcedureUnrolledComputesSameAsGradientProcedure.
private void gradientProcedureUnrolledComputesSameAsGradientProcedure(RandomSeed seed, int nparams, boolean precomputed) {
final int iter = 10;
final ArrayList<double[]> paramsList = new ArrayList<>(iter);
createFakeParams(RngUtils.create(seed.getSeed()), nparams, iter, paramsList);
Gradient1Function func = new FakeGradientFunction(blockWidth, nparams);
if (precomputed) {
func = OffsetGradient1Function.wrapGradient1Function(func, SimpleArrayUtils.newArray(func.size(), 0.1, 1.3));
}
// Create messages
final IntArrayFormatSupplier msgOal = getMessage(nparams, "[%d] Observations: Not same alpha linear @ %d");
final IntArrayFormatSupplier msgOam = getMessage(nparams, "[%d] Observations: Not same alpha matrix @ %d");
for (int i = 0; i < paramsList.size(); i++) {
final PoissonGradientProcedure p1 = new PoissonGradientProcedure(func);
p1.computeFisherInformation(paramsList.get(i));
final PoissonGradientProcedure p2 = PoissonGradientProcedureUtils.create(func);
p2.computeFisherInformation(paramsList.get(i));
// Exactly the same ...
Assertions.assertArrayEquals(p1.getLinear(), p2.getLinear(), msgOal.set(1, i));
final double[][] am1 = p1.getMatrix();
final double[][] am2 = p2.getMatrix();
Assertions.assertArrayEquals(am1, am2, msgOam.set(1, i));
}
}
use of uk.ac.sussex.gdsc.test.utils.functions.IntArrayFormatSupplier in project GDSC-SMLM by aherbert.
the class PoissonGradientProcedureTest method getMessage.
private static IntArrayFormatSupplier getMessage(int nparams, String format) {
final IntArrayFormatSupplier msg = new IntArrayFormatSupplier(format, 2);
msg.set(0, nparams);
return msg;
}
use of uk.ac.sussex.gdsc.test.utils.functions.IntArrayFormatSupplier in project GDSC-SMLM by aherbert.
the class FastMleGradient2ProcedureTest method getMessage.
private static IntArrayFormatSupplier getMessage(int nparams, String format) {
final IntArrayFormatSupplier msg = new IntArrayFormatSupplier(format, 2);
msg.set(0, nparams);
return msg;
}
Aggregations