Esempio n. 1
0
        public static void GrowthProb(string fileName)
        {
            FPTransitions transitions = LoadFromFile(fileName);
            FPTree        fpTree      = new FPTree(3);

            fpTree.mMaxDepth = 1;
            fpTree.GrowthProb(transitions);
            fpTree.Print();
        }
Esempio n. 2
0
        public static void Growth(string fileName)
        {
            FPTransitions transitions = LoadFromFile(fileName);
            FPTree        fpTree      = new FPTree(3);

            fpTree.mMaxDepth = 3;
            List <string> tmp = new List <string>();

            fpTree.Growth(transitions, tmp);
        }
Esempio n. 3
0
        private static FPTransition ParseStringToTransition(FPTransitions transitions, string source)
        {
            List <string> arrayOfTransition = new List <string>();
            string        temp = source.Trim();

            string[] itels = temp.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            arrayOfTransition.AddRange(itels);
            FPTransition transition = ParseArrayToTransition(transitions, arrayOfTransition);

            return(transition);
        }
Esempio n. 4
0
        private static FPTransition ParseArrayToTransition(FPTransitions transitions, List <string> sourceArray)
        {
            FPTransition transition = new FPTransition();
            int          size       = sourceArray.Count;

            for (int i = 0; i < size; ++i)
            {
                FPItem item = ParseStringToItem(transitions, sourceArray[i]);
                transition.AddItem(item, transitions.mDuplicate);
            }
            return(transition);
        }
Esempio n. 5
0
        public static FPTransitions ParseFromArray(List <string> sources, bool duplicate)
        {
            FPTransitions transitions = new FPTransitions(duplicate);
            int           isize       = sources.Count;

            for (int i = 0; i < isize; ++i)
            {
                FPTransition transition = ParseStringToTransition(transitions, sources[i]);
                transitions.AddTransition(transition);
            }
            return(transitions);
        }
Esempio n. 6
0
        private static FPTransitions LoadFromFile(string fileName, bool duplicate = false)
        {
            List <string> tmp = new List <string>();

            tmp.Add("1 2 3 4 5");
            tmp.Add("1 3 5 10");
            tmp.Add("2 4 6 12");
            tmp.Add("1 4 7 13");
            tmp.Add("1 4 7 13");
            FPTransitions transitions = ParseFromArray(tmp, duplicate);

            return(transitions);
        }
Esempio n. 7
0
        private FPNodeHeadTable BuildHeaderTable(FPTransitions transitions)
        {
            FPNodeHeadTable table = new FPNodeHeadTable();

            foreach (FPItem item in transitions.mItems.Values)
            {
                if (item.mSupport > mMinSupport)
                {
                    table.AddTableNode(item.CreateNode());
                }
            }
            table.Sort();
            return(table);
        }
Esempio n. 8
0
        private FPTreeNode BuildFPTree(FPTransitions transitions, FPNodeHeadTable table)
        {
            FPTreeNode root = new FPTreeNode("", null);
            int        size = transitions.Size();

            for (int i = 0; i < size; ++i)
            {
                Queue <FPItem> record = new Queue <FPItem>();
                SortByTable(transitions[i], table, ref record);
                FPTreeNode subTreeRoot = root;
                FPTreeNode tmpRoot     = null;
                while (record.Count > 0 && ((tmpRoot = subTreeRoot.FindChild(record.Peek().mName)) != null))
                {
                    tmpRoot.Increasement(1);
                    subTreeRoot = tmpRoot;
                    record.Dequeue();
                }
                AddNodes(subTreeRoot, record, table);
            }
            return(root);
        }
Esempio n. 9
0
        public void GrowthProb(FPTransitions transitions)
        {
            SetMinSupport(mMinSupport, transitions.Size());
            FPNodeHeadTable table = BuildHeaderTable(transitions);
            FPTreeNode      root  = BuildFPTree(transitions, table);

            if (transitions.mDepth > mMaxDepth)
            {
                return;
            }
            int total = transitions.Size();
            int size  = table.Size();

            if (size == 0)
            {
                return;
            }
            GenerateProbOne(root, table, ref total);
            GenerateProbTwo(root, table, ref total);
            GenerateProbThree(root, table, ref total);
        }
Esempio n. 10
0
 private static FPItem ParseStringToItem(FPTransitions transitions, string source)
 {
     return(transitions.AddItem(source));
 }
Esempio n. 11
0
        public void Growth(FPTransitions transitions, List <string> postPatterns)
        {
            SetMinSupport(mMinSupport, transitions.Size());
            FPNodeHeadTable table = BuildHeaderTable(transitions);
            FPTreeNode      root  = BuildFPTree(transitions, table);

            if (transitions.Depth > mMaxDepth)
            {
                return;
            }
            int size = table.Size();

            if (size == 0)
            {
                return;
            }
            string post = "";

            if (postPatterns != null)
            {
                int num = postPatterns.Count;
                for (int n = num - 1; n >= 0; --n)
                {
                    post += postPatterns[n] + " ";
                }
                post.Trim();
            }
            for (int i = 0; i < size; ++i)
            {
                FPTreeNode    child          = table.mHeaderNode[i];
                FPTreeNode    next           = child.NextNode;
                FPTransitions newTransitions = null;
                List <string> samples        = new List <string>();
                while (next != null)
                {
                    string     str    = "";
                    FPTreeNode parent = next.mParent;

                    while (parent != null)
                    {
                        str   += parent.mName;
                        str   += " ";
                        parent = parent.mParent;
                    }
                    str.Trim();
                    if (str == "")
                    {
                        next = next.NextNode;
                        continue;
                    }

                    if (transitions.Depth <= mMaxDepth)
                    {
                        for (int j = 0; j < next.mCount; ++j)
                        {
                            samples.Add(str);
                        }
                    }
                    if (post == "")
                    {
                        Debug.Log(str);
                    }
                    else
                    {
                        Debug.Log(str + " : " + post);
                    }
                    next = next.NextNode;
                }
                if (transitions.Depth <= mMaxDepth)
                {
                    newTransitions = FPGrowth.ParseFromArray(samples, transitions.mDuplicate);
                    List <string> newPostPattern = new List <string>();
                    int           num            = postPatterns.Count;
                    for (int n = 0; n < num; ++n)
                    {
                        newPostPattern.Add(postPatterns[n]);
                    }
                    newPostPattern.Add(child.mName);
                    if (newTransitions != null)
                    {
                        newTransitions.Depth = transitions.Depth + 1;
                        Growth(newTransitions, newPostPattern);
                    }
                }
            }
        }