Search in sources :

Example 46 with Max

use of org.apache.commons.math3.stat.descriptive.rank.Max in project GDSC-SMLM by aherbert.

the class PoissonCalculatorTest method cumulativeProbabilityIsOneWithRealData.

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

        public double value(double x) {
            double v;
            v = PoissonCalculator.likelihood(mu, 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 47 with Max

use of org.apache.commons.math3.stat.descriptive.rank.Max in project GDSC-SMLM by aherbert.

the class PoissonCalculatorTest method cumulativeProbabilityIsOneWithRealDataForCountAbove4.

@Test
public void cumulativeProbabilityIsOneWithRealDataForCountAbove4() {
    for (double mu : photons) {
        // Determine upper limit for a Poisson
        double max = new PoissonDistribution(mu).inverseCumulativeProbability(P_LIMIT);
        // Determine lower limit
        double sd = Math.sqrt(mu);
        double min = (int) Math.max(0, mu - 4 * sd);
        cumulativeProbabilityIsOneWithRealData(mu, min, max, mu >= 4);
    }
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) Test(org.junit.Test)

Example 48 with Max

use of org.apache.commons.math3.stat.descriptive.rank.Max in project GDSC-SMLM by aherbert.

the class PulseActivationAnalysis method createShapes.

private Shape[] createShapes(RandomDataGenerator rdg, int c) {
    RandomGenerator rand = rdg.getRandomGenerator();
    Shape[] shapes;
    double min = sim_size / 20;
    double max = sim_size / 10;
    double range = max - min;
    switch(sim_distribution[c]) {
        case CIRCLE:
            shapes = new Shape[10];
            for (int i = 0; i < shapes.length; i++) {
                float x = nextCoordinate(rand);
                float y = nextCoordinate(rand);
                double radius = rand.nextDouble() * range + min;
                shapes[i] = new Circle(x, y, radius);
            }
            break;
        case LINE:
            shapes = new Shape[10];
            for (int i = 0; i < shapes.length; i++) {
                float x = nextCoordinate(rand);
                float y = nextCoordinate(rand);
                double angle = rand.nextDouble() * Math.PI;
                double radius = rand.nextDouble() * range + min;
                shapes[i] = new Line(x, y, angle, radius);
            }
            break;
        case POINT:
        default:
            shapes = new Shape[sim_nMolecules[c]];
            for (int i = 0; i < shapes.length; i++) {
                float x = nextCoordinate(rand);
                float y = nextCoordinate(rand);
                shapes[i] = new Point(x, y);
            }
    }
    return shapes;
}
Also used : RandomGenerator(org.apache.commons.math3.random.RandomGenerator)

Example 49 with Max

use of org.apache.commons.math3.stat.descriptive.rank.Max 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 50 with Max

use of org.apache.commons.math3.stat.descriptive.rank.Max in project GDSC-SMLM by aherbert.

the class SCMOSLikelihoodWrapperTest method cumulativeProbabilityIsOneWithRealDataForCountAbove8.

@Test
public void cumulativeProbabilityIsOneWithRealDataForCountAbove8() {
    for (double mu : photons) {
        // Determine upper limit for a Poisson
        double max = new PoissonDistribution(mu).inverseCumulativeProbability(P_LIMIT);
        // Determine lower limit
        double sd = Math.sqrt(mu);
        double min = (int) Math.max(0, mu - 4 * sd);
        // Map to observed values using the gain and offset
        max = max * G + O;
        min = min * G + O;
        cumulativeProbabilityIsOneWithRealData(mu, min, max, mu > 8);
    }
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)26 List (java.util.List)19 Collectors (java.util.stream.Collectors)13 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)13 Arrays (java.util.Arrays)11 Map (java.util.Map)11 IntStream (java.util.stream.IntStream)10 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)10 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)9 RealMatrix (org.apache.commons.math3.linear.RealMatrix)9 Plot2 (ij.gui.Plot2)8 File (java.io.File)8 IOException (java.io.IOException)8 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)7 Test (org.testng.annotations.Test)7 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)6 Collections (java.util.Collections)6 HashMap (java.util.HashMap)6 Random (java.util.Random)6 UnivariateFunction (org.apache.commons.math3.analysis.UnivariateFunction)6