forked from DEAP/deap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
148 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.mplot3d import Axes3D | ||
|
||
from deap import tools | ||
|
||
NOBJ = 3 | ||
P = 12 | ||
|
||
fig = plt.figure(figsize=(7, 7)) | ||
ax = fig.add_subplot(111, projection="3d") | ||
|
||
# the coordinate origin (black + sign) | ||
ax.scatter(0, 0, 0, c="k", marker="+", s=100) | ||
|
||
# reference points (gray) | ||
ref_points = tools.uniform_reference_points(NOBJ, P) | ||
for rp in ref_points: | ||
ax.scatter(rp[0], rp[1], rp[2], marker="o", color="darkblue", s=48) | ||
|
||
# final figure details | ||
ax.set_xlabel("$f_1(\mathbf{x})$", fontsize=15) | ||
ax.set_ylabel("$f_2(\mathbf{x})$", fontsize=15) | ||
ax.set_zlabel("$f_3(\mathbf{x})$", fontsize=15) | ||
ax.view_init(elev=11, azim=-25) | ||
ax.autoscale(tight=True) | ||
plt.tight_layout() | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
.. _nsga-3: | ||
|
||
====================================================== | ||
Non-dominated Sorting Genetic Algorithm III (NSGA-III) | ||
====================================================== | ||
The Non-dominated Sorting Genetic Algorithm III (NSGA-III) [Deb2014]_ | ||
is implemented in the :func:`deap.tools.selNSGA3` function. This example | ||
shows how it can be used in DEAP for many objective optimization. | ||
|
||
Problem Definition | ||
------------------ | ||
First we need to define the problem we want to work on. We will use | ||
the first problem tested in the paper, 3 objectives DTLZ2 with ``k = 10`` | ||
and ``p = 12``. We will use `pymop <https://github.com/msu-coinlab/pymop>`_ | ||
for problem implementation as it provides the exact Pareto front that we | ||
will use later for computing the performance of the algorithm. | ||
|
||
.. literalinclude:: /../examples/ga/nsga3.py | ||
:start-after: # Problem definition | ||
:end-before: ## | ||
|
||
Algorithm Parameters | ||
-------------------- | ||
Then we define the various parameters for the algorithm, including the | ||
population size set to the first multiple of 4 greater than H, the | ||
number of generations and variation probabilities. | ||
|
||
.. literalinclude:: /../examples/ga/nsga3.py | ||
:start-after: # Algorithm parameters | ||
:end-before: ## | ||
|
||
Classes and Tools | ||
----------------- | ||
Next, NSGA-III selection requires a reference point set. The reference point | ||
set serves to guide the evolution into creating a uniform Pareto front in | ||
the objective space. | ||
|
||
.. literalinclude:: /../examples/ga/nsga3.py | ||
:start-after: # Create uniform reference point | ||
:lines: 1 | ||
|
||
The next figure shows an example of reference point set with ``p = 12``. | ||
The cross represents the the utopian point (0, 0, 0). | ||
|
||
.. plot:: code/examples/nsga3_ref_points.py | ||
|
||
As in any DEAP program, we need to populate the creator with the type | ||
of individual we require for our optimization. In this case we will use | ||
a basic list genotype and minimization fitness. | ||
|
||
.. literalinclude:: /../examples/ga/nsga3.py | ||
:start-after: # Create classes | ||
:end-before: ## | ||
|
||
Moreover, we need to populate the evolutionary toolbox with initialization, | ||
variation and selection operators. Note how we provide the reference point | ||
set to the NSGA-III selection scheme. | ||
|
||
.. literalinclude:: /../examples/ga/nsga3.py | ||
:start-after: # Toolbox initialization | ||
:end-before: ## | ||
|
||
Evolution | ||
--------- | ||
The main part of the evolution is mostly similar to any other | ||
DEAP example. The algorithm used is close to the | ||
:func:`~deap.algorithms.eaSimple` algorithm as crossover and mutation are | ||
applied to every individual (see variation probabilities above). However, | ||
the selection is made from the parent and offspring populations instead | ||
of completely replacing the parents with the offspring. | ||
|
||
.. literalinclude:: /../examples/ga/nsga3.py | ||
:pyobject: main | ||
|
||
Finally, we can have a look at the final population | ||
|
||
.. image:: /_images/nsga3.png | ||
:align: center | ||
|
||
Conclusion | ||
---------- | ||
That's it for the NSGA-III algorithm using DEAP, now you can leverage | ||
the power of many-objective optimization with DEAP. If you're interrested, | ||
you can now change the evaluation function and try applying it to | ||
your own problem. | ||
|
||
.. [Deb2014] Deb, K., & Jain, H. (2014). An Evolutionary Many-Objective Optimization | ||
Algorithm Using Reference-Point-Based Nondominated Sorting Approach, | ||
Part I: Solving Problems With Box Constraints. IEEE Transactions on | ||
Evolutionary Computation, 18(4), 577-601. doi:10.1109/TEVC.2013.2281535. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters