MCPcopy Index your code
hub / github.com/DEAP/deap / eaMuPlusLambda

Function eaMuPlusLambda

deap/algorithms.py:248–337  ·  view source on GitHub ↗

r"""This is the :math:`(\mu + \lambda)` evolutionary algorithm. :param population: A list of individuals. :param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution operators. :param mu: The number of individuals to select for the next generation.

(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,
                   stats=None, halloffame=None, verbose=__debug__)

Source from the content-addressed store, hash-verified

246
247
248def eaMuPlusLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,
249 stats=None, halloffame=None, verbose=__debug__):
250 r"""This is the :math:`(\mu + \lambda)` evolutionary algorithm.
251
252 :param population: A list of individuals.
253 :param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution
254 operators.
255 :param mu: The number of individuals to select for the next generation.
256 :param lambda\_: The number of children to produce at each generation.
257 :param cxpb: The probability that an offspring is produced by crossover.
258 :param mutpb: The probability that an offspring is produced by mutation.
259 :param ngen: The number of generation.
260 :param stats: A :class:`~deap.tools.Statistics` object that is updated
261 inplace, optional.
262 :param halloffame: A :class:`~deap.tools.HallOfFame` object that will
263 contain the best individuals, optional.
264 :param verbose: Whether or not to log the statistics.
265 :returns: The final population
266 :returns: A class:`~deap.tools.Logbook` with the statistics of the
267 evolution.
268
269 The algorithm takes in a population and evolves it in place using the
270 :func:`varOr` function. It returns the optimized population and a
271 :class:`~deap.tools.Logbook` with the statistics of the evolution. The
272 logbook will contain the generation number, the number of evaluations for
273 each generation and the statistics if a :class:`~deap.tools.Statistics` is
274 given as argument. The *cxpb* and *mutpb* arguments are passed to the
275 :func:`varOr` function. The pseudocode goes as follow ::
276
277 evaluate(population)
278 for g in range(ngen):
279 offspring = varOr(population, toolbox, lambda_, cxpb, mutpb)
280 evaluate(offspring)
281 population = select(population + offspring, mu)
282
283 First, the individuals having an invalid fitness are evaluated. Second,
284 the evolutionary loop begins by producing *lambda_* offspring from the
285 population, the offspring are generated by the :func:`varOr` function. The
286 offspring are then evaluated and the next generation population is
287 selected from both the offspring **and** the population. Finally, when
288 *ngen* generations are done, the algorithm returns a tuple with the final
289 population and a :class:`~deap.tools.Logbook` of the evolution.
290
291 This function expects :meth:`toolbox.mate`, :meth:`toolbox.mutate`,
292 :meth:`toolbox.select` and :meth:`toolbox.evaluate` aliases to be
293 registered in the toolbox. This algorithm uses the :func:`varOr`
294 variation.
295 """
296 logbook = tools.Logbook()
297 logbook.header = ['gen', 'nevals'] + (stats.fields if stats else [])
298
299 # Evaluate the individuals with an invalid fitness
300 invalid_ind = [ind for ind in population if not ind.fitness.valid]
301 fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
302 for ind, fit in zip(invalid_ind, fitnesses):
303 ind.fitness.values = fit
304
305 if halloffame is not None:

Callers

nothing calls this directly

Calls 5

recordMethod · 0.95
varOrFunction · 0.85
selectMethod · 0.80
updateMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…