本文整理汇总了Java中org.apache.commons.math3.stat.descriptive.SummaryStatistics.getVariance方法的典型用法代码示例。如果您正苦于以下问题:Java SummaryStatistics.getVariance方法的具体用法?Java SummaryStatistics.getVariance怎么用?Java SummaryStatistics.getVariance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.stat.descriptive.SummaryStatistics
的用法示例。
在下文中一共展示了SummaryStatistics.getVariance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStats
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
private static Stats getStats(FloatColumn values, SummaryStatistics summaryStatistics) {
Stats stats = new Stats("Column: " + values.name());
stats.min = (float) summaryStatistics.getMin();
stats.max = (float) summaryStatistics.getMax();
stats.n = summaryStatistics.getN();
stats.sum = summaryStatistics.getSum();
stats.variance = summaryStatistics.getVariance();
stats.populationVariance = summaryStatistics.getPopulationVariance();
stats.quadraticMean = summaryStatistics.getQuadraticMean();
stats.geometricMean = summaryStatistics.getGeometricMean();
stats.mean = summaryStatistics.getMean();
stats.standardDeviation = summaryStatistics.getStandardDeviation();
stats.sumOfLogs = summaryStatistics.getSumOfLogs();
stats.sumOfSquares = summaryStatistics.getSumsq();
stats.secondMoment = summaryStatistics.getSecondMoment();
return stats;
}
示例2: getKernel
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
/**
* The within-bin smoothing kernel. Returns a Gaussian distribution
* parameterized by {@code bStats}, unless the bin contains only one
* observation, in which case a constant distribution is returned.
*
* @param bStats summary statistics for the bin
* @return within-bin kernel parameterized by bStats
*/
protected RealDistribution getKernel(SummaryStatistics bStats) {
if (bStats.getN() == 1 || bStats.getVariance() == 0) {
return new ConstantRealDistribution(bStats.getMean());
} else {
return new NormalDistribution(randomData.getRandomGenerator(),
bStats.getMean(), bStats.getStandardDeviation(),
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
}
示例3: meanTest
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
/**
* Runs the mean test for the specified instance of Random.
* @param random The RNG instance to test.
* @param doAssert Flag to indicate whether result should be asserted or simply logged.
*/
private void meanTest(Random random, boolean doAssert) {
final String methodName = "meanTest : ";
ndigits = new int[10];
// Initialize the array
for (int i = 0; i < 10; i++) {
ndigits[i] = 0;
}
double x;
int n;
SummaryStatistics stats = new SummaryStatistics();
long start = System.currentTimeMillis();
// Test the random number generator a whole lot
for (long i = 0; i < values; i++) {
// generate a new random number between 0 and 9
x = random.nextDouble() * 10.0;
n = (int) x;
stats.addValue(n);
// count the digits in the random number
ndigits[n]++;
}
long end = System.currentTimeMillis();
LOGGER.info("{} Time: {}ms", methodName, end - start);
LOGGER.info("{} Distribution:", methodName);
// Print the results
for (int i = 0; i < 10; i++) {
LOGGER.info("{} {}: {}", methodName, i, ndigits[i]);
}
double sampleMean = stats.getMean();
double sampleVar = stats.getVariance();
double meanDiff = (sampleMean - mean)/mean;
LOGGER.info("{} mean: {}, diff: {}", methodName, sampleMean, meanDiff);
LOGGER.info("{} sd: {}", methodName, stats.getStandardDeviation());
LOGGER.info("{} var: {}", methodName, sampleVar);
// Verify results.
boolean varResult = sampleVar < var;
String varMsg = "Random Variance exceeds max expectation!";
boolean ci99Result = sampleMean >= smLowerRng3SD
&& sampleMean <= smUpperRng3SD;
String ci99Msg = "Random 99.7% CI test failed!";
boolean ci95Result = sampleMean >= smLowerRng2SD
&& sampleMean <= smUpperRng2SD;
String ci95Msg = "Random 95% CI test failed!";
if (doAssert) {
assertTrue(varMsg, varResult);
assertTrue(ci99Msg, ci99Result);
assertTrue(ci95Msg, ci95Result);
}
else {
if (!varResult) {
LOGGER.warn("{} {}", methodName, varMsg);
}
if (!ci99Result) {
LOGGER.warn("{} {}", methodName, ci99Msg);
}
if (!ci95Result) {
LOGGER.warn("{} {}", methodName, ci95Msg);
}
}
}
示例4: testRdRandRandomMean
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; //导入方法依赖的package包/类
/**
* Tests RdRandRandom by verifying the average of the distribution of digits 0-9
* over 100 million values. Also runs the test for Random and SecureRandom for
* reference.
* Based on Mean Test outlined in <i>Beautiful Testing</i> published by O'Reilly.
* @throws GeneralSecurityException
* @throws SeedException
*/
@Test
public final void testRdRandRandomMean() throws GeneralSecurityException, SeedException {
final String methodName = "testRdRandRandom : ";
SummaryStatistics stats = new SummaryStatistics();
// Initialize the array
ndigits = new int[10];
for (int i = 0; i < 10; i++) {
ndigits[i] = 0;
stats.addValue(i);
}
// Calculate the confidence intervals to assert.
mean = stats.getMean();
stdDev = stats.getStandardDeviation();
var = stats.getVariance();
LOGGER.info("{} Normal mean: {}", methodName, mean);
LOGGER.info("{} Normal std: {}", methodName, stdDev);
LOGGER.info("{} Normal var: {}", methodName, var);
// 99.7% CI is within 3 std.
double expectedDev3SD = 3 * stdDev / Math.sqrt(values);
smLowerRng3SD = mean - expectedDev3SD;
smUpperRng3SD = mean + expectedDev3SD;
// 95% CI is within 2 std.
double expectedDev2SD = 2 * stdDev / Math.sqrt(values);
smLowerRng2SD = mean - expectedDev2SD;
smUpperRng2SD = mean + expectedDev2SD;
LOGGER.info("{} Generating {} values.", methodName, values);
LOGGER.info(
"{} Sample mean expected in range {} - {} 99.7% of the times.",
methodName, smLowerRng3SD, smUpperRng3SD);
LOGGER.info(
"{} Sample mean expected in range {} - {} 95% of the times.",
methodName, smLowerRng2SD, smUpperRng2SD);
LOGGER.info("{} Running for Random..", methodName);
Random random = new Random();
meanTest(random, false);
LOGGER.info("{} Running for RdRand..", methodName);
random = new RdRandRandom();
meanTest(random, true);
LOGGER.info("{} Running for SecureRandom..", methodName);
random = new SecureRandom();
meanTest(random, false);
LOGGER.info("{} Running Uncommons Maths AESCounterRNG using RdRandSeedGenerator..", methodName);
random = new AESCounterRNG(new RdRandSeedGenerator());
meanTest(random, false);
}