def test_should_generalize_randomly_unchanging_condition_attribute( self, _condition, _effect, _soa_before, _soa_after, cfg): # given condition = Condition(_condition, cfg) effect = Effect(_effect, cfg) cl = Classifier(condition=condition, effect=effect, cfg=cfg) assert len(cl.specified_unchanging_attributes) == _soa_before # when cl.generalize_unchanging_condition_attribute() # then assert (len(cl.specified_unchanging_attributes)) == _soa_after
def expected_case(cl: Classifier, p0: Perception, time: int) -> Optional[Classifier]: diff = cl.mark.get_differences(p0) if diff.specificity == 0: cl.increase_quality() return None no_spec = len(cl.specified_unchanging_attributes) no_spec_new = diff.specificity child = cl.copy_from(cl, time) if no_spec >= cl.cfg.u_max: while no_spec >= cl.cfg.u_max: res = cl.generalize_unchanging_condition_attribute() assert res is True no_spec -= 1 while no_spec + no_spec_new > cl.cfg.u_max: if random.random() < 0.5: diff.generalize_specific_attribute_randomly() no_spec_new -= 1 else: if cl.generalize_unchanging_condition_attribute(): no_spec -= 1 else: while no_spec + no_spec_new > cl.cfg.u_max: diff.generalize_specific_attribute_randomly() no_spec_new -= 1 child.condition.specialize_with_condition(diff) if child.q < 0.5: child.q = 0.5 return child