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


Java RandomGenerator.nextInt方法代码示例

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


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

示例1: testLargeSamples

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testLargeSamples() throws IOException {
    RandomGenerator random = new Well1024a(0x35ddecfc78131e1dl);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
    for (int k = 0; k < 50; ++k) {

        // define the reference sphere we want to compute
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector3D refCenter = new Vector3D(d, new Vector3D(sr.nextVector()));
        // set up a large sample inside the reference sphere
        int nbPoints = random.nextInt(1000);
        List<Vector3D> points = new ArrayList<Vector3D>();
        for (int i = 0; i < nbPoints; ++i) {
            double r = refRadius * random.nextDouble();
            points.add(new Vector3D(1.0, refCenter, r, new Vector3D(sr.nextVector())));
        }

        // test we find a sphere at most as large as the one used for random drawings
        checkSphere(points, refRadius);

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

示例2: uniformSelect

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
public static <T> T uniformSelect( Collection<T> collection ) {
	if (collection.size()==0) {
		System.out.println("IS EMPTY!!!");
		return null;
	}
	int idx = 0;
	if (collection.size()>1) {
		RandomGenerator rg = getInstance().get();
		idx = rg.nextInt(collection.size());
	}
	int counter = 0;
	T last = null;
	for (T t : collection) {
		last = t;
		if (counter == idx) {
			return t;
		} else {
			counter++;
		}
	}
	return last;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:RandomGeneratorRegistry.java

示例3: randomize

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public Iterator<E> randomize(final RandomGenerator random) {
    return new Iterator<E>() {

        private final int size = sample.size();
        private int resampleIdx = 0;

        @Override
        public boolean hasNext() {
            return resampleIdx < size;
        }

        @Override
        public E next() {
            final int sourceIdx = random.nextInt(size);
            resampleIdx++;
            return sample.get(sourceIdx);
        }

    };
}
 
开发者ID:subes,项目名称:invesdwin-util,代码行数:22,代码来源:BootstrapRandomizer.java

示例4: randomize

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public Iterator<E> randomize(final RandomGenerator random) {
    return new Iterator<E>() {

        private int resampleIdx = 0;

        @Override
        public boolean hasNext() {
            return resampleIdx < sampleSize;
        }

        @Override
        public E next() {
            final List<E> sampleChunk = getSampleChunk(random);
            final int sourceIdx = random.nextInt(sampleChunk.size());
            resampleIdx++;
            return sampleChunk.get(sourceIdx);
        }

    };
}
 
开发者ID:subes,项目名称:invesdwin-util,代码行数:22,代码来源:WeightedChunksAscendingRandomizer.java

示例5: sample

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/**
 * Sample a dataset
 * @param numSamples the number of samples to getFromOrigin
 * @param rng the rng to use
 * @param withReplacement whether to allow duplicates (only tracked by example row number)
 * @return the sample dataset
 */
@Override
public DataSet sample(int numSamples, RandomGenerator rng, boolean withReplacement) {
    if(numSamples >= numExamples())
        return this;
    else {
        INDArray examples = Nd4j.create(numSamples, getFeatures().columns());
        INDArray outcomes = Nd4j.create(numSamples, numOutcomes());
        Set<Integer> added = new HashSet<Integer>();
        for(int i = 0; i < numSamples; i++) {
            int picked = rng.nextInt(numExamples());
            if(!withReplacement)
                while(added.contains(picked)) {
                    picked = rng.nextInt(numExamples());

                }
            examples.putRow(i,get(picked).getFeatures());
            outcomes.putRow(i,get(picked).getLabels());

        }
        return new DataSet(examples,outcomes);
    }
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:30,代码来源:DataSet.java

示例6: generate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  int user = random.nextInt(numUsers);
  int randProduct = random.nextInt(numProducts);
  // Want product === user mod features
  int product = ((user % features) + (randProduct / features) * features) % numProducts;
  String datum = ALSUtilsTest.idToStringID(user) + "," + ALSUtilsTest.idToStringID(product) +
      ",1," + System.currentTimeMillis();
  return new Pair<>(Integer.toString(id), datum);
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:11,代码来源:FeaturesALSDataGenerator.java

示例7: generate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  String userString = ALSUtilsTest.idToStringID(random.nextInt(numUsers));
  String itemString = ALSUtilsTest.idToStringID(random.nextInt(numProducts));
  int rating = random.nextInt(maxRating - minRating + 1) + minRating;
  String datum = userString + "," +  itemString + "," + rating + "," + System.currentTimeMillis();
  return new Pair<>(Integer.toString(id), datum);
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:9,代码来源:RandomALSDataGenerator.java

示例8: generate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  return new Pair<>(Integer.toString(id),
                    id + "," +
                    random.nextInt(100) + ',' +
                    random.nextBoolean() + ',' +
                    random.nextGaussian());
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:9,代码来源:DefaultCSVDatumGenerator.java

示例9: getDestination

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
public static int getDestination(double now, int loc, RandomGenerator r) {
		if (loc == getLocId(1, 1)) {
			return r.nextInt(NUMBER_OF_LOCATIONS);
		} else {
			return getLocId(1, 1);
		}
//		return r.nextInt(NUMBER_OF_LOCATIONS);
	}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:9,代码来源:SmartTaxisDefinitions.java

示例10: testLargeSamples

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testLargeSamples() {
    RandomGenerator random = new Well1024a(0xa2a63cad12c01fb2l);
    for (int k = 0; k < 100; ++k) {
        int nbPoints = random.nextInt(10000);
        List<Vector2D> points = new ArrayList<Vector2D>();
        for (int i = 0; i < nbPoints; ++i) {
            double x = random.nextDouble();
            double y = random.nextDouble();
            points.add(new Vector2D(x, y));
        }
        checkDisk(points);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:15,代码来源:WelzlEncloser2DTest.java

示例11: testFloorDivModInt

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testFloorDivModInt() {
    RandomGenerator generator = new Well1024a(0x7ccab45edeaab90al);
    for (int i = 0; i < 10000; ++i) {
        int a = generator.nextInt();
        int b = generator.nextInt();
        if (b == 0) {
            try {
                FastMath.floorDiv(a, b);
                Assert.fail("an exception should have been thrown");
            } catch (MathArithmeticException mae) {
                // expected
            }
        } else {
            int d = FastMath.floorDiv(a, b);
            int m = FastMath.floorMod(a, b);
            Assert.assertEquals(FastMath.toIntExact(poorManFloorDiv(a, b)), d);
            Assert.assertEquals(FastMath.toIntExact(poorManFloorMod(a, b)), m);
            Assert.assertEquals(a, d * b + m);
            if (b < 0) {
                Assert.assertTrue(m <= 0);
                Assert.assertTrue(-m < -b);
            } else {
                Assert.assertTrue(m >= 0);
                Assert.assertTrue(m < b);
            }
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:30,代码来源:FastMathTest.java

示例12: randomPositions

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
public static List<SimpleInterval> randomPositions(final String contig, final int chainLength, final RandomGenerator rng, final double separationScale) {
    final List<SimpleInterval> positions = new ArrayList<>();
    int position = 1;
    for (int n = 0; n < chainLength; n++) {
        position += rng.nextInt((int) separationScale);
        final SimpleInterval interval = new SimpleInterval(contig, position, position);
        positions.add(interval);
    }
    return positions;
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:11,代码来源:CopyRatioSegmenterUnitTest.java

示例13: setValueToRandom

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public void setValueToRandom(RandomGenerator rg) {
    size = rg.nextInt(maxSize);
    super.setValueToRandom(rg);
}
 
开发者ID:AVMf,项目名称:avmf,代码行数:6,代码来源:StringVariable.java

示例14: setValueToRandom

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public void setValueToRandom(RandomGenerator randomGenerator) {
    int range = max - min + 1;
    int randomValue = randomGenerator.nextInt(range);
    setValue(min + randomValue);
}
 
开发者ID:AVMf,项目名称:avmf,代码行数:7,代码来源:AtomicVariable.java

示例15: mate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/**
 * Helper for {@link #crossover(Chromosome, Chromosome)}. Performs the actual crossover.
 *
 * @param first the first chromosome
 * @param second the second chromosome
 * @return the pair of new chromosomes that resulted from the crossover
 * @throws DimensionMismatchException if the length of the two chromosomes is different
 * @throws NumberIsTooLargeException if the number of crossoverPoints is too large for the actual chromosomes
 */
private ChromosomePair mate(final AbstractListChromosome<T> first,
                            final AbstractListChromosome<T> second)
    throws DimensionMismatchException, NumberIsTooLargeException {

    final int length = first.getLength();
    if (length != second.getLength()) {
        throw new DimensionMismatchException(second.getLength(), length);
    }
    if (crossoverPoints >= length) {
        throw new NumberIsTooLargeException(crossoverPoints, length, false);
    }

    // array representations of the parents
    final List<T> parent1Rep = first.getRepresentation();
    final List<T> parent2Rep = second.getRepresentation();
    // and of the children
    final List<T> child1Rep = new ArrayList<T>(length);
    final List<T> child2Rep = new ArrayList<T>(length);

    final RandomGenerator random = GeneticAlgorithm.getRandomGenerator();

    List<T> c1 = child1Rep;
    List<T> c2 = child2Rep;

    int remainingPoints = crossoverPoints;
    int lastIndex = 0;
    for (int i = 0; i < crossoverPoints; i++, remainingPoints--) {
        // select the next crossover point at random
        final int crossoverIndex = 1 + lastIndex + random.nextInt(length - lastIndex - remainingPoints);

        // copy the current segment
        for (int j = lastIndex; j < crossoverIndex; j++) {
            c1.add(parent1Rep.get(j));
            c2.add(parent2Rep.get(j));
        }

        // swap the children for the next segment
        List<T> tmp = c1;
        c1 = c2;
        c2 = tmp;

        lastIndex = crossoverIndex;
    }

    // copy the last segment
    for (int j = lastIndex; j < length; j++) {
        c1.add(parent1Rep.get(j));
        c2.add(parent2Rep.get(j));
    }

    return new ChromosomePair(first.newFixedLengthChromosome(child1Rep),
                              second.newFixedLengthChromosome(child2Rep));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:63,代码来源:NPointCrossover.java


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