Search in sources :

Example 6 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class TwoSampleTTestNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec spec = inSpecs[0];
    if (m_settings.getGroupingColumn() == null || !spec.containsName(m_settings.getGroupingColumn())) {
        throw new InvalidSettingsException("Please define a grouping column.");
    }
    if (m_settings.getGroupOne() == null) {
        throw new InvalidSettingsException("Value of group one is not set.");
    }
    if (m_settings.getGroupTwo() == null) {
        throw new InvalidSettingsException("Value of group two is not set.");
    }
    FilterResult filterResult = m_settings.getTestColumns().applyTo(spec);
    if (filterResult.getIncludes().length == 0) {
        if (filterResult.getExcludes().length > 0) {
            throw new InvalidSettingsException("Please select at least " + "one test column.");
        } else {
            throw new InvalidSettingsException("There are no numeric columns " + "in the input table. At least one numeric column " + "is needed to perform the test.");
        }
    }
    if (m_settings.getConfidenceIntervalProb() > 0.99 || m_settings.getConfidenceIntervalProb() < 0.01) {
        throw new InvalidSettingsException("The property " + "\"Confidence Interval (in %)\" must be in the range " + "[1, 99].");
    }
    return new DataTableSpec[] { TwoSampleTTestStatistics.getTableSpec(), LeveneTestStatistics.getTableSpec(), TwoSampleTTestStatistics.getGroupStatisticsSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 7 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class TwoSampleTTestNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    Map<Group, String> groups = new LinkedHashMap<Group, String>();
    groups.put(Group.GroupX, m_settings.getGroupOne());
    groups.put(Group.GroupY, m_settings.getGroupTwo());
    Grouping grouping = new StringValueGrouping(m_settings.getGroupingColumn(), groups);
    DataTableSpec spec = inData[0].getSpec();
    FilterResult filter = m_settings.getTestColumns().applyTo(spec);
    TwoSampleTTest test = new TwoSampleTTest(filter.getIncludes(), grouping, m_settings.getConfidenceIntervalProb());
    TwoSampleTTestStatistics[] result = test.execute(inData[0], exec);
    LeveneTest leveneTest = new LeveneTest(filter.getIncludes(), m_settings.getGroupingColumn(), Arrays.asList(new String[] { m_settings.getGroupOne(), m_settings.getGroupTwo() }), getGroupSummaryStats(result));
    LeveneTestStatistics[] leveneResult = leveneTest.execute(inData[0], exec);
    leveneResult[0].getTTestCells();
    m_descStats = getDescriptiveStatisticsTable(result, exec);
    m_leveneStats = getLeveneStatistices(leveneResult, exec);
    m_stats = getTestStatisticsTable(result, exec);
    return new BufferedDataTable[] { m_stats, m_leveneStats, m_descStats };
}
Also used : Group(org.knime.base.node.stats.testing.ttest.Grouping.Group) DataTableSpec(org.knime.core.data.DataTableSpec) LeveneTest(org.knime.base.node.stats.testing.levene.LeveneTest) LeveneTestStatistics(org.knime.base.node.stats.testing.levene.LeveneTestStatistics) LinkedHashMap(java.util.LinkedHashMap) BufferedDataTable(org.knime.core.node.BufferedDataTable) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 8 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class TreeEnsembleLearnerConfiguration method checkColumnSelection.

/**
 * To be used in the configure of the learner nodes. Checks if the column selection makes sense and throws an
 * InvalidSettingsException otherwise. The sanity checks include: <br>
 * Existence and type check of fingerprint columns if specified. <br>
 * Check if any attributes are selected if no fingerprint column is used for learning.
 *
 * @param inSpec Spec of the incoming table
 * @throws InvalidSettingsException thrown if the column selection makes no sense
 */
public void checkColumnSelection(final DataTableSpec inSpec) throws InvalidSettingsException {
    FilterResult filterResult = m_columnFilterConfig.applyTo(inSpec);
    if (m_fingerprintColumn != null) {
        DataColumnSpec colSpec = inSpec.getColumnSpec(m_fingerprintColumn);
        if (colSpec == null) {
            throw new InvalidSettingsException("The fingerprint column is not contained in the incoming table.");
        }
        DataType colType = colSpec.getType();
        if (!(colType.isCompatible(BitVectorValue.class) || colType.isCompatible(ByteVectorValue.class) || colType.isCompatible(DoubleVectorValue.class))) {
            throw new InvalidSettingsException("The specified fingerprint column is not of a compatible vector type.");
        }
    } else if (filterResult.getIncludes().length > 0) {
    // ok, there are some features selected
    } else {
        throw new InvalidSettingsException("No attributes are selected.");
    }
}
Also used : DoubleVectorValue(org.knime.core.data.vector.doublevector.DoubleVectorValue) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 9 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class TreeEnsembleLearnerConfiguration method filterLearnColumns.

/**
 * @param spec
 * @return ColumnRearranger that filters out all columns not part of the learning columns.
 * @throws InvalidSettingsException
 */
