Search in sources :

Example 1 with JumpDistanceCumulFunction

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