Example usage for org.apache.commons.math3.distribution IntegerDistribution getNumericalMean

List of usage examples for org.apache.commons.math3.distribution IntegerDistribution getNumericalMean

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution IntegerDistribution getNumericalMean.

Prototype

double getNumericalMean();

Source Link

Document

Use this method to get the numerical value of the mean of this distribution.

Usage

From source file:com.cloudera.oryx.common.OryxTest.java

/**
 * Asserts that the probability of sampling a value as or more extreme than the given value,
 * from the given discrete distribution, is at least 0.001.
 *
 * @param value sample value//from   w w  w .j a v  a  2s  .  c om
 * @param dist discrete distribution
 */
public static void checkDiscreteProbability(int value, IntegerDistribution dist) {
    double probAsExtreme = value <= dist.getNumericalMean() ? dist.cumulativeProbability(value)
            : (1.0 - dist.cumulativeProbability(value - 1));
    assertTrue(value + " is not likely (" + probAsExtreme + " ) to differ from expected value "
            + dist.getNumericalMean() + " by chance", probAsExtreme >= 0.001);
}

From source file:com.wormsim.utils.Utils.java

/**
 * Returns a string representation of the provided distribution. TODO: Make
 * this complete TODO: Make this compatible with custom distributions (or just
 * more complex ones).// www .j a v  a2 s.  c om
 *
 * @param dist The distribution to translate
 *
 * @return The distribution as a string.
 */
public static String integerDistributionToString(IntegerDistribution dist) {
    if (dist instanceof EnumeratedIntegerDistribution) {
        return Double.toString(dist.getNumericalMean());
    } else if (dist instanceof UniformIntegerDistribution) {
        return "Uniform(" + dist.getSupportLowerBound() + "," + dist.getSupportUpperBound() + ")";
    } else if (dist instanceof BinomialDistribution) {
        BinomialDistribution dist2 = (BinomialDistribution) dist;
        return "Binomial(" + dist2.getNumberOfTrials() + "," + dist2.getProbabilityOfSuccess() + ")";
    } else {
        return dist.toString();
    }
}

From source file:com.cloudera.oryx.ml.SimpleMLUpdateIT.java

@Test
public void testMLUpdate() throws Exception {
    Path tempDir = getTempDir();// w ww .  ja  va2 s  .  c  o  m
    Path dataDir = tempDir.resolve("data");
    Path modelDir = tempDir.resolve("model");
    Map<String, String> overlayConfig = new HashMap<>();
    overlayConfig.put("oryx.batch.update-class", MockMLUpdate.class.getName());
    ConfigUtils.set(overlayConfig, "oryx.batch.storage.data-dir", dataDir);
    ConfigUtils.set(overlayConfig, "oryx.batch.storage.model-dir", modelDir);
    overlayConfig.put("oryx.batch.generation-interval-sec", Integer.toString(GEN_INTERVAL_SEC));
    overlayConfig.put("oryx.batch.block-interval-sec", Integer.toString(BLOCK_INTERVAL_SEC));
    overlayConfig.put("oryx.ml.eval.test-fraction", Double.toString(TEST_FRACTION));
    Config config = ConfigUtils.overlayOn(overlayConfig, getConfig());

    startMessaging();

    List<Integer> trainCounts = new ArrayList<>();
    List<Integer> testCounts = new ArrayList<>();

    MockMLUpdate.setCountHolders(trainCounts, testCounts);

    startServerProduceConsumeTopics(config, DATA_TO_WRITE, WRITE_INTERVAL_MSEC);

    // If lists are unequal at this point, there must have been an empty test set
    // which yielded no call to evaluate(). Fill in the blank
    while (trainCounts.size() > testCounts.size()) {
        testCounts.add(0);
    }

    log.info("trainCounts = {}", trainCounts);
    log.info("testCounts = {}", testCounts);

    checkOutputData(dataDir, DATA_TO_WRITE);
    checkIntervals(trainCounts.size(), DATA_TO_WRITE, WRITE_INTERVAL_MSEC, GEN_INTERVAL_SEC);

    assertEquals(testCounts.size(), trainCounts.size());

    RandomGenerator random = RandomManager.getRandom();
    int lastTotalTrainCount = 0;
    int lastTestCount = 0;
    for (int i = 0; i < testCounts.size(); i++) {
        int totalTrainCount = trainCounts.get(i);
        int testCount = testCounts.get(i);
        int newTrainInGen = totalTrainCount - (lastTotalTrainCount + lastTestCount);
        if (newTrainInGen == 0) {
            continue;
        }
        lastTotalTrainCount = totalTrainCount;
        lastTestCount = testCount;
        int totalNew = testCount + newTrainInGen;

        IntegerDistribution dist = new BinomialDistribution(random, totalNew, TEST_FRACTION);
        double probability;
        if (testCount < dist.getNumericalMean()) {
            probability = dist.cumulativeProbability(testCount);
        } else {
            probability = 1.0 - dist.cumulativeProbability(testCount);
        }
        log.info("Probability of observing {} as {} sample of {}: {}", testCount, TEST_FRACTION, totalNew,
                probability);
        assertTrue(probability >= 0.001);
    }

}

From source file:fr.obeo.emf.specimen.SpecimenGenerator.java

private boolean booleanInDistribution(IntegerDistribution distribution) {
    int sample = distribution.sample();
    return sample < distribution.getNumericalMean();
}

From source file:fr.obeo.emf.specimen.DirectWriteSpecimenGenerator.java

protected boolean booleanInDistribution(IntegerDistribution distribution) {
    int sample = distribution.sample();
    return sample <= distribution.getNumericalMean();
}

From source file:eu.opensourceprojects.mondo.benchmarks.transformationzoo.instantiator.SpecimenGenerator.java

private boolean booleanInDistribution(IntegerDistribution distribution) {
    int sample = distribution.sample();
    //System.out.println(sample < distribution.getNumericalMean());
    return sample < distribution.getNumericalMean();
}