Пример #1
0
        static void addTransactions()
        {
            //   int lineNum = 0;
            string line;
            using (StreamReader sr = new StreamReader("data/topic-1.txt"))
            {

                while ((line = sr.ReadLine()) != null)
                {
                    List<string> data = line.Split(' ').ToList();
                    ItemSet set = new ItemSet();
                    foreach (string d in data)
                    {
                        if (!d.Equals(""))
                        {
                            Item it = new Item(d);
                            set.add(it);
                        }

                    }
                    set.sort();
                    transactions.Add(set);

                    //  lineNum++;
                }
            }
        }
Пример #2
0
        static double GetSupport(ItemSet i1)
        {
            double support = 0;

            foreach (ItemSet transaction in transactions)
            {
                if (transaction.contains(i1))
                {
                    support++;
                }
            }

            return support;
        }
Пример #3
0
        public bool contains(ItemSet itemset)
        {
            int numItemContains = 0;
            List<string> itemNames = items.Select(x => x.Name).ToList();
            foreach (Item i in itemset.items)
            {
                if (itemNames.Contains(i.Name))
                {
                    numItemContains++;
                }
            }

            if (numItemContains >= itemset.items.Count())
            {
                return true;
            }
            return false;
            //items.co
        }
Пример #4
0
        private static bool isclosed(ItemSet iset, List<ItemSet> parents)
        {
            foreach (ItemSet parent in parents)
            {
                if (iset.support == parent.support)
                {
                    return false;
                }
            }

            return true;
        }
Пример #5
0
        private static List<ItemSet> retrieveParents(ItemSet iset, int p, List<ItemSet> allfreqItemsets)
        {
            List<ItemSet> parents = new List<ItemSet>();

            for (int j = p; j < allfreqItemsets.Count(); j++)
            {
                ItemSet parent = allfreqItemsets[j];

                if (parent.Count() == iset.Count() + 1)
                {
                    if (parent.contains(iset))
                    {
                        parents.Add(parent);
                    }
                }
            }

            return parents;
        }
Пример #6
0
        static ItemSet NewCandidateItemSet(ItemSet i1, ItemSet i2)
        {
            ItemSet newItemSet = new ItemSet();
            i1.clone(newItemSet);
            int length = i1.items.Count();

            if (length == 1)
            {
                newItemSet.items.AddRange(i2.items);
                return newItemSet;
            }
            else
            {

                ItemSet firstSubString = new ItemSet();
                ItemSet secondSubString = new ItemSet();

                firstSubString.items = i1.items.GetRange(0, length - 1);
                secondSubString.items = i2.items.GetRange(0, length - 1);
                firstSubString.sort();
                secondSubString.sort();
                if (firstSubString.stringRepresentation().Equals(secondSubString.stringRepresentation()))
                {
                    newItemSet.items.Add(i2.items[length - 1]);
                    return newItemSet;
                }

                ItemSet empt = new ItemSet();
                return empt;

            }
        }
Пример #7
0
        static List<ItemSet> l1scan(List<ItemSet> candidateItemsets, int patternNum)
        {
            List<ItemSet> newcandidateItemsets = new List<ItemSet>();

            foreach (ItemSet iset in candidateItemsets)
            {
                ItemSet newcandidate = new ItemSet();// = iset;

                iset.support = GetSupport(iset);
                iset.clone(newcandidate);
                if (newcandidate.support >= minsup)
                {
                    newcandidateItemsets.Add(newcandidate);
                }
            }
            //Console.WriteLine("Frequent Pattern for " + patternNum + " - Itemset and min support");
            //foreach (ItemSet i in newcandidateItemsets)
            //Console.WriteLine(i.stringRepresentationWithSpace() +  " " + i.support);
            return newcandidateItemsets;
        }
Пример #8
0
 internal void clone(ItemSet newItemSet)
 {
     foreach (Item item in items)
     {
         newItemSet.add(item);
     }
     newItemSet.support = this.support;
 }