Beispiel #1
0
        public void TestMaxHeapFPGrowth()
        {
            FPGrowth<string> fp = new FPGrowth<string>();

            List<KeyValuePair<List<string>, long>> transactions = new List<KeyValuePair<List<string>, long>>();
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("E", "A", "D", "B"), 1L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("D", "A", "C", "E", "B"), 1L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("C", "A", "B", "E"), 1L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("B", "A", "D"), 1L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("D"), 1L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("D", "B"), 1L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("A", "D", "E"), 1L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("B", "C"), 1L));

            using (var outWriter = new StringWriter())
            {
                fp.GenerateTopKFrequentPatterns(
                    transactions,
                    fp.GenerateFList(transactions, 3),
                    3,
                    100,
                    new HashSet<string>(),
                    new StringOutputConverter(new SequenceFileOutputCollector<string, TopKStringPatterns>(outWriter, "{0}\t{1},")),
                    new ContextStatusUpdater());

                var res = @"C	([B,C],3),"
                        + @"E	([A,E],4), ([A,B,E],3), ([A,D,E],3),"
                        + @"A	([A],5), ([A,D],4), ([A,E],4), ([A,B],4), ([A,B,E],3), ([A,D,E],3), ([A,B,D],3),"
                        + @"D	([D],6), ([B,D],4), ([A,D],4), ([A,D,E],3), ([A,B,D],3),"
                        + @"B	([B],6), ([A,B],4), ([B,D],4), ([A,B,D],3), ([A,B,E],3), ([B,C],3),";
                Assert.AreEqual(outWriter.ToString(), res);
            }
        }
Beispiel #2
0
        public void TestMaxHeapFPGrowthData2() {
            FPGrowth<String> fp = new FPGrowth<String>();

            ICollection<KeyValuePair<List<string>, long>> transactions = new List<KeyValuePair<List<string>, long>>();
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("X"), 12L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("Y"), 4L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("X", "Y"), 10L));
            transactions.Add(new KeyValuePair<List<string>, long>(Arrays.asList("X", "Y", "Z"), 11L));

            using (var outWriter = new StringWriter())
            {
                Console.WriteLine(fp.GenerateFList(transactions, 2));

                fp.GenerateTopKFrequentPatterns(
                        transactions,
                        fp.GenerateFList(transactions, 2),
                        2,
                        100,
                        new HashSet<string>(),
                        new StringOutputConverter(new SequenceFileOutputCollector<string, TopKStringPatterns>(outWriter, "({0},{1}), ")),
                        new ContextStatusUpdater());

                var res = @"(Z,([X,Y,Z],11)), (Y,([Y],25), ([X,Y],21), ([X,Y,Z],11)), (X,([X],33), ([X,Y],21), ([X,Y,Z],11)), ";

                Assert.AreEqual(outWriter.ToString(), res);
            }
        }