private FPTree getPatternsAndTree(FPTree tree, int column) { FPTree result = new FPTree(); if (tree.header.ContainsKey(column)) { result.root.Count = 0; FPTreeNode colNode = tree.header[column]; while (colNode != null) { // get a path int count = colNode.Count; result.root.Count += count; ArrayList reversePath = new ArrayList(); FPTreeNode current = colNode.Parent; while (current.Column != -1) { reversePath.Add(current.Column); current = current.Parent; } int[] path = new int[reversePath.Count]; for (int i = 0; i < path.Length; ++i) { path[i] = (int)reversePath[path.Length - 1 - i]; } result.insert(path, count); colNode = colNode.ColumnBrother; } } return(result); }
public FP(String[] colNames, int recordCount, int[] colCount) { fpTree = new FPTree(); allPatterns = new ArrayList(); filteredPatterns = new ArrayList(); this.colNames = colNames; this.colCount = colCount; this.sortedCols = new int[colNames.Length]; for (int i = 0; i < colNames.Length; ++i) { this.sortedCols[i] = i; } }
private void fpGrowth(FPTree tree, int[] columns, int minCount, int[] containsCols = null) { if (columns != null && tree.root.Count >= minCount) { allPatterns.Add(new Pattern(columns, tree.root.Count, tree.root.Count / (double)this.recordCount)); if (containsCols != null) { // check if this pattern contains any required column Boolean contains = false; for (int i = 0; i < containsCols.Length && !contains; ++i) { for (int j = 0; j < columns.Length; ++j) { if (columns[j] == containsCols[i]) { filteredPatterns.Add(new Pattern(columns, tree.root.Count, tree.root.Count / (double)this.recordCount)); contains = true; break; } } } } } else if (columns != null) { return; } foreach (int column in tree.header.Keys) { int[] postfix = insertPrefix(column, columns); FPTree newTree = getPatternsAndTree(tree, postfix[0]); fpGrowth(newTree, postfix, minCount, containsCols); } }
private FPTree getPatternsAndTree(FPTree tree, int column) { FPTree result = new FPTree(); if (tree.header.ContainsKey(column)) { result.root.Count = 0; FPTreeNode colNode = tree.header[column]; while (colNode != null) { // get a path int count = colNode.Count; result.root.Count += count; ArrayList reversePath = new ArrayList(); FPTreeNode current = colNode.Parent; while (current.Column != -1) { reversePath.Add(current.Column); current = current.Parent; } int[] path = new int[reversePath.Count]; for (int i = 0; i < path.Length; ++i) { path[i] = (int)reversePath[path.Length - 1 - i]; } result.insert(path, count); colNode = colNode.ColumnBrother; } } return result; }