Esempio n. 1
0
        public static ItemsetCollection FindSubsets(Itemset itemset, int n)
        {
            ItemsetCollection subsets = new ItemsetCollection();

            int subsetCount = (int)Math.Pow(2, itemset.Count);

            for (int i = 0; i < subsetCount; i++)
            {
                if (n == 0 || GetOnCount(i, itemset.Count) == n)
                {
                    string binary = DecimalToBinary(i, itemset.Count);

                    Itemset subset = new Itemset();
                    for (int charIndex = 0; charIndex < binary.Length; charIndex++)
                    {
                        if (binary[charIndex] == '1')
                        {
                            subset.Add(itemset[charIndex]);
                        }
                    }
                    subsets.Add(subset);
                }
            }

            return(subsets);
        }
Esempio n. 2
0
        static ItemsetCollection AprioriCalc(ItemsetCollection db, double supportThreshold)
        {
            Itemset           I         = db.GetUniqueItems();
            ItemsetCollection LitemList = new ItemsetCollection();
            ItemsetCollection PitemList = new ItemsetCollection();

            foreach (string item in I)
            {
                PitemList.Add(new Itemset()
                {
                    item
                });
            }
            int k = 2;

            while (PitemList.Count != 0)
            {
                LitemList.Clear();
                foreach (Itemset index in PitemList)
                {
                    index.Support = db.FindSupport(index);

                    if (index.Support >= supportThreshold)
                    {
                        LitemList.Add(index);
                        itemList.Add(index);
                    }
                }
                PitemList.Clear();
                PitemList.AddRange(Bit.FindSubsets(LitemList.GetUniqueItems(), k)); //get k-item subsets
                k += 1;
            }
            return(itemList);
        }
Esempio n. 3
0
        public ItemsetCollection setData()
        {
            _items = new Itemset();
            _items.Add("Game");
            _items.Add("Water");
            _items.Add("Monster");
            _items.Add("Candy");
            _items.Add("Shoes");
            _items.Add("Controller");
            _items.Add("PizzaRolls");
            _items.Add("Console");

            _db = new ItemsetCollection();
            _db.Add(new Itemset()
            {
                _items[0], _items[2], _items[3], _items[5]
            });
            _db.Add(new Itemset()
            {
                _items[1], _items[4]
            });
            _db.Add(new Itemset()
            {
                _items[0], _items[2], _items[6]
            });
            _db.Add(new Itemset()
            {
                _items[1], _items[3], _items[4], _items[7]
            });
            _db.Add(new Itemset()
            {
                _items[0], _items[1], _items[6]
            });

            return(_db);
        }