Search in sources :

Example 1 with JumpDistanceFunction

use of gdsc.smlm.fitting.JumpDistanceAnalysis.JumpDistanceFunction in project GDSC-SMLM by aherbert.

the class JumpDistanceAnalysisTest method canIntegrateProbabilityToCumulativeWithSinglePopulation.

// Commented out as this test always passes
//@Test
public void canIntegrateProbabilityToCumulativeWithSinglePopulation() {
    JumpDistanceAnalysis jd = new JumpDistanceAnalysis();
    jd.setMinD(0);
    jd.setMinFraction(0);
    SimpsonIntegrator si = new SimpsonIntegrator(1e-3, 1e-8, 2, SimpsonIntegrator.SIMPSON_MAX_ITERATIONS_COUNT);
    for (double d : D) {
        final double[] params = new double[] { d };
        final JumpDistanceFunction fp = jd.new JumpDistanceFunction(null, d);
        JumpDistanceCumulFunction fc = jd.new JumpDistanceCumulFunction(null, null, d);
        double x = d / 8;
        UnivariateFunction func = new UnivariateFunction() {

            public double value(double x) {
                return fp.evaluate(x, params);
            }
        };
        for (int i = 1; i < 10; i++, x *= 2) {
            double e = fc.evaluate(x, params);
            // Integrate
            double o = si.integrate(10000, func, 0, x);
            //log("Integrate d=%.1f : x=%.1f, e=%f, o=%f, iter=%d, eval=%d\n", d, x, e, o, si.getIterations(),
            //		si.getEvaluations());
            Assert.assertEquals("Failed to integrate", e, o, e * 1e-2);
        }
    }
}
Also used : SimpsonIntegrator(org.apache.commons.math3.analysis.integration.SimpsonIntegrator) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction) JumpDistanceCumulFunction(gdsc.smlm.fitting.JumpDistanceAnalysis.JumpDistanceCumulFunction) MixedJumpDistanceCumulFunction(gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceCumulFunction) JumpDistanceFunction(gdsc.smlm.fitting.JumpDistanceAnalysis.JumpDistanceFunction) MixedJumpDistanceFunction(gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceFunction)

Aggregations

JumpDistanceCumulFunction (gdsc.smlm.fitting.JumpDistanceAnalysis.JumpDistanceCumulFunction)1 JumpDistanceFunction (gdsc.smlm.fitting.JumpDistanceAnalysis.JumpDistanceFunction)1 MixedJumpDistanceCumulFunction (gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceCumulFunction)1 MixedJumpDistanceFunction (gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceFunction)1 UnivariateFunction (org.apache.commons.math3.analysis.UnivariateFunction)1 SimpsonIntegrator (org.apache.commons.math3.analysis.integration.SimpsonIntegrator)1