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