Skip to content

Commit bd4fd60

Browse files
authored
Merge pull request #311 from ahmedfgad/github-actions
GitHub actions
2 parents dd07de9 + 13e5713 commit bd4fd60

File tree

3 files changed

+209
-146
lines changed

3 files changed

+209
-146
lines changed

docs/source/visualize.rst

+101-41
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ visualization in PyGAD.
1010
This section discusses the different options to visualize the results in
1111
PyGAD through these methods:
1212

13-
1. ``plot_fitness()``: Create plots for the fitness.
13+
1. ``plot_fitness()``: Creates plots for the fitness.
1414

15-
2. ``plot_genes()``: Create plots for the genes.
15+
2. ``plot_genes()``: Creates plots for the genes.
1616

17-
3. ``plot_new_solution_rate()``: Create plots for the new solution rate.
17+
3. ``plot_new_solution_rate()``: Creates plots for the new solution
18+
rate.
19+
20+
4. ``plot_pareto_front_curve()``: Creates plots for the pareto front for
21+
multi-objective problems.
1822

1923
In the following code, the ``save_solutions`` flag is set to ``True``
2024
which means all solutions are saved in the ``solutions`` attribute. The
@@ -87,7 +91,7 @@ This method accepts the following parameters:
8791

8892
9. ``save_dir``: Directory to save the figure.
8993

90-
.. _plottypeplot:
94+
.. _plottype=plot:
9195

9296
``plot_type="plot"``
9397
~~~~~~~~~~~~~~~~~~~~
@@ -101,10 +105,9 @@ line connecting the fitness values across all generations:
101105
ga_instance.plot_fitness()
102106
# ga_instance.plot_fitness(plot_type="plot")
103107
104-
.. image:: https://user-images.githubusercontent.com/16560492/122472609-d02f5280-cf8e-11eb-88a7-f9366ff6e7c6.png
105-
:alt:
108+
|image1|
106109

107-
.. _plottypescatter:
110+
.. _plottype=scatter:
108111

109112
``plot_type="scatter"``
110113
~~~~~~~~~~~~~~~~~~~~~~~
@@ -117,10 +120,9 @@ these dots can be changed using the ``linewidth`` parameter.
117120
118121
ga_instance.plot_fitness(plot_type="scatter")
119122
120-
.. image:: https://user-images.githubusercontent.com/16560492/122473159-75e2c180-cf8f-11eb-942d-31279b286dbd.png
121-
:alt:
123+
|image2|
122124

123-
.. _plottypebar:
125+
.. _plottype=bar:
124126

125127
``plot_type="bar"``
126128
~~~~~~~~~~~~~~~~~~~
@@ -132,8 +134,7 @@ bar graph with each individual fitness represented as a bar.
132134
133135
ga_instance.plot_fitness(plot_type="bar")
134136
135-
.. image:: https://user-images.githubusercontent.com/16560492/122473340-b7736c80-cf8f-11eb-89c5-4f7db3b653cc.png
136-
:alt:
137+
|image3|
137138

