FPGrowth { public List<FrequentPattern> run(List<List<Tuple>> transactions, double minSupport, int maxLength){ return run(transactions, new FrequentPattern(1), (int)Math.ceil(minSupport*transactions.size()), maxLength, true); } FPGrowth(); void setParallel(boolean parallel); void buildTree(List<List<Tuple>> transactions, int minSupportCount); List<FrequentPattern> run(List<List<Tuple>> transactions, double minSupport, int maxLength); List<FrequentPattern> run(List<List<Tuple>> transactions, int minSupportCount, int maxLength); FPTree getTree(); int getSize();  }
@Test public void audiologyTest() throws IOException{ loadAudioLogy(); FPGrowth fpGrowth = new FPGrowth(); List<List<Tuple>> t = train.stream().map(item -> { List<Tuple> tuples = new ArrayList<>(); for(String key:item.keys()){ for(String val:item.get(key)){ tuples.add(new Tuple(key,val)); } } return tuples; }).collect(Collectors.toList()); List<FrequentPattern> fps = null; fps = fpGrowth.run(t, 0.1, 2); Assert.assertEquals(40, fps.size()); }
@Test public void irisTest() throws IOException{ loadIris(); FPGrowth fpGrowth = new FPGrowth(); List<List<Tuple>> t = train.stream().map(item -> { List<Tuple> tuples = new ArrayList<>(); for(String key:item.keys()){ for(String val:item.get(key)){ tuples.add(new Tuple(key,val)); } } return tuples; }).collect(Collectors.toList()); List<FrequentPattern> fps = null; fps = fpGrowth.run(t, 0.05, 2); System.out.println(fps); Assert.assertEquals(40, fps.size()); }
@Test public void zooTest() throws IOException{ loadTrain(); FPGrowth fpGrowth = new FPGrowth(); List<List<Tuple>> t = train.stream().map(item -> { List<Tuple> tuples = new ArrayList<>(); for(String key:item.keys()){ for(String val:item.get(key)){ tuples.add(new Tuple(key,val)); } } return tuples; }).collect(Collectors.toList()); List<FrequentPattern> fps = null; fps = fpGrowth.run(t, 0.7, 3); Assert.assertEquals(23, fps.size()); fps = fpGrowth.run(t, 0.5, 3); fps = fps.stream(). sorted( Comparator.comparing(fp -> fp.getPattern().toString()) ) .collect(Collectors.toList()); System.out.println(fps); Assert.assertEquals(144, fps.size()); fps = fpGrowth.run(t, 0.001, 3); Assert.assertEquals(6505, fps.size()); fps = fpGrowth.run(t, 0.001, 5); Assert.assertEquals(138326, fps.size()); fps = fpGrowth.run(t, 0.1, 50); Assert.assertEquals(240865, fps.size()); }
@Test public void averageTimeOfZoo() throws IOException{ List<Double> times = new LinkedList<>(); for (int i = 0; i < 30; i++) { loadTrain(); long startTime = System.nanoTime(); FPGrowth fpGrowth = new FPGrowth(); List<List<Tuple>> t = train.stream().map(item -> { List<Tuple> tuples = new ArrayList<>(); for(String key:item.keys()){ for(String val:item.get(key)){ tuples.add(new Tuple(key,val)); } } return tuples; }).collect(Collectors.toList()); List<FrequentPattern> fps = fpGrowth.run(t, 0.001, 3); System.out.println("FP: "+fps.size()); System.out.println("FPG: "+(System.nanoTime()-startTime)/1000000+" ms"); times.add((double) ((System.nanoTime()-startTime)/1000000)); } System.out.println(times.stream().mapToDouble(a -> a).average().getAsDouble()); }