use of uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate in project GDSC-SMLM by aherbert.
the class FastMleJacobianGradient2ProcedureTest method gradientProcedureComputesSameAsBaseGradientProcedure.
@SeededTest
void gradientProcedureComputesSameAsBaseGradientProcedure(RandomSeed seed) {
// Test the base functionality of computing the partial derivatives is the same
final DoubleDoubleBiPredicate equality = TestHelper.doublesAreClose(1e-5, 0);
gradientProcedureComputesSameAsBaseGradientProcedure(seed, 4, equality);
gradientProcedureComputesSameAsBaseGradientProcedure(seed, 5, equality);
gradientProcedureComputesSameAsBaseGradientProcedure(seed, 6, equality);
gradientProcedureComputesSameAsBaseGradientProcedure(seed, 11, equality);
gradientProcedureComputesSameAsBaseGradientProcedure(seed, 21, equality);
}
use of uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate in project GDSC-SMLM by aherbert.
the class JumpDistanceAnalysisTest method canIntegrateProbabilityToCumulativeWithMixedPopulation.
@Disabled("Commented out as this test always passes")
@Test
void canIntegrateProbabilityToCumulativeWithMixedPopulation() {
final JumpDistanceAnalysis jd = new JumpDistanceAnalysis();
jd.setMinD(0);
jd.setMinFraction(0);
final SimpsonIntegrator si = new SimpsonIntegrator(1e-3, 1e-8, 2, SimpsonIntegrator.SIMPSON_MAX_ITERATIONS_COUNT);
final DoubleDoubleBiPredicate equality = TestHelper.doublesAreClose(1e-2, 0);
for (final double d : D) {
for (final double f : new double[] { 0, 0.1, 0.2, 0.4, 0.7, 0.9, 1 }) {
final double[] params = new double[] { f, d, 1 - f, d * 0.1 };
final MixedJumpDistanceFunction fp = new MixedJumpDistanceFunction(null, d, 2);
final MixedJumpDistanceCumulFunction fc = new MixedJumpDistanceCumulFunction(null, null, d, 2);
final UnivariateFunction func = new UnivariateFunction() {
@Override
public double value(double x) {
return fp.evaluate(x, params);
}
};
double x = d / 8;
for (int i = 1; i < 10; i++, x *= 2) {
final double e = fc.evaluate(x, params);
// Integrate
final double o = si.integrate(10000, func, 0, x);
// logger.info(FunctionUtils.getSupplier("Integrate d=%.1f, f=%.1f : x=%.1f, e=%f, o=%f,
// iter=%d, eval=%d", d, f, x, e, o,
// si.getIterations(), si.getEvaluations());
TestAssertions.assertTest(e, o, equality, FunctionUtils.getSupplier("Failed to integrate: x=%g", x));
}
}
}
}
use of uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate in project GDSC-SMLM by aherbert.
the class JumpDistanceAnalysisTest method canIntegrateProbabilityToCumulativeWithSinglePopulation.
@Disabled("Commented out as this test always passes")
@Test
void canIntegrateProbabilityToCumulativeWithSinglePopulation() {
final JumpDistanceAnalysis jd = new JumpDistanceAnalysis();
jd.setMinD(0);
jd.setMinFraction(0);
final SimpsonIntegrator si = new SimpsonIntegrator(1e-3, 1e-8, 2, SimpsonIntegrator.SIMPSON_MAX_ITERATIONS_COUNT);
final DoubleDoubleBiPredicate equality = TestHelper.doublesAreClose(1e-2, 0);
for (final double d : D) {
final double[] params = new double[] { d };
final JumpDistanceFunction fp = new JumpDistanceFunction(null, d);
final JumpDistanceCumulFunction fc = new JumpDistanceCumulFunction(null, null, d);
double x = d / 8;
final UnivariateFunction func = new UnivariateFunction() {
@Override
public double value(double x) {
return fp.evaluate(x, params);
}
};
for (int i = 1; i < 10; i++, x *= 2) {
final double e = fc.evaluate(x, params);
// Integrate
final double o = si.integrate(10000, func, 0, x);
// logger.info(FunctionUtils.getSupplier("Integrate d=%.1f : x=%.1f, e=%f, o=%f, iter=%d,
// eval=%d", d, x, e, o, si.getIterations(),
// si.getEvaluations());
TestAssertions.assertTest(e, o, equality, FunctionUtils.getSupplier("Failed to integrate: x=%g", x));
}
}
}
use of uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate in project GDSC-SMLM by aherbert.
the class SolverSpeedTest method solveLinearAndGaussJordanReturnSameSolutionResult.
@SeededTest
void solveLinearAndGaussJordanReturnSameSolutionResult(RandomSeed seed) {
final int iter = 100;
final SolverSpeedTestData data = ensureData(seed, iter);
final ArrayList<double[][]> adata = copyAdouble(data.adata, iter);
final ArrayList<double[]> bdata = copyBdouble(data.bdata, iter);
final ArrayList<double[][]> adata2 = copyAdouble(data.adata, iter);
final ArrayList<double[]> bdata2 = copyBdouble(data.bdata, iter);
final GaussJordan solver = new GaussJordan();
final EjmlLinearSolver solver2 = new EjmlLinearSolver();
final int failureLimit = TestCounter.computeFailureLimit(iter, 0.1);
final TestCounter failCounter = new TestCounter(failureLimit);
final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-2, 0);
int fail = 0;
for (int i = 0; i < iter; i++) {
final double[][] a1 = adata.get(i);
final double[] b1 = bdata.get(i);
final double[][] a2 = adata2.get(i);
final double[] b2 = bdata2.get(i);
final boolean r1 = solver.solve(a1, b1);
final boolean r2 = solver2.solve(a2, b2);
// Assertions.assertTrue("Different solve result @ " + i, r1 == r2);
if (r1 && r2) {
failCounter.run(() -> {
TestAssertions.assertArrayTest(b1, b2, predicate, "Different b result");
});
} else {
fail++;
}
}
if (fail > iter / 2) {
Assertions.fail(String.format("Failed to solve %d / %d", fail, iter));
}
}
use of uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate in project GDSC-SMLM by aherbert.
the class SolverSpeedTest method gaussJordanFloatAndDoubleReturnSameSolutionAndInversionResult.
@SeededTest
void gaussJordanFloatAndDoubleReturnSameSolutionAndInversionResult(RandomSeed seed) {
final int iter = 100;
final SolverSpeedTestData data = ensureData(seed, iter);
final ArrayList<float[][]> adata = copyAfloat(data.adata, iter);
final ArrayList<float[]> bdata = copyBfloat(data.bdata, iter);
final ArrayList<double[][]> adata2 = copyAdouble(data.adata, iter);
final ArrayList<double[]> bdata2 = copyBdouble(data.bdata, iter);
final GaussJordan solver = new GaussJordan();
final int failureLimit = TestCounter.computeFailureLimit(iter, 0.1);
final TestCounter failCounter = new TestCounter(failureLimit, 2);
final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-2, 0);
int fail = 0;
for (int i = 0; i < adata.size(); i++) {
final float[][] a1 = adata.get(i);
final float[] b1 = bdata.get(i);
final double[][] a2 = adata2.get(i);
final double[] b2 = bdata2.get(i);
final boolean r1 = solver.solve(a1, b1);
final boolean r2 = solver.solve(a2, b2);
// Assertions.assertTrue("Different solve result @ " + i, r1 == r2);
if (r1 && r2) {
final double[] db1 = SimpleArrayUtils.toDouble(b1);
final double[][] da1 = new double[a1.length][];
for (int j = a1.length; j-- > 0; ) {
da1[j] = SimpleArrayUtils.toDouble(a1[j]);
}
failCounter.run(0, () -> {
TestAssertions.assertArrayTest(db1, b2, predicate, "Different b result");
});
failCounter.run(1, () -> {
TestAssertions.assertArrayTest(da1, a2, predicate, "Different a result");
});
} else {
fail++;
}
}
if (fail > iter / 2) {
Assertions.fail(String.format("Failed to solve %d / %d", fail, iter));
}
}
Aggregations