use of org.knime.base.data.statistics.calculation.Median in project knime-core by knime.
the class StatisticCalculatorTest method testMedian.
/**
* Tests the median.
*
* @throws InvalidSettingsException
* @throws CanceledExecutionException
*/
@Test
public void testMedian() throws InvalidSettingsException, CanceledExecutionException {
Median median = new Median(FEATURE1, FEATURE2, STRING_FEATURE);
StatisticCalculator statisticCalculator = new StatisticCalculator(testTable.getDataTableSpec(), median);
statisticCalculator.evaluate(testTable, EXEC_CONTEXT);
System.out.println(median.getMedian(STRING_FEATURE));
Statistics3Table stat3Table = new Statistics3Table(testTable, true, 0, Collections.<String>emptyList(), EXEC_CONTEXT, ascendingIntArray(testTable.getDataTableSpec().getNumColumns()));
assertEquals(stat3Table.getMedian(0), Double.valueOf(median.getMedian(FEATURE1).toString()), 0.001);
assertEquals(stat3Table.getMedian(1), Double.valueOf(median.getMedian(FEATURE2).toString()), 0.001);
assertEquals("F", median.getMedian(STRING_FEATURE).toString());
}
use of org.knime.base.data.statistics.calculation.Median in project knime-core by knime.
the class StatisticCalculatorTest method medianPerformanceTest.
/**
* Test median performance.
*
* @throws Exception
*/
@Test
@Ignore
public void medianPerformanceTest() throws Exception {
int cols = 100;
final BufferedDataTable table = createRandomTableWithMissingValues(cols, 500000);
System.out.println("MEASSURING NOW: " + "Sorting");
long t = System.currentTimeMillis();
Median median = new Median();
// Mean mean = new Mean();
StatisticCalculator statisticCalculator = new StatisticCalculator(table.getDataTableSpec(), table.getDataTableSpec().getColumnNames(), median);
statisticCalculator.evaluate(table, EXEC_CONTEXT);
System.out.println("Result: " + median.getMedian("0"));
System.out.println("finished: " + (System.currentTimeMillis() - t) / 1000d + " sec");
}
use of org.knime.base.data.statistics.calculation.Median in project knime-core by knime.
the class StatisticCalculatorTest method doubleMedianTest.
/**
* Tests the median with double cells.
*
* @throws Exception e
*/
@Test
public void doubleMedianTest() throws Exception {
// create some random tables with random missing values
for (int i = 0; i < 50; i++) {
final BufferedDataTable table = createRandomTableWithMissingValues(4, 100);
Statistics3Table statistics3Table = new Statistics3Table(table, true, 0, Collections.<String>emptyList(), EXEC_CONTEXT, ascendingIntArray(4));
Median median = new Median();
StatisticCalculator statisticCalculator = new StatisticCalculator(table.getDataTableSpec(), table.getDataTableSpec().getColumnNames(), median);
statisticCalculator.evaluate(table, EXEC_CONTEXT);
for (int j = 0; j < 4; j++) {
double oldMed = statistics3Table.getMedian(j);
double newMed = ((DoubleValue) median.getMedian(table.getDataTableSpec().getColumnSpec(j).getName())).getDoubleValue();
assertEquals(oldMed, newMed, 0.00001);
}
}
}
Aggregations