def get_differences(self, p0: Perception) -> Condition: """ Determines the strongest differences in between the mark and current perception. :param: perception :return: condition that specifies all the differences. """ diff = Condition.empty(length=self.cfg.classifier_length) nr1, nr2 = 0, 0 # Count difference types for idx, item in enumerate(self): if len(item) > 0 and p0[idx] not in item: nr1 += 1 elif len(item) > 1: nr2 += 1 if nr1 > 0: possible_idx = [pi for pi, p in enumerate(p0) if p not in self[pi] and len(self[pi]) > 0] rand_idx = random.choice(possible_idx) diff[rand_idx] = p0[rand_idx] elif nr2 > 0: for idx, item in enumerate(self): if len(item) > 1: diff[idx] = p0[idx] return diff
def test_should_get_differences_1(self, _p0, cfg): # given generic_condition = Condition.empty(length=cfg.classifier_length) p0 = Perception(_p0) mark = PMark(cfg) # when diff = mark.get_differences(p0) # then assert diff == generic_condition
def is_general(self): cl_length = self.cfg.classifier_length return self.condition == Condition.empty(cl_length) \ and self.effect == Effect.empty(cl_length)