Exemplo n.º 1
0
        public int CreateFPTreeAndGenerateFrequentItemsets(
            IInputDatabaseHelper _inputHelper, IOutputDatabaseHelper _outHelper, float minSup)
        {
            outputDatabaseHelper = _outHelper;
            var    watch   = System.Diagnostics.Stopwatch.StartNew();
            FPTree _fpTree = new FPTree(_inputHelper, minSup);

            fpTree = _fpTree;
            int totalFrequentItemSets = GenerateFrequentItemSets();

            watch.Stop();
            outputDatabaseHelper.WriteAggregatedResult(_inputHelper.DatabaseName, minSup, totalFrequentItemSets, (double)watch.ElapsedMilliseconds);
            return(totalFrequentItemSets);
        }
Exemplo n.º 2
0
        private int Mine(FPTree fpTree, ItemSet anItemSet)
        {
            int    minedItemSets = 0;
            FPTree projectedTree;

            projectedTree = fpTree.Project(anItemSet.GetLastItem());
            minedItemSets = projectedTree.FrequentItems.Count;
            foreach (Item anItem in projectedTree.FrequentItems)
            {
                ItemSet nextItemSet = anItemSet.Clone();
                nextItemSet.AddItem(anItem);
                minedItemSets += Mine(projectedTree, nextItemSet);
            }
            return(minedItemSets);
        }
Exemplo n.º 3
0
        public FPTree Project(Item anItem)
        {
            FPTree tree = new FPTree();

            tree.minimumSupport      = minimumSupport;
            tree.minimumSupportCount = minimumSupportCount;

            Node startNode = headerTable[anItem.Symbol];

            while (startNode != null)
            {
                int         projectedFPCount = startNode.FpCount;
                Node        tempNode         = startNode;
                List <Node> aBranch          = new List <Node>();
                while (null != tempNode.Parent)
                {
                    Node parentNode = tempNode.Parent;
                    if (parentNode.IsNull())
                    {
                        break;
                    }
                    Node newNode = new Node(parentNode.Symbol);
                    //newNode.Parent = parentNode.Parent;
                    newNode.FpCount = projectedFPCount;
                    aBranch.Add(newNode);
                    tempNode = tempNode.Parent;
                }
                aBranch.Reverse();
                tree.InsertBranch(aBranch);
                startNode = startNode.NextHeader;
            }

            //prune infrequents

            /*foreach(KeyValuePair<string,Node> hEntry in tree.headerTable)
             * {
             *  int c = tree.GetTotalSupportCount(hEntry.Value.Symbol);
             *  if(c < minimumSupportCount)
             *  {
             *      tree.headerTable.Remove(hEntry);
             *  }
             * }*/
            IDictionary <string, Node> inFrequentHeaderTable = tree.headerTable.
                                                               Where(x => tree.GetTotalSupportCount(x.Value.Symbol) < minimumSupportCount).
                                                               ToDictionary(p => p.Key, p => p.Value);

            tree.headerTable = tree.headerTable.
                               Where(x => tree.GetTotalSupportCount(x.Value.Symbol) >= minimumSupportCount).
                               ToDictionary(p => p.Key, p => p.Value);

            foreach (KeyValuePair <string, Node> hEntry in inFrequentHeaderTable)
            {
                Node temp = hEntry.Value;
                while (null != temp)
                {
                    Node tempNext   = temp.NextHeader;
                    Node tempParent = temp.Parent;
                    tempParent.Children.Remove(temp);
                    temp = tempNext;
                }
            }

            tree.frequentItems = frequentItems.FindAll
                                 (
                delegate(Item item)
            {
                return(tree.headerTable.ContainsKey(item.Symbol));
            }
                                 );
            return(tree);
        }
Exemplo n.º 4
0
 public FPGrowth(FPTree tree, IOutputDatabaseHelper outDatabaseHelper)
     : this()
 {
     fpTree = tree;
     outputDatabaseHelper = outDatabaseHelper;
 }
Exemplo n.º 5
0
 public FPGrowth()
 {
     fpTree = null;
     outputDatabaseHelper = null;
 }