Search in sources :

Example 1 with MixedJumpDistanceFunction

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

the class JumpDistanceAnalysisTest method canIntegrateProbabilityToCumulativeWithMixedPopulation.

// Commented out as this test always passes
//@Test
public void canIntegrateProbabilityToCumulativeWithMixedPopulation() {
    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) {
        for (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 = jd.new MixedJumpDistanceFunction(null, d, 2);
            MixedJumpDistanceCumulFunction fc = jd.new MixedJumpDistanceCumulFunction(null, null, d, 2);
            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, f=%.1f : x=%.1f, e=%f, o=%f, iter=%d, eval=%d\n", d, f, 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) MixedJumpDistanceCumulFunction(gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceCumulFunction) MixedJumpDistanceFunction(gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceFunction) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction)

Aggregations

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