From 9213a556df6f3152543d9c114bc30ae8cf76453f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Michel=20De=20Rainville?= Date: Sat, 29 Jun 2013 19:55:55 -0400 Subject: [PATCH] Adjusted the cmaes_plotting example to the new logbook and adjusted the documentation accordingly. --HG-- branch : dev --- doc/examples/cmaes_plotting.rst | 12 ++++++------ examples/es/cma_plotting.py | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/examples/cmaes_plotting.rst b/doc/examples/cmaes_plotting.rst index 9c6d62715..c37532d9f 100644 --- a/doc/examples/cmaes_plotting.rst +++ b/doc/examples/cmaes_plotting.rst @@ -19,35 +19,35 @@ The beginning of this example is exactly the same as the :ref:`CMA-ES :func:`~deap.algorithms.eaGenerateUpdate` is somewhat insufficient for our purpose. We need to gather the required data on each generation. So instead of using the :func:`~deap.algorithms.eaGenerateUpdate` function, we'll develop -it to get a grip on what is recorded. First, we'll created objects to record +it to get a grip on what is recorded. First, we'll create objects to record our data. Here we want to plot, in addition to what the -:class:`~deap.Statistics` and :class:`~deap.HallOfFame` objects contain, the +:class:`~deap.tools.Logbook` and :class:`~deap.tools.HallOfFame` objects contain, the step size, the axis ratio and the major axis of the covariace matrix, the best value so far, the best coordinates so far and the standard deviation of the all coordinates at each generation. .. literalinclude:: /code/examples/es/cma_plotting.py - :lines: 56-61 + :lines: 59-64 Once the objects are created, the evolution loop, based on a generational stopping criterion, calls repeatedly the :meth:`generate`, :meth:`evaluate` and :meth:`update` methods registered in the toolbox. .. literalinclude:: /code/examples/es/cma_plotting.py - :lines: 63-72 + :lines: 66-75 Then, the previoulsy created objects start to play their role. The according data is recorded in each object on each generation. .. literalinclude:: /code/examples/es/cma_plotting.py - :lines: 77,84-89 + :lines: 80,81,88-93 Now that the data is recorded the only thing left to do is to plot it. We'll use `matplotlib `_ to generate the graphics from the recorded data. .. literalinclude:: /code/examples/es/cma_plotting.py - :lines: 92-120 + :lines: 95-124 Which gives the following result. diff --git a/examples/es/cma_plotting.py b/examples/es/cma_plotting.py index 03d4dab53..9e727f76e 100644 --- a/examples/es/cma_plotting.py +++ b/examples/es/cma_plotting.py @@ -51,6 +51,9 @@ def main(verbose=True): stats.register("std", numpy.std) stats.register("min", numpy.min) stats.register("max", numpy.max) + + logbook = tools.Logbook() + logbook.header = "gen", "evals", "std", "min", "avg", "max" # Objects that will compile the data sigma = numpy.ndarray((NGEN,1)) @@ -74,10 +77,11 @@ def main(verbose=True): # Update the hall of fame and the statistics with the # currently evaluated population halloffame.update(population) - stats.record(population, evals=len(population), gen=gen,) + record = stats.compile(population) + logbook.record(evals=len(population), gen=gen, **record) if verbose: - print(stats.stream) + print(logbook.stream) # Save more data along the evolution for latter plotting # diagD is sorted and sqrooted in the update method @@ -90,7 +94,7 @@ def main(verbose=True): # The x-axis will be the number of evaluations x = list(range(0, strategy.lambda_ * NGEN, strategy.lambda_)) - avg, max_, min_ = stats.select("avg", "max", "min") + avg, max_, min_ = logbook.select("avg", "max", "min") plt.figure() plt.subplot(2, 2, 1) plt.semilogy(x, avg, "--b")