This is algorithm implements the ask-tell model proposed in [Colette2010]_, where ask is called `generate` and tell is called `update`. :param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution operators. :param ngen: The number of generation. :pa
(toolbox, ngen, halloffame=None, stats=None,
verbose=__debug__)
| 438 | |
| 439 | |
| 440 | def eaGenerateUpdate(toolbox, ngen, halloffame=None, stats=None, |
| 441 | verbose=__debug__): |
| 442 | """This is algorithm implements the ask-tell model proposed in |
| 443 | [Colette2010]_, where ask is called `generate` and tell is called `update`. |
| 444 | |
| 445 | :param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution |
| 446 | operators. |
| 447 | :param ngen: The number of generation. |
| 448 | :param stats: A :class:`~deap.tools.Statistics` object that is updated |
| 449 | inplace, optional. |
| 450 | :param halloffame: A :class:`~deap.tools.HallOfFame` object that will |
| 451 | contain the best individuals, optional. |
| 452 | :param verbose: Whether or not to log the statistics. |
| 453 | :returns: The final population |
| 454 | :returns: A class:`~deap.tools.Logbook` with the statistics of the |
| 455 | evolution |
| 456 | |
| 457 | The algorithm generates the individuals using the :func:`toolbox.generate` |
| 458 | function and updates the generation method with the :func:`toolbox.update` |
| 459 | function. It returns the optimized population and a |
| 460 | :class:`~deap.tools.Logbook` with the statistics of the evolution. The |
| 461 | logbook will contain the generation number, the number of evaluations for |
| 462 | each generation and the statistics if a :class:`~deap.tools.Statistics` is |
| 463 | given as argument. The pseudocode goes as follow :: |
| 464 | |
| 465 | for g in range(ngen): |
| 466 | population = toolbox.generate() |
| 467 | evaluate(population) |
| 468 | toolbox.update(population) |
| 469 | |
| 470 | |
| 471 | This function expects :meth:`toolbox.generate` and :meth:`toolbox.evaluate` aliases to be |
| 472 | registered in the toolbox. |
| 473 | |
| 474 | .. [Colette2010] Collette, Y., N. Hansen, G. Pujol, D. Salazar Aponte and |
| 475 | R. Le Riche (2010). On Object-Oriented Programming of Optimizers - |
| 476 | Examples in Scilab. In P. Breitkopf and R. F. Coelho, eds.: |
| 477 | Multidisciplinary Design Optimization in Computational Mechanics, |
| 478 | Wiley, pp. 527-565; |
| 479 | |
| 480 | """ |
| 481 | logbook = tools.Logbook() |
| 482 | logbook.header = ['gen', 'nevals'] + (stats.fields if stats else []) |
| 483 | |
| 484 | for gen in range(ngen): |
| 485 | # Generate a new population |
| 486 | population = toolbox.generate() |
| 487 | # Evaluate the individuals |
| 488 | fitnesses = toolbox.map(toolbox.evaluate, population) |
| 489 | for ind, fit in zip(population, fitnesses): |
| 490 | ind.fitness.values = fit |
| 491 | |
| 492 | if halloffame is not None: |
| 493 | halloffame.update(population) |
| 494 | |
| 495 | # Update the strategy with the evaluated individuals |
| 496 | toolbox.update(population) |
| 497 |