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


Java RandomGenerator.setSeed方法代码示例

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


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

示例1: testNaNsFixedTiesRandom

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testNaNsFixedTiesRandom() {
    RandomGenerator randomGenerator = new JDKRandomGenerator();
    randomGenerator.setSeed(1000);
    NaturalRanking ranking = new NaturalRanking(NaNStrategy.FIXED,
            randomGenerator);
    double[] ranks = ranking.rank(exampleData);
    double[] correctRanks = { 5, 3, 6, 7, 3, 8, Double.NaN, 1, 2 };
    TestUtils.assertEquals(correctRanks, ranks, 0d);
    ranks = ranking.rank(tiesFirst);
    correctRanks = new double[] { 1, 2, 4, 3, 5 };
    TestUtils.assertEquals(correctRanks, ranks, 0d);
    ranks = ranking.rank(tiesLast);
    correctRanks = new double[] { 3, 3, 2, 1 };
    TestUtils.assertEquals(correctRanks, ranks, 0d);
    ranks = ranking.rank(multipleNaNs);
    correctRanks = new double[] { 1, 2, Double.NaN, Double.NaN };
    TestUtils.assertEquals(correctRanks, ranks, 0d);
    ranks = ranking.rank(multipleTies);
    correctRanks = new double[] { 3, 2, 4, 4, 6, 7, 1 };
    TestUtils.assertEquals(correctRanks, ranks, 0d);
    ranks = ranking.rank(allSame);
    correctRanks = new double[] { 2, 3, 3, 3 };
    TestUtils.assertEquals(correctRanks, ranks, 0d);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:NaturalRankingTest.java

示例2: testStoredVsDirect

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testStoredVsDirect() {
    final RandomGenerator rand= new JDKRandomGenerator();
    rand.setSeed(Long.MAX_VALUE);
    for (final int sampleSize:sampleSizes) {
        final double[] data = new NormalDistribution(rand,4000, 50)
                            .sample(sampleSize);
        for (final double p:new double[] {50d,95d}) {
            for (final Percentile.EstimationType e : Percentile.EstimationType.values()) {
                reset(p, e);
                final Percentile pStoredData = getUnivariateStatistic();
                pStoredData.setData(data);
                final double storedDataResult=pStoredData.evaluate();
                pStoredData.setData(null);
                final Percentile pDirect = getUnivariateStatistic();
                Assert.assertEquals("Sample="+sampleSize+",P="+p+" e="+e,
                        storedDataResult,
                        pDirect.evaluate(data),0d);
            }
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:PercentileTest.java

示例3: RandomStructureGenerator

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/**
 * Creates the generator
 * @param nVariables number of nodes in the BN
 * @param maxNParents Maximum number of parents per nodes - sampled from U(0,maxNParents) 
 * @param maxNValuesPerNode Maximum number of outcome per nodes - sampled from U(2,maxNValuesPerNode)
 * @param nDataPoints Number of samples to generate
 * @param alphaDirichlet will sample each multinomial in the CPT (ie line) from Dir(alphaDirichlet). The highest value of alpha, the harder it will be to detect the correlations. 
 * @param seed Seed to pass to one of the random generator
 */
public RandomStructureGenerator(int nVariables, int maxNParents,int maxNValuesPerNode,int nDataPoints, double alphaDirichlet, long seed) {
	this.nVariables = nVariables;
	this.nDataPoints = nDataPoints;
	this.maxNParents = maxNParents;
	this.maxNValuesPerNode = maxNValuesPerNode;
	this.alphaDirichlet = alphaDirichlet; 

	RandomGenerator rg = new JDKRandomGenerator();
	rg.setSeed(seed);
	this.r = new RandomDataGenerator(rg);
	this.bn = null;
}
 
开发者ID:fpetitjean,项目名称:DataGeneratorBN,代码行数:22,代码来源:RandomStructureGenerator.java

示例4: generate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
public void generate(int sleep_frequency) throws InterruptedException {
//        GenerateCentroids();
        centroids = loadCentroids();
        long time = System.currentTimeMillis();
        ThroughputLog throughput = new ThroughputLog(this.getClass().getSimpleName());
        Random centroid_random = new Random(2342342170123L);
        RandomGenerator point_random = new JDKRandomGenerator();
        point_random.setSeed(8624214);

        for (long generated_points = 0; generated_points < POINT_NUM; generated_points++) {

            int centroid_index = centroid_random.nextInt(centroids.size());
            MultivariateNormalDistribution distribution = new MultivariateNormalDistribution(point_random, means, covariances);

            double[] point = distribution.sample();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < dimension - 1; i++) {
                point[i] += centroids.get(centroid_index).location[i];
                sb.append(point[i]).append("\t");
            }
            point[dimension - 1] += centroids.get(centroid_index).location[dimension - 1];
            sb.append(point[dimension - 1]).append(Constant.TimeSeparator).append(System.currentTimeMillis());

            throughput.execute();
            ProducerRecord<String, String> newRecord = new ProducerRecord<>(TOPIC, sb.toString());
            producer.send(newRecord);
//            System.out.println(sb.toString());
            // control data generate speed
            if (sleep_frequency > 0 && generated_points % sleep_frequency == 0) {
                Thread.sleep(1);
            }
        }

        producer.close();
        logger.info("LatencyLog: " + String.valueOf(System.currentTimeMillis() - time));
    }
 
开发者ID:wangyangjun,项目名称:StreamBench,代码行数:37,代码来源:KMeansPoints.java

示例5: makeEmpirical

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/** Create empirical distribution from given samples.
 * 
 * @param samples Samples (does not need to be distinct) to use.
 * @return Empirical distribution built from the samples.
 */
public static EmpiricalDistribution makeEmpirical(double[] samples) {
	/* Be deterministic for now. */
	RandomGenerator gen = new JDKRandomGenerator();
	gen.setSeed(0);
	
	EmpiricalDistribution result = new EmpiricalDistribution(samples.length / 10 + 1, gen);
	result.load(samples);
	
	return result;
}
 
开发者ID:D-iii-S,项目名称:spl-evaluation-java,代码行数:16,代码来源:DistributionUtils.java

示例6: testInterleavingGenerator

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testInterleavingGenerator() {

	final Random random = new Random(1);
	final Random randomI = new Random(10);
	final RandomGenerator randomC = new JDKRandomGenerator();
	randomC.setSeed(100);

	final Multiset<Sequence> seqsI = HashMultiset.create();
	seqsI.add(new Sequence(1, 2, 3));
	seqsI.add(new Sequence(4, 5));
	seqsI.add(new Sequence(6));
	seqsI.add(new Sequence(7));

	final HashMap<Sequence, Double> seqsG = new HashMap<>();
	for (final Sequence seq : seqsI.elementSet()) {
		seqsG.put(seq, 1.0);
	}

	final Map<Sequence, EnumeratedIntegerDistribution> countDists = new HashMap<>();
	final EnumeratedIntegerDistribution oneRepeat = new EnumeratedIntegerDistribution(randomC, new int[] { 1 },
			new double[] { 1.0 });
	countDists.put(new Sequence(1, 2, 3), oneRepeat);
	countDists.put(new Sequence(4, 5), oneRepeat);
	countDists.put(new Sequence(6), oneRepeat);
	countDists.put(new Sequence(7), oneRepeat);

	final HashSet<Transaction> transG = new HashSet<>();
	for (int i = 0; i < 700000; i++)
		transG.add(
				TransactionGenerator.sampleFromDistribution(random, seqsG, countDists, new HashMap<>(), randomI));
	// Note that upper bound is exact when there are no repetitions
	assertEquals(transG.size(), modP(seqsI.iterator()), EPS);
}
 
开发者ID:mast-group,项目名称:sequence-mining,代码行数:35,代码来源:PartitionTest.java

示例7: generateTransactionDatabase

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/**
 * Generate transactions from set of interesting sequences
 *
 * @return set of sequences added to transaction
 */
public static HashMap<Sequence, Double> generateTransactionDatabase(final Map<Sequence, Double> sequences,
		final Table<Sequence, Integer, Double> probabilities, final int noTransactions, final File outFile)
				throws IOException {

	// Set random number seeds
	final Random random = new Random(1);
	final Random randomI = new Random(10);
	final RandomGenerator randomC = new JDKRandomGenerator();
	randomC.setSeed(100);

	// Storage for sequences actually added
	final HashMap<Sequence, Double> addedSequences = new HashMap<>();

	// Set output file
	final PrintWriter out = new PrintWriter(outFile, "UTF-8");

	// Add to distribution class for easy sampling
	final Map<Sequence, EnumeratedIntegerDistribution> dists = new HashMap<>();
	for (final Sequence seq : sequences.keySet()) {
		final List<Integer> singletons = new ArrayList<>();
		final List<Double> probs = new ArrayList<>();
		for (final Entry<Integer, Double> entry : probabilities.row(seq).entrySet()) {
			singletons.add(entry.getKey());
			probs.add(entry.getValue());
		}
		final EnumeratedIntegerDistribution dist = new EnumeratedIntegerDistribution(randomC,
				Ints.toArray(singletons), Doubles.toArray(probs));
		dists.put(seq, dist);
	}

	// Generate transaction database
	int count = 0;
	while (count < noTransactions) {

		// Generate transaction from distribution
		final Transaction transaction = sampleFromDistribution(random, sequences, dists, addedSequences, randomI);
		for (final int item : transaction) {
			out.print(item + " -1 ");
		}
		if (!transaction.isEmpty()) {
			out.print("-2");
			out.println();
			count++;
		}

	}
	out.close();

	// Print file to screen
	if (VERBOSE) {
		final FileReader reader = new FileReader(outFile);
		final LineIterator it = new LineIterator(reader);
		while (it.hasNext()) {
			System.out.println(it.nextLine());
		}
		LineIterator.closeQuietly(it);
	}

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


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