当前位置: 首页>>代码示例>>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;未经允许,请勿转载。