Search in sources :

Example 91 with DataType

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

the class Smoter method distance.

/* Determines the Euclidean distance of two rows. */
private double distance(final DataRow row1, final DataRow row2) {
    double d = 0.0;
    for (int i = 0; i < row1.getNumCells(); i++) {
        DataType t = m_inTable.getDataTableSpec().getColumnSpec(i).getType();
        if (t.isCompatible(DoubleValue.class)) {
            double dis;
            DataCell fCell = row1.getCell(i);
            DataCell tCell = row2.getCell(i);
            if (fCell.isMissing() || tCell.isMissing()) {
                dis = 0.0;
            } else {
                DoubleValue cell1 = (DoubleValue) fCell;
                DoubleValue cell2 = (DoubleValue) tCell;
                dis = cell1.getDoubleValue() - cell2.getDoubleValue();
            }
            d += dis * dis;
        }
    }
    return Math.sqrt(d);
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell)

Example 92 with DataType

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

the class SotaNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
    assert (settings != null && specs != null);
    int numberCells = 0;
    int fuzzyCells = 0;
    for (int i = 0; i < specs[SotaNodeModel.INPORT].getNumColumns(); i++) {
        DataType type = specs[SotaNodeModel.INPORT].getColumnSpec(i).getType();
        if (SotaUtil.isNumberType(type)) {
            numberCells++;
        } else if (SotaUtil.isFuzzyIntervalType(type)) {
            fuzzyCells++;
        }
    }
    StringBuffer buffer = new StringBuffer();
    if (numberCells <= 0 && fuzzyCells <= 0) {
        buffer.append("No FuzzyIntervalCells or NumberCells found !" + " Is the node fully connected ?");
    }
    // if buffer throw exception
    if (buffer.length() > 0) {
        throw new NotConfigurableException(buffer.toString());
    }
    m_settings.loadSettingsFrom(settings, specs);
    m_hierarchicalFuzzyDataSettings.loadSettingsFrom(settings, specs);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataType(org.knime.core.data.DataType)

Example 93 with DataType

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

the class SotaFuzzyMath method getMaxCoreDilatation.

/**
 * Approximates dilatation of Core region, by using Pythagoras.
 * Dilatation d = (sum(ai))^(1/2), with ai = (Cmax - Cmin) / 2.
 * -1 is returned if the given DataRow contains no FuzzyIntervalCells.
 *
 * @param cells row which contains FuzzyIntervalCells
 * @param spec spec of the row, to see which cells are FuzzyIntervalCells
 * @return core dilatation of given FuzzyIntervalCells. If the row contains
 *         no FuzzyIntervalCells -1 is returned.
 */
public static double getMaxCoreDilatation(final DataRow cells, final DataTableSpec spec) {
    double d = -1;
    if (cells.getNumCells() > 0) {
        d = 0;
        for (int i = 0; i < cells.getNumCells(); i++) {
            DataType type = spec.getColumnSpec(i).getType();
            if (type.isCompatible(FuzzyIntervalValue.class)) {
                if (!(cells.getCell(i).isMissing())) {
                    d += Math.pow(SotaFuzzyMath.getMaxCoreDistanceToCenter((FuzzyIntervalValue) cells.getCell(i)), 2);
                }
            }
        }
        d = Math.sqrt(d);
    }
    return d;
}
Also used : DataType(org.knime.core.data.DataType)

Example 94 with DataType

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

the class SotaNumberHelper method initializeDimension.

/**
 * {@inheritDoc}
 */
@Override
public int initializeDimension() {
    int dimension = 0;
    // 
    for (int i = 0; i < this.getRowContainer().getDataTableSpec().getNumColumns(); i++) {
        DataType type = this.getRowContainer().getDataTableSpec().getColumnSpec(i).getType();
        if (SotaUtil.isNumberType(type)) {
            dimension++;
        }
    }
    this.setDimension(dimension);
    return this.getDimension();
}
Also used : DataType(org.knime.core.data.DataType)

Example 95 with DataType

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

the class AggregateOutputNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = inSpecs[0];
    if ((m_settings.targetColumn() == null) && (m_settings.predictionColumn() == null)) {
        List<DataColumnSpec> colSpecs = new ArrayList<DataColumnSpec>();
        for (int i = 0; i < inSpec.getNumColumns(); i++) {
            colSpecs.add(inSpec.getColumnSpec(i));
        }
        outer: for (int i = colSpecs.size() - 1; i >= 0; i--) {
            for (int j = i - 1; j >= 0; j--) {
                DataType commonType = DataType.getCommonSuperType(colSpecs.get(i).getType(), colSpecs.get(j).getType());
                if ((commonType.getValueClasses().size() > 1) || (commonType.getValueClasses().get(0) != DataValue.class)) {
                    m_settings.predictionColumn(colSpecs.get(i).getName());
                    m_settings.targetColumn(colSpecs.get(j).getName());
                    setWarningMessage("Selected columns '" + m_settings.predictionColumn() + "' and '" + m_settings.targetColumn() + "' as prediction" + " and target columns");
                    break outer;
                }
            }
        }
    }
    if (m_settings.targetColumn() == null) {
        throw new InvalidSettingsException("No target column selected");
    }
    int targetColIndex = inSpec.findColumnIndex(m_settings.targetColumn());
    if (targetColIndex < 0) {
        throw new InvalidSettingsException("No such column: " + m_settings.targetColumn());
    }
    if (m_settings.predictionColumn() == null) {
        throw new InvalidSettingsException("No prediction column selected");
    }
    int predictColIndex = inSpec.findColumnIndex(m_settings.predictionColumn());
    if (predictColIndex < 0) {
        throw new InvalidSettingsException("No such column: " + m_settings.predictionColumn());
    }
    DataType commonType = DataType.getCommonSuperType(inSpec.getColumnSpec(targetColIndex).getType(), inSpec.getColumnSpec(predictColIndex).getType());
    if ((commonType.getValueClasses().size() == 1) && (commonType.getValueClasses().get(0) == DataValue.class)) {
        throw new InvalidSettingsException("Target and prediction column " + "are not of compatible type");
    }
    if (inSpec.getColumnSpec(targetColIndex).getType().isCompatible(DoubleValue.class)) {
        return new DataTableSpec[] { createPredictionSpec(inSpec), NUMERIC_STATISTICS_SPEC };
    } else {
        return new DataTableSpec[] { createPredictionSpec(inSpec), NOMINAL_STATISTICS_SPEC };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataValue(org.knime.core.data.DataValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) DataType(org.knime.core.data.DataType)

Aggregations

DataType (org.knime.core.data.DataType)330 DataColumnSpec (org.knime.core.data.DataColumnSpec)142 DataTableSpec (org.knime.core.data.DataTableSpec)101 DataCell (org.knime.core.data.DataCell)96 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)95 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)71 DoubleValue (org.knime.core.data.DoubleValue)67 DataRow (org.knime.core.data.DataRow)61 ArrayList (java.util.ArrayList)55 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)34 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)32 DefaultRow (org.knime.core.data.def.DefaultRow)24 HashSet (java.util.HashSet)23 HashMap (java.util.HashMap)20 StringCell (org.knime.core.data.def.StringCell)20 NominalValue (org.knime.core.data.NominalValue)18 DoubleCell (org.knime.core.data.def.DoubleCell)18 IntCell (org.knime.core.data.def.IntCell)18 BitVectorValue (org.knime.core.data.vector.bitvector.BitVectorValue)18 ByteVectorValue (org.knime.core.data.vector.bytevector.ByteVectorValue)18