示例#1
0
    def test_should_create_new_classifier_with_covering(
            self, _p0, _p1, _child_cond, _child_effect, cfg):

        # given
        cfg.cover_noise = 0.0

        p0 = Perception(_p0, oktypes=(float, ))
        p1 = Perception(_p1, oktypes=(float, ))
        action = random.randint(0, cfg.number_of_possible_actions)
        time = random.randint(0, 100)

        # when
        new_cl = cover(p0, action, p1, time, cfg)

        # then
        assert new_cl is not None
        assert new_cl.condition == Condition(_child_cond, cfg)
        assert new_cl.action == action
        assert new_cl.effect == Effect(_child_effect, cfg)
        assert new_cl.q == .5
        assert new_cl.r == 0
        assert new_cl.ir == 0
        assert new_cl.tav == 0
        assert new_cl.tga == time
        assert new_cl.talp == time
        # assert new_cl.num == 1
        assert new_cl.exp == 0
示例#2
0
    def apply_alp(population: ClassifierList,
                  match_set: ClassifierList,
                  action_set: ClassifierList,
                  p0: Perception,
                  action: int,
                  p1: Perception,
                  time: int,
                  theta_exp: int,
                  cfg: Configuration) -> None:

        new_list = ClassifierList()
        new_cl: Optional[Classifier] = None
        was_expected_case = False
        delete_counter = 0

        for cl in action_set:
            cl.increase_experience()
            cl.set_alp_timestamp(time)

            if cl.does_anticipate_correctly(p0, p1):
                new_cl = alp_racs.expected_case(cl, p0, time)
                was_expected_case = True
            else:
                new_cl = alp_racs.unexpected_case(cl, p0, p1, time)
                if cl.is_inadequate():
                    delete_counter += 1

                    lists = [x for x in [population, match_set, action_set]
                             if x]
                    for lst in lists:
                        lst.safe_remove(cl)

            if new_cl is not None:
                new_cl.tga = time
                alp.add_classifier(new_cl, action_set, new_list, theta_exp)

        # No classifier anticipated correctly - generate new one
        if not was_expected_case:
            new_cl = alp_racs.cover(p0, action, p1, time, cfg)
            alp.add_classifier(new_cl, action_set, new_list, theta_exp)

        # Merge classifiers from new_list into self and population
        action_set.extend(new_list)
        population.extend(new_list)

        if match_set is not None:
            new_matching = [cl for cl in new_list if
                            cl.condition.does_match(p1)]
            match_set.extend(new_matching)