예제 #1
0
    def test_simulated_annealing_runtime(self):
        import simulations.turkish_vowel_harmony as current_simulation
        configurations.load_configurations_from_dict(
            current_simulation.configurations_dict)
        self.initialise_segment_table('turkish_segment_table.txt')

        initial_hmm = None
        initial_rule_set = None
        initial_hypothesis = Hypothesis.create_initial_hypothesis(
            current_simulation.data, initial_hmm, initial_rule_set)
        target_tuple = current_simulation.target_tuple
        data = current_simulation.data
        target_rule_set = RuleSet.load_form_flat_list(target_tuple[1])
        target_hypothesis = Hypothesis.create_hypothesis(
            HMM(target_tuple[0]), target_rule_set, data)
        target_energy = target_hypothesis.get_energy()

        simulated_annealing = SimulatedAnnealing(initial_hypothesis,
                                                 target_energy)
        simulated_annealing.before_loop()

        # mutate hypothesis for some time before measuring steps
        for i in range(500):
            simulated_annealing.make_step()

        @timeit_best_of_N
        def make_step_profiled():
            simulated_annealing.make_step()

        make_step_profiled()
 def init_target_hypothesis(self):
     target_tuple = self.simulation.target_tuple
     target_rule_set = RuleSet.load_form_flat_list(target_tuple[1])
     target_hypothesis = Hypothesis.create_hypothesis(
         HMM(deepcopy(target_tuple[0])), target_rule_set)
     target_energy = target_hypothesis.get_energy()
     self.logger.info('Target hypothesis:')
     log_hypothesis(target_hypothesis, self.logger.info)
     self.logger.info('Target energy: {}'.format(target_energy))
     self.logger.info('Target hypothesis energy signature: {}'.format(
         target_hypothesis.get_recent_energy_signature()))
     return target_hypothesis, target_energy