Search in sources :

Example 6 with PoissonDistribution

use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project systemml by apache.

the class PoissonPRNGenerator method setup.

public void setup(double mean, long sd) {
    seed = sd;
    SynchronizedRandomGenerator srg = new SynchronizedRandomGenerator(new Well1024a());
    srg.setSeed(seed);
    _pdist = new PoissonDistribution(srg, _mean, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) SynchronizedRandomGenerator(org.apache.commons.math3.random.SynchronizedRandomGenerator) Well1024a(org.apache.commons.math3.random.Well1024a)

Example 7 with PoissonDistribution

use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project presto by prestodb.

the class MathFunctions method poissonCdf.

@Description("Poisson cdf given the lambda (mean) parameter and value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double poissonCdf(@SqlType(StandardTypes.DOUBLE) double lambda, @SqlType(StandardTypes.INTEGER) long value) {
    checkCondition(value >= 0, INVALID_FUNCTION_ARGUMENT, "value must be a non-negative integer");
    checkCondition(lambda > 0, INVALID_FUNCTION_ARGUMENT, "lambda must be greater than 0");
    PoissonDistribution distribution = new PoissonDistribution(lambda);
    return distribution.cumulativeProbability((int) value);
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 8 with PoissonDistribution

use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project presto by prestodb.

the class TestTDigestFunctions method testPoissonDistribution.

@Test(enabled = false)
public void testPoissonDistribution() {
    int trials = 10;
    for (int k = 1; k < trials; k++) {
        TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
        PoissonDistribution poisson = new PoissonDistribution(k * 0.1);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < NUMBER_OF_ENTRIES; i++) {
            int sample = poisson.sample();
            tDigest.add(sample);
            list.add(sample);
        }
        Collections.sort(list);
        for (int i = 0; i < quantiles.length; i++) {
            assertDiscreteQuantileWithinBound(quantiles[i], STANDARD_ERROR, list, tDigest);
        }
    }
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) TDigest(com.facebook.presto.tdigest.TDigest) TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 9 with PoissonDistribution

use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project GDSC-SMLM by aherbert.

the class PoissonCalculatorTest method cumulativeProbabilityIsOneWithRealDataForCountAbove4.

private static void cumulativeProbabilityIsOneWithRealDataForCountAbove4(int function) {
    for (final double mu : photons) {
        // Determine upper limit for a Poisson
        final double max = new PoissonDistribution(mu).inverseCumulativeProbability(P_LIMIT);
        // Determine lower limit
        final double sd = Math.sqrt(mu);
        final double min = (int) Math.max(0, mu - 4 * sd);
        PoissonFunction fun;
        switch(function) {
            case 2:
                fun = new PoissonFunction(mu) {

                    @Override
                    double likelihood(double mu, double x) {
                        return PoissonCalculator.fastLikelihood(mu, x, FastLogFactory.getFastLog());
                    }
                };
                break;
            case 1:
                fun = new PoissonFunction(mu) {

                    @Override
                    double likelihood(double mu, double x) {
                        return PoissonCalculator.fastLikelihood(mu, x);
                    }
                };
                break;
            case 0:
                fun = new PoissonFunction(mu) {

                    @Override
                    double likelihood(double mu, double x) {
                        return PoissonCalculator.likelihood(mu, x);
                    }
                };
                break;
            default:
                throw new IllegalStateException();
        }
        cumulativeProbabilityIsOneWithRealData(min, max, mu >= 4, fun);
    }
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution)

Example 10 with PoissonDistribution

use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project GDSC-SMLM by aherbert.

the class PoissonCalculatorTest method canComputeFastLog_FastLikelihoodForIntegerData.

@Test
void canComputeFastLog_FastLikelihoodForIntegerData() {
    final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-4, 0);
    final FastLog fastLog = FastLogFactory.getFastLog();
    for (final double u : photons) {
        final PoissonDistribution pd = new PoissonDistribution(u);
        for (int x = 0; x < 100; x++) {
            double expected = pd.probability(x);
            double observed = PoissonCalculator.fastLikelihood(u, x, fastLog);
            if (expected > 1e-100) {
                TestAssertions.assertTest(expected, observed, predicate);
            }
            expected = pd.logProbability(x);
            observed = PoissonCalculator.fastLogLikelihood(u, x, fastLog);
            TestAssertions.assertTest(expected, observed, predicate);
        }
    }
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) DoubleDoubleBiPredicate(uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test)

Aggregations

PoissonDistribution (org.apache.commons.math3.distribution.PoissonDistribution)39 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)7 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)5 Test (org.junit.jupiter.api.Test)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)3 Test (org.junit.Test)3 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)2 Description (com.facebook.presto.spi.function.Description)2 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)2 SqlType (com.facebook.presto.spi.function.SqlType)2 TDigest.createTDigest (com.facebook.presto.tdigest.TDigest.createTDigest)2 DecimalOperators.modulusScalarFunction (com.facebook.presto.type.DecimalOperators.modulusScalarFunction)2 Sets (com.google.cloud.dataflow.sdk.repackaged.com.google.common.collect.Sets)2 java.util (java.util)2 GuaguaRuntimeException (ml.shifu.guagua.GuaguaRuntimeException)2 GridSearch (ml.shifu.shifu.core.dtrain.gs.GridSearch)2 PoissonDistribution (uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution)2