private List<VerticalItemSetDto> GenerateInitialItemSets(List<TransactionDto> Transactions)
        {
            List<VerticalItemSetDto> ret = new List<VerticalItemSetDto>();

            foreach (TransactionDto t in Transactions)
            {
                foreach (string s in t.items)
                {
                    List<string> ts = new List<string>();
                    ts.Add(s);
                    VerticalItemSetDto temp = new VerticalItemSetDto(ts);
                    temp.Increment(t.tid);

                    if (ret.Contains(temp))
                    {
                        ret[ret.IndexOf(temp)].Increment(t.tid);
                    }//if
                    else
                    {
                        ret.Add(temp);
                    }//else
                }//foreach in productList
            }//foreach in Transactions

            return ret;
        }
예제 #2
0
        private List <VerticalItemSetDto> GenerateInitialItemSets(List <TransactionDto> Transactions)
        {
            List <VerticalItemSetDto> ret = new List <VerticalItemSetDto>();

            foreach (TransactionDto t in Transactions)
            {
                foreach (string s in t.items)
                {
                    List <string> ts = new List <string>();
                    ts.Add(s);
                    VerticalItemSetDto temp = new VerticalItemSetDto(ts);
                    temp.Increment(t.tid);

                    if (ret.Contains(temp))
                    {
                        ret[ret.IndexOf(temp)].Increment(t.tid);
                    }//if
                    else
                    {
                        ret.Add(temp);
                    } //else
                }     //foreach in productList
            }         //foreach in Transactions

            return(ret);
        }//GenerateInitialItemSets
예제 #3
0
        }//prune

        private List <VerticalItemSetDto> join(List <VerticalItemSetDto> survivors)
        {
            List <VerticalItemSetDto> ret = new List <VerticalItemSetDto>();

            for (int i = 0; i < survivors.Count; i++)
            {
                for (int j = i + 1; j < survivors.Count; j++)
                {
                    for (int x = 0; x < survivors[j].Itemset.Count; x++)
                    {
                        List <string> newItems = new List <string>();
                        newItems.AddRange(survivors[i].Itemset);

                        if (!survivors[i].Itemset.Contains(survivors[j].Itemset[x]))
                        {
                            newItems.Add(survivors[j].Itemset[x]);
                        }//if

                        VerticalItemSetDto newItemset = new VerticalItemSetDto(newItems);

                        if (!ret.Contains(newItemset))
                        {
                            ret.Add(newItemset);
                        } //if
                    }     //for x
                }         //for j
            }             //for i

            return(ret);
        }//join
예제 #4
0
        }//GetFrequentItemSets

        private List <VerticalItemSetDto> prune(List <VerticalItemSetDto> joinedCandidates, List <VerticalItemSetDto> oldItems)
        {
            List <VerticalItemSetDto> ret = new List <VerticalItemSetDto>();
            bool good;

            foreach (VerticalItemSetDto isd in joinedCandidates)
            {
                good = true;
                List <string> combinations = new List <string>();

                //suggestion for generating combinations from
                // http://stackoverflow.com/questions/7802822/all-possible-combinations-of-a-list-of-values-in-c-sharp
                double count = Math.Pow(2, isd.Itemset.Count);
                for (int i = 1; i <= count - 1; i++)
                {
                    string str = Convert.ToString(i, 2).PadLeft(isd.Itemset.Count, '0');
                    for (int j = 0; j < str.Length; j++)
                    {
                        if (str[j] == '1')
                        {
                            combinations.Add(isd.Itemset[j]);
                        } //if
                    }     //for j
                    if (combinations.Count == isd.Itemset.Count - 1)
                    {
                        VerticalItemSetDto c = new VerticalItemSetDto(combinations);
                        if (!oldItems.Contains(c))
                        {
                            good = false;
                            break;
                        }
                    } //if
                }     //for i

                if (good)
                {
                    ret.Add(isd);
                } //if
            }     //foreach

            return(ret);
        }//prune
예제 #5
0
        private List<VerticalItemSetDto> prune(List<VerticalItemSetDto> joinedCandidates, List<VerticalItemSetDto> oldItems)
        {
            List<VerticalItemSetDto> ret = new List<VerticalItemSetDto>();
            bool good;

            foreach (VerticalItemSetDto isd in joinedCandidates)
            {
                good = true;
                List<string> combinations = new List<string>();

                //suggestion for generating combinations from
                // http://stackoverflow.com/questions/7802822/all-possible-combinations-of-a-list-of-values-in-c-sharp
                double count = Math.Pow(2, isd.Itemset.Count);
                for (int i = 1; i <= count - 1; i++)
                {
                    string str = Convert.ToString(i, 2).PadLeft(isd.Itemset.Count, '0');
                    for (int j = 0; j < str.Length; j++)
                    {
                        if (str[j] == '1')
                        {
                            combinations.Add(isd.Itemset[j]);
                        }//if
                    }//for j
                    if (combinations.Count == isd.Itemset.Count - 1)
                    {
                        VerticalItemSetDto c = new VerticalItemSetDto(combinations);
                        if (!oldItems.Contains(c))
                        {
                            good = false;
                            break;
                        }
                    }//if
                }//for i

                if (good)
                {
                    ret.Add(isd);
                }//if
            }//foreach

            return ret;
        }
예제 #6
0
        private List<VerticalItemSetDto> join(List<VerticalItemSetDto> survivors)
        {
            List<VerticalItemSetDto> ret = new List<VerticalItemSetDto>();

            for (int i = 0; i < survivors.Count; i++)
            {
                for (int j = i + 1; j < survivors.Count; j++)
                {
                    for (int x = 0; x < survivors[j].Itemset.Count; x++)
                    {
                        List<string> newItems = new List<string>();
                        newItems.AddRange(survivors[i].Itemset);

                        if (!survivors[i].Itemset.Contains(survivors[j].Itemset[x]))
                        {
                            newItems.Add(survivors[j].Itemset[x]);
                        }//if

                        VerticalItemSetDto newItemset = new VerticalItemSetDto(newItems);

                        if (!ret.Contains(newItemset))
                        {
                            ret.Add(newItemset);
                        }//if
                    }//for x
                }//for j
            }//for i

            return ret;
        }