Skip to content

Commit

Permalink
Merge pull request DEAP#47 from joernhees/patch-2
Browse files Browse the repository at this point in the history
tutorial part3: typos
  • Loading branch information
fmder committed Nov 1, 2014
2 parents 85fd8dd + b14b124 commit 5a83dc6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions doc/tutorials/basic/part3.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Computing Statistics
====================
Often, one wants to compile statistics on what is going on in the optimization.
The :class:`~deap.tools.Statistics` are able to compile such data on arbitrary attributes of any designated object. To do that, one need to register the desired statistic functions inside the stats object using the exact same syntax as the toolbox.
The :class:`~deap.tools.Statistics` are able to compile such data on arbitrary attributes of any designated object. To do that, one needs to register the desired statistic functions inside the stats object using the exact same syntax as in the toolbox.

.. literalinclude:: /code/tutorials/part_3/stats.py
:lines: 12
Expand All @@ -24,12 +24,12 @@ Statistics will automatically be computed on the population every generation. Th

Writing Your Own Algorithm
--------------------------
When writing your own algorithm, including statistics is very simple. One need only to compile the statistics on the desired object. For example, compiling the statistics on a given population is done by calling the :meth:`~deap.tools.Statistics.compile` method.
When writing your own algorithm, including statistics is very simple. One only needs to compile the statistics on the desired object. For example, compiling the statistics on a given population is done by calling the :meth:`~deap.tools.Statistics.compile` method.

.. literalinclude:: /code/tutorials/part_3/stats.py
:lines: 38

The argument to the compile function must be an iterable of elements on which the key will be called. Here, our population (``pop``) contains individuals. The statistics object will call the key function on every individual to retrieve their :attr:`fitness.values` attribute. The resulting array of values is finally given the each statistic function and the result is put into the ``record`` dictionary under the key associated with the function. Printing the record reveals its nature.
The argument to the compile function must be an iterable of elements on which the key will be called. Here, our population (``pop``) contains individuals. The statistics object will call the key function on every individual to retrieve their :attr:`fitness.values` attribute. The resulting array of values is finally given to each statistic function and the result is put into the ``record`` dictionary under the key associated with the function. Printing the record reveals its nature.

>>> print(record)
{'std': 4.96, 'max': 63.0, 'avg': 50.2, 'min': 39.0}
Expand All @@ -38,7 +38,7 @@ How to save and pretty print the statistics is shown in the :ref:`next section <

Multi-objective Statistics
--------------------------
As statistics are computed directly on the values with numpy function, all the objectives are combined together by the default behaviour of numpy. Thus, one need to specify the axis on which to operate. This is achieved by giving the axis as an aditional argument to the register function.
As statistics are computed directly on the values with numpy function, all the objectives are combined together by the default behaviour of numpy. Thus, one needs to specify the axis on which to operate. This is achieved by giving the axis as an additional argument to the register function.

.. literalinclude:: /code/tutorials/part_3/stats.py
:lines: 41-45
Expand All @@ -51,7 +51,7 @@ One can always specify the axis even in the case of single objective. The only e

Multiple Statistics
-------------------
It is also possible to compute statistics on different attributes of the population individuals. For instance, it is quite common in genetic programming to have statistics on the height of the trees in addition to their fitness. One can combine multiple :class:`~deap.tools.Statistics` object in a :class:`~deap.tools.MultiStatistics`.
It is also possible to compute statistics on different attributes of the population individuals. For instance, it is quite common in genetic programming to have statistics on the height of the trees in addition to their fitness. One can combine multiple :class:`~deap.tools.Statistics` objects in a :class:`~deap.tools.MultiStatistics`.

.. literalinclude:: /code/tutorials/part_3/multistats.py
:lines: 14-16
Expand All @@ -66,7 +66,7 @@ The multi-statistics object can be given to an algorithm or they can be compiled
.. literalinclude:: /code/tutorials/part_3/multistats.py
:lines: 54

This time the ``record`` is a dictionary of dictionaries. The first level contains the keywords under which the statistics objects have been registered and the second level is similar to the previous simple statistics object.::
This time the ``record`` is a dictionary of dictionaries. The first level contains the keywords under which the statistics objects have been registered and the second level is similar to the previous simple statistics object.

>>> print(record)
{'fitness': {'std': 1.64, 'max': 6.86, 'avg': 1.71, 'min': 0.166},
Expand All @@ -81,7 +81,7 @@ Once the data is produced by the statistics (or multi-statistics), one can save
.. literalinclude:: /code/tutorials/part_3/logbook.py
:lines: 7-8

The :meth:`~deap.tools.Logbook.record` method takes a variable number of argument, each of which is a data to be recorded. In the last example, we saved the generation, the number of evaluations and everything contained in the ``record`` produced by a statistics object using the star magic. All record will be kept in the logbook until its destruction.
The :meth:`~deap.tools.Logbook.record` method takes a variable number of arguments, each of which is data to be recorded. In the last example, we saved the generation, the number of evaluations and everything contained in the ``record`` produced by a statistics object using the star magic. All records will be kept in the logbook until its destruction.

After a number of records, one may want to retrieve the information contained in the logbook.

Expand All @@ -97,7 +97,7 @@ A logbook is a picklable object (as long as all inserted objects are picklable)

.. note::

Every algorithm returns a logbook containing the statistics for every generation and the number of evaluation for the whole evolution.
Every algorithm returns a logbook containing the statistics for every generation and the number of evaluations for the whole evolution.

Printing to Screen
------------------
Expand Down Expand Up @@ -153,7 +153,7 @@ The generations, minimum fitness and average size are obtained, chronologically

Some Plotting Sugar
-------------------
One of the most common operation when an optimization is finished is to plot the data during the evolution. The :class:`~deap.tools.Logbook` allows to do this very efficiently. Using the select method, one can retrieve the desired data and plot it using matplotlib.
One of the most common operations when an optimization is finished is to plot the data during the evolution. The :class:`~deap.tools.Logbook` allows to do this very efficiently. Using the select method, one can retrieve the desired data and plot it using matplotlib.

.. literalinclude:: /code/tutorials/part_3/logbook.py
:lines: 39-62
Expand Down

0 comments on commit 5a83dc6

Please sign in to comment.