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