示例#1
0
        public void Example()
        {
            List <Transaction <char> > database = new List <Transaction <char> >();

            database.Add(new Transaction <char>('a', 'c', 'd', 'e')
            {
                ID = 10
            });
            database.Add(new Transaction <char>('a', 'b', 'e')
            {
                ID = 20
            });
            database.Add(new Transaction <char>('b', 'c', 'e')
            {
                ID = 30
            });
            database.Add(new Transaction <char>('b', 'c', 'e')
            {
                ID = 40
            });

            Apriori <char>  method   = new Apriori <char>();
            ItemSets <char> itemsets = method.MinePatterns(database, 2, new List <char>()
            {
                'a', 'b', 'c', 'd', 'e'
            });

            for (int i = 0; i < itemsets.Count; ++i)
            {
                ItemSet <char> itemset = itemsets[i];

                Console.WriteLine(itemset);
            }
        }
        public virtual ItemSets <MultiLevelItem <T> > MinePatterns(IEnumerable <TransactionWithMultiLevelItems <T> > database, MultiLevelItem <T> hierarchy)
        {
            IList <MultiLevelItem <T> > domain2 = hierarchy.Flatten();

            domain2.Remove(hierarchy);

            return(mMethod.MinePatterns(database,
                                        (itemset) =>
            {
                double minSupport = 1;
                for (int i = 0; i < itemset.Count; ++i)
                {
                    minSupport = System.Math.Min(minSupport, itemset[i].MinSupport);
                }
                return minSupport;
            }, domain2));
        }