當前位置: 首頁>>代碼示例>>Java>>正文


Java RandomDataGenerator.reSeed方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.random.RandomDataGenerator.reSeed方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomDataGenerator.reSeed方法的具體用法?Java RandomDataGenerator.reSeed怎麽用?Java RandomDataGenerator.reSeed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.random.RandomDataGenerator的用法示例。


在下文中一共展示了RandomDataGenerator.reSeed方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testExpectedValues

import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
@Test
public void testExpectedValues() {
	
	long seed = 0;
	Random rand = new Random (seed);
	RandomDataGenerator randomData = new RandomDataGenerator(); 

	double uniformAverage = 0.0;
	double binomialAverage = 0.0;
	double normalAverage = 0.0;
	double exponentialAverage = 0.0;
	
	for(int i=0; i<1e6; i++){
		
		// set current seed
		randomData.reSeed(seed);

		// draw random numbers
		double n = randomData.nextGaussian(0, 1);
		double u = randomData.nextUniform(0, 1);
		double b = randomData.nextBinomial(1, 0.5);
		double e = randomData.nextExponential(0.25);
		
		// average mean random number
		uniformAverage += (1. / (1.+i))*(u - uniformAverage);
		binomialAverage += (1. / (1.+i))*(b - binomialAverage);
		normalAverage += (1. / (1.+i))*(n - normalAverage);
		exponentialAverage += (1. / (1.+i))*(e - exponentialAverage);
		
		// draw new seed from global random generator
		seed = rand.nextLong();
	}
	
	assertEquals (0.5, uniformAverage, 0.001);
	assertEquals (0.5, binomialAverage, 0.001);
	assertEquals (0.0, normalAverage, 0.001);
	assertEquals (0.25, exponentialAverage, 0.001);
}
 
開發者ID:siemens,項目名稱:industrialbenchmark,代碼行數:39,代碼來源:RandomNumberExpectedValueTest.java

示例2: createMatrixOfGaussianValues

import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
private RealMatrix createMatrixOfGaussianValues(int numRows, int numCols, final double mean, final double sigma) {
    final RealMatrix bigCounts = new Array2DRowRealMatrix(numRows, numCols);
    final RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
    randomDataGenerator.reSeed(337337337);
    bigCounts.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() {
        @Override
        public double visit(int row, int column, double value) {
            return randomDataGenerator.nextGaussian(mean, sigma);
        }
    });
    return bigCounts;
}
 
開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:13,代碼來源:HDF5LibraryUnitTest.java

示例3: createMatrixOfGaussianValues

import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
private static RealMatrix createMatrixOfGaussianValues(final int numRows,
                                                       final int numColumns,
                                                       final double mean,
                                                       final double sigma) {
    final RealMatrix largeMatrix = new Array2DRowRealMatrix(numRows, numColumns);
    final RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
    randomDataGenerator.reSeed(337337337);
    largeMatrix.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() {
        @Override
        public double visit(int row, int column, double value) {
            return randomDataGenerator.nextGaussian(mean, sigma);
        }
    });
    return largeMatrix;
}
 
開發者ID:broadinstitute,項目名稱:gatk,代碼行數:16,代碼來源:HDF5UtilsUnitTest.java

示例4: DataGenerator

import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
public DataGenerator() {
    rand = new RandomDataGenerator();
    rand.reSeed();
    deleteLater = new Vector<EmitterModel>();
}
 
開發者ID:zitmen,項目名稱:thunderstorm,代碼行數:6,代碼來源:DataGenerator.java

示例5: generate

import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
public void generate(int sleep_frequency) throws InterruptedException {
        ThroughputLog throughput = new ThroughputLog(this.getClass().getSimpleName());
        long time = System.currentTimeMillis();

        // Obtain a cached thread pool
        ExecutorService cachedPool = Executors.newCachedThreadPool();

        RandomDataGenerator generator = new RandomDataGenerator();
        generator.reSeed(10000000L);
        // sub thread use variable in main thread
        // for loop to generate advertisement

        ArrayList<Advertisement> advList = new ArrayList<>();
        for (long i = 1; i < ADV_NUM; ++i) {
            // advertisement id
            String advId = UUID.randomUUID().toString();
            long timestamp = System.currentTimeMillis();
            producer.send(new ProducerRecord<>(ADV_TOPIC, advId, String.format("%d\t%s", timestamp, advId)));
//            System.out.println("Shown: " + System.currentTimeMillis() + "\t" + advId);

            // whether customer clicked this advertisement
            if (generator.nextUniform(0, 1) <= clickProbability) {
//                long deltaT = (long)generator.nextExponential(clickLambda)*1000;
                long deltaT = (long) generator.nextGaussian(clickLambda, 1) * 1000;
//                System.out.println(deltaT);
                advList.add(new Advertisement(advId, timestamp + deltaT));
            }

            if (i % 100 == 0) {
                cachedPool.submit(new ClickThread(advList));
                advList = new ArrayList<>();
            }

            throughput.execute();
            // control data generate speed
            if (sleep_frequency > 0 && i % sleep_frequency == 0) {
                Thread.sleep(1);
            }

        }
        cachedPool.shutdown();
        try {
            cachedPool.awaitTermination(1, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
        }

        logger.info("LatencyLog: " + String.valueOf(System.currentTimeMillis() - time));

    }
 
開發者ID:wangyangjun,項目名稱:StreamBench,代碼行數:50,代碼來源:AdvClick.java


注:本文中的org.apache.commons.math3.random.RandomDataGenerator.reSeed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。