当前位置: 首页>>代码示例>>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;未经允许,请勿转载。