Ejemplo n.º 1
0
 /// <summary>
 /// 对当前候选集中的项集求support counting
 /// </summary>
 /// <param name="candidate">候选项集</param>
 /// <param name="depth">当前的候选项集的项的个数</param>
 /// <returns>返回support counting大于等于minsup的项集</returns>
 static Candidates<int> DoSupportCounting(Candidates<int> candidate, int depth)
 {
     //建立hash树
     HashTree<int> tree = new HashTree<int>(HashCode, 0, 2, depth, NodePrint);
     foreach (var tmp in candidate.ItemSets)
     {
         tree.AddNode(tmp);
     }
     //计算候选集中的support counting
     foreach (var tmp in transactions)
     {
         tree.ClearTag(tree.Root);
         tree.SupportCounting(tmp, tree.Root, -1);
     }
     //将support counting大于minsup的加入频繁项的集合
     Candidates<int> tmpCandi = new Candidates<int>();
     tree.ClearTag(tree.Root);
     TreeNode<int> node = tree.GetLeaves(tree.Root);
     while (node != null)
     {
         foreach (var d in node.list)
         {
             if (d.value >= minsup * transactions.Count()) tmpCandi.AddCandidate(d);
         }
         node = tree.GetLeaves(tree.Root);
     }
     return SortInTrie(tmpCandi);
 }