def test_MAR_MaxSC_OneClass_4(self):

        # From publication example 3.a
        analyzer = GCA(self.db_rules,
                       1 / 7)  # percentage indicated in publication
        analyzer.clean_database()
        analyzer.mine()

        rule_miner = RAMCM(analyzer.lcg_into_list())
        lcg_S = rule_miner.MFCS_FromLattice(rule_miner.lcg,
                                            set(['c', 'e', 'a', 'g', 'i']),
                                            2 / 7, 1 / 7, 5 / 7)

        # Generate rules for S_star_S1 = set(['c', 'e', 'a', 'g', 'i'])
        L_C1 = set(['c', 'e', 'g'])
        match = analyzer.search_node_with_closure(L_C1, lcg_S)
        gen_L_C1 = match.generators
        R1 = set(['a', 'i'])
        S_star_S1 = set(['a', 'c', 'i'])
        match = analyzer.search_node_with_closure(S_star_S1, lcg_S)
        gen_S_star_S1 = match.generators
        S1 = set(['c', 'e', 'a', 'g', 'i'])

        rules = rule_miner.MAR_MaxSC_OneClass(L_C1, gen_L_C1, R1, S_star_S1,
                                              gen_S_star_S1, S_star_S1)

        self.assertEqual(len(rules), 2)
        expected_rules = []
    def test_mine_rules_1_integer(self):
        analyzer = GCA(self.db_rules_integer,
                       1 / 7)  # percentage indicated in publication
        analyzer.clean_database()
        analyzer.mine()

        L1 = set({3, 5, 7})
        R1 = set([1, 9])
        rule_miner = RAMCM(analyzer.lcg_into_list())
        rule_miner.mine(1 / 7, 5 / 7, 1 / 3, 0.9, L1, R1)

        self.assertEqual(len(rule_miner.ars), 14)
    def test_mine_rules_2_integer(self):
        # From publication example 3.b
        analyzer = GCA(self.db_rules_integer,
                       1 / 7)  # percentage indicated in publication
        analyzer.clean_database()
        analyzer.mine()

        L1 = set({1})
        R1 = set([3, 6, 8, 9])
        rule_miner = RAMCM(analyzer.lcg_into_list())
        rule_miner.mine(1 / 7, 5 / 7, 1 / 3, 0.9, L1, R1)

        self.assertEqual(len(rule_miner.ars), 12)
    def test_mine_rules_1(self):
        # From publication example 3.a
        analyzer = GCA(self.db_rules,
                       1 / 7)  # percentage indicated in publication
        analyzer.clean_database()
        analyzer.mine()

        L1 = set({'c', 'e', 'g'})
        R1 = set(['a', 'i'])
        rule_miner = RAMCM(analyzer.lcg_into_list())
        rule_miner.mine(1 / 7, 5 / 7, 1 / 3, 0.9, L1, R1)

        self.assertEqual(len(rule_miner.ars), 14)
    def test_MFS_RestrictMaxSC_1(self):
        # From publication example 3.a
        analyzer = GCA(self.db_rules,
                       1 / 7)  # percentage indicated in publication
        analyzer.clean_database()
        analyzer.mine()

        rule_miner = RAMCM(analyzer.lcg_into_list())
        lcg_S = rule_miner.MFCS_FromLattice(rule_miner.lcg,
                                            set(['c', 'e', 'a', 'g', 'i']),
                                            2 / 7, 1 / 7, 1)

        #Enumerate left side
        Y = set(['c', 'e', 'g'])
        X = set([])
        Z1 = set(['c', 'e', 'g'])
        match = analyzer.search_node_with_closure(Y, lcg_S)
        gen_X_Y = match.generators
        fs_star_Y = rule_miner.MFS_RestrictMaxSC(Y, X, Z1, gen_X_Y)

        self.assertEqual(len(fs_star_Y), 6)
        expected_itemsets = []
        expected_itemsets.append(set(['e']))
        expected_itemsets.append(set(['e', 'c']))
        expected_itemsets.append(set(['e', 'g']))
        expected_itemsets.append(set(['e', 'c', 'g']))
        expected_itemsets.append(set(['g']))
        expected_itemsets.append(set(['g', 'c']))
        for itemset in expected_itemsets:
            self.assertIn(itemset, fs_star_Y)

        #Enumerate right side in accordance with left hand side 'e'
        Y = frozenset(['c', 'e', 'a', 'g', 'i']).difference(frozenset('e'))
        X = set(['e'])
        Z1 = set(['a', 'i'])
        match = analyzer.search_node_with_closure(Y, lcg_S)
        gen_X_Y = match.generators
        fs_star_Y = rule_miner.MFS_RestrictMaxSC(Y, X, Z1, gen_X_Y)

        self.assertEqual(len(fs_star_Y), 2)
        expected_itemsets = []
        expected_itemsets.append(set(['a']))
        expected_itemsets.append(set(['a', 'i']))
        for itemset in expected_itemsets:
            self.assertIn(itemset, fs_star_Y)
    def test_MFCS_FromLattice(self):
        analyzer = GCA(self.db_rules,
                       1 / 7)  # percentage indicated in publication
        analyzer.clean_database()
        analyzer.mine()

        rule_miner = RAMCM(analyzer.lcg_into_list())
        lcg_S = rule_miner.MFCS_FromLattice(
            rule_miner.lcg, set(['a', 'c', 'f', 'h', 'i']),
            rule_miner._get_support(set(['a', 'c', 'f', 'h', 'i'])), 1 / 7, 1)

        self.assertEqual(len(lcg_S), 6)

        expected_LGC = []
        expected_LGC.append(
            GCA.Node(2 / 7, set(['a', 'c', 'f', 'h', 'i']),
                     [['c', 'f'], ['c', 'h']], None))
        expected_LGC.append(
            GCA.Node(4 / 7, set(['a', 'c', 'i']), [['a', 'c']], None))
        expected_LGC.append(
            GCA.Node(3 / 7, set(['a', 'f', 'h', 'i']), [['f'], ['h']], None))
        expected_LGC.append(GCA.Node(6 / 7, set(['c', 'i']), [['c']], None))
        expected_LGC.append(GCA.Node(5 / 7, set(['a', 'i']), [['a']], None))
        expected_LGC.append(GCA.Node(7 / 7, set(['i']), [['i']], None))

        for index, expected in enumerate(expected_LGC):
            # check closure
            match = analyzer.search_node_with_closure(expected.closure, lcg_S)
            self.assertSequenceEqual(expected.closure, match.closure)

            # check support
            self.assertEqual(expected.support, match.support)

            # check generators
            for generator in expected.generators:
                self.assertTrue(
                    is_in_generators(generator, match.generators, True))