use of cern.jet.random.ChiSquare in project voldemort by voldemort.
the class ConsistentRoutingStrategyTest method assertWellBalanced.
private void assertWellBalanced(int numNodes, Multiset<Integer> ids) {
// compute the chi-sq statistic
double expected = ids.size() / (double) numNodes;
double chiSq = 0.0;
int df = numNodes - 1;
NumberFormat prct = NumberFormat.getPercentInstance();
prct.setMaximumFractionDigits(4);
NumberFormat num = NumberFormat.getInstance();
num.setMaximumFractionDigits(4);
num.setMinimumFractionDigits(4);
System.out.println("node\treqs\tX^2\tskew");
for (Integer id : ids.elementSet()) {
System.out.println(id + "\t" + ids.count(id) + "\t" + num.format(chiSq(ids.count(id), expected)) + "\t" + prct.format((ids.count(id) - expected) / expected));
chiSq += chiSq(ids.count(id), expected);
}
System.out.println("X^2 = " + chiSq);
ChiSquare dist = new ChiSquare(df, new MersenneTwister());
// p-value is ~= prob of seeing this distribution from fair router
double pValue = 1.0 - dist.cdf(chiSq);
System.out.println("p-value = " + pValue);
assertTrue("Non-uniform load distribution detected.", pValue >= 0.05);
}
use of cern.jet.random.ChiSquare in project processdash by dtuma.
the class LognormalConfidenceInterval method generateBootstrapSamples.
private double[] generateBootstrapSamples() {
RandomEngine u = new MersenneTwister();
Normal normal = new Normal(0, 1, u);
ChiSquare chisquare = new ChiSquare(numSamples - 1, u);
int bootstrapSize = Settings.getInt("logCI.bootstrapSize", 2000);
double[] samples = new double[bootstrapSize];
for (int i = bootstrapSize; i-- > 0; ) samples[i] = generateBootstrapSample(normal, chisquare, numSamples, logstd);
Arrays.sort(samples);
return samples;
}
Aggregations