Esempio n. 1
0
    def test_should_return_best_fitness_action(self, cfg):
        # given
        population = ClassifiersList(cfg=cfg)

        # when & then
        # C1 - does not anticipate change
        c1 = Classifier(action=1, cfg=cfg)
        population.append(c1)

        # Some random action should be selected here
        best_action = exploit(population)
        assert best_action is not None

        # when & then
        # C2 - does anticipate some change
        c2 = Classifier(action=2, effect='1###0###', reward=0.25, cfg=cfg)
        population.append(c2)

        # Here C2 action should be selected
        best_action = exploit(population)
        assert 2 == best_action

        # when & then
        # C3 - does anticipate change and is quite good
        c3 = Classifier(action=3,
                        effect='1#######',
                        quality=0.8,
                        reward=5,
                        cfg=cfg)
        population.append(c3)

        # Here C3 has the biggest fitness score
        best_action = exploit(population)
        assert 3 == best_action
Esempio n. 2
0
    def test_should_exploit_with_single_classifier(self, cfg):
        # given
        cl = Classifier(action=2, effect='1###0###', reward=0.25, cfg=cfg)
        population = ClassifiersList(*[cl])

        # when
        action = exploit(population, cfg.number_of_possible_actions)

        # then
        assert action == 2
Esempio n. 3
0
    def test_should_exploit_when_no_effect_specified(self, cfg):
        # given a classifier not anticipating change
        cl = Classifier(action=1, cfg=cfg)
        population = ClassifiersList(*[cl])

        # when
        action = exploit(population, cfg.number_of_possible_actions)

        # then random action is returned
        assert action is not None
Esempio n. 4
0
    def test_should_exploit_using_majority_voting(self, cfg):
        # given
        cl1 = Classifier(action=1, effect='1###0###',
                         reward=0.1, quality=0.7, numerosity=9, cfg=cfg)

        cl2 = Classifier(action=2, effect='1###0###',
                         reward=0.1, quality=0.7, numerosity=10, cfg=cfg)
        population = ClassifiersList(*[cl1, cl2])

        # when
        action = exploit(population, cfg.number_of_possible_actions)

        # then
        assert action == 2