138139
New Solution Rate
139140
=================
@@ -174,7 +175,7 @@ in the ``plot_fitness()`` method (it also have 3 possible values for
174175

175176
8. ``save_dir``: Directory to save the figure.
176177

177-
.. _plottypeplot-2:
178+
.. _plottype=plot-2:
178179

179180
``plot_type="plot"``
180181
~~~~~~~~~~~~~~~~~~~~
@@ -192,10 +193,9 @@ first generation is always equal to the number of solutions in the
192193
population (i.e. the value assigned to the ``sol_per_pop`` parameter in
193194
the constructor of the ``pygad.GA`` class) which is 10 in this example.
194195

195-
.. image:: https://user-images.githubusercontent.com/16560492/122475815-3322e880-cf93-11eb-9648-bf66f823234b.png
196-
:alt:
196+
|image4|
197197

198-
.. _plottypescatter-2:
198+
.. _plottype=scatter-2:
199199

200200
``plot_type="scatter"``
201201
~~~~~~~~~~~~~~~~~~~~~~~
@@ -207,10 +207,9 @@ The previous graph can be represented as scattered points by setting
207207
208208
ga_instance.plot_new_solution_rate(plot_type="scatter")
209209
210-
.. image:: https://user-images.githubusercontent.com/16560492/122476108-adec0380-cf93-11eb-80ac-7588bf90492f.png
211-
:alt:
210+
|image5|
212211

213-
.. _plottypebar-2:
212+
.. _plottype=bar-2:
214213

215214
``plot_type="bar"``
216215
~~~~~~~~~~~~~~~~~~~
@@ -222,8 +221,7 @@ vertical bar.
222221
223222
ga_instance.plot_new_solution_rate(plot_type="bar")
224223
225-
.. image:: https://user-images.githubusercontent.com/16560492/122476173-c2c89700-cf93-11eb-9e77-d39737cd3a96.png
226-
:alt:
224+
|image6|
227225

228226
Genes
229227
=====
@@ -307,13 +305,13 @@ solutions in the population or from just the best solutions.
307305

308306
An exception is raised if:
309307

310-
- ``solutions="all"`` while ``save_solutions=False`` in the constructor
311-
of the ``pygad.GA`` class. .
308+
- ``solutions="all"`` while ``save_solutions=False`` in the constructor
309+
of the ``pygad.GA`` class. .
312310

313-
- ``solutions="best"`` while ``save_best_solutions=False`` in the
314-
constructor of the ``pygad.GA`` class. .
311+
- ``solutions="best"`` while ``save_best_solutions=False`` in the
312+
constructor of the ``pygad.GA`` class. .
315313

316-
.. _graphtypeplot:
314+
.. _graphtype=plot:
317315

318316
``graph_type="plot"``
319317
~~~~~~~~~~~~~~~~~~~~~
@@ -322,7 +320,7 @@ When ``graph_type="plot"``, then the figure creates a normal graph where
322320
the relationship between the gene values and the generation numbers is
323321
represented as a continuous plot, scattered points, or bars.
324322

325-
.. _plottypeplot-3:
323+
.. _plottype=plot-3:
326324

327325
``plot_type="plot"``
328326
^^^^^^^^^^^^^^^^^^^^
@@ -345,8 +343,7 @@ of the next graph) lasted for 83 generations.
345343
ga_instance.plot_genes(graph_type="plot",
346344
plot_type="plot")
347345
348-
.. image:: https://user-images.githubusercontent.com/16560492/122477158-4a62d580-cf95-11eb-8c93-9b6e74cb814c.png
349-
:alt:
346+
|image7|
350347

351348
As the default value for the ``solutions`` parameter is ``"all"``, then
352349
the following method calls generate the same plot.
@@ -365,7 +362,7 @@ the following method calls generate the same plot.
365362
plot_type="plot",
366363
solutions="all")
367364
368-
.. _plottypescatter-3:
365+
.. _plottype=scatter-3:
369366

370367
``plot_type="scatter"``
371368
^^^^^^^^^^^^^^^^^^^^^^^
@@ -381,10 +378,9 @@ scatter plot.
381378
plot_type="scatter",
382379
solutions='all')
383380
384-
.. image:: https://user-images.githubusercontent.com/16560492/122477273-73836600-cf95-11eb-828f-f357c7b0f815.png
385-
:alt:
381+
|image8|
386382

387-
.. _plottypebar-3:
383+
.. _plottype=bar-3:
388384

389385
``plot_type="bar"``
390386
^^^^^^^^^^^^^^^^^^^
@@ -397,10 +393,9 @@ scatter plot.
397393
plot_type="bar",
398394
solutions='all')
399395
400-
.. image:: https://user-images.githubusercontent.com/16560492/122477370-99106f80-cf95-11eb-8643-865b55e6b844.png
401-
:alt:
396+
|image9|
402397

403-
.. _graphtypeboxplot:
398+
.. _graphtype=boxplot:
404399

405400
``graph_type="boxplot"``
406401
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -419,10 +414,9 @@ figure as the default value for the ``solutions`` parameter is
419414
ga_instance.plot_genes(graph_type="boxplot",
420415
solutions='all')
421416
422-
.. image:: https://user-images.githubusercontent.com/16560492/122479260-beeb4380-cf98-11eb-8f08-23707929b12c.png
423-
:alt:
417+
|image10|
424418

425-
.. _graphtypehistogram:
419+
.. _graphtype=histogram:
426420

