Search in sources :

Example 16 with DataColumnDomainCreator

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

the class DefaultDataArray method setMaxValue.

/**
 * Sets a new max value for the specified column.
 *
 * @param colIdx the index of the column to set the new max value for
 * @param newMaxValue the new max value for the specified column. Must not
 *            be <code>null</code> and must fit the type of the column.
 */
public void setMaxValue(final int colIdx, final DataCell newMaxValue) {
    if (newMaxValue == null) {
        throw new IllegalArgumentException("The new maximum value must not be null");
    }
    if (!m_tSpec.getColumnSpec(colIdx).getType().isASuperTypeOf(newMaxValue.getType())) {
        throw new IllegalArgumentException("new maximum value is of wrong type");
    }
    DataColumnSpec[] colSpecs = new DataColumnSpec[m_tSpec.getNumColumns()];
    for (int i = 0; i < colSpecs.length; i++) {
        colSpecs[i] = m_tSpec.getColumnSpec(i);
    }
    DataColumnSpecCreator sCrea = new DataColumnSpecCreator(colSpecs[colIdx]);
    DataColumnDomainCreator dCrea = new DataColumnDomainCreator(colSpecs[colIdx].getDomain());
    dCrea.setUpperBound(newMaxValue);
    sCrea.setDomain(dCrea.createDomain());
    colSpecs[colIdx] = sCrea.createSpec();
    m_tSpec = new DataTableSpec(m_tSpec.getName(), colSpecs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 17 with DataColumnDomainCreator

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

the class DefaultDataArray method setMinValue.

/**
 * Sets a new min value for the specified column.
 *
 * @param colIdx the index of the column to set the new min value for. Must
 *            be between zero and the size of this container.
 * @param newMinValue the new min value for the specified column. Must not
 *            be <code>null</code> and must fit the type of the column.
 */
public void setMinValue(final int colIdx, final DataCell newMinValue) {
    if (newMinValue == null) {
        throw new IllegalArgumentException("The new minimum value must not be null");
    }
    if (!m_tSpec.getColumnSpec(colIdx).getType().isASuperTypeOf(newMinValue.getType())) {
        throw new IllegalArgumentException("new minimum value is of wrong type");
    }
    DataColumnSpec[] colSpecs = new DataColumnSpec[m_tSpec.getNumColumns()];
    for (int i = 0; i < colSpecs.length; i++) {
        colSpecs[i] = m_tSpec.getColumnSpec(i);
    }
    DataColumnSpecCreator sCrea = new DataColumnSpecCreator(colSpecs[colIdx]);
    DataColumnDomainCreator dCrea = new DataColumnDomainCreator(colSpecs[colIdx].getDomain());
    dCrea.setLowerBound(newMinValue);
    sCrea.setDomain(dCrea.createDomain());
    colSpecs[colIdx] = sCrea.createSpec();
    m_tSpec = new DataTableSpec(m_tSpec.getName(), colSpecs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 18 with DataColumnDomainCreator

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

the class SVMPredictor method getColumnSpecs.

/**
 * {@inheritDoc}
 */
@Override
public DataColumnSpec[] getColumnSpecs() {
    DataColumnSpecCreator colspeccreator = new DataColumnSpecCreator(m_predictionColumnName, StringCell.TYPE);
    if (m_appendProbabilities) {
        final DataColumnSpec[] ret = new DataColumnSpec[m_svms.length + 1];
        PredictorHelper ph = PredictorHelper.getInstance();
        final DataColumnSpecCreator creator = new DataColumnSpecCreator("Dummy", DoubleCell.TYPE);
        creator.setDomain(new DataColumnDomainCreator(new DoubleCell(0), new DoubleCell(1)).createDomain());
        for (int i = m_svms.length; i-- > 0; ) {
            String name = ph.probabilityColumnName(m_trainingColumn, m_svms[i].getPositive(), m_suffix);
            creator.setName(name);
            ret[i] = creator.createSpec();
        }
        ret[m_svms.length] = colspeccreator.createSpec();
        return ret;
    }
    return new DataColumnSpec[] { colspeccreator.createSpec() };
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) PredictorHelper(org.knime.base.node.mine.util.PredictorHelper) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 19 with DataColumnDomainCreator

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

the class PredictorHelper method createOutTableSpec.

/**
 * Computes the output table's specifaction based on common node settings.
 *
 * @param dataSpec The input table {@link DataColumnSpec}.
 * @param modelSpec The model {@link PMMLPortObjectSpec}.
 * @param addProbs Add the probability columns?
 * @param predictionCol Custom name of the prediction column.
 * @param shouldOverride Should we use that name?
 * @param suffix Suffix for probability columns.
 * @return The output table {@link DataTableSpec}.
 * @throws InvalidSettingsException Invalid settings for the prediction column name.
 */
public DataTableSpec createOutTableSpec(final PortObjectSpec dataSpec, final PortObjectSpec modelSpec, final boolean addProbs, final String predictionCol, final boolean shouldOverride, final String suffix) throws InvalidSettingsException {
    CheckUtils.checkSettingNotNull(predictionCol, "Prediction column name cannot be null");
    CheckUtils.checkSetting(!predictionCol.trim().isEmpty(), "Prediction column name cannot be empty");
    List<DataCell> predValues = null;
    if (addProbs) {
        predValues = getPredictionValues((PMMLPortObjectSpec) modelSpec);
        if (predValues == null) {
            // no out spec can be determined
            return null;
        }
    }
    int numCols = (predValues == null ? 0 : predValues.size()) + 1;
    DataTableSpec inSpec = (DataTableSpec) dataSpec;
    DataColumnSpec[] newCols = new DataColumnSpec[numCols];
    /* Set bar renderer and domain [0,1] as default for the double cells
         * containing the distribution */
    // DataColumnProperties propsRendering = new DataColumnProperties(
    // Collections.singletonMap(
    // DataValueRenderer.PROPERTY_PREFERRED_RENDERER,
    // DoubleBarRenderer.DESCRIPTION));
    DataColumnDomain domain = new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0)).createDomain();
    String trainingColumnName = ((PMMLPortObjectSpec) modelSpec).getTargetFields().iterator().next();
    // add all distribution columns
    for (int i = 0; i < numCols - 1; i++) {
        assert predValues != null;
        DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(probabilityColumnName(trainingColumnName, predValues.get(i).toString(), suffix), DoubleCell.TYPE);
        // colSpecCreator.setProperties(propsRendering);
        colSpecCreator.setDomain(domain);
        newCols[i] = colSpecCreator.createSpec();
    }
    // add the prediction column
    String predictionColumnName = computePredictionColumnName(predictionCol, shouldOverride, trainingColumnName);
    newCols[numCols - 1] = new DataColumnSpecCreator(predictionColumnName, StringCell.TYPE).createSpec();
    DataTableSpec newColSpec = new DataTableSpec(newCols);
    return new DataTableSpec(inSpec, newColSpec);
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DialogComponentString(org.knime.core.node.defaultnodesettings.DialogComponentString)

Example 20 with DataColumnDomainCreator

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

the class OneMissingValueReplacementFunction method getDataTableSpec.

/**
 * {@inheritDoc}
 */
@Override
public DataTableSpec getDataTableSpec() {
    DataTableSpec spec = getFactory().getModelSpec();
    final int idx = spec.getNumColumns() - 5;
    final DataColumnSpec cspec = spec.getColumnSpec(idx);
    DataColumnSpecCreator cr = new DataColumnSpecCreator(cspec);
    TreeSet<DataCell> domValues = new TreeSet<DataCell>(cspec.getType().getComparator());
    domValues.addAll(m_bfs.keySet());
    if (cspec.getDomain().hasValues()) {
        domValues.addAll(cspec.getDomain().getValues());
    }
    cr.setDomain(new DataColumnDomainCreator(domValues).createDomain());
    ColumnRearranger colre = new ColumnRearranger(spec);
    colre.replace(new SingleCellFactory(cr.createSpec()) {

        @Override
        public DataCell getCell(final DataRow row) {
            return row.getCell(idx);
        }
    }, idx);
    return colre.createSpec();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TreeSet(java.util.TreeSet) DataCell(org.knime.core.data.DataCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow)

Aggregations

DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)57 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)51 DataColumnSpec (org.knime.core.data.DataColumnSpec)43 DoubleCell (org.knime.core.data.def.DoubleCell)28 DataCell (org.knime.core.data.DataCell)27 DataTableSpec (org.knime.core.data.DataTableSpec)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)15 ArrayList (java.util.ArrayList)14 DataColumnDomain (org.knime.core.data.DataColumnDomain)12 DataRow (org.knime.core.data.DataRow)12 DataType (org.knime.core.data.DataType)12 DoubleValue (org.knime.core.data.DoubleValue)11 StringCell (org.knime.core.data.def.StringCell)8 BufferedDataTable (org.knime.core.node.BufferedDataTable)7 LinkedHashSet (java.util.LinkedHashSet)6 Coordinate (org.knime.base.util.coordinate.Coordinate)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 LinkedHashMap (java.util.LinkedHashMap)5 NumericCoordinate (org.knime.base.util.coordinate.NumericCoordinate)5