FPGrowth { public List<ItemsetWithCount> getItemsetsWithSupportRatio(List<Set<Integer>> transactions, Double supportRatio) { return getItemsetsWithSupportRatio(transactions, null, supportRatio); }  List<ItemsetWithCount> getItemsetsWithSupportRatio(List<Set<Integer>> transactions,
                                                              Double supportRatio); List<ItemsetWithCount> getItemsetsWithSupportRatio(List<Set<Integer>> transactions,
                                                              Map<Integer, Double> initialCounts,
                                                              Double supportRatio); List<ItemsetWithCount> getItemsetsWithSupportCount(List<Set<Integer>> transactions,
                                                              Double supportCount); List<ItemsetWithCount> getItemsetsWithSupportCount(List<Set<Integer>> transactions,
                                                              Map<Integer, Double> initialCounts,
                                                              Double supportCount); List<ItemsetWithCount> getItemsetsWithSupportCount(List<Set<Integer>> transactions,
                                                              Map<Integer, Double> initialCounts,
                                                              Double supportCount,
                                                              boolean printTreeDebug); List<ItemsetWithCount> getCounts(
            List<Set<Integer>> transactions,
            Map<Integer, Double> initialCounts,
            Set<Integer> targetItems,
            List<ItemsetWithCount> toCount);  }
@Test public void testFPFromPaper() { List<Set<Integer>> txns = new ArrayList<>(); txns.add(intIfy("f, a, c, d, g, i, m, p")); txns.add(intIfy("a, b, c, f, l, m, o")); txns.add(intIfy("b, f, h, j, o")); txns.add(intIfy("b, c, k, s, p")); txns.add(intIfy("a, f, c, e, l, p, m, n")); FPGrowth fp = new FPGrowth(); Apriori ap = new Apriori(); Set<ItemsetWithCount> ap_itemsets = ap.getItemsets(txns, .6); List<ItemsetWithCount> itemsets = fp.getItemsetsWithSupportRatio(txns, .6); assertEquals(18, itemsets.size()); assert(compareResults(ap_itemsets, itemsets)); }
@Test public void testFPLonger() { List<Set<Integer>> txns = new ArrayList<>(); txns.add(intIfy("f, a, c, d, g, i, m, p")); txns.add(intIfy("a, b, c, f, l, m, o")); FPGrowth fp = new FPGrowth(); List<ItemsetWithCount> itemsets = fp.getItemsetsWithSupportRatio(txns, .2); Apriori ap = new Apriori(); Set<ItemsetWithCount> api = ap.getItemsets(txns, .2); List<Set<Integer>> apil = api.stream().map(i -> i.getItems()).collect(Collectors.toList()); Set<Set<Integer>> dupdetector = new HashSet<>(); int numDup = 0; for (Set<Integer> s : apil) { if (!dupdetector.add(s)) { numDup++; } } assertEquals(0, numDup); Set<Set<Integer>> iss = itemsets.stream().map(i -> i.getItems()).collect(Collectors.toSet()); assertEquals(api.size(), itemsets.size()); }
@Test public void simpleTest() { List<Set<Integer>> txns = new ArrayList<>(); txns.add(intIfy("a, b, c")); txns.add(intIfy("a, b")); txns.add(intIfy("a")); FPGrowth fp = new FPGrowth(); Apriori ap = new Apriori(); Set<ItemsetWithCount> ap_itemsets = ap.getItemsets(txns, .7); List<ItemsetWithCount> itemsets = fp.getItemsetsWithSupportRatio(txns, .7); assertEquals(3, itemsets.size()); assert(compareResults(ap_itemsets, itemsets)); }