Search in sources :

Example 31 with Min

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

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

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

the class SearchSpace method sampleWithRounding.

/**
	 * Sample with rounding. The input dimensions are used purely for rounding. The limits of the range have been
	 * precomputed.
	 *
	 * @param samples
	 *            the samples
	 * @param generator
	 *            the generator
	 * @param indices
	 *            the indices
	 * @param dimensions
	 *            the dimensions
	 * @param size
	 *            the size
	 * @param centre
	 *            the centre
	 * @param lower
	 *            the lower
	 * @param range
	 *            the range
	 * @return the sample
	 */
private static double[][] sampleWithRounding(int samples, RandomVectorGenerator[] generator, final int[] indices, final Dimension[] dimensions, int size, final double[] centre, final double[] lower, final double[] range) {
    RandomVectorGenerator g = createGenerator(generator, size);
    // Generate random points
    final double[][] searchSpace = new double[samples][];
    for (int i = 0; i < samples; i++) {
        final double[] r = g.nextVector();
        final double[] p = centre.clone();
        for (int j = 0; j < size; j++) {
            // Ensure the min interval is respected
            p[indices[j]] = dimensions[j].round(lower[j] + r[j] * range[j]);
        }
        searchSpace[i] = p;
    }
    return searchSpace;
}
Also used : RandomVectorGenerator(org.apache.commons.math3.random.RandomVectorGenerator)

Example 34 with Min

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

use of org.apache.commons.math3.stat.descriptive.rank.Min 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)16 List (java.util.List)10 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)8 SummaryStatistics (org.apache.commons.math3.stat.descriptive.SummaryStatistics)7 Map (java.util.Map)6 UnivariateFunction (org.apache.commons.math3.analysis.UnivariateFunction)6 MaxEval (org.apache.commons.math3.optim.MaxEval)6 Collectors (java.util.stream.Collectors)5 ExpressionException (cbit.vcell.parser.ExpressionException)4 Plot2 (ij.gui.Plot2)4 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)4 InitialGuess (org.apache.commons.math3.optim.InitialGuess)4 PointValuePair (org.apache.commons.math3.optim.PointValuePair)4 RandomDataGenerator (org.apache.commons.math3.random.RandomDataGenerator)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)3 HashMap (java.util.HashMap)3 SimpsonIntegrator (org.apache.commons.math3.analysis.integration.SimpsonIntegrator)3 BrentOptimizer (org.apache.commons.math3.optim.univariate.BrentOptimizer)3 SearchInterval (org.apache.commons.math3.optim.univariate.SearchInterval)3