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 };
}
Aggregations