Search in sources :

Example 1 with PMCCPortObjectAndSpec

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

the class RankCorrelationComputeNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec in = (DataTableSpec) inSpecs[0];
    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), null };
}
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) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 2 with PMCCPortObjectAndSpec

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

the class StandCronbachNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    PMCCPortObjectAndSpec model = (PMCCPortObjectAndSpec) inData[0];
    HalfDoubleMatrix mat = model.getCorrelationMatrix();
    double sum = 0;
    double count = 0;
    for (int i = 0; i < mat.getRowCount(); i++) {
        for (int j = i + 1; j < mat.getRowCount(); j++) {
            if (Double.isNaN(mat.get(i, j))) {
                throw new IOException("No NAN values supported for the calculation, " + "try using an alternative correlation meassure");
            }
            sum += mat.get(i, j);
            count++;
        }
    }
    double mean = sum / count;
    double cronbach = (mat.getRowCount() * mean) / (1 + (mat.getRowCount() - 1) * mean);
    BufferedDataContainer out = exec.createDataContainer(getDataTableSpec());
    RowKey k = new RowKey("Cronbach");
    DataRow r = new DefaultRow(k, new DoubleCell(cronbach));
    out.addRowToTable(r);
    out.close();
    return new BufferedDataTable[] { out.getTable() };
}
Also used : PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) HalfDoubleMatrix(org.knime.base.util.HalfDoubleMatrix) BufferedDataTable(org.knime.core.node.BufferedDataTable) IOException(java.io.IOException) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow)

Example 3 with PMCCPortObjectAndSpec

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

the class CorrelationComputeNodeModel 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 DataTableSpec filteredTableSpec = filteredTable.getDataTableSpec();
    double progStep1 = 0.48;
    double progStep2 = 0.48;
    double progFinish = 1.0 - progStep1 - progStep2;
    CorrelationComputer calculator = new CorrelationComputer(filteredTableSpec, m_maxPossValueCountModel.getIntValue());
    exec.setMessage("Calculating table statistics");
    ExecutionContext execStep1 = exec.createSubExecutionContext(progStep1);
    calculator.calculateStatistics(filteredTable, execStep1);
    execStep1.setProgress(1.0);
    exec.setMessage("Calculating correlation values");
    ExecutionMonitor execStep2 = exec.createSubExecutionContext(progStep2);
    HalfDoubleMatrix correlationMatrix = calculator.calculateOutput(filteredTable, 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;
    String missValueString = calculator.getNumericMissingValueWarning(4);
    StringBuilder warning = null;
    if (missValueString != null) {
        LOGGER.debug(calculator.getNumericMissingValueWarning(1000));
        warning = new StringBuilder(missValueString);
    }
    String constantColString = calculator.getNumericConstantColumnPairs(4);
    if (constantColString != null) {
        LOGGER.debug(calculator.getNumericConstantColumnPairs(1000));
        if (warning == null) {
            warning = new StringBuilder(constantColString);
        } else {
            warning.append("\n");
            warning.append(constantColString);
        }
    }
    if (warning != null) {
        setWarningMessage(warning.toString());
    }
    return new PortObject[] { out, pmccModel };
}
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) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PortObject(org.knime.core.node.port.PortObject)

Example 4 with PMCCPortObjectAndSpec

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

the class CorrelationFilterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    PMCCPortObjectAndSpec model = (PMCCPortObjectAndSpec) inData[0];
    BufferedDataTable in = (BufferedDataTable) inData[1];
    ColumnRearranger arranger = createColumnRearranger(in.getSpec(), model);
    BufferedDataTable out = exec.createColumnRearrangeTable(in, arranger, exec);
    return new BufferedDataTable[] { out };
}
Also used : PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 5 with PMCCPortObjectAndSpec

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

the class CorrelationFilterNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    PMCCPortObjectAndSpec modelS = (PMCCPortObjectAndSpec) inSpecs[0];
    DataTableSpec dataS = (DataTableSpec) inSpecs[1];
    if (m_threshold < 0.0 || m_threshold > 1.0) {
        throw new IllegalArgumentException("No valid threshold: " + m_threshold);
    }
    ColumnRearranger arranger = createColumnRearranger(dataS, modelS);
    if (arranger == null) {
        return null;
    }
    return new DataTableSpec[] { arranger.createSpec() };
}
Also used : PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger)

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