當前位置: 首頁>>代碼示例>>Python>>正文


Python Program.mutate方法代碼示例

本文整理匯總了Python中program.Program.mutate方法的典型用法代碼示例。如果您正苦於以下問題:Python Program.mutate方法的具體用法?Python Program.mutate怎麽用?Python Program.mutate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在program.Program的用法示例。


在下文中一共展示了Program.mutate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mutate

# 需要導入模塊: from program import Program [as 別名]
# 或者: from program.Program import mutate [as 別名]
    def mutate(self, programs_population):
        """
        Generates mutation chances and mutate the team if it is a valid mutation.
        """
        if Config.USER['advanced_training_parameters']['use_agressive_mutations']:
            mutation_chance = 1
            while (mutation_chance > random.random() 
                and len(self.programs) > Config.USER['training_parameters']['team_size']['min']):
                self._randomly_remove_program()
                mutation_chance = mutation_chance * Config.USER['training_parameters']['mutation']['team']['remove_program']

            mutation_chance = 1
            while (mutation_chance > random.random() 
                and len(self.programs) < Config.USER['training_parameters']['team_size']['max']):
                self._randomly_add_program(programs_population)
                mutation_chance = mutation_chance * Config.USER['training_parameters']['mutation']['team']['add_program']
        else:
            if len(self.programs) > Config.USER['training_parameters']['team_size']['min']:
                mutation_chance = random.random()
                if mutation_chance <= Config.USER['training_parameters']['mutation']['team']['remove_program']:
                    self._randomly_remove_program()

            if len(self.programs) < Config.USER['training_parameters']['team_size']['max']:
                mutation_chance = random.random()
                if mutation_chance <= Config.USER['training_parameters']['mutation']['team']['add_program']:
                    self._randomly_add_program(programs_population)

        to_mutate = []
        while len(to_mutate) == 0:
            for program in self.programs:
                mutation_chance = random.random()
                if mutation_chance <= Config.USER['training_parameters']['mutation']['team']['mutate_program']:
                    to_mutate.append(program)
        for program in to_mutate:
            clone = Program(self.generation, copy.deepcopy(program.instructions), program.action)
            clone.mutate()
            self._add_program(clone)
            programs_population.append(clone)
            if self._is_ok_to_remove(program):
                self.remove_program(program)
        return programs_population
開發者ID:jpbonson,項目名稱:SBBReinforcementLearner,代碼行數:43,代碼來源:team.py


注:本文中的program.Program.mutate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。