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


Java IntegerDistribution.sample方法代码示例

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


在下文中一共展示了IntegerDistribution.sample方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: flipOneNonUniform

import org.apache.commons.math3.distribution.IntegerDistribution; //导入方法依赖的package包/类
/**
 * y0: w=(0,1)
 * y1: w=(1,1)
 * y2: w=(1,0)
 * y3: w=(1,-1)
 * @param numData
 * @return
 */
public static MultiLabelClfDataSet flipOneNonUniform(int numData){
    int numClass = 4;
    int numFeature = 2;

    MultiLabelClfDataSet dataSet = MLClfDataSetBuilder.getBuilder().numFeatures(numFeature)
            .numClasses(numClass)
            .numDataPoints(numData)
            .build();

    // generate weights
    Vector[] weights = new Vector[numClass];
    for (int k=0;k<numClass;k++){
        Vector vector = new DenseVector(numFeature);
        weights[k] = vector;
    }

    weights[0].set(0,0);
    weights[0].set(1,1);

    weights[1].set(0, 1);
    weights[1].set(1, 1);

    weights[2].set(0, 1);
    weights[2].set(1, 0);

    weights[3].set(0,1);
    weights[3].set(1,-1);


    // generate features
    for (int i=0;i<numData;i++){
        for (int j=0;j<numFeature;j++){
            dataSet.setFeatureValue(i,j,Sampling.doubleUniform(-1, 1));
        }
    }

    // assign labels
    for (int i=0;i<numData;i++){
        for (int k=0;k<numClass;k++){
            double dot = weights[k].dot(dataSet.getRow(i));
            if (dot>=0){
                dataSet.addLabel(i,k);
            }
        }
    }

    int[] indices = {0,1,2,3};
    double[] probs = {0.4,0.2,0.2,0.2};
    IntegerDistribution distribution = new EnumeratedIntegerDistribution(indices,probs);

    // flip
    for (int i=0;i<numData;i++){
        int toChange = distribution.sample();
        MultiLabel label = dataSet.getMultiLabels()[i];
        if (label.matchClass(toChange)){
            label.removeLabel(toChange);
        } else {
            label.addLabel(toChange);
        }

    }


    return dataSet;
}
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:74,代码来源:MultiLabelSynthesizer.java

示例13: sampleFromMix

import org.apache.commons.math3.distribution.IntegerDistribution; //导入方法依赖的package包/类
/**
 * C0, y0: w=(0,1)
 * C0, y1: w=(1,1)
 * C1, y0: w=(1,0)
 * C1, y1: w=(1,-1)
 * @return
 */
public static MultiLabelClfDataSet sampleFromMix(){
    int numData = 10000;
    int numClass = 2;
    int numFeature = 2;
    int numClusters = 2;
    double[] proportions = {0.4,0.6};
    int[] indices = {0,1};

    MultiLabelClfDataSet dataSet = MLClfDataSetBuilder.getBuilder()
            .numFeatures(numFeature)
            .numClasses(numClass)
            .numDataPoints(numData)
            .build();

    // generate weights
    Vector[][] weights = new Vector[numClusters][numClass];
    for (int c=0;c<numClusters;c++){
        for (int l=0;l<numClass;l++){
            Vector vector = new DenseVector(numFeature);
            weights[c][l] = vector;
        }
    }


    weights[0][0].set(0, 0);
    weights[0][0].set(1, 1);

    weights[0][1].set(0, 1);
    weights[0][1].set(1, 1);


    weights[1][0].set(0, 1);
    weights[1][0].set(1, 0);

    weights[1][1].set(0, 1);
    weights[1][1].set(1,-1);

    // generate features
    for (int i=0;i<numData;i++){
        for (int j=0;j<numFeature;j++){
            dataSet.setFeatureValue(i,j,Sampling.doubleUniform(-1, 1));
        }
    }
    IntegerDistribution distribution = new EnumeratedIntegerDistribution(indices,proportions);
    // assign labels
    for (int i=0;i<numData;i++){
        int cluster = distribution.sample();
        System.out.println("cluster "+cluster);
        for (int l=0;l<numClass;l++){
            System.out.println("row = "+dataSet.getRow(i));
            System.out.println("weight = "+ weights[cluster][l]);
            double dot = weights[cluster][l].dot(dataSet.getRow(i));
            System.out.println("dot = "+dot);
            if (dot>=0){
                dataSet.addLabel(i,l);
            }
        }
    }

    return dataSet;
}
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:69,代码来源:MultiLabelSynthesizer.java

示例14: 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.sample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。