Search in sources :

Example 1 with MDSCellFactory

use of org.knime.base.node.mine.mds.MDSCellFactory in project knime-core by knime.

the class MDSProjectionNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final DataTableSpec inSpecData = inData[IN_DATA_INDEX].getSpec();
    final ColumnRearranger colFilter = new ColumnRearranger(inSpecData);
    if (m_includeList != null) {
        colFilter.keepOnly(m_includeList.toArray(new String[m_includeList.size()]));
    }
    BufferedDataTable rowCutDataTable = exec.createColumnRearrangeTable(inData[IN_DATA_INDEX], colFilter, exec.createSilentSubProgress(0.0));
    int rowsToUse = m_rowsModel.getIntValue();
    if (m_useRowsModel.getBooleanValue()) {
        rowsToUse = inData[IN_DATA_INDEX].getRowCount();
    }
    // Warn if number of rows is greater than chosen number of rows
    if (inData[IN_DATA_INDEX].getRowCount() > rowsToUse) {
        setWarningMessage("Maximal number of rows to report is less than number of rows in input data table !");
    }
    // use only specified rows
    DataTable dataContainer = new DefaultDataArray(rowCutDataTable, 1, rowsToUse);
    // create BufferedDataTable
    rowCutDataTable = exec.createBufferedDataTable(dataContainer, exec);
    // get the indices of the fixed mds columns
    List<String> fixedCols = m_fixedMdsColModel.getIncludeList();
    int[] fixedMdsColsIndicies = new int[fixedCols.size()];
    DataTableSpec spec = inData[FIXED_DATA_INDEX].getSpec();
    for (int i = 0; i < fixedCols.size(); i++) {
        fixedMdsColsIndicies[i] = spec.findColumnIndex(fixedCols.get(i));
    }
    // create MDS manager, init and train stuff
    m_manager = new MDSProjectionManager(m_outputDimModel.getIntValue(), m_distModel.getStringValue(), m_fuzzy, rowCutDataTable, inData[FIXED_DATA_INDEX], fixedMdsColsIndicies, exec);
    m_manager.setProjectOnly(m_projectOnly.getBooleanValue());
    m_manager.init(m_seedModel.getIntValue());
    m_manager.train(m_epochsModel.getIntValue(), m_learnrateModel.getDoubleValue());
    // create BufferedDataTable out of mapped data.
    ColumnRearranger rearranger = createColumnRearranger(inSpecData, new MDSCellFactory(m_manager.getDataPoints(), m_manager.getDimension()));
    return new BufferedDataTable[] { exec.createColumnRearrangeTable(inData[IN_DATA_INDEX], rearranger, exec.createSubProgress(0.1)) };
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) MDSCellFactory(org.knime.base.node.mine.mds.MDSCellFactory)

Example 2 with MDSCellFactory

use of org.knime.base.node.mine.mds.MDSCellFactory in project knime-core by knime.

the class MDSProjectionNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    assert inSpecs.length == 2;
    m_includeList = m_colModel.getIncludeList();
    StringBuffer buffer = new StringBuffer();
    // 
    // / Check input data
    // 
    // check number of selected columns
    List<String> allColumns = new ArrayList<String>();
    int numberCells = 0;
    int fuzzyCells = 0;
    for (int i = 0; i < inSpecs[IN_DATA_INDEX].getNumColumns(); i++) {
        allColumns.add(inSpecs[IN_DATA_INDEX].getColumnSpec(i).getName());
        if (m_includeList.contains(inSpecs[IN_DATA_INDEX].getColumnSpec(i).getName())) {
            DataType type = inSpecs[IN_DATA_INDEX].getColumnSpec(i).getType();
            if (SotaUtil.isNumberType(type)) {
                numberCells++;
            } else if (SotaUtil.isFuzzyIntervalType(type)) {
                fuzzyCells++;
            }
        }
    }
    // check if selected columns are still in spec
    for (String s : m_includeList) {
        if (!allColumns.contains(s)) {
            buffer.append("Selected column are not in spec !");
        }
    }
    // throw exception if number of selected columns is not valid.
    if (numberCells <= 0 && fuzzyCells <= 0) {
        buffer.append("Number of columns has to be " + "greater than zero !");
    } else if (numberCells > 0 && fuzzyCells > 0) {
        buffer.append("Number cells and fuzzy cells must not be mixed !");
    } else if (fuzzyCells > 0) {
        m_fuzzy = true;
    } else if (numberCells > 0) {
        m_fuzzy = false;
    }
    // 
    // / Check fixed data
    // 
    List<String> fixedColumns = new ArrayList<String>();
    for (int i = 0; i < inSpecs[FIXED_DATA_INDEX].getNumColumns(); i++) {
        fixedColumns.add(inSpecs[FIXED_DATA_INDEX].getColumnSpec(i).getName());
    }
    if (numberCells <= 0) {
        buffer.append("Number of columns containing fixed data has " + "to be greater than zero !");
    }
    // check if selected columns are still in spec
    List<String> fixedColInlucdeList = m_fixedMdsColModel.getIncludeList();
    for (String s : fixedColInlucdeList) {
        if (!fixedColumns.contains(s)) {
            buffer.append("Selected fixed column are not in spec !");
        }
    }
    // create output table spec (input spec with the additional mds columns
    // appended).
    ColumnRearranger rearranger = createColumnRearranger(inSpecs[IN_DATA_INDEX], new MDSCellFactory(null, m_outputDimModel.getIntValue()));
    return new DataTableSpec[] { rearranger.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ArrayList(java.util.ArrayList) DataType(org.knime.core.data.DataType) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) MDSCellFactory(org.knime.base.node.mine.mds.MDSCellFactory)

Aggregations

MDSCellFactory (org.knime.base.node.mine.mds.MDSCellFactory)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)2 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)2 ArrayList (java.util.ArrayList)1 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)1 DataTable (org.knime.core.data.DataTable)1 DataType (org.knime.core.data.DataType)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1