コード例 #1
0
    def test_should_handle_expected_case_1(self, cfg):
        # given
        p0 = Perception([.5, .5], oktypes=(float, ))
        q = random.random()
        cl = Classifier(quality=q, cfg=cfg)
        time = random.randint(0, 1000)

        # when
        child = expected_case(cl, p0, time)

        # then
        # classifier is not marked - no child should be generated
        assert child is None
        assert cl.q > q
コード例 #2
0
ファイル: ClassifierList.py プロジェクト: e-dzia/pyalcs
    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)
コード例 #3
0
    def test_should_handle_expected_case_3(self, cfg):
        # given
        p0 = Perception([.5, .5], oktypes=(float, ))
        q = 0.4
        cl = Classifier(quality=q, cfg=cfg)
        cl.mark[0].add(2)
        time = random.randint(0, 1000)

        # when
        child = expected_case(cl, p0, time)

        # then
        assert child is not None
        assert child.condition == Condition([UBR(8, 8), UBR(0, 15)], cfg)
        assert child.q == 0.5
コード例 #4
0
    def test_should_handle_expected_case_2(self, cfg):
        # given
        p0 = Perception([.5, .5], oktypes=(float, ))
        q = random.random()
        cl = Classifier(quality=q, cfg=cfg)
        cl.mark[0].add(8)
        cl.mark[1].add(8)
        time = random.randint(0, 1000)

        # when
        child = expected_case(cl, p0, time)

        # then
        # there are no differences
        assert child is None
        assert cl.q > q