Search in sources :

Example 41 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class MedianTableTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    Random random = new Random(37);
    DataColumnSpec[] colSpecs = new DataColumnSpec[] { new DataColumnSpecCreator("AscendingDouble", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("DescendingDouble", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("ThreeValuesSingleMedian", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("ThreeValuesDifferentMedian", DoubleCell.TYPE).createSpec() // new DataColumnSpecCreator("FourValuesSingleMedian", DoubleCell.TYPE).createSpec(),
    // new DataColumnSpecCreator("FourValuesDifferentMedian", DoubleCell.TYPE).createSpec()
    };
    DataTableSpec spec = new DataTableSpec(colSpecs);
    final BufferedDataContainer container = EXEC_CONTEXT.createDataContainer(spec);
    try {
        int count = 100;
        for (int i = 0; i < count; ++i) {
            int col = 0;
            DataCell[] rowVals = new DataCell[colSpecs.length];
            rowVals[col++] = new DoubleCell(i);
            rowVals[col++] = new DoubleCell(count - i - 1);
            rowVals[col++] = i == 4 ? DataType.getMissingCell() : new DoubleCell(i < count / 2 ? 0 : i * 2 >= count + 2 ? 4 : 1);
            rowVals[col++] = new DoubleCell(i < count / 2 ? 0 : i * 2 >= count + 2 ? 4 : 1);
            container.addRowToTable(new DefaultRow(Integer.toString(i), rowVals));
        }
    } finally {
        container.close();
    }
    smallTable = container.getTable();
    NodeLogger.getLogger(getClass()).debug("Contents of test table:");
    for (DataRow row : smallTable) {
        StringBuilder buf = new StringBuilder();
        for (DataCell dataCell : row) {
            buf.append(dataCell + "\t");
        }
        NodeLogger.getLogger(getClass()).debug(buf.toString());
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) DataRow(org.knime.core.data.DataRow) DataColumnSpec(org.knime.core.data.DataColumnSpec) Random(java.util.Random) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) Before(org.junit.Before)

Example 42 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class StatisticCalculatorTest method createRandomTableWithMissingValues.

private static BufferedDataTable createRandomTableWithMissingValues(final int cols, final int rows) {
    long currentTimeMillis = System.currentTimeMillis();
    System.out.println("Using seed: " + currentTimeMillis);
    Random random = new Random(currentTimeMillis);
    DataTableSpecCreator creator = new DataTableSpecCreator();
    for (int i = 0; i < cols; i++) {
        creator.addColumns(new DataColumnSpecCreator("" + i, DoubleCell.TYPE).createSpec());
    }
    final BufferedDataContainer container = EXEC_CONTEXT.createDataContainer(creator.createSpec());
    for (int i = 0; i < rows; i++) {
        DataCell[] rowVals = new DataCell[cols];
        for (int j = 0; j < cols; j++) {
            rowVals[j] = random.nextDouble() > 0.66 ? new DoubleCell(random.nextDouble()) : DataType.getMissingCell();
        }
        container.addRowToTable(new DefaultRow(Integer.toString(i), rowVals));
        if (i % 1000 == 0) {
            System.out.println("Added row: " + i);
        }
    }
    container.close();
    return container.getTable();
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Random(java.util.Random) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 43 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class SorterNodeModelTest method testExecuteBufferedDataTableArrayExecutionContext.

/**
 * Test method for {@link org.knime.base.node.preproc.sorter.SorterNodeModel#execute(org.knime.core.node.BufferedDataTable[], org.knime.core.node.ExecutionContext)}.
 * @throws Exception
 * @throws CanceledExecutionException
 */
@Test
public final void testExecuteBufferedDataTableArrayExecutionContext() throws CanceledExecutionException, Exception {
    // try to sort a table with 1 entry
    String[] columnNames = { "col1", "col2", "col3", "col4" };
    DataType[] columnTypes = { DoubleCell.TYPE, StringCell.TYPE, IntCell.TYPE, DoubleCell.TYPE };
    DataRow[] rows = new DataRow[1];
    DataCell[] myRow = new DataCell[4];
    myRow[0] = new DoubleCell(2.4325);
    myRow[1] = new StringCell("Test");
    myRow[2] = new IntCell(7);
    myRow[3] = new DoubleCell(32432.324);
    rows[0] = new DefaultRow(Integer.toString(1), myRow);
    DataTable[] inputTable = { new DefaultTable(rows, columnNames, columnTypes) };
    DataTable[] resultTable = { new DefaultTable(rows, columnNames, columnTypes) };
    // set settings
    String[] includeCols = { "col1", "col2", "col3", "col4" };
    m_settings.addStringArray(SorterNodeModel.INCLUDELIST_KEY, includeCols);
    boolean[] sortorder = { true, true, true, true };
    m_settings.addBooleanArray(SorterNodeModel.SORTORDER_KEY, sortorder);
    m_snm.loadValidatedSettingsFrom(m_settings);
    resultTable = m_snm.execute(EXEC_CONTEXT.createBufferedDataTables(inputTable, EXEC_CONTEXT), EXEC_CONTEXT);
    // test output
    RowIterator rowIt = resultTable[0].iterator();
    Assert.assertTrue(rowIt.hasNext());
    Assert.assertEquals(rows[0], rowIt.next());
    Assert.assertFalse(rowIt.hasNext());
    m_snm.reset();
    // *********************************************//
    // try to sort a large array of DataRows
    // In this case we generate a unit matrix
    // *********************************************//
    // start with a little one
    int dimension = 50;
    // *********************************************//
    // set settings
    includeCols = new String[dimension];
    for (int i = 0; i < dimension; i++) {
        includeCols[i] = "col" + i;
    }
    m_settings.addStringArray(SorterNodeModel.INCLUDELIST_KEY, includeCols);
    sortorder = new boolean[dimension];
    for (int i = 0; i < dimension; i++) {
        sortorder[i] = true;
    }
    m_settings.addBooleanArray(SorterNodeModel.SORTORDER_KEY, sortorder);
    DataTable[] inputTable2 = { generateUnitMatrixTable(dimension) };
    m_snm.loadValidatedSettingsFrom(m_settings);
    resultTable = m_snm.execute(EXEC_CONTEXT.createBufferedDataTables(inputTable2, EXEC_CONTEXT), EXEC_CONTEXT);
    // test output (should have sorted all rows in reverse order)
    rowIt = resultTable[0].iterator();
    Assert.assertTrue(rowIt.hasNext());
    int k = dimension - 1;
    while (rowIt.hasNext()) {
        RowKey rk = rowIt.next().getKey();
        int ic = Integer.parseInt(rk.getString());
        Assert.assertEquals(k, ic);
        k--;
    }
    Assert.assertFalse(rowIt.hasNext());
    m_snm.reset();
    // *********************************************//
    // try to sort a very large array of DataRows
    // In this case we generate a unit matrix
    // *********************************************//
    // dimension 300 => 15,8 secs.
    // dimension 500 => 49,7 secs.
    dimension = 100;
    // *********************************************//
    // set settings
    includeCols = new String[dimension];
    for (int i = 0; i < dimension; i++) {
        includeCols[i] = "col" + i;
    }
    m_settings.addStringArray(SorterNodeModel.INCLUDELIST_KEY, includeCols);
    sortorder = new boolean[dimension];
    for (int i = 0; i < dimension; i++) {
        sortorder[i] = true;
    }
    m_settings.addBooleanArray(SorterNodeModel.SORTORDER_KEY, sortorder);
    DataTable[] inputTable3 = { generateUnitMatrixTable(dimension) };
    m_snm.loadValidatedSettingsFrom(m_settings);
    resultTable = m_snm.execute(EXEC_CONTEXT.createBufferedDataTables(inputTable3, EXEC_CONTEXT), EXEC_CONTEXT);
    // test output (should have sorted all rows in reverse order)
    rowIt = resultTable[0].iterator();
    Assert.assertTrue(rowIt.hasNext());
    k = dimension - 1;
    while (rowIt.hasNext()) {
        RowKey rk = rowIt.next().getKey();
        int ic = Integer.parseInt(rk.getString());
        Assert.assertEquals(k, ic);
        k--;
    }
    Assert.assertFalse(rowIt.hasNext());
    m_snm.reset();
}
Also used : DataTable(org.knime.core.data.DataTable) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultTable(org.knime.core.data.def.DefaultTable) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell) StringCell(org.knime.core.data.def.StringCell) RowIterator(org.knime.core.data.RowIterator) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) Test(org.junit.Test)

Example 44 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class LogisticRegressionContent method createCoeffStatisticsTablePortObject.

/**
 * Creates a BufferedDataTable with the
 * @param exec The execution context
 * @return a port object
 */
public BufferedDataTable createCoeffStatisticsTablePortObject(final ExecutionContext exec) {
    DataTableSpec tableOutSpec = LogRegCoordinator.createCoeffStatisticsTableSpec();
    BufferedDataContainer dc = exec.createDataContainer(tableOutSpec);
    List<DataCell> logits = this.getLogits();
    List<String> parameters = this.getParameters();
    int c = 0;
    for (DataCell logit : logits) {
        Map<String, Double> coefficients = this.getCoefficients(logit);
        Map<String, Double> stdErrs;
        Map<String, Double> zScores;
        Map<String, Double> pValues;
        if (m_covMat == null) {
            HashMap<String, Double> emptyMap = new HashMap<>();
            stdErrs = emptyMap;
            zScores = emptyMap;
            pValues = emptyMap;
        } else {
            stdErrs = this.getStandardErrors(logit);
            zScores = this.getZScores(logit);
            pValues = this.getPValues(logit);
        }
        for (String parameter : parameters) {
            List<DataCell> cells = new ArrayList<>();
            cells.add(new StringCell(logit.toString()));
            cells.add(new StringCell(parameter));
            cells.add(new DoubleCell(coefficients.get(parameter)));
            if (m_covMat != null) {
                cells.add(new DoubleCell(stdErrs.get(parameter)));
                cells.add(new DoubleCell(zScores.get(parameter)));
                cells.add(new DoubleCell(pValues.get(parameter)));
            } else {
                cells.add(NOT_INVERTIBLE_MISSING);
                cells.add(NOT_INVERTIBLE_MISSING);
                cells.add(NOT_INVERTIBLE_MISSING);
            }
            c++;
            dc.addRowToTable(new DefaultRow("Row" + c, cells));
        }
        List<DataCell> cells = new ArrayList<>();
        cells.add(new StringCell(logit.toString()));
        cells.add(new StringCell("Constant"));
        cells.add(new DoubleCell(this.getIntercept(logit)));
        if (m_covMat != null) {
            cells.add(new DoubleCell(this.getInterceptStdErr(logit)));
            cells.add(new DoubleCell(this.getInterceptZScore(logit)));
            cells.add(new DoubleCell(this.getInterceptPValue(logit)));
        } else {
            cells.add(NOT_INVERTIBLE_MISSING);
            cells.add(NOT_INVERTIBLE_MISSING);
            cells.add(NOT_INVERTIBLE_MISSING);
        }
        c++;
        dc.addRowToTable(new DefaultRow("Row" + c, cells));
    }
    dc.close();
    return dc.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 45 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class SampleDataNodeModel method createRow.

private static DataRow createRow(final RowKey key, final double[] d, final DataCell cl) {
    DataCell[] cells = new DataCell[d.length + 1];
    for (int i = 0; i < d.length; i++) {
        cells[i] = new DoubleCell(d[i]);
    }
    cells[d.length] = cl;
    return new DefaultRow(key, cells);
}
Also used : DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

DoubleCell (org.knime.core.data.def.DoubleCell)189 DataCell (org.knime.core.data.DataCell)129 IntCell (org.knime.core.data.def.IntCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)66 StringCell (org.knime.core.data.def.StringCell)65 DataRow (org.knime.core.data.DataRow)57 DataTableSpec (org.knime.core.data.DataTableSpec)55 ArrayList (java.util.ArrayList)42 DataColumnSpec (org.knime.core.data.DataColumnSpec)42 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)41 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)39 RowKey (org.knime.core.data.RowKey)37 DoubleValue (org.knime.core.data.DoubleValue)35 BufferedDataTable (org.knime.core.node.BufferedDataTable)28 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)22 DataType (org.knime.core.data.DataType)20 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 Point (java.awt.Point)12