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(minSup, totalFrequentItemSets, (double)watch.ElapsedMilliseconds); return(totalFrequentItemSets); }
//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); }