Java Code Examples for org.apache.commons.math3.distribution.PoissonDistribution#inverseCumulativeProbability()

The following examples show how to use org.apache.commons.math3.distribution.PoissonDistribution#inverseCumulativeProbability() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KempSmallMeanPoissonSamplerTest.java    From commons-rng with Apache License 2.0 6 votes vote down vote up
/**
 * Test the sampler functions at the upper bound on the mean.
 */
@Test
public void testSamplerAtUpperBounds() {
    final double mean = SUPPORTED_UPPER_BOUND;

    // Test some ranges for the cumulative probability
    final PoissonDistribution pd = new PoissonDistribution(null, mean,
        PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);

    final FixedRNG rng = new FixedRNG(0);
    final SharedStateDiscreteSampler sampler = KempSmallMeanPoissonSampler.of(rng, mean);

    // Lower bound should be zero
    testSample(rng, sampler, 0, 0, 0);

    // Upper bound should exceed 99.99% of the range
    testSample(rng, sampler, 1, pd.inverseCumulativeProbability(0.9999), Integer.MAX_VALUE);

    // A sample from within the cumulative probability should be within the expected range
    for (int i = 1; i < 10; i++) {
        final double p = i * 0.1;
        final int lower = pd.inverseCumulativeProbability(p - 0.01);
        final int upper = pd.inverseCumulativeProbability(p + 0.01);
        testSample(rng, sampler, p, lower, upper);
    }
}
 
Example 2
Source File: GuideTableDiscreteSamplerTest.java    From commons-rng with Apache License 2.0 5 votes vote down vote up
/**
 * Test sampling from a Poisson distribution.
 */
@Test
public void testPoissonSamples() {
    final double mean = 3.14;
    final PoissonDistribution dist = new PoissonDistribution(null, mean,
        PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
    final int maxN = dist.inverseCumulativeProbability(1 - 1e-6);
    final double[] expected = new double[maxN];
    for (int i = 0; i < expected.length; i++) {
        expected[i] = dist.probability(i);
    }
    checkSamples(expected, 1.0);
}
 
Example 3
Source File: AliasMethodDiscreteSamplerTest.java    From commons-rng with Apache License 2.0 5 votes vote down vote up
/**
 * Test sampling from a Poisson distribution.
 */
@Test
public void testPoissonSamples() {
    final double mean = 3.14;
    final PoissonDistribution dist = new PoissonDistribution(null, mean,
        PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
    final int maxN = dist.inverseCumulativeProbability(1 - 1e-6);
    double[] expected = new double[maxN];
    for (int i = 0; i < expected.length; i++) {
        expected[i] = dist.probability(i);
    }
    checkSamples(expected);
}
 
Example 4
Source File: NuMTFilterTool.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@VisibleForTesting
static int getMaxAltDepthCutoff(final double maxNuMTAutosomalCopies, final double medianAutosomalCoverage) {
    final PoissonDistribution autosomalCoverage = new PoissonDistribution(medianAutosomalCoverage * maxNuMTAutosomalCopies / 2.0);
    return autosomalCoverage.inverseCumulativeProbability(1 - LOWER_BOUND_PROB);
}