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() };
}
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);
}
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());
}
}
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;
}
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();
}
Aggregations