427421
``graph_type="histogram"``
428422
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -442,8 +436,74 @@ figure as the default value for the ``solutions`` parameter is
442436
ga_instance.plot_genes(graph_type="histogram",
443437
solutions='all')
444438
445-
.. image:: https://user-images.githubusercontent.com/16560492/122477314-8007be80-cf95-11eb-9c95-da3f49204151.png
446-
:alt:
439+
|image11|
447440

448441
All the previous figures can be created for only the best solutions by
449442
setting ``solutions="best"``.
443+
444+
Pareto Front
445+
============
446+
447+
.. _plotparetofrontcurve:
448+
449+
``plot_pareto_front_curve()``
450+
-----------------------------
451+
452+
The ``plot_pareto_front_curve()`` method creates the Pareto front curve
453+
for multi-objective optimization problems. It creates, shows, and
454+
returns a figure that shows the Pareto front curve and points
455+
representing the fitness. It only works when 2 objectives are used.
456+
457+
It works only after completing at least 1 generation. If no generation
458+
is completed (at least 1), an exception is raised.
459+
460+
This method accepts the following parameters:
461+
462+
1. ``title``: Title of the figure.
463+
464+
2. ``xlabel``: X-axis label.
465+
466+
3. ``ylabel``: Y-axis label.
467+
468+
4. ``linewidth``: Line width of the plot. Defaults to ``3``.
469+
470+
5. ``font_size``: Font size for the labels and title. Defaults to
471+
``14``.
472+
473+
6. ``label``: The label used for the legend.
474+
475+
7. ``color``: Color of the plot which defaults to the royal blue color
476+
``#FF6347``.
477+
478+
8. ``color_fitness``: Color of the fitness points which defaults to the
479+
tomato red color ``#4169E1``.
480+
481+
9. ``grid``: Either ``True`` or ``False`` to control the visibility of
482+
the grid.
483+
484+
10. ``alpha``: The transparency of the pareto front curve.
485+
486+
11. ``marker``: The marker of the fitness points.
487+
488+
12. ``save_dir``: Directory to save the figure.
489+
490+
This is an example of calling the ``plot_pareto_front_curve()`` method.
491+
492+
.. code:: python
493+
494+
ga_instance.plot_pareto_front_curve()
495+
496+
|image12|
497+
498+
.. |image1| image:: https://user-images.githubusercontent.com/16560492/122472609-d02f5280-cf8e-11eb-88a7-f9366ff6e7c6.png
499+
.. |image2| image:: https://user-images.githubusercontent.com/16560492/122473159-75e2c180-cf8f-11eb-942d-31279b286dbd.png
500+
.. |image3| image:: https://user-images.githubusercontent.com/16560492/122473340-b7736c80-cf8f-11eb-89c5-4f7db3b653cc.png
501+
.. |image4| image:: https://user-images.githubusercontent.com/16560492/122475815-3322e880-cf93-11eb-9648-bf66f823234b.png
502+
.. |image5| image:: https://user-images.githubusercontent.com/16560492/122476108-adec0380-cf93-11eb-80ac-7588bf90492f.png
503+
.. |image6| image:: https://user-images.githubusercontent.com/16560492/122476173-c2c89700-cf93-11eb-9e77-d39737cd3a96.png
504+
.. |image7| image:: https://user-images.githubusercontent.com/16560492/122477158-4a62d580-cf95-11eb-8c93-9b6e74cb814c.png
505+
.. |image8| image:: https://user-images.githubusercontent.com/16560492/122477273-73836600-cf95-11eb-828f-f357c7b0f815.png
506+
.. |image9| image:: https://user-images.githubusercontent.com/16560492/122477370-99106f80-cf95-11eb-8643-865b55e6b844.png
507+
.. |image10| image:: https://user-images.githubusercontent.com/16560492/122479260-beeb4380-cf98-11eb-8f08-23707929b12c.png
508+
.. |image11| image:: https://user-images.githubusercontent.com/16560492/122477314-8007be80-cf95-11eb-9c95-da3f49204151.png
509+
.. |image12| image:: https://github.com/user-attachments/assets/606d853c-7370-41a0-8ddb-857a4c6c7fb9

0 commit comments

Comments
 (0)