本文整理匯總了Java中org.apache.commons.math3.random.RandomDataGenerator.nextBinomial方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomDataGenerator.nextBinomial方法的具體用法?Java RandomDataGenerator.nextBinomial怎麽用?Java RandomDataGenerator.nextBinomial使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.random.RandomDataGenerator
的用法示例。
在下文中一共展示了RandomDataGenerator.nextBinomial方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getBlinks
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
private int getBlinks(RandomDataGenerator dataGenerator, double averageBlinks)
{
switch (blinkingDistribution)
{
case 3:
// Binomial distribution
return dataGenerator.nextBinomial((int) Math.round(averageBlinks), p);
case 2:
return (int) Math.round(averageBlinks);
case 1:
return StandardFluorophoreSequenceModel.getBlinks(true, dataGenerator, averageBlinks);
default:
return StandardFluorophoreSequenceModel.getBlinks(false, dataGenerator, averageBlinks);
}
}
示例2: 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);
}