示例#1
0
        public Itemset Remove(Itemset itemset)
        {
            Itemset removed = new Itemset();

            removed.AddRange(from item in this
                             where !itemset.Contains(item)
                             select item);
            return(removed);
        }
示例#2
0
        public static ItemsetCollection DoAprioriNew(ItemsetCollection db, double supportThreshold)
        {
            //Itemset I = db.GetUniqueItems();
            ItemsetCollection Fre = new ItemsetCollection(); //List of Items > support
            ItemsetCollection L   = new ItemsetCollection(); //resultant large itemsets
            ItemsetCollection T   = new ItemsetCollection(); //frequent items

            //item > support
            Itemset I = db.GetUniqueItems();

            foreach (int item in I)
            {
                Itemset itemset = new Itemset()
                {
                    item
                };
                itemset.Support = db.FindSupport(itemset);
                if (itemset.Support >= supportThreshold)
                {
                    Fre.Add(itemset);
                }
            }
            ItemsetCollection subsets = Bit.FindSubsets(Fre.GetUniqueItems(), 0); //get all subsets

            //Dictionary<Itemset, int> subsetsDic = subsets.Select((x, i) => new {x = x, i = 0 }).ToDictionary(k => k.x,k=>k.i);

            //frequent items
            foreach (Itemset itemdata in db)
            {
                Itemset itemset = new Itemset();
                foreach (Itemset itemFre in Fre)
                {
                    if (itemdata.Contains(itemFre[0]))
                    {
                        itemset.Add(itemFre[0]);
                    }
                }
                if (itemset.Count > 0)
                {
                    T.Add(itemset);
                    foreach (Itemset items in subsets)
                    {
                        if (itemset.Contains(items))
                        {
                            items.Support++;
                        }
                    }
                }
            }

            foreach (Itemset items in subsets)
            {
                if (items.Count > 0)
                {
                    items.Support = (items.Support / (double)db.Count) * 100.0;
                    if (items.Support >= supportThreshold)
                    {
                        L.Add(items);
                    }
                }
            }
            return(L);
        }