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


Python tools.selBest方法代码示例

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


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

示例1: main

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import selBest [as 别名]
def main():
    random.seed(64)
    NISLES = 5
    islands = [toolbox.population(n=300) for i in range(NISLES)]

    # Unregister unpicklable methods before sending the toolbox.
    toolbox.unregister("attr_bool")
    toolbox.unregister("individual")
    toolbox.unregister("population")

    NGEN, FREQ = 40, 5
    toolbox.register("algorithm", algorithms.eaSimple, toolbox=toolbox, 
                     cxpb=0.5, mutpb=0.2, ngen=FREQ, verbose=False)
    for i in range(0, NGEN, FREQ):
        results = toolbox.map(toolbox.algorithm, islands)
        islands = [pop for pop, logbook in results]
        tools.migRing(islands, 15, tools.selBest)

    return islands 
开发者ID:DEAP,项目名称:deap,代码行数:21,代码来源:onemax_island_scoop.py

示例2: filterAwayWorst

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import selBest [as 别名]
def filterAwayWorst(population, N=5):
    aliveSize = len(population) - 5
    population = tools.selBest(population, aliveSize)
    return population 
开发者ID:Gab0,项目名称:japonicus,代码行数:6,代码来源:evolutionHooks.py

示例3: selBest

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import selBest [as 别名]
def selBest(individuals, number):
    chosen = sorted(individuals, key=selectCriteria, reverse=True)
    return chosen[:number] 
开发者ID:Gab0,项目名称:japonicus,代码行数:5,代码来源:evolutionHooks.py

示例4: test_cma

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import selBest [as 别名]
def test_cma():
    NDIM = 5

    strategy = cma.Strategy(centroid=[0.0]*NDIM, sigma=1.0)

    toolbox = base.Toolbox()
    toolbox.register("evaluate", benchmarks.sphere)
    toolbox.register("generate", strategy.generate, creator.__dict__[INDCLSNAME])
    toolbox.register("update", strategy.update)

    pop, _ = algorithms.eaGenerateUpdate(toolbox, ngen=100)
    best, = tools.selBest(pop, k=1)

    assert best.fitness.values < (1e-8,), "CMA algorithm did not converged properly." 
开发者ID:DEAP,项目名称:deap,代码行数:16,代码来源:test_algorithms.py

示例5: end

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import selBest [as 别名]
def end(self):
        """
        See :meth:`~l2l.optimizers.optimizer.Optimizer.end`
        """
        # ------------ Finished all runs and print result --------------- #
        logger.info("-- End of (successful) evolution --")
        best_inds = tools.selBest(self.pop, 10)
        for best_ind in best_inds:
            logger.info("Best individual is %s, %s" % (best_ind, best_ind.fitness.values))

        logger.info("-- Hall of fame --")
        for hof_ind in self.hall_of_fame:
            logger.info("HOF individual is %s, %s" % (hof_ind, hof_ind.fitness.values)) 
开发者ID:IGITUGraz,项目名称:L2L,代码行数:15,代码来源:optimizer.py

示例6: main

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import selBest [as 别名]
def main(procid, pipein, pipeout, sync, seed=None):
    random.seed(seed)
    toolbox.register("migrate", migPipe, k=5, pipein=pipein, pipeout=pipeout,
        selection=tools.selBest, replacement=random.sample)

    MU = 300
    NGEN = 40
    CXPB = 0.5
    MUTPB = 0.2
    MIG_RATE = 5
    
    deme = toolbox.population(n=MU)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)
    
    logbook = tools.Logbook()
    logbook.header = "gen", "deme", "evals", "std", "min", "avg", "max"
    
    for ind in deme:
        ind.fitness.values = toolbox.evaluate(ind)
    record = stats.compile(deme)
    logbook.record(gen=0, deme=procid, evals=len(deme), **record)
    hof.update(deme)
    
    if procid == 0:
        # Synchronization needed to log header on top and only once
        print(logbook.stream)
        sync.set()
    else:
        logbook.log_header = False  # Never output the header
        sync.wait()
        print(logbook.stream)
    
    for gen in range(1, NGEN):
        deme = toolbox.select(deme, len(deme))
        deme = algorithms.varAnd(deme, toolbox, cxpb=CXPB, mutpb=MUTPB)
        
        invalid_ind = [ind for ind in deme if not ind.fitness.valid]
        for ind in invalid_ind:
            ind.fitness.values = toolbox.evaluate(ind)
        
        hof.update(deme)
        record = stats.compile(deme)
        logbook.record(gen=gen, deme=procid, evals=len(deme), **record)
        print(logbook.stream)
            
        if gen % MIG_RATE == 0 and gen > 0:
            toolbox.migrate(deme) 
开发者ID:DEAP,项目名称:deap,代码行数:54,代码来源:onemax_island.py


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