Search in sources :

Example 1 with MixedJumpDistanceFunction

use of uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceFunction 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));
            }
        }
    }
}
Also used : SimpsonIntegrator(org.apache.commons.math3.analysis.integration.SimpsonIntegrator) MixedJumpDistanceCumulFunction(uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceCumulFunction) DoubleDoubleBiPredicate(uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate) MixedJumpDistanceFunction(uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceFunction) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

UnivariateFunction (org.apache.commons.math3.analysis.UnivariateFunction)1 SimpsonIntegrator (org.apache.commons.math3.analysis.integration.SimpsonIntegrator)1 Disabled (org.junit.jupiter.api.Disabled)1 Test (org.junit.jupiter.api.Test)1 MixedJumpDistanceCumulFunction (uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceCumulFunction)1 MixedJumpDistanceFunction (uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceFunction)1 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)1 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)1