private void AddTransactionNodes(Transaction transaction) { FPTreeNode actualNode = _rootNode; var transactionItems = GetTransactionItems(transaction); for (int i = 0; i < transactionItems.Length; i++) { // Because we order transaction's items by support, // we can break loop when we find the first non-frequent item in transaction. if (!IsFrequent(transactionItems[i])) { break; } FPTreeNode subNode; if (actualNode.TryGetSubNode(transactionItems[i], out subNode)) { subNode.Support++; actualNode = subNode; } else { AddSubNodesForTransactionItems(actualNode, transactionItems, i); break; } } }
private FPTreeNode FindOrCreateNode(FPTreeNode actualTreeNode, out bool found) { FPTreeNode existingNode; found = _visitedNodesMapping.TryGetValue(actualTreeNode, out existingNode); return(found ? existingNode : new FPTreeNode(FPTreeNodeType.Node) { Item = actualTreeNode.Item }); }
internal FPTreeNode AddSubNode(UInt32 item) { FPTreeNode subNode = new FPTreeNode { Support = 1, Item = item, Type = FPTreeNodeType.Node, ParentNode = this }; _subNodes.Add(item, subNode); return(subNode); }
private void AddSubNodesForTransactionItems(FPTreeNode parentNode, UInt32[] transaction, int transactionStartIndex) { FPTreeNode actualNode = parentNode; for (int i = transactionStartIndex; i < transaction.Length; i++) { actualNode = actualNode.AddSubNode(transaction[i]); _header.Add(actualNode); } // Last item is on leaf node, save it. _leafNodes.Add(actualNode); }
public FPTreePrefixPathItem Add(FPTreeNode node) { FPTreePrefixPathItem item = new FPTreePrefixPathItem { FPTreeNode = node }; List <FPTreePrefixPathItem> itemList; if (!_items.TryGetValue(node.Item, out itemList)) { itemList = new List <FPTreePrefixPathItem>(); _items.Add(node.Item, itemList); } itemList.Add(item); return(item); }
internal void AddTransaction(FPTreeNode fPTreeNode, Int32 support) { if (fPTreeNode.Type == FPTreeNodeType.Root) { return; } FPTreeNode curretNodeInConditioanlTree = null; FPTreeNode currentNodeInInputFpTree = fPTreeNode; // We are navigatin from botton to up in origin transaction and creating a new one. while (currentNodeInInputFpTree.Type != FPTreeNodeType.Root) { bool existingNode; FPTreeNode node = FindOrCreateNode(currentNodeInInputFpTree, out existingNode); node.Support += support; if (curretNodeInConditioanlTree != null) { curretNodeInConditioanlTree.ParentNode = node; } if (!existingNode) { _visitedNodesMapping.Add(currentNodeInInputFpTree, node); _header.Add(node); } // TODO: When we have found already visited node, we can traverse it to up and just increment support. // Move upward in tree traversing; curretNodeInConditioanlTree = node; currentNodeInInputFpTree = currentNodeInInputFpTree.ParentNode; } curretNodeInConditioanlTree.ParentNode = currentNodeInInputFpTree; }
public bool TryGetSubNode(UInt32 item, out FPTreeNode subNode) { return(_subNodes.TryGetValue(item, out subNode)); }