当前位置: 首页>>代码示例>>Python>>正文


Python tools.mutFlipBit方法代码示例

本文整理汇总了Python中deap.tools.mutFlipBit方法的典型用法代码示例。如果您正苦于以下问题:Python tools.mutFlipBit方法的具体用法?Python tools.mutFlipBit怎么用?Python tools.mutFlipBit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在deap.tools的用法示例。


在下文中一共展示了tools.mutFlipBit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: geneticAlgorithm

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import mutFlipBit [as 别名]
def geneticAlgorithm(X, y, n_population, n_generation):
    """
    Deap global variables
    Initialize variables to use eaSimple
    """
    # create individual
    creator.create("FitnessMax", base.Fitness, weights=(1.0,))
    creator.create("Individual", list, fitness=creator.FitnessMax)

    # create toolbox
    toolbox = base.Toolbox()
    toolbox.register("attr_bool", random.randint, 0, 1)
    toolbox.register("individual", tools.initRepeat,
                     creator.Individual, toolbox.attr_bool, len(X.columns))
    toolbox.register("population", tools.initRepeat, list,
                     toolbox.individual)
    toolbox.register("evaluate", getFitness, X=X, y=y)
    toolbox.register("mate", tools.cxOnePoint)
    toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)
    toolbox.register("select", tools.selTournament, tournsize=3)

    # initialize parameters
    pop = toolbox.population(n=n_population)
    hof = tools.HallOfFame(n_population * n_generation)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", np.mean)
    stats.register("min", np.min)
    stats.register("max", np.max)

    # genetic algorithm
    pop, log = algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2,
                                   ngen=n_generation, stats=stats, halloffame=hof,
                                   verbose=True)

    # return hall of fame
    return hof 
开发者ID:renatoosousa,项目名称:GeneticAlgorithmForFeatureSelection,代码行数:38,代码来源:gaFeatureSelection.py

示例2: mutate

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import mutFlipBit [as 别名]
def mutate(self, individual, probability):
        if self.method == 'Shuffle':
            return tools.mutShuffleIndexes(individual, probability)[0]
        elif self.method == 'Flipbit':
            return tools.mutFlipBit(individual, probability)[0] 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:7,代码来源:mutations.py

示例3: create_toolbox

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import mutFlipBit [as 别名]
def create_toolbox(num_bits):
    creator.create("FitnessMax", base.Fitness, weights=(1.0,))
    creator.create("Individual", list, fitness=creator.FitnessMax)

    # Initialize the toolbox
    toolbox = base.Toolbox()

    # Generate attributes 
    toolbox.register("attr_bool", random.randint, 0, 1)

    # Initialize structures
    toolbox.register("individual", tools.initRepeat, creator.Individual, 
        toolbox.attr_bool, num_bits)

    # Define the population to be a list of individuals
    toolbox.register("population", tools.initRepeat, list, toolbox.individual)

    # Register the evaluation operator 
    toolbox.register("evaluate", eval_func)

    # Register the crossover operator
    toolbox.register("mate", tools.cxTwoPoint)

    # Register a mutation operator
    toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)

    # Operator for selecting individuals for breeding
    toolbox.register("select", tools.selTournament, tournsize=3)
    
    return toolbox 
开发者ID:PacktPublishing,项目名称:Artificial-Intelligence-with-Python,代码行数:32,代码来源:bit_counter.py


注:本文中的deap.tools.mutFlipBit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。