예제 #1
0
 public FPGrowth(List <List <int> > dsp, double ms)
 {
     DSProcessed   = dsp;
     MinSupportDbl = ms;
     MinSupportInt = (int)(DSProcessed.Count * MinSupportDbl);
     FP_Tree       = new FPTree();
     L             = new List <List <Item> >();
     Patterns      = new List <Pattern>();
 }
예제 #2
0
        public FPTree BuildTree(List <Pattern> ptns)
        {
            FPTree fptree = Preproccess(ptns);

            foreach (Pattern ptn  in ptns)
            {
                Insert(fptree.Root, ptn, fptree.HeadTable);
            }

            return(fptree);
        }
예제 #3
0
        public FPTree Preproccess(List <Pattern> ptns)//generate headtable, fptree
        {
            if (ptns.Count == 0)
            {
                return(new FPTree());
            }

            FPTree fptree = new FPTree();

            List <int> hash = Enumerable.Repeat(0, ptns.Select(x => x.Items.Max()).Max() + 1).ToList();

            //calc item count
            List <List <int> > lli = ptns.Select(x => x.Items).ToList();

            for (int i = 0; i < lli.Count; i++)
            {
                for (int j = 0; j < lli[i].Count; j++)
                {
                    hash[lli[i][j]] += ptns[i].PtnCnt;
                }
            }

            //generate headtable
            for (int i = 0; i < hash.Count; i++)
            {
                if (hash[i] >= MinSupportInt)
                {
                    fptree.HeadTable.HeadNodes.Add(new HeadNode(new Pattern(new List <int>()
                    {
                        i
                    }, hash[i])));
                    fptree.HeadTable.Count.Add(i, hash[i]);
                }
            }

            IComparer <HeadNode> PS = new HeadNodeSorter();

            fptree.HeadTable.HeadNodes.Sort(PS);

            fptree.HeadTable.CalcIndex();

            return(fptree);
        }