def test_if_selected_close_to_other_both_umarked_tav_considered2( self, cfg): # given cl = Classifier(quality=0.8, tav=0.1, cfg=cfg) cl_del = Classifier(quality=0.85, tav=0.1, cfg=cfg) # when selected_cl = ClassifiersList(cfg=cfg)\ .select_preferred_to_delete(cl, cl_del) # then assert cl.is_marked() is False assert cl_del.is_marked() is False assert cl_del == selected_cl
def test_if_selected_somewhat_close_to_other_marked_considered2(self, cfg): # given cl = Classifier(quality=0.8, cfg=cfg) cl_del = Classifier(quality=0.85, cfg=cfg) cl_del.mark[0].add('0') # when selected_cl = ClassifiersList(cfg=cfg)\ .select_preferred_to_delete(cl, cl_del) # then assert cl.is_marked() is False assert cl_del.is_marked() is True assert cl_del == selected_cl
def expected_case(cl: Classifier, p0: Perception, time: int) -> Optional[Classifier]: """ Controls the expected case of a classifier. If the classifier is too specific it tries to add some randomness to it by generalizing some attributes. :param cl: :param p0: :param time: :return: new classifier or None """ if cl.cfg.do_pee: cl.effect.update_enhanced_effect_probs(p0, cl.cfg.beta) diff = cl.mark.get_differences(p0) if diff.specificity == 0: if cl.cfg.do_pee and cl.is_marked(): cl.ee = True 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() < 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