Search in sources :

Example 46 with DataColumnDomainCreator

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

the class SubgroupMinerModel2 method createItemsetOutputSpec.

private DataTableSpec createItemsetOutputSpec(final DataTableSpec spec) {
    /*
         * creating the output spec with (maxDepth + 1) String columns and the
         * first column as an int column (the support)
         */
    DataColumnSpec[] colSpecs = new DataColumnSpec[2];
    DataColumnSpecCreator colspeccreator = new DataColumnSpecCreator("Support(0-1):", DoubleCell.TYPE);
    colspeccreator.setDomain(new DataColumnDomainCreator(new DoubleCell(0), new DoubleCell(1)).createDomain());
    colSpecs[0] = colspeccreator.createSpec();
    DataType transType = spec.getColumnSpec(m_transactionColumn.getStringValue()).getType();
    DataType transCollType = transType.getCollectionElementType();
    colSpecs[1] = new DataColumnSpecCreator("Items", transCollType == null ? SetCell.getCollectionType(StringCell.TYPE) : SetCell.getCollectionType(transCollType)).createSpec();
    return new DataTableSpec(colSpecs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataType(org.knime.core.data.DataType)

Example 47 with DataColumnDomainCreator

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

the class BinningCellFactory method getColumnSpecs.

/**
 * {@inheritDoc}
 */
public DataColumnSpec[] getColumnSpecs() {
    DataColumnSpecCreator creator = new DataColumnSpecCreator(m_name, StringCell.TYPE);
    DataCell[] values = new DataCell[m_bins.size()];
    for (int i = 0; i < values.length; i++) {
        values[i] = m_bins.get(i).getValue();
    }
    DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(values);
    creator.setDomain(domainCreator.createDomain());
    return new DataColumnSpec[] { creator.createSpec() };
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 48 with DataColumnDomainCreator

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

the class AutoBinner method calcDomainBoundsIfNeccessary.

/**
 * Determines the per column min/max values of the given data if not already present in the domain.
 *
 * @param data the data
 * @param exec the execution context
 * @param recalcValuesFor The columns
 * @return The data with extended domain information
 * @throws InvalidSettingsException ...
 * @throws CanceledExecutionException ...
 */
public BufferedDataTable calcDomainBoundsIfNeccessary(final BufferedDataTable data, final ExecutionContext exec, final List<String> recalcValuesFor) throws InvalidSettingsException, CanceledExecutionException {
    if (null == recalcValuesFor || recalcValuesFor.isEmpty()) {
        return data;
    }
    List<Integer> valuesI = new ArrayList<Integer>();
    for (String colName : recalcValuesFor) {
        DataColumnSpec colSpec = data.getDataTableSpec().getColumnSpec(colName);
        if (!colSpec.getType().isCompatible(DoubleValue.class)) {
            throw new InvalidSettingsException("Can only process numeric " + "data. The column \"" + colSpec.getName() + "\" is not numeric.");
        }
        if (recalcValuesFor.contains(colName) && !colSpec.getDomain().hasBounds()) {
            valuesI.add(data.getDataTableSpec().findColumnIndex(colName));
        }
    }
    if (valuesI.isEmpty()) {
        return data;
    }
    Map<Integer, Double> min = new HashMap<Integer, Double>();
    Map<Integer, Double> max = new HashMap<Integer, Double>();
    for (int col : valuesI) {
        min.put(col, Double.MAX_VALUE);
        max.put(col, Double.MIN_VALUE);
    }
    int c = 0;
    for (DataRow row : data) {
        c++;
        exec.checkCanceled();
        exec.setProgress(c / (double) data.size());
        for (int col : valuesI) {
            double val = ((DoubleValue) row.getCell(col)).getDoubleValue();
            if (min.get(col) > val) {
                min.put(col, val);
            }
            if (max.get(col) < val) {
                min.put(col, val);
            }
        }
    }
    List<DataColumnSpec> newColSpecList = new ArrayList<DataColumnSpec>();
    int cc = 0;
    for (DataColumnSpec columnSpec : data.getDataTableSpec()) {
        if (recalcValuesFor.contains(columnSpec.getName())) {
            DataColumnSpecCreator specCreator = new DataColumnSpecCreator(columnSpec);
            DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(new DoubleCell(min.get(cc)), new DoubleCell(max.get(cc)));
            specCreator.setDomain(domainCreator.createDomain());
            DataColumnSpec newColSpec = specCreator.createSpec();
            newColSpecList.add(newColSpec);
        } else {
            newColSpecList.add(columnSpec);
        }
        cc++;
    }
    DataTableSpec spec = new DataTableSpec(newColSpecList.toArray(new DataColumnSpec[0]));
    BufferedDataTable newDataTable = exec.createSpecReplacerTable(data, spec);
    return newDataTable;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataRow(org.knime.core.data.DataRow) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 49 with DataColumnDomainCreator

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

the class ClusterMembershipFactory method getColumnSpecs.

/**
 * {@inheritDoc}
 */
public DataColumnSpec[] getColumnSpecs() {
    int nrclusters = m_nrClusters;
    DataColumnSpec[] newSpec = new DataColumnSpec[nrclusters + 1];
    int cluster = 0;
    DataColumnSpecCreator colspecCreator = null;
    for (int j = 0; j < nrclusters; j++) {
        if (m_noise && j == (newSpec.length - 2)) {
            colspecCreator = new DataColumnSpecCreator(FuzzyClusterNodeModel.NOISESPEC_KEY, DoubleCell.TYPE);
            colspecCreator.setProperties(new DataColumnProperties(Collections.singletonMap(DataValueRenderer.PROPERTY_PREFERRED_RENDERER, DoubleBarRenderer.DESCRIPTION)));
            colspecCreator.setDomain(new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0)).createDomain());
            newSpec[j] = colspecCreator.createSpec();
            break;
        }
        colspecCreator = new DataColumnSpecCreator(FuzzyClusterNodeModel.CLUSTER_KEY + cluster, DoubleCell.TYPE);
        colspecCreator.setProperties(new DataColumnProperties(Collections.singletonMap(DataValueRenderer.PROPERTY_PREFERRED_RENDERER, DoubleBarRenderer.DESCRIPTION)));
        colspecCreator.setDomain(new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0)).createDomain());
        newSpec[j] = colspecCreator.createSpec();
        cluster++;
    }
    newSpec[newSpec.length - 1] = new DataColumnSpecCreator("Winner Cluster", StringCell.TYPE).createSpec();
    return newSpec;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataColumnProperties(org.knime.core.data.DataColumnProperties)

Example 50 with DataColumnDomainCreator

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

the class DecTreePredictorNodeModel method createOutTableSpec.

private DataTableSpec createOutTableSpec(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    List<DataCell> predValues = null;
    if (m_showDistribution.getBooleanValue()) {
        predValues = getPredictionValues((PMMLPortObjectSpec) inSpecs[INMODELPORT]);
        if (predValues == null) {
            // no out spec can be determined
            return null;
        }
    }
    int numCols = (predValues == null ? 0 : predValues.size()) + 1;
    DataTableSpec inSpec = (DataTableSpec) inSpecs[INDATAPORT];
    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();
    PredictorHelper predictorHelper = PredictorHelper.getInstance();
    String trainingColumnName = ((PMMLPortObjectSpec) inSpecs[INMODELPORT]).getTargetFields().iterator().next();
    // add all distribution columns
    for (int i = 0; i < numCols - 1; i++) {
        assert predValues != null;
        DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(predictorHelper.probabilityColumnName(trainingColumnName, predValues.get(i).toString(), m_probabilitySuffix.getStringValue()), DoubleCell.TYPE);
        // colSpecCreator.setProperties(propsRendering);
        colSpecCreator.setDomain(domain);
        newCols[i] = colSpecCreator.createSpec();
    }
    // add the prediction column
    String predictionColumnName = predictorHelper.computePredictionColumnName(m_predictionColumn.getStringValue(), m_overridePrediction.getBooleanValue(), 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) PredictorHelper(org.knime.base.node.mine.util.PredictorHelper) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataCell(org.knime.core.data.DataCell)

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