當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。