/* Returns C(1), the candidate item sets with size 1 */ public ItemSetTable FindFirstCandidateItemSetTable() { ItemSetTable candidateItemSets = new ItemSetTable(); candidateItemSets.order = 1; SortedSet <int> set = new SortedSet <int>(); foreach (Transaction t in this) { foreach (int item in t) { set.Add(item); } } foreach (int item in set) { ItemSet itemSet = new ItemSet(); itemSet.Add(item); candidateItemSets.Add(itemSet, 0); } IncrementCandidatesIn(candidateItemSets); return(candidateItemSets); }
/* Returns L(k+1), candidates in C(k+1) with min_support */ public ItemSetTable BuildFrequentItemSet() { int count = 0; ItemSetTable frequentTable = new ItemSetTable(this.order); ICollection <ItemSet> keys = new List <ItemSet>(this.Keys); foreach (ItemSet itemSet in keys) { int support = this[itemSet]; if (support >= minSupport) { frequentTable.Add(itemSet, support); ++count; } } // If no item set has higher support than min_support, return null. if (count == 0) { return(null); } else { return(frequentTable); } }
/* Returns the candidates C(k+1) generated from L(k) */ public ItemSetTable BuildCandidateItemSet() { ItemSetTable candidateTable = new ItemSetTable(this.order + 1); foreach (ItemSet I1 in this.Keys) // this = L(k) { foreach (ItemSet I2 in this.Keys) { ItemSet c = null; IList <int> iList1 = new List <int>(I1); IList <int> iList2 = new List <int>(I2); bool joinCondition = false; for (int i = 0; i < this.order; ++i) { // last element if (i == this.order - 1) { if (iList1[i] < iList2[i]) { joinCondition = true; } } else { if (iList1[i] != iList2[i]) { joinCondition = false; break; } } } if (joinCondition == true) { c = ItemSet.UnionBetween(I1, I2); // join step: generate candidates if (hasInfrequentSubSet(c) == false) { candidateTable.Add(c, 0); } } } } return(candidateTable); }