示例#1
0
    def test_should_detect_correctable_classifier(self, _c, _e, _p0, _p1,
                                                  _result, cfg):

        cl = Classifier(condition=_c, effect=_e, cfg=cfg)
        p0 = Perception(_p0)
        p1 = Perception(_p1)

        assert cl.can_be_corrected(p0, p1) is _result
示例#2
0
文件: alp.py 项目: mk5135795/pyalcs
def apply(p0: Perception, p1: Perception, cl: Classifier,
          population: ClassifiersList):
    if not _perception_changed(p0, p1):
        handle_useless_case(cl)
    elif cl.does_anticipate_correctly(p0, p1):
        handle_expected_case(cl)
    elif not cl.does_anticipate_correctly(p0, p1) and _perception_changed(
            p0, p1) and cl.can_be_corrected(p0, p1):
        handle_correctable_case(p0, p1, cl, population)
    else:
        handle_not_correctable_case(cl, p0)

    # Remove inadequate classifiers
    for cl in population:
        if cl.is_inadequate() and not cl.is_general():
            population.remove(cl)
示例#3
0
文件: alp.py 项目: mk5135795/pyalcs
def handle_correctable_case(p0: Perception, p1: Perception, cl: Classifier,
                            population: ClassifiersList):
    new_cl = Classifier.build_corrected(cl, p0, p1)
    existing = [cl for cl in population if cl == new_cl]

    if len(existing) == 0:
        population.append(new_cl)
示例#4
0
    def test_should_construct_correct_classifier(self, cfg):
        cl = Classifier(condition="000#", effect="000#", quality=0.2, cfg=cfg)
        p0 = Perception("0000")
        p1 = Perception("0001")
        assert cl.does_match(p0)

        new_cl = Classifier.build_corrected(cl, p0, p1)

        assert new_cl is not cl
        assert new_cl.condition is not cl.condition
        assert new_cl.effect is not cl.effect
        assert new_cl.condition == Condition("0000")
        assert new_cl.action == cl.action
        assert new_cl.effect == Effect("0001")
        assert new_cl.q == 0.5
        assert new_cl.does_match(p0)
示例#5
0
文件: alp.py 项目: mk5135795/pyalcs
def handle_not_correctable_case(cl: Classifier, p0: Perception):
    cl.decrease_quality()
    cl.set_mark(p0)
示例#6
0
文件: alp.py 项目: mk5135795/pyalcs
def handle_expected_case(cl: Classifier):
    cl.increase_quality()
示例#7
0
文件: alp.py 项目: mk5135795/pyalcs
def handle_useless_case(cl: Classifier):
    cl.decrease_quality()
示例#8
0
    def test_should_increase_quality(self, cfg):
        cl = Classifier(cfg=cfg)

        cl.increase_quality()

        assert cl.q == 0.525
示例#9
0
    def test_should_decrease_quality(self, cfg):
        cl = Classifier(cfg=cfg)

        cl.decrease_quality()

        assert cl.q == 0.475
示例#10
0
    def test_distinguish_general_classifier(self, _c, _e, _result, cfg):
        cl = Classifier(condition=Condition(_c), effect=Effect(_e), cfg=cfg)

        assert cl.is_general() == _result
示例#11
0
    def test_should_create_general_classifier(self, cfg):
        cl = Classifier.general(action=1, cfg=cfg)

        assert cl.condition == Condition("####")
        assert cl.action == 1
        assert cl.condition == Effect("####")
示例#12
0
    def _initial_population(self):
        cls = []
        for action in range(0, self.cfg.number_of_possible_actions):
            cls.append(Classifier.general(action, cfg=self.cfg))

        return ClassifiersList(*cls)