Search in sources :

Example 6 with SimpsonIntegrator

use of org.apache.commons.math3.analysis.integration.SimpsonIntegrator in project GDSC-SMLM by aherbert.

the class SCMOSLikelihoodWrapperTest method cumulativeProbabilityIsOneWithRealData.

private void cumulativeProbabilityIsOneWithRealData(final double mu, double min, double max, boolean test) {
    double p = 0;
    // Test using a standard Poisson-Gaussian convolution
    //min = -max;
    //final PoissonGaussianFunction pgf = PoissonGaussianFunction.createWithVariance(1, 1, VAR);
    UnivariateIntegrator in = new SimpsonIntegrator();
    p = in.integrate(20000, new UnivariateFunction() {

        public double value(double x) {
            double v;
            v = SCMOSLikelihoodWrapper.likelihood(mu, VAR, G, O, x);
            //System.out.printf("x=%f, v=%f\n", x, v);
            return v;
        }
    }, min, max);
    //System.out.printf("mu=%f, p=%f\n", mu, p);
    if (test) {
        Assert.assertEquals(String.format("mu=%f", mu), P_LIMIT, p, 0.02);
    }
}
Also used : SimpsonIntegrator(org.apache.commons.math3.analysis.integration.SimpsonIntegrator) UnivariateIntegrator(org.apache.commons.math3.analysis.integration.UnivariateIntegrator) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction)

Example 7 with SimpsonIntegrator

use of org.apache.commons.math3.analysis.integration.SimpsonIntegrator in project GDSC-SMLM by aherbert.

the class PoissonLikelihoodWrapperTest method cumulativeProbabilityIsOneWithRealData.

private void cumulativeProbabilityIsOneWithRealData(final double mu, int max) {
    double p = 0;
    SimpsonIntegrator in = new SimpsonIntegrator();
    p = in.integrate(20000, new UnivariateFunction() {

        public double value(double x) {
            return PoissonLikelihoodWrapper.likelihood(mu, x);
        }
    }, 0, max);
    System.out.printf("mu=%f, p=%f\n", mu, p);
    Assert.assertEquals(String.format("mu=%f", mu), 1, p, 0.02);
}
Also used : SimpsonIntegrator(org.apache.commons.math3.analysis.integration.SimpsonIntegrator) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction)

Example 8 with SimpsonIntegrator

use of org.apache.commons.math3.analysis.integration.SimpsonIntegrator 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)

Example 9 with SimpsonIntegrator

use of org.apache.commons.math3.analysis.integration.SimpsonIntegrator in project gatk-protected by broadinstitute.

the class CNLOHCaller method calcEffectiveAlpha.

protected double calcEffectiveAlpha(final double[] effectivePhis) {
    final QAlphaUnivariateFunction qAlpha = new QAlphaUnivariateFunction(effectivePhis);
    final AQAlphaUnivariateFunction aQAlpha = new AQAlphaUnivariateFunction(effectivePhis);
    final BaseAbstractUnivariateIntegrator integrator = new SimpsonIntegrator();
    final double numerator = integrator.integrate(10, aQAlpha, MIN_E_ELPHA_INTEGRATION_RANGE, MAX_E_ELPHA_INTEGRATION_RANGE);
    final double denominator = integrator.integrate(10, qAlpha, MIN_E_ELPHA_INTEGRATION_RANGE, MAX_E_ELPHA_INTEGRATION_RANGE);
    return numerator / denominator;
}
Also used : SimpsonIntegrator(org.apache.commons.math3.analysis.integration.SimpsonIntegrator) BaseAbstractUnivariateIntegrator(org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator)

Aggregations

SimpsonIntegrator (org.apache.commons.math3.analysis.integration.SimpsonIntegrator)9 UnivariateFunction (org.apache.commons.math3.analysis.UnivariateFunction)7 UnivariateIntegrator (org.apache.commons.math3.analysis.integration.UnivariateIntegrator)3 MixedJumpDistanceCumulFunction (gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceCumulFunction)2 MixedJumpDistanceFunction (gdsc.smlm.fitting.JumpDistanceAnalysis.MixedJumpDistanceFunction)2 BaseAbstractUnivariateIntegrator (org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator)2 JumpDistanceCumulFunction (gdsc.smlm.fitting.JumpDistanceAnalysis.JumpDistanceCumulFunction)1 JumpDistanceFunction (gdsc.smlm.fitting.JumpDistanceAnalysis.JumpDistanceFunction)1 SplineInterpolator (org.apache.commons.math3.analysis.interpolation.SplineInterpolator)1 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)1