Ejemplo n.º 1
0
        void AddNodes(FPTreeNode ancestor, Queue <FPItem> record, FPNodeHeadTable nodeTable)
        {
            int size = record.Count;

            if (size > 0)
            {
                FPItem     item = record.Dequeue();
                FPTreeNode node = item.CreateNode();
                node.mCount  = 1;
                node.mParent = ancestor;
                ancestor.AddChild(node);
                int        count    = nodeTable.Size();
                FPTreeNode tempNode = null;
                for (int j = 0; j < count; ++j)
                {
                    tempNode = nodeTable.At(j);
                    if (tempNode.mName == node.mName)
                    {
                        node.NextNode     = tempNode.NextNode;
                        tempNode.NextNode = node;
                        //while (tempNode.NextNode != null)
                        //{
                        //    tempNode = tempNode.NextNode;
                        //}
                        //tempNode.NextNode = node;
                        break;
                    }
                }
                AddNodes(node, record, nodeTable);
            }
        }
Ejemplo n.º 2
0
        int CalcuelateSharedCount(FPTreeNode nodeA, FPTreeNode nodeB, FPTreeNode nodeC)
        {
            int        count  = 0;
            FPTreeNode next   = nodeC.NextNode;
            FPTreeNode parent = null;
            bool       flagB  = false;
            bool       flagA  = false;

            while (next != null)
            {
                parent = next.mParent;
                while (parent != null)
                {
                    if (!flagB && parent.mName == nodeB.mName)
                    {
                        flagB = true;
                    }
                    else if (flagB && !flagA && parent.mName == nodeA.mName)
                    {
                        flagA = true;
                    }
                    else if (flagB && flagA)
                    {
                        count += next.mCount;
                        break;
                    }
                    parent = parent.mParent;
                }
                flagB = false;
                flagA = false;
                next  = next.NextNode;
            }
            return(count);
        }
Ejemplo n.º 3
0
 public FPTreeNode(string name, FPItem item)
 {
     mName             = name;
     mOwner            = item;
     mParent           = null;
     mSameNameNextNode = null;
     mCount            = 0;
     mChildren         = new List <FPTreeNode>();
 }
Ejemplo n.º 4
0
        void GenerateProbOne(FPTreeNode root, FPNodeHeadTable table, ref int total)
        {
            int size = table.Size();

            for (int i = 0; i < size; ++i)
            {
                FPTreeNode child = table.At(i);
                mProbs.Add(child.mName, child.mOwner.mSupport * 1.0f / total);
                mExistCount.Add(child.mName, child.mOwner.mSupport);
            }
        }
Ejemplo n.º 5
0
        void GenerateProbTwo(FPTreeNode root, FPNodeHeadTable table, ref int total)
        {
            int size = table.Size();

            if (size <= 2)
            {
                return;
            }
            FPTreeNode childI = null;
            List <List <FPTreeNode> > calculate = new List <List <FPTreeNode> >();

            for (int i = 0; i < size - 1; ++i)
            {
                childI = table.At(i);
                FPTreeNode childJ = null;
                for (int j = i + 1; j < size; ++j)
                {
                    List <FPTreeNode> temp = new List <FPTreeNode>();
                    childJ = table.At(j);
                    temp.Add(childI);
                    temp.Add(childJ);
                    calculate.Add(temp);
                }
            }
            size = calculate.Count;
            for (int i = 0; i < size; ++i)
            {
                FPTreeNode nodeA      = calculate[i][0];
                FPTreeNode nodeB      = calculate[i][1];
                int        shareCount = CalcuelateSharedCount(nodeA, nodeB);
                if (shareCount == 0)
                {
                    continue;
                }
                float AB = shareCount * 1.0f / mExistCount[nodeA.mName];
                float BA = shareCount * 1.0f / mExistCount[nodeB.mName];
                mProbs.Add(nodeA.mName + " " + nodeB.mName, AB);
                mProbs.Add(nodeB.mName + " " + nodeA.mName, BA);
                mExistCount.Add(nodeA.mName + " " + nodeB.mName, shareCount);
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        int CalcuelateSharedCount(FPTreeNode nodeA, FPTreeNode nodeB)
        {
            int        count  = 0;
            FPTreeNode next   = nodeB.NextNode;
            FPTreeNode parent = null;

            while (next != null)
            {
                parent = next.mParent;
                while (parent != null)
                {
                    if (parent.mName == nodeA.mName)
                    {
                        count += next.mCount;
                        break;
                    }
                    parent = parent.mParent;
                }
                next = next.NextNode;
            }
            return(count);
        }
Ejemplo n.º 9
0
        void GenerateProbThree(FPTreeNode root, FPNodeHeadTable table, ref int total)
        {
            int size = table.Size();

            if (size <= 3)
            {
                return;
            }
            FPTreeNode childI = null;
            FPTreeNode childJ = null;
            FPTreeNode childK = null;
            List <List <FPTreeNode> > calculate = new List <List <FPTreeNode> >();

            for (int i = 0; i < size - 2; ++i)
            {
                childI = table.At(i);
                for (int j = i + 1; j < size - 1; ++j)
                {
                    childJ = table.At(j);
                    for (int k = j + 1; k < size; ++k)
                    {
                        childK = table.At(k);
                        List <FPTreeNode> temp = new List <FPTreeNode>();
                        temp.Add(childI);
                        temp.Add(childJ);
                        temp.Add(childK);
                        calculate.Add(temp);
                    }
                }
            }
            size = calculate.Count;
            for (int i = 0; i < size; ++i)
            {
                FPTreeNode nodeA      = calculate[i][0];
                FPTreeNode nodeB      = calculate[i][1];
                FPTreeNode nodeC      = calculate[i][2];
                int        shareCount = CalcuelateSharedCount(nodeA, nodeB, nodeC);
                if (shareCount == 0)
                {
                    continue;
                }
                string ABC = nodeA.mName + " " + nodeB.mName;
                string ACB = nodeA.mName + " " + nodeC.mName;
                string BCA = nodeB.mName + " " + nodeC.mName;
                string BAC = nodeB.mName + " " + nodeA.mName;
                string CAB = nodeC.mName + " " + nodeA.mName;
                string CBA = nodeC.mName + " " + nodeB.mName;
                float  abc = shareCount * 1.0f / mExistCount[ABC];
                float  acb = shareCount * 1.0f / mExistCount[ACB];
                float  bca = shareCount * 1.0f / mExistCount[BCA];
                float  bac = shareCount * 1.0f / mExistCount[ABC];
                float  cab = shareCount * 1.0f / mExistCount[ACB];
                float  cba = shareCount * 1.0f / mExistCount[BCA];

                mProbs.Add(ABC + " " + nodeC.mName, abc);
                mProbs.Add(ACB + " " + nodeB.mName, acb);
                mProbs.Add(BCA + " " + nodeA.mName, bca);
                mProbs.Add(BAC + " " + nodeC.mName, bac);
                mProbs.Add(CAB + " " + nodeB.mName, cab);
                mProbs.Add(CBA + " " + nodeA.mName, cba);
                mExistCount.Add(ABC + " " + nodeC.mName, shareCount);
            }
        }
Ejemplo n.º 10
0
        public void Growth(FPTransitions transitions, List <string> postPatterns)
        {
            SetMinSupport(mMinSupport, transitions.Size());
            FPNodeHeadTable table = BuildHeaderTable(transitions);

            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);
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public void AddTableNode(FPTreeNode node)
 {
     mHeaderNode.Add(node);
 }
Ejemplo n.º 12
0
 public void AddChild(FPTreeNode node)
 {
     mChildren.Add(node);
 }