Search in sources :

Example 6 with PMCCPortObjectAndSpec

use of org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec in project knime-core by knime.

the class CorrelationComputeNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec in = (DataTableSpec) inSpecs[0];
    if (!in.containsCompatibleType(DoubleValue.class) && !in.containsCompatibleType(NominalValue.class)) {
        throw new InvalidSettingsException("No double or nominal compatible columns in input");
    }
    final String[] includes;
    if (m_columnFilterModel == null) {
        m_columnFilterModel = createColumnFilterModel();
        // auto-configure, no previous configuration
        m_columnFilterModel.loadDefaults(in);
        includes = m_columnFilterModel.applyTo(in).getIncludes();
        setWarningMessage("Auto configuration: Using all suitable " + "columns (in total " + includes.length + ")");
    } else {
        FilterResult applyTo = m_columnFilterModel.applyTo(in);
        includes = applyTo.getIncludes();
    }
    if (includes.length == 0) {
        throw new InvalidSettingsException("No columns selected");
    }
    return new PortObjectSpec[] { PMCCPortObjectAndSpec.createOutSpec(includes), new PMCCPortObjectAndSpec(includes) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 7 with PMCCPortObjectAndSpec

use of org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec in project knime-core by knime.

the class RankCorrelationComputeNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable in = (BufferedDataTable) inData[0];
    final DataTableSpec inSpec = in.getDataTableSpec();
    ColumnRearranger filteredTableRearranger = new ColumnRearranger(inSpec);
    String[] includeNames = m_columnFilterModel.applyTo(inSpec).getIncludes();
    filteredTableRearranger.keepOnly(includeNames);
    final BufferedDataTable filteredTable = exec.createColumnRearrangeTable(in, filteredTableRearranger, exec.createSilentSubExecutionContext(0.0));
    final BufferedDataTable noMissTable = filterMissings(filteredTable, exec);
    if (noMissTable.getRowCount() < filteredTable.getRowCount()) {
        setWarningMessage("Rows containing missing values are filtered. Please resolve them" + " with the Missing Value node.");
    }
    double progStep1 = 0.48;
    double progStep2 = 0.48;
    double progFinish = 1.0 - progStep1 - progStep2;
    SortedCorrelationComputer calculator = new SortedCorrelationComputer();
    exec.setMessage("Generate ranking");
    ExecutionContext execStep1 = exec.createSubExecutionContext(progStep1);
    calculator.generateRank(noMissTable, execStep1);
    execStep1.setProgress(1.0);
    exec.setMessage("Calculating correlation values");
    ExecutionContext execStep2 = exec.createSubExecutionContext(progStep2);
    HalfDoubleMatrix correlationMatrix;
    if (m_corrType.getStringValue().equals(CFG_SPEARMAN)) {
        correlationMatrix = calculator.calculateSpearman(execStep2);
    } else {
        correlationMatrix = calculator.calculateKendallInMemory(m_corrType.getStringValue(), execStep2);
    }
    execStep2.setProgress(1.0);
    exec.setMessage("Assembling output");
    ExecutionContext execFinish = exec.createSubExecutionContext(progFinish);
    PMCCPortObjectAndSpec pmccModel = new PMCCPortObjectAndSpec(includeNames, correlationMatrix);
    BufferedDataTable out = pmccModel.createCorrelationMatrix(execFinish);
    m_correlationTable = out;
    if (in.getRowCount() == 0) {
        setWarningMessage("Empty input table! Generating missing values as correlation values.");
    }
    return new PortObject[] { out, pmccModel, calculator.getRankTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ExecutionContext(org.knime.core.node.ExecutionContext) HalfDoubleMatrix(org.knime.base.util.HalfDoubleMatrix) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PortObject(org.knime.core.node.port.PortObject)

Aggregations

PMCCPortObjectAndSpec (org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec)7 DataTableSpec (org.knime.core.data.DataTableSpec)5 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 HalfDoubleMatrix (org.knime.base.util.HalfDoubleMatrix)3 ExecutionContext (org.knime.core.node.ExecutionContext)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)2 PortObject (org.knime.core.node.port.PortObject)2 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)2 FilterResult (org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)2 IOException (java.io.IOException)1 DataRow (org.knime.core.data.DataRow)1 RowKey (org.knime.core.data.RowKey)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1