Search in sources :

Example 96 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class KnnNodeModel method createRearranger.

/*
     * @param maxRows - can be -1 if can't be determined (streaming)
     */
private ColumnRearranger createRearranger(final DataTableSpec in, final DataColumnSpec classColumnSpec, final List<Integer> featureColumns, final Map<Integer, Integer> firstToSecond, final KDTree<DataCell> tree, final double maxRows) {
    ColumnRearranger c = new ColumnRearranger(in);
    String newName = "Class [kNN]";
    while (in.containsName(newName)) {
        newName += "_dup";
    }
    List<DataColumnSpec> colSpecs = new ArrayList<DataColumnSpec>();
    DataColumnSpecCreator crea = new DataColumnSpecCreator(classColumnSpec);
    crea.setName(newName);
    colSpecs.add(crea.createSpec());
    final DataCell[] possibleValues;
    if (m_settings.outputClassProbabilities()) {
        possibleValues = classColumnSpec.getDomain().getValues().toArray(new DataCell[0]);
        Arrays.sort(possibleValues, new Comparator<DataCell>() {

            @Override
            public int compare(final DataCell o1, final DataCell o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
        for (DataCell posVal : possibleValues) {
            newName = posVal.toString();
            while (in.containsName(newName)) {
                newName += "_dup";
            }
            crea = new DataColumnSpecCreator(newName, DoubleCell.TYPE);
            colSpecs.add(crea.createSpec());
        }
    } else {
        possibleValues = new DataCell[0];
    }
    final DataColumnSpec[] colSpecArray = colSpecs.toArray(new DataColumnSpec[colSpecs.size()]);
    c.append(new AbstractCellFactory(colSpecArray) {

        /**
         * {@inheritDoc}
         */
        @Override
        public void setProgress(final long curRowNr, final long rowCount, final RowKey lastKey, final ExecutionMonitor exec) {
            if (maxRows > 0) {
                exec.setProgress(curRowNr / maxRows, "Classifying row " + lastKey);
            } else {
                exec.setProgress("Classifying row " + lastKey);
            }
        }

        @Override
        public DataCell[] getCells(final DataRow row) {
            List<DataCell> output = classify(row, tree, featureColumns, firstToSecond, possibleValues);
            return output.toArray(new DataCell[output.size()]);
        }
    });
    return c;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) RowKey(org.knime.core.data.RowKey) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) ArrayList(java.util.ArrayList) DataRow(org.knime.core.data.DataRow) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 97 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class PCANodeModel method createAddTableSpec.

/**
 * create part of table spec to be added to the input table.
 *
 * @param inSpecs
 *            input specs (for unique column names)
 * @param resultDimensions
 *            number of dimensions in output
 * @return part of table spec to be added to input table
 */
public static DataColumnSpec[] createAddTableSpec(final DataTableSpec inSpecs, final int resultDimensions) {
    // append pca columns
    final DataColumnSpec[] specs = new DataColumnSpec[resultDimensions];
    for (int i = 0; i < resultDimensions; i++) {
        final String colName = DataTableSpec.getUniqueColumnName(inSpecs, PCA_COL_PREFIX + i);
        final DataColumnSpecCreator specCreator = new DataColumnSpecCreator(colName, DataType.getType(DoubleCell.class));
        specs[i] = specCreator.createSpec();
    }
    return specs;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString)

Example 98 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class PCANodeModel method createDecompositionTableSpec.

/**
 * create table spec for output of spectral decomposition.
 *
 * @param columnNames
 *            names of the input columns
 * @return table spec (first col for eigenvalues, others for components of
 *         eigenvectors)
 */
public static DataTableSpec createDecompositionTableSpec(final String[] columnNames) {
    final DataColumnSpecCreator createEVCol = new DataColumnSpecCreator("eigenvalue", DoubleCell.TYPE);
    final DataColumnSpec[] colsSpecs = new DataColumnSpec[columnNames.length + 1];
    colsSpecs[0] = createEVCol.createSpec();
    for (int i = 1; i < colsSpecs.length; i++) {
        colsSpecs[i] = new DataColumnSpecCreator(columnNames[i - 1], DoubleCell.TYPE).createSpec();
    }
    final DataTableSpec info = new DataTableSpec("spectral decomposition", colsSpecs);
    return info;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec)

Example 99 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class MDSNodeModel method getColumnSpecs.

/**
 * The <code>DataColumnSpec</code>s of the mds data (columns).
 *
 * @param dimensions The dimension of the mds data.
 * @return The <code>DataColumnSpec</code>s of the mds data.
 * @deprecated should not be used anymore, since column rearranger creates
 * the output spec.
 */
@Deprecated
static DataColumnSpec[] getColumnSpecs(final int dimensions) {
    DataColumnSpec[] specs = new DataColumnSpec[dimensions];
    for (int i = 0; i < dimensions; i++) {
        DataColumnSpecCreator creator = new DataColumnSpecCreator("MDS Col " + (i + 1), DoubleCell.TYPE);
        specs[i] = creator.createSpec();
    }
    return specs;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator)

Example 100 with DataColumnSpecCreator

use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.

the class MDSProjectionNodeModel method getColumnSpecs.

/**
 * The <code>DataColumnSpec</code>s of the mds data (columns).
 *
 * @param dimensions The dimension of the mds data.
 * @return The <code>DataColumnSpec</code>s of the mds data.
 * @deprecated should not be used anymore, since column rearranger creates
 * the output spec.
 * @since 2.6
 *    @Deprecated
 */
@Deprecated
static DataColumnSpec[] getColumnSpecs(final int dimensions) {
    DataColumnSpec[] specs = new DataColumnSpec[dimensions];
    for (int i = 0; i < dimensions; i++) {
        DataColumnSpecCreator creator = new DataColumnSpecCreator("MDS Col " + (i + 1), DoubleCell.TYPE);
        specs[i] = creator.createSpec();
    }
    return specs;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator)

Aggregations

DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)267 DataColumnSpec (org.knime.core.data.DataColumnSpec)210 DataTableSpec (org.knime.core.data.DataTableSpec)132 DataCell (org.knime.core.data.DataCell)92 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)77 DataType (org.knime.core.data.DataType)74 DataRow (org.knime.core.data.DataRow)73 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)57 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)51 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)48 ArrayList (java.util.ArrayList)46 DoubleCell (org.knime.core.data.def.DoubleCell)45 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)44 StringCell (org.knime.core.data.def.StringCell)29 BufferedDataTable (org.knime.core.node.BufferedDataTable)23 DoubleValue (org.knime.core.data.DoubleValue)22 HashSet (java.util.HashSet)19 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)17 DataColumnDomain (org.knime.core.data.DataColumnDomain)16 DefaultRow (org.knime.core.data.def.DefaultRow)16