test_class.file: legacy/src/test/java/macrobase/analysis/summary/itemset/AprioriTest.java
test_class.identifier: AprioriTest
test_case.body: @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"));
  
          Apriori fp = new Apriori();
  
          Set<ItemsetWithCount> itemsets = fp.getItemsets(txns, .7);
  
          //printItemsets(itemsets);
  
          assertEquals(3, itemsets.size());
      }
test_case.class_method_signature: AprioriTest.simpleTest()
test_case.full_signature: @Test public void simpleTest()
test_case.identifier: simpleTest
test_case.invocations: add intIfy add intIfy add intIfy getItemsets assertEquals size
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void simpleTest()
focal_class.file: legacy/src/main/java/macrobase/analysis/summary/itemset/Apriori.java
focal_class.identifier: Apriori
focal_class.class_method_signature: Apriori.genCandidates(List<ItemsetWithCount> prevRound,
                                              int desiredSize)
focal_class.full_signature: private Set<Set<Integer>> genCandidates(List<ItemsetWithCount> prevRound,
                                              int desiredSize)
focal_class.identifier: genCandidates
focal_class.modifiers: private
focal_class.parameters: (List<ItemsetWithCount> prevRound,
                                              int desiredSize)
focal_class.return: Set<Set<Integer>>
focal_class.signature: Set<Set<Integer>> genCandidates(List<ItemsetWithCount> prevRound,
                                              int desiredSize)
focal_class.class_method_signature: Apriori.filterItems(List<Set<Integer>> transactions,
                                                 Set<Set<Integer>> candidates,
                                                 Set<Integer> infrequentIndex,
                                                 int minSupportCount)
focal_class.full_signature: private List<ItemsetWithCount> filterItems(List<Set<Integer>> transactions,
                                                 Set<Set<Integer>> candidates,
                                                 Set<Integer> infrequentIndex,
                                                 int minSupportCount)
focal_class.identifier: filterItems
focal_class.modifiers: private
focal_class.parameters: (List<Set<Integer>> transactions,
                                                 Set<Set<Integer>> candidates,
                                                 Set<Integer> infrequentIndex,
                                                 int minSupportCount)
focal_class.return: List<ItemsetWithCount>
focal_class.signature: List<ItemsetWithCount> filterItems(List<Set<Integer>> transactions,
                                                 Set<Set<Integer>> candidates,
                                                 Set<Integer> infrequentIndex,
                                                 int minSupportCount)
focal_class.class_method_signature: Apriori.getItemsets(List<Set<Integer>> transactions,
                                               Double support)
focal_class.full_signature: public Set<ItemsetWithCount> getItemsets(List<Set<Integer>> transactions,
                                               Double support)
focal_class.identifier: getItemsets
focal_class.modifiers: public
focal_class.parameters: (List<Set<Integer>> transactions,
                                               Double support)
focal_class.return: Set<ItemsetWithCount>
focal_class.signature: Set<ItemsetWithCount> getItemsets(List<Set<Integer>> transactions,
                                               Double support)
focal_method.body: public Set<ItemsetWithCount> getItemsets(List<Set<Integer>> transactions,
                                               Double support) {
          Set<ItemsetWithCount> ret = new HashSet<>();
  
          int minSupportCount = (int) (support * transactions.size());
  
          // first round candidates are all items; just count them
          HashMap<Integer, Integer> itemCounts = new HashMap<>();
          for (Set<Integer> t : transactions) {
              for (int i : t) {
                  itemCounts.compute(i, (k, v) -> v == null ? 1 : v + 1);
              }
          }
  
          for (Map.Entry<Integer, Integer> e : itemCounts.entrySet()) {
              if (e.getValue() >= minSupportCount) {
                  HashSet<Integer> singletonSet = new HashSet<>();
                  singletonSet.add(e.getKey());
                  ret.add(new ItemsetWithCount(singletonSet, e.getValue()));
              }
          }
  
          if (ret.size() == 0) {
              return ret;
          }
  
          // second round, don't explicitly construct pairs
          HashMap<Set<Integer>, Integer> pairCandidateCounts = new HashMap<>();
  
          for (Set<Integer> t : transactions) {
              List<Integer> txList = Lists.newArrayList(t);
              for (int i = 0; i < t.size(); ++i) {
                  for (int j = i + 1; j < t.size(); ++j) {
                      HashSet<Integer> pairSet = new HashSet<>();
                      pairSet.add(txList.get(i));
                      pairSet.add(txList.get(j));
                      pairCandidateCounts.compute(pairSet, (k, v) -> v == null ? 1 : v + 1);
                  }
              }
          }
  
          List<ItemsetWithCount> pairItemsets = new ArrayList<>();
  
          for (Map.Entry<Set<Integer>, Integer> e : pairCandidateCounts.entrySet()) {
              if (e.getValue() >= minSupportCount) {
                  ItemsetWithCount ic = new ItemsetWithCount(e.getKey(), e.getValue());
                  ret.add(ic);
                  pairItemsets.add(ic);
              }
          }
  
          if (pairItemsets.isEmpty()) {
              return ret;
          }
  
          List<ItemsetWithCount> prevRoundItemsets = pairItemsets;
          Set<Integer> infrequentIndex = new HashSet<>();
  
          int newSize = 3;
          while (true) {
              Set<Set<Integer>> candidates = genCandidates(prevRoundItemsets, newSize);
              prevRoundItemsets = filterItems(transactions,
                                              candidates,
                                              infrequentIndex,
                                              minSupportCount);
              if (prevRoundItemsets.isEmpty()) {
                  return ret;
              } else {
                  ret.addAll(prevRoundItemsets);
                  newSize += 1;
              }
          }
      }
focal_method.class_method_signature: Apriori.getItemsets(List<Set<Integer>> transactions,
                                               Double support)
focal_method.full_signature: public Set<ItemsetWithCount> getItemsets(List<Set<Integer>> transactions,
                                               Double support)
focal_method.identifier: getItemsets
focal_method.invocations: size compute entrySet getValue add getKey add getValue size newArrayList size size add get add get compute entrySet getValue getKey getValue add add isEmpty genCandidates filterItems isEmpty addAll
focal_method.modifiers: public
focal_method.parameters: (List<Set<Integer>> transactions,
                                               Double support)
focal_method.return: Set<ItemsetWithCount>
focal_method.signature: Set<ItemsetWithCount> getItemsets(List<Set<Integer>> transactions,
                                               Double support)