本文整理汇总了Java中org.apache.commons.math3.stat.inference.TTest类的典型用法代码示例。如果您正苦于以下问题:Java TTest类的具体用法?Java TTest怎么用?Java TTest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TTest类属于org.apache.commons.math3.stat.inference包,在下文中一共展示了TTest类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: acceptSignificantBenefitWith10Threads
import org.apache.commons.math3.stat.inference.TTest; //导入依赖的package包/类
@Test
public void acceptSignificantBenefitWith10Threads() throws Exception {
// given
final int nThreads = 10;
// when
final Tuple2<DescriptiveStatistics, DescriptiveStatistics> results =
measure(nThreads, generatorSupplier, nMeasurements, taskFactory);
// then
assertThat(results.second().getMean(), is(lessThan(results.first().getMean())));
double p = new TTest().tTest(results.first(), results.second());
System.out.println("t-Test: p=" + p);
assertThat(p, is(lessThanOrEqualTo(HIGHLY_SIGNIFICANT.getAlpha())));
}
示例2: checkTimeSeriesSimularityTtest
import org.apache.commons.math3.stat.inference.TTest; //导入依赖的package包/类
private boolean checkTimeSeriesSimularityTtest(double[] r_generated, double[] java_generated) {
TTest t_test_obj = new TTest();
// Performs a paired t-test evaluating the null hypothesis that the mean of the paired
// differences between sample1
// and sample2 is 0 in favor of the two-sided alternative that the mean paired difference is not
// equal to 0,
// with significance level 0.05.
double p_value = t_test_obj.tTest(r_generated, java_generated);
boolean reject_null_hyphothesis = (p_value < 0.05);
return reject_null_hyphothesis;
}
示例3: evaluate
import org.apache.commons.math3.stat.inference.TTest; //导入依赖的package包/类
@Override
public double evaluate(double[] baseline, double[] treatment) {
double[] boostedBaseline = multiply(baseline, boost);
/*
double sampleSum = 0;
double sampleSumSquares = 0;
int n = boostedBaseline.length;
for (int i = 0; i < baseline.length; i++) {
double delta = treatment[i] - boostedBaseline[i];
sampleSum += delta;
sampleSumSquares += delta * delta;
}
double sampleVariance = sampleSumSquares / (n - 1);
double sampleMean = sampleSum / baseline.length;
double sampleDeviation = Math.sqrt(sampleVariance);
double meanDeviation = sampleDeviation / Math.sqrt(n);
double t = sampleMean / meanDeviation;
return 1.0 - Stat.studentTProb(t, n - 1);
*/
//- Use Apache Commons Math3 directly for t-test p-value calculation
TTest tt = new TTest();
double pval = tt.tTest (boostedBaseline, treatment);
return 1.0 - pval;
}
示例4: checkTimeSeriesSimularityTtest
import org.apache.commons.math3.stat.inference.TTest; //导入依赖的package包/类
private boolean checkTimeSeriesSimularityTtest(double[] r_generated, double[] java_generated) {
TTest t_test_obj = new TTest();
// Performs a paired t-test evaluating the null hypothesis that the mean of the paired differences between sample1
// and sample2 is 0 in favor of the two-sided alternative that the mean paired difference is not equal to 0,
// with significance level 0.05.
double p_value = t_test_obj.tTest(r_generated, java_generated);
boolean reject_null_hyphothesis = (p_value < 0.05);
return reject_null_hyphothesis;
}
示例5: evaluate
import org.apache.commons.math3.stat.inference.TTest; //导入依赖的package包/类
/**
* T-test on a given pair of ArrayOfDoublesSketches
* @param serializedSketchA ArrayOfDoublesSketch in as serialized binary
* @param serializedSketchB ArrayOfDoublesSketch in as serialized binary
* @return list of p-values
*/
public List<Double> evaluate(final BytesWritable serializedSketchA, final BytesWritable serializedSketchB) {
if (serializedSketchA == null || serializedSketchB == null) { return null; }
final ArrayOfDoublesSketch sketchA =
ArrayOfDoublesSketches.wrapSketch(Memory.wrap(serializedSketchA.getBytes()));
final ArrayOfDoublesSketch sketchB =
ArrayOfDoublesSketches.wrapSketch(Memory.wrap(serializedSketchB.getBytes()));
if (sketchA.getNumValues() != sketchB.getNumValues()) {
throw new IllegalArgumentException("Both sketches must have the same number of values");
}
// If the sketches contain fewer than 2 values, the p-value can't be calculated
if (sketchA.getRetainedEntries() < 2 || sketchB.getRetainedEntries() < 2) {
return null;
}
final SummaryStatistics[] summariesA = ArrayOfDoublesSketchStats.sketchToSummaryStatistics(sketchA);
final SummaryStatistics[] summariesB = ArrayOfDoublesSketchStats.sketchToSummaryStatistics(sketchB);
final TTest tTest = new TTest();
final List<Double> pValues = new ArrayList<Double>(sketchA.getNumValues());
for (int i = 0; i < sketchA.getNumValues(); i++) {
pValues.add(tTest.tTest(summariesA[i], summariesB[i]));
}
return pValues;
}
示例6: exec
import org.apache.commons.math3.stat.inference.TTest; //导入依赖的package包/类
@Override
public Tuple exec(final Tuple input) throws IOException {
if ((input == null) || (input.size() != 2)) {
return null;
}
// Get the two sketches
final DataByteArray dbaA = (DataByteArray) input.get(0);
final DataByteArray dbaB = (DataByteArray) input.get(1);
final ArrayOfDoublesSketch sketchA = ArrayOfDoublesSketches.wrapSketch(Memory.wrap(dbaA.get()));
final ArrayOfDoublesSketch sketchB = ArrayOfDoublesSketches.wrapSketch(Memory.wrap(dbaB.get()));
// Check that the size of the arrays in the sketches are the same
if (sketchA.getNumValues() != sketchB.getNumValues()) {
throw new IllegalArgumentException("Both sketches must have the same number of values");
}
// Store the number of metrics
final int numMetrics = sketchA.getNumValues();
// If the sketches contain fewer than 2 values, the p-value can't be calculated
if (sketchA.getRetainedEntries() < 2 || sketchB.getRetainedEntries() < 2) {
return null;
}
// Get the statistical summary from each sketch
final SummaryStatistics[] summariesA = ArrayOfDoublesSketchStats.sketchToSummaryStatistics(sketchA);
final SummaryStatistics[] summariesB = ArrayOfDoublesSketchStats.sketchToSummaryStatistics(sketchB);
// Calculate the p-values
final TTest tTest = new TTest();
final Tuple pValues = TupleFactory.getInstance().newTuple(numMetrics);
for (int i = 0; i < numMetrics; i++) {
// Pass the sampled values for each metric
pValues.set(i, tTest.tTest(summariesA[i], summariesB[i]));
}
return pValues;
}
示例7: predictLabelsForColumn
import org.apache.commons.math3.stat.inference.TTest; //导入依赖的package包/类
public boolean predictLabelsForColumn(Map<String, ArrayList<Double>> trainingLabelToExamplesMap,
ArrayList<Double> testExamples, int numPred, ArrayList<String> predictions, ArrayList<Double> confidenceScores) {
List<Prediction> sortedPredictions = new ArrayList<Prediction>(); // descending order of p-Value
TTest test = new TTest();
double pValue;
double[] sample1 = new double[testExamples.size()];
for(int i = 0; i < testExamples.size(); i++){
sample1[i] = testExamples.get(i);
}
for (Entry<String, ArrayList<Double>> entry : trainingLabelToExamplesMap.entrySet()) {
String label = entry.getKey();
ArrayList<Double> trainExamples = entry.getValue();
double[] sample2 = new double[trainExamples.size()];
for(int i = 0; i < trainExamples.size(); i++){
sample2[i] = trainExamples.get(i);
}
pValue = test.tTest(sample1, sample2);
Prediction pred = new Prediction(label, pValue);
// double tValue = Math.abs(test.t(sample1, sample2));
// Prediction pred = new Prediction(label, tValue);
sortedPredictions.add(pred);
}
// sorting based on p-Value
Collections.sort(sortedPredictions, new PredictionComparator());
for(int j=0; j<numPred && j<sortedPredictions.size(); j++)
{
predictions.add(sortedPredictions.get(j).predictionLabel);
confidenceScores.add(sortedPredictions.get(j).confidenceScore);
}
return true;
}