Search in sources :

Example 41 with DefaultRow

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

the class TreeEnsembleModelExtractorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    TreeEnsembleModelPortObject treeEnsembleModel = (TreeEnsembleModelPortObject) inObjects[0];
    DataTableSpec outSpec = createOutSpec();
    BufferedDataContainer container = exec.createDataContainer(outSpec, false, 0);
    int nrModels = treeEnsembleModel.getEnsembleModel().getNrModels();
    for (int i = 0; i < nrModels; i++) {
        PMMLPortObject pmmlObject = treeEnsembleModel.createDecisionTreePMMLPortObject(i);
        DataCell cell = PMMLCellFactory.create(pmmlObject.getPMMLValue().toString());
        RowKey key = RowKey.createRowKey(i);
        container.addRowToTable(new DefaultRow(key, cell));
        exec.checkCanceled();
        exec.setProgress(i / (double) nrModels, "Exported model " + (i + 1) + "/" + nrModels);
    }
    container.close();
    return new BufferedDataTable[] { container.getTable() };
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) RowKey(org.knime.core.data.RowKey) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 42 with DefaultRow

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

the class JoinedTableTest method getRandomRow.

private static final DataRow getRandomRow(final String id) {
    DataCell[] cells = new DataCell[3];
    cells[0] = new StringCell(id + "-" + RAND.nextInt(100));
    cells[1] = new IntCell(RAND.nextInt());
    cells[2] = new DoubleCell(RAND.nextDouble());
    return new DefaultRow(id, cells);
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 43 with DefaultRow

use of org.knime.core.data.def.DefaultRow 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 44 with DefaultRow

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

the class CovarianceMatrixCalculatorTest method generateData.

/**
 * @param random
 * @param size
 * @param data
 */
private BufferedDataContainer generateData(final Random random, final double[][] data, final DataTableSpec spec) {
    BufferedDataContainer createDataContainer = m_exec.createDataContainer(spec);
    for (int j = 0; j < data.length; j++) {
        double[] row = new double[spec.getNumColumns()];
        for (int i = 0; i < spec.getNumColumns(); i++) {
            {
                row[i] = random.nextDouble();
            }
        }
        data[j] = row;
        createDataContainer.addRowToTable(new DefaultRow(RowKey.createRowKey(j), row));
    }
    return createDataContainer;
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 45 with DefaultRow

use of org.knime.core.data.def.DefaultRow 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)

Aggregations

DefaultRow (org.knime.core.data.def.DefaultRow)207 DataCell (org.knime.core.data.DataCell)165 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)94 DataTableSpec (org.knime.core.data.DataTableSpec)92 DataRow (org.knime.core.data.DataRow)88 RowKey (org.knime.core.data.RowKey)80 DoubleCell (org.knime.core.data.def.DoubleCell)66 StringCell (org.knime.core.data.def.StringCell)65 BufferedDataTable (org.knime.core.node.BufferedDataTable)56 IntCell (org.knime.core.data.def.IntCell)46 ArrayList (java.util.ArrayList)26 DataType (org.knime.core.data.DataType)26 DataColumnSpec (org.knime.core.data.DataColumnSpec)22 DataContainer (org.knime.core.data.container.DataContainer)21 HashSet (java.util.HashSet)18 LinkedHashMap (java.util.LinkedHashMap)17 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)16 LinkedHashSet (java.util.LinkedHashSet)14 DoubleValue (org.knime.core.data.DoubleValue)14 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)14