This algorithm reproduce the simplest evolutionary algorithm as presented in chapter 7 of [Back2000]_. :param population: A list of individuals. :param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution operators. :param cxpb: The probability of m
(population, toolbox, cxpb, mutpb, ngen, stats=None,
halloffame=None, verbose=__debug__)
| 83 | |
| 84 | |
| 85 | def eaSimple(population, toolbox, cxpb, mutpb, ngen, stats=None, |
| 86 | halloffame=None, verbose=__debug__): |
| 87 | """This algorithm reproduce the simplest evolutionary algorithm as |
| 88 | presented in chapter 7 of [Back2000]_. |
| 89 | |
| 90 | :param population: A list of individuals. |
| 91 | :param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution |
| 92 | operators. |
| 93 | :param cxpb: The probability of mating two individuals. |
| 94 | :param mutpb: The probability of mutating an individual. |
| 95 | :param ngen: The number of generation. |
| 96 | :param stats: A :class:`~deap.tools.Statistics` object that is updated |
| 97 | inplace, optional. |
| 98 | :param halloffame: A :class:`~deap.tools.HallOfFame` object that will |
| 99 | contain the best individuals, optional. |
| 100 | :param verbose: Whether or not to log the statistics. |
| 101 | :returns: The final population |
| 102 | :returns: A class:`~deap.tools.Logbook` with the statistics of the |
| 103 | evolution |
| 104 | |
| 105 | The algorithm takes in a population and evolves it in place using the |
| 106 | :meth:`varAnd` method. It returns the optimized population and a |
| 107 | :class:`~deap.tools.Logbook` with the statistics of the evolution. The |
| 108 | logbook will contain the generation number, the number of evaluations for |
| 109 | each generation and the statistics if a :class:`~deap.tools.Statistics` is |
| 110 | given as argument. The *cxpb* and *mutpb* arguments are passed to the |
| 111 | :func:`varAnd` function. The pseudocode goes as follow :: |
| 112 | |
| 113 | evaluate(population) |
| 114 | for g in range(ngen): |
| 115 | population = select(population, len(population)) |
| 116 | offspring = varAnd(population, toolbox, cxpb, mutpb) |
| 117 | evaluate(offspring) |
| 118 | population = offspring |
| 119 | |
| 120 | As stated in the pseudocode above, the algorithm goes as follow. First, it |
| 121 | evaluates the individuals with an invalid fitness. Second, it enters the |
| 122 | generational loop where the selection procedure is applied to entirely |
| 123 | replace the parental population. The 1:1 replacement ratio of this |
| 124 | algorithm **requires** the selection procedure to be stochastic and to |
| 125 | select multiple times the same individual, for example, |
| 126 | :func:`~deap.tools.selTournament` and :func:`~deap.tools.selRoulette`. |
| 127 | Third, it applies the :func:`varAnd` function to produce the next |
| 128 | generation population. Fourth, it evaluates the new individuals and |
| 129 | compute the statistics on this population. Finally, when *ngen* |
| 130 | generations are done, the algorithm returns a tuple with the final |
| 131 | population and a :class:`~deap.tools.Logbook` of the evolution. |
| 132 | |
| 133 | .. note:: |
| 134 | |
| 135 | Using a non-stochastic selection method will result in no selection as |
| 136 | the operator selects *n* individuals from a pool of *n*. |
| 137 | |
| 138 | This function expects the :meth:`toolbox.mate`, :meth:`toolbox.mutate`, |
| 139 | :meth:`toolbox.select` and :meth:`toolbox.evaluate` aliases to be |
| 140 | registered in the toolbox. |
| 141 | |
| 142 | .. [Back2000] Back, Fogel and Michalewicz, "Evolutionary Computation 1 : |