public FilterLearnColumnRearranger filterLearnColumns(final DataTableSpec spec) throws InvalidSettingsException {
    // (ColumnRearranger is a final class in v2.5)
    if (m_targetColumn == null) {
        throw new InvalidSettingsException("Target column not set");
    }
    DataColumnSpec targetCol = spec.getColumnSpec(m_targetColumn);
    if (targetCol == null || !targetCol.getType().isCompatible(getRequiredTargetClass())) {
        throw new InvalidSettingsException("Target column \"" + m_targetColumn + "\" does not exist or is not of the " + "correct type");
    }
    FilterResult filterResult = m_columnFilterConfig.applyTo(spec);
    List<String> noDomainColumns = new ArrayList<String>();
    FilterLearnColumnRearranger rearranger = new FilterLearnColumnRearranger(spec);
    if (m_fingerprintColumn == null) {
        // use ordinary data
        Set<String> incl = new HashSet<String>(Arrays.asList(filterResult.getIncludes()));
        // the target column can possibly show up in the include list of the filter result
        // therefore we have to remove it
        incl.remove(targetCol.getName());
        for (DataColumnSpec col : spec) {
            String colName = col.getName();
            if (colName.equals(m_targetColumn)) {
                continue;
            }
            DataType type = col.getType();
            boolean ignoreColumn = false;
            boolean isAppropriateType = type.isCompatible(DoubleValue.class) || type.isCompatible(NominalValue.class);
            if (incl.remove(colName)) {
                // accept unless type mismatch
                if (!isAppropriateType) {
                    throw new InvalidSettingsException("Attribute column \"" + colName + "\" is " + "not of the expected type (must be " + "numeric or nominal).");
                } else if (shouldIgnoreLearnColumn(col)) {
                    ignoreColumn = true;
                    noDomainColumns.add(colName);
                } else {
                // accept
                }
            } else {
                ignoreColumn = true;
            }
            // }
            if (ignoreColumn) {
                rearranger.remove(colName);
            }
        }
        if (rearranger.getColumnCount() <= 1) {
            StringBuilder b = new StringBuilder("Input table has no valid " + "learning columns (need one additional numeric or " + "nominal column).");
            if (!noDomainColumns.isEmpty()) {
                b.append(" ").append(noDomainColumns.size());
                b.append(" column(s) were ignored due to missing domain ");
                b.append("information -- execute predecessor and/or ");
                b.append(" use Domain Calculator node.");
                throw new InvalidSettingsException(b.toString());
            }
        }
        if (/*!m_includeAllColumns &&*/
        !incl.isEmpty()) {
            StringBuilder missings = new StringBuilder();
            int i = 0;
            for (Iterator<String> it = incl.iterator(); it.hasNext() && i < 4; i++) {
                String s = it.next();
                missings.append(i > 0 ? ", " : "").append(s);
                it.remove();
            }
            if (!incl.isEmpty()) {
                missings.append(",...").append(incl.size()).append(" more");
            }
            throw new InvalidSettingsException("Some selected attributes " + "are not present in the input table: " + missings);
        }
    } else {
        // use fingerprint data
        DataColumnSpec fpCol = spec.getColumnSpec(m_fingerprintColumn);
        if (fpCol == null || !(fpCol.getType().isCompatible(BitVectorValue.class) || fpCol.getType().isCompatible(ByteVectorValue.class) || fpCol.getType().isCompatible(DoubleVectorValue.class))) {
            throw new InvalidSettingsException("Fingerprint columnn \"" + m_fingerprintColumn + "\" does not exist or is not " + "of correct type.");
        }
        rearranger.keepOnly(m_targetColumn, m_fingerprintColumn);
    }
    rearranger.move(m_targetColumn, rearranger.getColumnCount());
    String warn = null;
    if (!noDomainColumns.isEmpty()) {
        StringBuilder b = new StringBuilder();
        b.append(noDomainColumns.size());
        b.append(" column(s) were ignored due to missing domain");
        b.append(" information: [");
        int index = 0;
        for (String s : noDomainColumns) {
            if (index > 3) {
                b.append(", ...");
                break;
            }
            if (index > 0) {
                b.append(", ");
            }
            b.append("\"").append(s).append("\"");
            index++;
        }
        b.append("] -- change the node configuration or use a");
        b.append(" Domain Calculator node to fix it");
        warn = b.toString();
    }
    rearranger.setWarning(warn);
    return rearranger;
}
Also used : NominalValue(org.knime.core.data.NominalValue) ArrayList(java.util.ArrayList) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) HashSet(java.util.HashSet)

Example 10 with FilterResult

use of org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult in project knime-core by knime.

the class NameFilterConfigurationTest method testSomeExtra.

private void testSomeExtra(final NameFilterConfiguration conf) {
    FilterResult applyTo = conf.applyTo(new String[] { "I1", "I2", "N1", "I3", "E1", "E2", "N2" });
    Assert.assertArrayEquals(applyTo.getIncludes(), new String[] { "I1", "I2", "N1", "I3", "N2" });
    Assert.assertArrayEquals(applyTo.getExcludes(), m_defExcludes);
    Assert.assertArrayEquals(applyTo.getRemovedFromIncludes(), new String[] {});
    Assert.assertArrayEquals(applyTo.getRemovedFromExcludes(), new String[] {});
}
Also used : FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Aggregations

FilterResult (org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)54 DataTableSpec (org.knime.core.data.DataTableSpec)29 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)29 DataColumnSpec (org.knime.core.data.DataColumnSpec)19 ArrayList (java.util.ArrayList)14 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)13 DataType (org.knime.core.data.DataType)10 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)10 BufferedDataTable (org.knime.core.node.BufferedDataTable)9 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)6 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)6 HashSet (java.util.HashSet)5 DataCell (org.knime.core.data.DataCell)5 DoubleValue (org.knime.core.data.DoubleValue)5 HashMap (java.util.HashMap)3 DataColumnProperties (org.knime.core.data.DataColumnProperties)3 DataRow (org.knime.core.data.DataRow)3 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2