Search in sources :

Example 1 with AprioriAlgorithm

use of org.knime.base.node.mine.subgroupminer.apriori.AprioriAlgorithm in project knime-core by knime.

the class SubgroupMinerModel2 method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable input = inData[0];
    DataTableSpec spec = input.getDataTableSpec();
    ExecutionMonitor exec1 = exec.createSubProgress(0.5);
    ExecutionMonitor exec2 = exec.createSubProgress(0.5);
    Map<Integer, RowKey> tidRowKeyMapping = new HashMap<Integer, RowKey>();
    LinkedList<DataCell> nameMapping = new LinkedList<DataCell>();
    List<BitVectorValue> transactions;
    AtomicInteger maxBitsetLength = new AtomicInteger(0);
    if (spec.getColumnSpec(m_transactionColumn.getStringValue()).getType().isCompatible(BitVectorValue.class)) {
        transactions = preprocess(input, exec1, tidRowKeyMapping, maxBitsetLength);
        List<String> columnstrings = spec.getColumnSpec(m_transactionColumn.getStringValue()).getElementNames();
        for (String s : columnstrings) {
            nameMapping.add(new StringCell(s));
        }
        // fix #2505: use maximum bitset length
        maxBitsetLength.set(Math.max(maxBitsetLength.get(), nameMapping.size()));
    } else if (spec.getColumnSpec(m_transactionColumn.getStringValue()).getType().isCompatible(CollectionDataValue.class)) {
        transactions = preprocessCollCells(input, exec1, nameMapping, tidRowKeyMapping, maxBitsetLength);
    // for the name Mapping is taken care in the preprocessing
    } else {
        // data value.
        throw new IOException("Selected column is not a possible transaction");
    }
    AprioriAlgorithm apriori = AprioriAlgorithmFactory.getAprioriAlgorithm(AprioriAlgorithmFactory.AlgorithmDataStructure.valueOf(m_underlyingStruct.getStringValue()), maxBitsetLength.get(), input.getRowCount());
    LOGGER.debug("support: " + m_minSupport);
    LOGGER.debug(m_minSupport + " start apriori: " + new Date());
    try {
        apriori.findFrequentItemSets(transactions, m_minSupport.getDoubleValue(), m_maxItemSetLength.getIntValue(), FrequentItemSet.Type.valueOf(m_itemSetType.getStringValue()), exec2);
    } catch (OutOfMemoryError oome) {
        throw new OutOfMemoryError("Execution resulted in an out of memory error, " + "please increase the support threshold.");
    }
    LOGGER.debug("ended apriori: " + new Date());
    BufferedDataTable itemSetTable = createOutputTable(spec, exec, apriori, nameMapping);
    return new BufferedDataTable[] { itemSetTable };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) HashMap(java.util.HashMap) AprioriAlgorithm(org.knime.base.node.mine.subgroupminer.apriori.AprioriAlgorithm) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Date(java.util.Date) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) CollectionDataValue(org.knime.core.data.collection.CollectionDataValue)

Aggregations

IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AprioriAlgorithm (org.knime.base.node.mine.subgroupminer.apriori.AprioriAlgorithm)1 DataCell (org.knime.core.data.DataCell)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 RowKey (org.knime.core.data.RowKey)1 CollectionDataValue (org.knime.core.data.collection.CollectionDataValue)1 StringCell (org.knime.core.data.def.StringCell)1 BitVectorValue (org.knime.core.data.vector.bitvector.BitVectorValue)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1