Beispiel #1
0
        //B1.4Thêm từng giao tác vào cây
        private void InsertTransaction(List <string> aTransaction)
        {
            List <Item> Allitems = inputDatabaseHelper.CalculateFrequencyAllItems();
            List <Item> items    = new List <Item>();

            //frequent items trong mỗi giao tác
            for (int i = 0; i < aTransaction.Count; i++)
            {
                bool containsItem = frequentItems.Any(item => item.Symbol == Allitems[i].Symbol);
                if (aTransaction[i].Equals("y") && containsItem)
                {
                    items.Add(Allitems[i]);
                }
            }
            items = items.OrderByDescending(x => x.SupportCount).ToList(); // Xong B1.2
            Node tempRoot = root;
            Node tempNode;

            //Thêm node vào cây
            foreach (Item anItem in items)
            {
                Node aNode = new Node(anItem.Symbol);
                aNode.FpCount = 1;
                if ((tempNode = tempRoot.Children.Find(c => c.Symbol == aNode.Symbol)) != null)
                {
                    tempNode.FpCount++;
                    tempRoot = tempNode;
                }
                else
                {
                    tempRoot.AddChild(aNode);
                    tempRoot = aNode;
                    if (headerTable.ContainsKey(aNode.Symbol)) // Table header các item phổ biến 1 hạng mục
                    {
                        aNode.NextHeader          = headerTable[aNode.Symbol];
                        headerTable[aNode.Symbol] = aNode;
                    }
                    else
                    {
                        headerTable[aNode.Symbol] = aNode;
                    }
                }
            }
        }
Beispiel #2
0
        private void CalculateFrequentItems()
        {
            List <Item> items = inputDatabaseHelper.CalculateFrequencyAllItems();

            foreach (Item anItem in items)
            {
                if (anItem.SupportCount >= minimumSupportCount)
                {
                    frequentItems.Add(anItem.Clone());
                }
            }
        }
        //generate frequent itemsets
        public int GenerateFrequentItemSets()
        {
            var            watch            = System.Diagnostics.Stopwatch.StartNew();
            List <ItemSet> previousItemSets = new List <ItemSet>(); //holds itemsets found in previous calculation

            //insert the frequent 1-itemsets
            List <Item> items = inputDatabaseHelper.CalculateFrequencyAllItems();

            foreach (Item anItem in items)
            {
                if (anItem.SupportCount >= MinimumSupportCount) // if frequent
                {
                    ItemSet anItemSet = new ItemSet();
                    anItemSet.AddItem(anItem);
                    previousItemSets.Add(anItemSet);
                }
            }
            int itemSetLength         = 1;
            int totalFrequentItemSets = 0;

            Console.WriteLine("generated " + itemSetLength.ToString() + "-itemset total " + previousItemSets.Count + " itemsets");
            totalFrequentItemSets += previousItemSets.Count;
            while (previousItemSets.Count != 0)
            {
                itemSetLength++;
                List <ItemSet> newCandidates = GetNextCandidates(previousItemSets);
                previousItemSets.Clear();
                previousItemSets       = GetFrequentItemSetsFromCandidates(newCandidates);
                totalFrequentItemSets += previousItemSets.Count;
                Console.WriteLine("generated " + itemSetLength.ToString() + "-itemset total " + previousItemSets.Count + " itemsets");
            }
            watch.Stop();
            outputDatabaseHelper.WriteAggregatedResult(inputDatabaseHelper.DatabaseName, MinimumSupport, totalFrequentItemSets, watch.ElapsedMilliseconds);
            Console.WriteLine("Aggregated Result Written to " + outputDatabaseHelper.DatabasePath);
            return(totalFrequentItemSets);
        }