use of org.knime.base.data.statistics.calculation.Mean in project knime-core by knime.
the class StatisticCalculatorTest method testGeneralStats.
/**
* Tests common statistics.
*
* @throws InvalidSettingsException
* @throws CanceledExecutionException
*/
@Test
public void testGeneralStats() throws InvalidSettingsException, CanceledExecutionException {
BufferedDataTable createRandomTable = createRandomTableWithMissingValues(20, 8);
Skewness skewness = new Skewness();
MinMax minMax = new MinMax();
DoubleMinMax doubleMinMax = new DoubleMinMax(true);
Kurtosis kurtosis = new Kurtosis();
Mean mean = new Mean();
Variance variance = new Variance();
StandardDeviation sDev = new StandardDeviation();
MissingValue missingValue = new MissingValue();
SpecialDoubleCells sdc = new SpecialDoubleCells();
StatisticCalculator statisticCalculator = new StatisticCalculator(createRandomTable.getDataTableSpec(), createRandomTable.getSpec().getColumnNames(), skewness, minMax, kurtosis, mean, variance, missingValue, sDev, doubleMinMax, sdc);
statisticCalculator.evaluate(createRandomTable, EXEC_CONTEXT);
Statistics3Table statistics3Table = new Statistics3Table(createRandomTable, false, 0, Collections.<String>emptyList(), EXEC_CONTEXT);
for (int i = 0; i < createRandomTable.getDataTableSpec().getNumColumns(); i++) {
String colName = "" + i;
assertEquals(statistics3Table.getMean(i), mean.getResult(colName), 0.0001);
assertEquals(statistics3Table.getKurtosis(i), kurtosis.getResult(colName), 0.0001);
checkValueOrMissingIfNaN(statistics3Table.getMin()[i], minMax.getMin(colName));
assertEquals(statistics3Table.getMinCells()[i], minMax.getMin(colName));
checkValueOrMissingIfNaN(doubleMinMax.getMin(colName), statistics3Table.getNonInfMin(i));
checkValueOrMissingIfNaN(statistics3Table.getMax()[i], minMax.getMax(colName));
assertEquals(statistics3Table.getMaxCells()[i], minMax.getMax(colName));
checkValueOrMissingIfNaN(doubleMinMax.getMax(colName), statistics3Table.getNonInfMax(i));
assertEquals(statistics3Table.getVariance(i), variance.getResult(colName), 0.0001);
assertEquals(statistics3Table.getStandardDeviation(i), sDev.getResult(colName), 0.0001);
assertEquals(statistics3Table.getNumberMissingValues(i), missingValue.getNumberMissingValues(colName), 0.0001);
assertEquals(statistics3Table.getNumberNegativeInfiniteValues(i), sdc.getNumberNegativeInfiniteValues(colName), 0.0001);
assertEquals(statistics3Table.getNumberPositiveInfiniteValues(i), sdc.getNumberPositiveInfiniteValues(colName), 0.0001);
assertEquals(statistics3Table.getNumberNaNValues(i), sdc.getNumberNaNValues(colName), 0.0001);
}
}
use of org.knime.base.data.statistics.calculation.Mean in project knime-core by knime.
the class StatisticCalculatorTest method testOrderingOfColumns.
/**
* Tests common statistics.
*
* @throws InvalidSettingsException
* @throws CanceledExecutionException
*/
@Test
public void testOrderingOfColumns() throws InvalidSettingsException, CanceledExecutionException {
Mean mean = new Mean();
StatisticCalculator statisticCalculator = new StatisticCalculator(testTable.getDataTableSpec(), new String[] { FEATURE2, FEATURE1 }, mean);
statisticCalculator.evaluate(testTable, EXEC_CONTEXT);
assertEquals(4.1111, mean.getResult(FEATURE1), 0.0001);
assertEquals(3.2857, mean.getResult(FEATURE2), 0.0001);
Mean mean2 = new Mean();
StatisticCalculator statisticCalculator2 = new StatisticCalculator(testTable.getDataTableSpec(), new String[] { FEATURE1, FEATURE2 }, mean2);
statisticCalculator2.evaluate(testTable, EXEC_CONTEXT);
assertEquals(4.1111, mean2.getResult(FEATURE1), 0.0001);
assertEquals(3.2857, mean2.getResult(FEATURE2), 0.0001);
}
Aggregations