Search in sources :

Example 1 with Median

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());
}
Also used : Median(org.knime.base.data.statistics.calculation.Median) Test(org.junit.Test)

Example 2 with Median

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");
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) Median(org.knime.base.data.statistics.calculation.Median) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Median

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);
        }
    }
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) BufferedDataTable(org.knime.core.node.BufferedDataTable) Median(org.knime.base.data.statistics.calculation.Median) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Median (org.knime.base.data.statistics.calculation.Median)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 Ignore (org.junit.Ignore)1 DoubleValue (org.knime.core.data.DoubleValue)1