def test_should_form_match_set(self, cfg):
        # given
        population = ClassifiersList(cfg=cfg)
        situation = Perception('11110000')

        # C1 - general condition
        c1 = Classifier(cfg=cfg)

        # C2 - matching condition
        c2 = Classifier(condition='1###0###', cfg=cfg)

        # C3 - non-matching condition
        c3 = Classifier(condition='0###1###', cfg=cfg)

        population.append(c1)
        population.append(c2)
        population.append(c3)

        # when
        match_set = ClassifiersList.form_match_set(population,
                                                   situation,
                                                   cfg=cfg)
        # then
        assert 2 == len(match_set)
        assert c1 in match_set
        assert c2 in match_set
    def test_should_form_match_set(self, cfg):
        # given
        cl_1 = Classifier(cfg=cfg)
        cl_2 = Classifier(condition='1###0###', cfg=cfg)
        cl_3 = Classifier(condition='0###1###', cfg=cfg)

        population = ClassifiersList(*[cl_1, cl_2, cl_3])
        p0 = Perception('11110000')

        # when
        match_set = ClassifiersList.form_match_set(population, p0)

        # then
        assert len(match_set) == 2
        assert cl_1 in match_set
        assert cl_2 in match_set
Exemple #3
0
        len([cl for cl in population if cl.is_reliable()])))


if __name__ == '__main__':

    # Play some games
    for g in range(GAMES):
        action_set = ClassifiersList(cfg=cfg)
        prev_state, action, reward, done = None, None, None, False
        state = board.reset()
        moves = 0

        while not done:
            player = determine_player(moves)  # Determine player

            match_set = ClassifiersList.form_match_set(population, state, cfg)

            if moves > 0:
                action_set.apply_alp(prev_state, action, state,
                                     ALL_MOVES + moves, population, match_set)
                action_set.apply_reinforcement_learning(
                    reward, match_set.get_maximum_fitness())
                if cfg.do_ga:
                    action_set.apply_ga(ALL_MOVES + moves, population,
                                        match_set, state)

            # Determine best action
            action = match_set.choose_action(cfg.epsilon)

            action_set = ClassifiersList.form_action_set(
                match_set, action, cfg)