def make_mutation(self): num_mutations = randint(1, ga_config.MAX_MUTATIONS) mutation_result = False for _ in range(num_mutations): if ga_config.MUTATE_BOTH_HMM_AND_RULES: rule_set_success = False hmm_success = False if configurations["EVOLVE_RULES"]: rule_set_success = self.rule_set.make_mutation() if configurations["EVOLVE_HMM"]: hmm_success = self.hmm.make_mutation() mutation_result = mutation_result or rule_set_success or hmm_success else: rule_set_mutation_weight = 0 if not configurations[ "EVOLVE_RULES"] else configurations["MUTATE_RULE_SET"] hmm_mutation_weight = 0 if not configurations[ "EVOLVE_HMM"] else configurations["MUTATE_HMM"] mutation_weights = [(self.rule_set, rule_set_mutation_weight), (self.hmm, hmm_mutation_weight)] weighted_mutatable_object_list = get_weighted_list( mutation_weights) object_to_mutate = choice(weighted_mutatable_object_list) mutation_result = object_to_mutate.make_mutation() return mutation_result
def make_mutation(self): mutation_weights = [(self._add_feature_bundle, configurations["ADD_FEATURE_BUNDLE"]), (self._remove_feature_bundle, configurations["REMOVE_FEATURE_BUNDLE"]), (self._change_existing_feature_bundle, configurations["CHANGE_EXISTING_FEATURE_BUNDLE"])] weighted_mutation_function_list = get_weighted_list(mutation_weights) mutation_result = choice(weighted_mutation_function_list)() return mutation_result
def make_mutation(self): mutation_weights = [(self._mutate_target, configurations["MUTATE_TARGET"]), (self._mutate_change, configurations["MUTATE_CHANGE"]), (self._mutate_left_context, configurations["MUTATE_LEFT_CONTEXT"]), (self._mutate_right_context, configurations["MUTATE_RIGHT_CONTEXT"]), (self._mutate_obligatory, configurations["MUTATE_OBLIGATORY"])] weighted_mutation_function_list = get_weighted_list(mutation_weights) mutation_result = choice(weighted_mutation_function_list)() if mutation_result: self.repr = None self.transducer_generated = False return mutation_result
def make_mutation(self): """ Randomly select a mutation function based on the probability distribution defined in the configuration. """ mutation_weights = [(self.add_rule, configurations["ADD_RULE"]), (self.remove_rule, configurations["REMOVE_RULE"]), (self.demote_rule, configurations["DEMOTE_RULE"]), (self.change_rule, configurations["CHANGE_RULE"])] mutations_list = get_weighted_list(mutation_weights) mutation = choice(mutations_list) mutation_result = mutation() return mutation_result
def make_mutation(self): mutation_weights = [(self._add_feature, configurations["ADD_FEATURE"]), (self._remove_feature, configurations["REMOVE_FEATURE"]), (self._change_feature_value, configurations["CHANGE_FEATURE_VALUE"])] if self.feature_dict and self._is_context_bundle( ): # Allow Kleene star mutation only if bundle has any features and in left/right context mutation_weights.append( (self._toggle_kleene, configurations["CHANGE_KLEENE_VALUE"])) weighted_mutation_function_list = get_weighted_list(mutation_weights) mutation_result = choice(weighted_mutation_function_list)() return mutation_result
def make_mutation(self): mutation_successful = False if ga_config.MUTATE_BOTH_HMM_AND_RULES: hmm_mutation_successful = False rule_set_mutation_successful = False if configurations["EVOLVE_HMM"]: hmm_mutation_successful = self.hmm.make_mutation() if configurations["EVOLVE_RULES"]: rule_set_mutation_successful = self.rule_set.make_mutation() mutation_successful = mutation_successful or rule_set_mutation_successful or hmm_mutation_successful if hmm_mutation_successful: self.invalidate_cached_hmm_transducer() if rule_set_mutation_successful: self.invalidate_cached_rule_set_transducer() else: rule_set_mutation_weight = 0 if not configurations["EVOLVE_RULES"] else configurations["MUTATE_RULE_SET"] hmm_mutation_weight = 0 if not configurations["EVOLVE_HMM"] else configurations["MUTATE_HMM"] mutation_weights = [('rule_set', rule_set_mutation_weight), ('hmm', hmm_mutation_weight)] weighted_mutatable_object_list = get_weighted_list(mutation_weights) object_name_to_mutate = choice(weighted_mutatable_object_list) if object_name_to_mutate == 'rule_set': object_to_mutate = self.rule_set elif object_name_to_mutate == 'hmm': object_to_mutate = self.hmm mutation_successful = object_to_mutate.make_mutation() if mutation_successful: if object_name_to_mutate == 'hmm': self.invalidate_cached_hmm_transducer() elif object_name_to_mutate == 'rule_set': self.invalidate_cached_rule_set_transducer() return mutation_successful