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