Search in sources :

Example 11 with DataColumnDomainCreator

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

the class TestDataGenerator method createNominalTargetColumn.

public static TreeTargetNominalColumnData createNominalTargetColumn(final String[] values) {
    DataColumnDomainCreator dc = new DataColumnDomainCreator(Arrays.stream(values).distinct().map(s -> new StringCell(s)).toArray(i -> new StringCell[i]));
    DataColumnSpecCreator specCreator = new DataColumnSpecCreator("test-target", StringCell.TYPE);
    specCreator.setDomain(dc.createDomain());
    DataColumnSpec targetSpec = specCreator.createSpec();
    TreeTargetColumnDataCreator targetCreator = new TreeTargetNominalColumnDataCreator(targetSpec);
    for (int i = 0; i < values.length; i++) {
        RowKey rowKey = RowKey.createRowKey((long) i);
        targetCreator.add(rowKey, new StringCell(values[i]));
    }
    return (TreeTargetNominalColumnData) targetCreator.createColumnData();
}
Also used : JDKRandomGenerator(org.apache.commons.math.random.JDKRandomGenerator) TreeType(org.knime.base.node.mine.treeensemble2.model.AbstractTreeEnsembleModel.TreeType) Arrays(java.util.Arrays) RandomData(org.apache.commons.math.random.RandomData) RowKey(org.knime.core.data.RowKey) RandomDataImpl(org.apache.commons.math.random.RandomDataImpl) DoubleCell(org.knime.core.data.def.DoubleCell) Lists(com.google.common.collect.Lists) TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) MissingCell(org.knime.core.data.MissingCell) Doubles(com.google.common.primitives.Doubles) StringCell(org.knime.core.data.def.StringCell) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) StringCell(org.knime.core.data.def.StringCell) RowKey(org.knime.core.data.RowKey) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 12 with DataColumnDomainCreator

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

the class AbstractPlotter method createNominalYCoordinate.

/**
 * Creates a nominal y axis.
 *
 * @param values the possible values.
 */
public void createNominalYCoordinate(final Set<DataCell> values) {
    DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
    domainCreator.setValues(values);
    DataColumnSpecCreator specCreator = new DataColumnSpecCreator("X", StringCell.TYPE);
    specCreator.setDomain(domainCreator.createDomain());
    Coordinate nominalCoordinate = Coordinate.createCoordinate(specCreator.createSpec());
    if (getYAxis() == null) {
        Axis yAxis = new Axis(Axis.VERTICAL, getDrawingPaneDimension().width);
        setYAxis(yAxis);
    }
    getYAxis().setCoordinate(nominalCoordinate);
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 13 with DataColumnDomainCreator

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

the class AbstractPlotter method createNominalXCoordinate.

/**
 * Creates a nominal x axis.
 *
 * @param values the possible values.
 */
public void createNominalXCoordinate(final Set<DataCell> values) {
    DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
    domainCreator.setValues(values);
    DataColumnSpecCreator specCreator = new DataColumnSpecCreator("X", StringCell.TYPE);
    specCreator.setDomain(domainCreator.createDomain());
    Coordinate nominalCoordinate = Coordinate.createCoordinate(specCreator.createSpec());
    if (getXAxis() == null) {
        Axis xAxis = new Axis(Axis.HORIZONTAL, getDrawingPaneDimension().width);
        setXAxis(xAxis);
    }
    getXAxis().setCoordinate(nominalCoordinate);
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 14 with DataColumnDomainCreator

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

the class AbstractPlotter method createXCoordinate.

/**
 * Recalculates the domain of the x axis. If preserve is set to false the
 * passed values are taken as min and max no matter was was set before. If
 * preserve is set to true (default) the possibly already available min and
 * max values are preserved.
 *
 * @param min the min value
 * @param max the max value {@link AbstractPlotter#setPreserve(boolean)}
 */
public void createXCoordinate(final double min, final double max) {
    DataColumnDomainCreator xDomainCreator = new DataColumnDomainCreator();
    double actualMin = min;
    double actualMax = max;
    if (getXAxis() != null && getXAxis().getCoordinate() != null && m_preserve) {
        if (!(getXAxis().getCoordinate() instanceof NumericCoordinate)) {
            return;
        }
        actualMin = Math.min(min, ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue());
        actualMax = Math.max(max, ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue());
    }
    xDomainCreator.setLowerBound(new DoubleCell(actualMin));
    xDomainCreator.setUpperBound(new DoubleCell(actualMax));
    DataColumnSpecCreator xSpecCreator = new DataColumnSpecCreator("X", DoubleCell.TYPE);
    xSpecCreator.setDomain(xDomainCreator.createDomain());
    Coordinate xCoordinate = Coordinate.createCoordinate(xSpecCreator.createSpec());
    if (getXAxis() == null) {
        Axis xAxis = new Axis(Axis.HORIZONTAL, getDrawingPaneDimension().width);
        setXAxis(xAxis);
    }
    getXAxis().setCoordinate(xCoordinate);
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 15 with DataColumnDomainCreator

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

the class AbstractPlotter method createYCoordinate.

/**
 * Recalculates the domain of the y axis. If preserve is set to false the
 * passed values are taken as min and max no matter was was set before. If
 * preserve is set to true (default) the possibly already available min and
 * max values are preserved.
 *
 * @param min the min value
 * @param max the max value {@link AbstractPlotter#setPreserve(boolean)}
 */
public void createYCoordinate(final double min, final double max) {
    DataColumnDomainCreator yDomainCreator = new DataColumnDomainCreator();
    double actualMin = min;
    double actualMax = max;
    if (getYAxis() != null && getYAxis().getCoordinate() != null && m_preserve) {
        if (!(getYAxis().getCoordinate() instanceof NumericCoordinate)) {
            return;
        }
        actualMin = Math.min(min, ((NumericCoordinate) getYAxis().getCoordinate()).getMinDomainValue());
        actualMax = Math.max(max, ((NumericCoordinate) getYAxis().getCoordinate()).getMaxDomainValue());
    }
    yDomainCreator.setLowerBound(new DoubleCell(actualMin));
    yDomainCreator.setUpperBound(new DoubleCell(actualMax));
    DataColumnSpecCreator ySpecCreator = new DataColumnSpecCreator("Y", DoubleCell.TYPE);
    ySpecCreator.setDomain(yDomainCreator.createDomain());
    Coordinate yCoordinate = Coordinate.createCoordinate(ySpecCreator.createSpec());
    if (getYAxis() == null) {
        Axis yAxis = new Axis(Axis.VERTICAL, getDrawingPaneDimension().height);
        setYAxis(yAxis);
    }
    getYAxis().setCoordinate(yCoordinate);
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

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