Java Code Examples for org.apache.commons.math3.distribution.PoissonDistribution#DEFAULT_MAX_ITERATIONS

The following examples show how to use org.apache.commons.math3.distribution.PoissonDistribution#DEFAULT_MAX_ITERATIONS . 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: BootstrappedDatasetBuilder.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public BootstrappedDatasetPartition build(
    LearningEnvironment env,
    Iterator<UpstreamEntry<K, V>> upstreamData,
    long upstreamDataSize,
    EmptyContext ctx) {

    BootstrappedVector[] dataset = new BootstrappedVector[Math.toIntExact(upstreamDataSize)];

    int cntr = 0;

    PoissonDistribution poissonDistribution = new PoissonDistribution(
        new Well19937c(env.randomNumbersGenerator().nextLong()),
        subsampleSize,
        PoissonDistribution.DEFAULT_EPSILON,
        PoissonDistribution.DEFAULT_MAX_ITERATIONS);

    while (upstreamData.hasNext()) {
        UpstreamEntry<K, V> nextRow = upstreamData.next();
        LabeledVector<Double> vecAndLb = preprocessor.apply(nextRow.getKey(), nextRow.getValue());
        Vector features = vecAndLb.features();
        Double lb = vecAndLb.label();
        int[] repetitionCounters = new int[samplesCnt];
        Arrays.setAll(repetitionCounters, i -> poissonDistribution.sample());
        dataset[cntr++] = new BootstrappedVector(features, lb, repetitionCounters);
    }

    return new BootstrappedDatasetPartition(dataset);
}
 
Example 5
Source File: BaggingUpstreamTransformer.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Stream<UpstreamEntry> transform(Stream<UpstreamEntry> upstream) {
    PoissonDistribution poisson = new PoissonDistribution(
        new Well19937c(seed),
        subsampleRatio,
        PoissonDistribution.DEFAULT_EPSILON,
        PoissonDistribution.DEFAULT_MAX_ITERATIONS);

    return upstream.sequential().flatMap(en -> Stream.generate(() -> en).limit(poisson.sample()));
}
 
Example 6
Source File: PoissonPRNGenerator.java    From systemds with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 7
Source File: ChangeFinder2DTest.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
public void testSota5D() throws HiveException {
    final int DIM = 5;
    final int EXAMPLES = 20001;

    final Double[] x = new Double[DIM];
    final List<Double> xList = Arrays.asList(x);

    Parameters params = new Parameters();
    params.set(LossFunction.logloss);
    params.r1 = 0.01d;
    params.k = 10;
    params.T1 = 10;
    params.T2 = 10;
    PrimitiveObjectInspector oi = PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
    ListObjectInspector listOI = ObjectInspectorFactory.getStandardListObjectInspector(oi);
    final ChangeFinder2D cf = new ChangeFinder2D(params, listOI);
    final double[] outScores = new double[2];

    RandomGenerator rng1 = new Well19937c(31L);
    final UniformIntegerDistribution uniform = new UniformIntegerDistribution(rng1, 0, 10);
    RandomGenerator rng2 = new Well19937c(41L);
    final PoissonDistribution poissonEvent = new PoissonDistribution(rng2, 1000.d,
        PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
    final StringBuilder buf = new StringBuilder(256);

    println("# time x0 x1 x2 x3 x4 mean0 mean1 mean2 mean3 mean4 outlier change");
    FIN: for (int i = 0; i < EXAMPLES;) {
        int len = poissonEvent.sample();
        double data[][] = new double[DIM][len];
        double mean[] = new double[DIM];
        double sd[] = new double[DIM];
        for (int j = 0; j < DIM; j++) {
            mean[j] = uniform.sample() * 5.d;
            sd[j] = uniform.sample() / 10.d * 5.d + 1.d;
            if (i % 5 == 0) {
                mean[j] += 50.d;
            }
            NormalDistribution normDist =
                    new NormalDistribution(new Well19937c(i + j), mean[j], sd[j]);
            data[j] = normDist.sample(len);
            data[j][len / (j + 2) + DIM % (j + 1)] = mean[j] + (j + 4) * sd[j];
        }
        for (int j = 0; j < len; j++) {
            if (i >= EXAMPLES) {
                break FIN;
            }
            x[0] = data[0][j];
            x[1] = data[1][j];
            x[2] = data[2][j];
            x[3] = data[3][j];
            x[4] = data[4][j];
            cf.update(xList, outScores);
            buf.append(i)
               .append(' ')
               .append(x[0].doubleValue())
               .append(' ')
               .append(x[1].doubleValue())
               .append(' ')
               .append(x[2].doubleValue())
               .append(' ')
               .append(x[3].doubleValue())
               .append(' ')
               .append(x[4].doubleValue())
               .append(' ')
               .append(mean[0])
               .append(' ')
               .append(mean[1])
               .append(' ')
               .append(mean[2])
               .append(' ')
               .append(mean[3])
               .append(' ')
               .append(mean[4])
               .append(' ')
               .append(outScores[0])
               .append(' ')
               .append(outScores[1]);
            println(buf.toString());
            StringUtils.clear(buf);
            i++;
        }
    }
}
 
Example 8
Source File: AlleleFractionSimulatedData.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static PoissonDistribution makePoisson(final RandomGenerator rng, final double mean) {
    return new PoissonDistribution(rng, mean, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
}
 
Example 9
Source File: PoissonPRNGenerator.java    From systemds with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 10
Source File: AlleleFractionSimulatedData.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static PoissonDistribution makePoisson(final RandomGenerator rng, final double mean) {
    return new PoissonDistribution(rng, mean, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
}
 
Example 11
Source File: CopyRatioSimulatedData.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static PoissonDistribution makePoisson(final RandomGenerator rng, final double mean) {
    return new PoissonDistribution(rng, mean, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
}
 
Example 12
Source File: EnumeratedDistributionSamplersPerformance.java    From commons-rng with Apache License 2.0 2 votes vote down vote up
/**
 * Creates the poisson distribution.
 *
 * @param mean the mean
 * @return the distribution
 */
private static IntegerDistribution createPoissonDistribution(double mean) {
    return new PoissonDistribution(null, mean,
        PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
}