当前位置: 首页>>代码示例>>Java>>正文


Java IntegerDistribution类代码示例

本文整理汇总了Java中org.apache.commons.math3.distribution.IntegerDistribution的典型用法代码示例。如果您正苦于以下问题:Java IntegerDistribution类的具体用法?Java IntegerDistribution怎么用?Java IntegerDistribution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IntegerDistribution类属于org.apache.commons.math3.distribution包,在下文中一共展示了IntegerDistribution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWithInitialCapacity

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Test
public void testWithInitialCapacity() {

    ResizableDoubleArray eDA2 = new ResizableDoubleArray(2);
    Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements());

    final IntegerDistribution randomData = new UniformIntegerDistribution(100, 1000);
    final int iterations = randomData.sample();

    for( int i = 0; i < iterations; i++) {
        eDA2.addElement( i );
    }

    Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements());

    eDA2.addElement( 2.0 );

    Assert.assertEquals("Number of elements should be equals to " + (iterations +1),
            iterations + 1 , eDA2.getNumElements() );
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:ResizableDoubleArrayTest.java

示例2: getBinomial

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Integer> getBinomial(
		final RandomNumberStream rng, final Number trials, final Number p)
{
	final IntegerDistribution dist = new BinomialDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			trials.intValue(), p.doubleValue());
	return new RandomNumberDistribution<Integer>()
	{
		@Override
		public Integer draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例3: getGeometric

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Integer> getGeometric(
		final RandomNumberStream rng, final Number p)
{
	final IntegerDistribution dist = new GeometricDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			p.doubleValue());
	return new RandomNumberDistribution<Integer>()
	{
		@Override
		public Integer draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例4: getHypergeometric

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Integer> getHypergeometric(
		final RandomNumberStream rng, final Number populationSize,
		final Number numberOfSuccesses, final Number sampleSize)
{
	final IntegerDistribution dist = new HypergeometricDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			populationSize.intValue(), numberOfSuccesses.intValue(),
			sampleSize.intValue());
	return new RandomNumberDistribution<Integer>()
	{
		@Override
		public Integer draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:19,代码来源:RandomDistributionFactoryImpl.java

示例5: getPascal

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Integer> getPascal(
		final RandomNumberStream rng, final Number r, final Number p)
{
	final IntegerDistribution dist = new PascalDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			r.intValue(), p.doubleValue());
	return new RandomNumberDistribution<Integer>()
	{
		@Override
		public Integer draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例6: getPoisson

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Integer> getPoisson(
		final RandomNumberStream rng, final Number alpha, final Number beta)
{
	final IntegerDistribution dist = new BinomialDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			alpha.intValue(), beta.doubleValue());
	return new RandomNumberDistribution<Integer>()
	{
		@Override
		public Integer draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例7: getUniformInteger

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Integer> getUniformInteger(
		final RandomNumberStream rng, final Number lower, final Number upper)
{
	final IntegerDistribution dist = new UniformIntegerDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			lower.intValue(), upper.intValue());
	return new RandomNumberDistribution<Integer>()
	{
		@Override
		public Integer draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例8: getZipf

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Integer> getZipf(
		final RandomNumberStream rng, final Number numberOfElements,
		final Number exponent)
{
	final IntegerDistribution dist = new ZipfDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			numberOfElements.intValue(), exponent.doubleValue());
	return new RandomNumberDistribution<Integer>()
	{
		@Override
		public Integer draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:18,代码来源:RandomDistributionFactoryImpl.java

示例9: generate

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
static BenchmarkData generate(int param, int howMany, int smallType, int bigType) {
  IntegerDistribution ud = new UniformIntegerDistribution(new Well19937c(param + 17),
      Short.MIN_VALUE, Short.MAX_VALUE);
  ClusteredDataGenerator cd = new ClusteredDataGenerator();
  IntegerDistribution p = new UniformIntegerDistribution(new Well19937c(param + 123),
      SMALLEST_ARRAY, BIGGEST_ARRAY / param);
  BenchmarkContainer[] smalls = new BenchmarkContainer[howMany];
  BenchmarkContainer[] bigs = new BenchmarkContainer[howMany];
  for (int i = 0; i < howMany; i++) {
    int smallSize = p.sample();
    int bigSize = smallSize * param;
    short[] small =
        smallType == 0 ? generateUniform(ud, smallSize) : generateClustered(cd, smallSize);
    short[] big = bigType == 0 ? generateUniform(ud, bigSize) : generateClustered(cd, bigSize);
    smalls[i] = new BenchmarkContainer(small);
    bigs[i] = new BenchmarkContainer(big);
  }
  return new BenchmarkData(smalls, bigs);
}
 
开发者ID:RoaringBitmap,项目名称:RoaringBitmap,代码行数:20,代码来源:UtilBenchmark.java

示例10: checkDiscreteProbability

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
/**
 * 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
 * @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);
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:16,代码来源:OryxTest.java

示例11: generateSample

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
/**
 * Generates a random sample of double values.
 * Sample size is random, between 10 and 100 and values are
 * uniformly distributed over [-100, 100].
 *
 * @return array of random double values
 */
private double[] generateSample() {
    final IntegerDistribution size = new UniformIntegerDistribution(10, 100);
    final RealDistribution randomData = new UniformRealDistribution(-100, 100);
    final int sampleSize = size.sample();
    final double[] out = randomData.sample(sampleSize);
    return out;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:15,代码来源:AggregateSummaryStatisticsTest.java

示例12: testMLUpdate

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Test
public void testMLUpdate() throws Exception {
  Path tempDir = getTempDir();
  Path dataDir = tempDir.resolve("data");
  Map<String,Object> 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", tempDir.resolve("model"));
  overlayConfig.put("oryx.batch.streaming.generation-interval-sec", GEN_INTERVAL_SEC);
  overlayConfig.put("oryx.ml.eval.test-fraction", TEST_FRACTION);
  overlayConfig.put("oryx.ml.eval.threshold", DATA_TO_WRITE / 2); // Should easily pass threshold
  Config config = ConfigUtils.overlayOn(overlayConfig, getConfig());

  startMessaging();

  List<Integer> trainCounts = MockMLUpdate.getResetTrainCounts();
  List<Integer> testCounts = MockMLUpdate.getResetTestCounts();

  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);
    checkDiscreteProbability(testCount, dist);
  }

}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:54,代码来源:SimpleMLUpdateIT.java

示例13: testWeightedConsistency

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
/**
 * Tests consistency of weighted statistic computation.
 * For statistics that support weighted evaluation, this test case compares
 * the result of direct computation on an array with repeated values with
 * a weighted computation on the corresponding (shorter) array with each
 * value appearing only once but with a weight value equal to its multiplicity
 * in the repeating array.
 */

@Test
public void testWeightedConsistency() {

    // See if this statistic computes weighted statistics
    // If not, skip this test
    UnivariateStatistic statistic = getUnivariateStatistic();
    if (!(statistic instanceof WeightedEvaluation)) {
        return;
    }

    // Create arrays of values and corresponding integral weights
    // and longer array with values repeated according to the weights
    final int len = 10;        // length of values array
    final double mu = 0;       // mean of test data
    final double sigma = 5;    // std dev of test data
    double[] values = new double[len];
    double[] weights = new double[len];

    // Fill weights array with random int values between 1 and 5
    int[] intWeights = new int[len];
    final IntegerDistribution weightDist = new UniformIntegerDistribution(1, 5);
    for (int i = 0; i < len; i++) {
        intWeights[i] = weightDist.sample();
        weights[i] = intWeights[i];
    }

    // Fill values array with random data from N(mu, sigma)
    // and fill valuesList with values from values array with
    // values[i] repeated weights[i] times, each i
    final RealDistribution valueDist = new NormalDistribution(mu, sigma);
    List<Double> valuesList = new ArrayList<Double>();
    for (int i = 0; i < len; i++) {
        double value = valueDist.sample();
        values[i] = value;
        for (int j = 0; j < intWeights[i]; j++) {
            valuesList.add(new Double(value));
        }
    }

    // Dump valuesList into repeatedValues array
    int sumWeights = valuesList.size();
    double[] repeatedValues = new double[sumWeights];
    for (int i = 0; i < sumWeights; i++) {
        repeatedValues[i] = valuesList.get(i);
    }

    // Compare result of weighted statistic computation with direct computation
    // on array of repeated values
    WeightedEvaluation weightedStatistic = (WeightedEvaluation) statistic;
    TestUtils.assertRelativelyEquals(statistic.evaluate(repeatedValues),
            weightedStatistic.evaluate(values, weights, 0, values.length),
            10E-12);

    // Check consistency of weighted evaluation methods
    Assert.assertEquals(weightedStatistic.evaluate(values, weights, 0, values.length),
            weightedStatistic.evaluate(values, weights), Double.MIN_VALUE);

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:68,代码来源:UnivariateStatisticAbstractTest.java

示例14: testWithInitialCapacityAndExpansionFactor

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Test
public void testWithInitialCapacityAndExpansionFactor() {

    ResizableDoubleArray eDA3 = new ResizableDoubleArray(3, 3.0, 3.5);
    Assert.assertEquals("Initial number of elements should be 0", 0, eDA3.getNumElements() );

    final IntegerDistribution randomData = new UniformIntegerDistribution(100, 3000);
    final int iterations = randomData.sample();

    for( int i = 0; i < iterations; i++) {
        eDA3.addElement( i );
    }

    Assert.assertEquals("Number of elements should be equal to " + iterations, iterations,eDA3.getNumElements());

    eDA3.addElement( 2.0 );

    Assert.assertEquals("Number of elements should be equals to " + (iterations +1),
            iterations +1, eDA3.getNumElements() );

    Assert.assertEquals("Expansion factor should equal 3.0", 3.0f, eDA3.getExpansionFactor(), Double.MIN_VALUE);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:ResizableDoubleArrayTest.java

示例15: testWithInitialCapacityAndExpansionFactor

import org.apache.commons.math3.distribution.IntegerDistribution; //导入依赖的package包/类
@Test
public void testWithInitialCapacityAndExpansionFactor() {

    ResizableDoubleArray eDA3 = new ResizableDoubleArray(3, 3.0f, 3.5f);
    Assert.assertEquals("Initial number of elements should be 0", 0, eDA3.getNumElements() );

    final IntegerDistribution randomData = new UniformIntegerDistribution(100, 3000);
    final int iterations = randomData.sample();

    for( int i = 0; i < iterations; i++) {
        eDA3.addElement( i );
    }

    Assert.assertEquals("Number of elements should be equal to " + iterations, iterations,eDA3.getNumElements());

    eDA3.addElement( 2.0 );

    Assert.assertEquals("Number of elements should be equals to " + (iterations +1),
            iterations +1, eDA3.getNumElements() );

    Assert.assertEquals("Expansion factor should equal 3.0", 3.0f, eDA3.getExpansionFactor(), Double.MIN_VALUE);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:ResizableDoubleArrayTest.java


注:本文中的org.apache.commons.math3.distribution.IntegerDistribution类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。