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


Java UniformIntegerDistribution类代码示例

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


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

示例1: testWithInitialCapacity

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的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: sampleUniqueUsingIndexSet

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
private static <T> Iterable<T> sampleUniqueUsingIndexSet(final Collection<? extends T> collection,
                                                         final int n, final RandomGenerator rng) {
    final UniformIntegerDistribution distribution =
            new UniformIntegerDistribution(rng, 0, collection.size() - 1);
    final LinkedHashSet<Integer> indexSet = Sets.newLinkedHashSet();
    while (indexSet.size() != n) {
        indexSet.add(distribution.sample());
    }

    return Iterables.transform(indexSet, new Function<Integer, T>() {
        @Nullable
        @Override
        public T apply(final Integer input) {
            return Iterables.get(collection, input);
        }
    });
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:18,代码来源:Samplings.java

示例3: get

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
@Override
public String get() {

    if (loremIpsumImage == null) {
        synchronized (LoremExtractGenerator.class) {
            if (loremIpsumImage == null) {
                CharBuffer image= loadLoremIpsum();
                loremIpsumImage = image;
            }
            sizeDistribution = new UniformIntegerDistribution(rng, minsize, maxsize);
            positionDistribution = new UniformIntegerDistribution(rng, 1, loremIpsumImage.limit() - maxsize);
        }
    }

    int offset = positionDistribution.sample();
    int length = sizeDistribution.sample();
    String sub = null;
    try {
        sub = loremIpsumImage.subSequence(offset, offset + length).toString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return sub;
}
 
开发者ID:jshook,项目名称:testclient,代码行数:25,代码来源:LoremExtractGenerator.java

示例4: getUniformInteger

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的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

示例5: GenerateBed

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
/**
 * Generate records in BED format.
 *
 * @param bedFile output BED file, if any
 * @param n number of BED records to generate, must be at least zero
 * @param size chromosome size, must be at least zero
 * @param chrom chromosome name, must not be null
 * @param random random generator, must not be null
 * @param length length distribution, must not be null
 */
public GenerateBed(final File bedFile, final int n, final int size, final String chrom, final RandomGenerator random, final RealDistribution length) {
    checkArgument(n >= 0, "n must be at least zero");
    checkArgument(size >= 0, "size must be at least zero");
    checkNotNull(chrom);
    checkNotNull(random);
    checkNotNull(length);
    this.bedFile = bedFile;
    this.n = n;
    this.size = size;
    this.chrom = chrom;
    this.random = random;
    this.length = length;

    int flanking = (int) (length.getNumericalMean() + length.getNumericalVariance());
    location = new UniformIntegerDistribution(this.random, 1 - flanking, size + flanking);
}
 
开发者ID:nmdp-bioinformatics,项目名称:ngs,代码行数:27,代码来源:GenerateBed.java

示例6: generate

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的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

示例7: RandomLineToString

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
public RandomLineToString(String filename, MersenneTwister rng) {
    this.rng = rng;
    this.filename = filename;
    this.lines = ResourceFinder.readDataFileLines(filename);
    this.lines = ResourceFinder.readDataFileLines(filename);
    itemDistribution= new UniformIntegerDistribution(rng, 0, lines.size()-2);
}
 
开发者ID:virtualdataset,项目名称:metagen-java,代码行数:8,代码来源:RandomLineToString.java

示例8: RandomFileExtractToString

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
public RandomFileExtractToString(String fileName, int minsize, int maxsize, long seed) {
    this.fileName = fileName;
    this.minsize = minsize;
    this.maxsize = maxsize;
    loadData();
    this.rng = new MersenneTwister(seed);
    this.sizeDistribution = new UniformIntegerDistribution(rng, minsize, maxsize);
    this.positionDistribution = new UniformIntegerDistribution(rng, 1, fileDataImage.limit() - maxsize);
}
 
开发者ID:virtualdataset,项目名称:metagen-java,代码行数:10,代码来源:RandomFileExtractToString.java

示例9: calculateUniformDistributedValue

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
/**
 * Select random Float value from the input with uniform distribution.
 *
 */
private void calculateUniformDistributedValue() {
	//		https://commons.apache.org/proper/commons-math/javadocs/api-3.2/org/apache/commons/math3/distribution/UniformIntegerDistribution.html
	String userInput = this.getInputOrDefault();
	if (!userInput.contains(";")) {
		this.value = Float.parseFloat(userInput);
		return;
	}
	String[] possibleValues = this.getInputOrDefault().split(";");
	UniformIntegerDistribution uniformIntegerDistribution = new UniformIntegerDistribution(0, possibleValues.length - 1);
	this.value = Float.parseFloat(possibleValues[uniformIntegerDistribution.sample()]);
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:16,代码来源:FloatAttributeInput.java

示例10: prepare

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) {
  this.targetTasks = targetTasks;
  int numTasks = targetTasks.size();
  if (numTasks % numShards != 0)
    throw new IllegalArgumentException("Number of tasks ("+numTasks+") should be a multiple of the number of shards ("+numShards+")!");

  this.tasksPerShard = numTasks/numShards;
  this.random = new UniformIntegerDistribution(0, tasksPerShard-1);

  CompositeIdRouter docRouter =  new CompositeIdRouter();
  this.ranges = docRouter.partitionRange(numShards, docRouter.fullRange());
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:13,代码来源:HashRangeGrouping.java

示例11: prepare

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) {
  this.targetTasks = targetTasks;
  int numTasks = targetTasks.size();
  int numShards = initShardInfo(); // setup for doing shard to task mapping 
  if (numTasks % numShards != 0)
    throw new IllegalArgumentException("Number of tasks ("+numTasks+") should be a multiple of the number of shards ("+numShards+")!");

  this.tasksPerShard = numTasks/numShards;
  this.random = new UniformIntegerDistribution(0, tasksPerShard-1);
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:11,代码来源:ShardGrouping.java

示例12: generateSample

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的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

示例13: generatePartition

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
/**
 * Generates a partition of <sample> into up to 5 sequentially selected
 * subsamples with randomly selected partition points.
 *
 * @param sample array to partition
 * @return rectangular array with rows = subsamples
 */
private double[][] generatePartition(double[] sample) {
    final int length = sample.length;
    final double[][] out = new double[5][];
    int cur = 0;          // beginning of current partition segment
    int offset = 0;       // end of current partition segment
    int sampleCount = 0;  // number of segments defined 
    for (int i = 0; i < 5; i++) {
        if (cur == length || offset == length) {
            break;
        }
        final int next;
        if (i == 4 || cur == length - 1) {
            next = length - 1;
        } else {
            next = (new UniformIntegerDistribution(cur, length - 1)).sample();
        }
        final int subLength = next - cur + 1;
        out[i] = new double[subLength];
        System.arraycopy(sample, offset, out[i], 0, subLength);
        cur = next + 1;
        sampleCount++;
        offset += subLength;
    }
    if (sampleCount < 5) {
        double[][] out2 = new double[sampleCount][];
        for (int j = 0; j < sampleCount; j++) {
            final int curSize = out[j].length;
            out2[j] = new double[curSize];
            System.arraycopy(out[j], 0, out2[j], 0, curSize);
        }
        return out2;
    } else {
        return out;
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:43,代码来源:AggregateSummaryStatisticsTest.java

示例14: GenerateReads

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
/**
 * Generate next generation sequencing (NGS/HTS) reads.
 *
 * @param reference reference, must not be null
 * @param variant FASTQ variant, must not be null
 * @param random random, must not be null
 * @param length length distribution, must not be null
 * @param quality quality strategy, must not be null
 * @param coverage coverage strategy, must not be null
 * @param mutationRate mutation rate, must be between <code>0.0</code> and <code>1.0</code>, inclusive
 * @param mutation mutation strategy, must not be null
 * @param appendable appendable, must not be null
 * @param writer FASTQ writer, must not be null
 */
public GenerateReads(final Sequence reference,
                              final FastqVariant variant,
                              final RandomGenerator random,
                              final RealDistribution length,
                              final QualityStrategy quality,
                              final CoverageStrategy coverage,
                              final double mutationRate,
                              final MutationStrategy mutation,
                              final Appendable appendable,
                              final FastqWriter writer) {

    checkNotNull(reference, "reference must not be null");
    checkNotNull(variant, "variant must not be null");
    checkNotNull(random, "random must not be null");
    checkNotNull(length, "length must not be null");
    checkNotNull(quality, "quality must not be null");
    checkNotNull(coverage, "coverage must not be null");
    checkArgument(mutationRate >= 0.0d, "mutationRate must be greater than or equal to 0.0d");
    checkArgument(mutationRate <= 1.0d, "mutationRate must be less than or equal to 1.0d");
    checkNotNull(mutation, "mutation must not be null");
    checkNotNull(appendable, "appendable must not be null");
    checkNotNull(writer, "writer must not be null");

    this.reference = reference;
    this.variant = variant;
    this.random = random;
    this.length = length;
    this.quality = quality;
    this.coverage = coverage;
    this.mutationRate = mutationRate;
    this.mutation = mutation;
    this.appendable = appendable;
    this.writer = writer;

    int flanking = (int) (length.getNumericalMean() + length.getNumericalVariance());
    location = new UniformIntegerDistribution(this.random, 1 - flanking, this.reference.length() + flanking);
}
 
开发者ID:nmdp-bioinformatics,项目名称:ngs,代码行数:52,代码来源:GenerateReads.java

示例15: generateBackgroundItemsets

import org.apache.commons.math3.distribution.UniformIntegerDistribution; //导入依赖的package包/类
/** Generate some disjoint itemsets as background noise */
public static HashMap<Itemset, Double> generateBackgroundItemsets(
		final int noItemsets, final double p, final int noItems,
		final double mu, final double sigma) {

	final HashMap<Itemset, Double> backgroundItemsets = Maps.newHashMap();

	final GeometricDistribution sizeDist = new GeometricDistribution(
			new Well19937c(1), p);
	final UniformIntegerDistribution itemDist = new UniformIntegerDistribution(
			20, 20 + noItems - 1);
	final LogNormalDistribution probDist = new LogNormalDistribution(
			new Well19937c(1), mu, sigma);

	while (backgroundItemsets.size() < noItemsets) {
		final int len = sizeDist.sample() + 1; // use shifted geometric
		final Itemset set = new Itemset();
		for (int i = 0; i < len; i++) {
			final int samp = itemDist.sample();
			set.add(samp);
		}
		final double num = probDist.sample();
		backgroundItemsets.put(set, num);
	}

	return backgroundItemsets;
}
 
开发者ID:mast-group,项目名称:itemset-mining,代码行数:28,代码来源:TransactionGenerator.java


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