def test_get_random_hmm(self): configurations['MIN_NUM_OF_INNER_STATES'] = 1 configurations['MAX_NUM_OF_INNER_STATES'] = 5 configurations['RANDOM_HMM_MAX_EMISSIONS_PER_STATE'] = 5 self.initialise_segment_table("plural_english_segment_table.txt") hmm = HMM.get_random_hmm(data=['dag', 'dagzook', 'kook', 'kooz']) log_hmm(hmm) self.write_to_dot_to_file(hmm, "random_hmm")
def test_remove_random(self): self.initialise_segment_table("plural_english_segment_table.txt") for _ in range(100000): hmm = HMM.get_random_hmm() try: hmm.make_mutation() # hmm.remove_random_state() hmm.get_transducer() except Exception: from traceback import print_exc log_hmm(hmm) print_exc() break
def test_random_hmms_crossover(self): self.initialise_segment_table("plural_english_segment_table.txt") for _ in range(1): hmm_1 = HMM.get_random_hmm(data=['dag', 'zook', 'kook', 'kooz']) hmm_2 = HMM.get_random_hmm(data=['dag', 'zook', 'kook', 'kooz']) print('HMM 1') log_hmm(hmm_1) print('HMM 2') log_hmm(hmm_2) offspring_1, offspring_2 = HMM.crossover(hmm_1, hmm_2) print('Offspring 1') print('HMM', offspring_1.inner_states, 'TRANSITIONS', offspring_1.transitions, 'EMISSIONS', offspring_1.emissions) print('Offspring 2') print('HMM', offspring_2.inner_states, 'TRANSITIONS', offspring_2.transitions, 'EMISSIONS', offspring_2.emissions) self.write_to_dot_to_file(hmm_1, 'random_parent_1') self.write_to_dot_to_file(hmm_2, 'random_parent_2') self.write_to_dot_to_file(offspring_1, 'random_offspring_1') self.write_to_dot_to_file(offspring_2, 'random_offspring_2') offspring_1.get_transducer() offspring_2.get_transducer()
def get_random_hypothesis_randomized(cls, simulation, data, initial_hmm=None, initial_rules=None): if initial_rules: rule_set = RuleSet.load_from_flat_list(initial_rules) elif not configurations['EVOLVE_RULES']: rule_set = RuleSet.load_from_flat_list(deepcopy(simulation.target_tuple[1])) else: rule_set = RuleSet.get_random_rule_set() if initial_hmm: hmm = HMM(deepcopy(initial_hmm)) elif not configurations['EVOLVE_HMM']: hmm = HMM(deepcopy(simulation.target_tuple[0])) else: hmm = HMM.get_random_hmm(data) grammar = Grammar(hmm, rule_set) return Hypothesis(grammar)