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); } }
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); } }
void SortByTable(FPTransition transition, FPNodeHeadTable nodeTable, ref Queue <FPItem> result) { int size = nodeTable.Size(); for (int i = 0; i < size; ++i) { if (transition.ContainItem(nodeTable.At(i).mOwner)) { result.Enqueue(nodeTable.At(i).mOwner); } } }
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); } }
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); }
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); } }
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); } } } }