本文整理匯總了Python中deap.tools.mutGaussian方法的典型用法代碼示例。如果您正苦於以下問題:Python tools.mutGaussian方法的具體用法?Python tools.mutGaussian怎麽用?Python tools.mutGaussian使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類deap.tools
的用法示例。
在下文中一共展示了tools.mutGaussian方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: runOptGenetic
# 需要導入模塊: from deap import tools [as 別名]
# 或者: from deap.tools import mutGaussian [as 別名]
def runOptGenetic():
'''
@return:
@rtype:
'''
# COULDDO parametrisation
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
creator.create("Individual", list, fitness=creator.FitnessMin)
IND_SIZE = num_slots * num_evs
POP_SIZE = 30
toolbox = base.Toolbox()
toolbox.register("attr_float", rd.random) # COULDDO heuristic init
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_float, n=IND_SIZE)
toolbox.register("population", tools.initRepeat, list, toolbox.individual, n=POP_SIZE)
toolbox.register("evaluate", evaluate)
toolbox.decorate("evaluate", tools.DeltaPenalty(feasible, 0.0, distance))
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", tools.mutGaussian, mu=0, sigma=0.5, indpb=0.5)
toolbox.register("select", tools.selTournament, tournsize=3)
stats = tools.Statistics(key=lambda ind: ind.fitness.values)
stats.register("avg", np.mean)
stats.register("std", np.std)
stats.register("min", np.min)
stats.register("max", np.max)
hof = tools.HallOfFame(1)
population = toolbox.population()
# if no of-the-shelf algorithm used...
# fits = toolbox.map(toolbox.evaluate, population)
# for fit, ind in zip(fits, population):
# ind.fitness.values = fit
population, logbook = algorithms.eaSimple(population, toolbox, cxpb=0.5, mutpb=0.3, ngen=5, stats=stats, verbose=True, halloffame=hof)
sorted_pop = sorted(population, key=lambda ind: ind.fitness)
ev_schedules = np.asarray(best).reshape((num_evs, num_slots))
schedules = np.zeros((num_households, num_slots)).tolist()
for i in range(num_evs):
schedules[evs[i].position] = ev_schedules[i].tolist()
evs[i].schedule = schedules[evs[i].position]
return schedules
# *****************************************************************************************************
# * Metaheuristics Side Functions
# *****************************************************************************************************
# UNUSED