@@ -10,11 +10,15 @@ visualization in PyGAD.
10
10
This section discusses the different options to visualize the results in
11
11
PyGAD through these methods:
12
12
13
- 1. ``plot_fitness() ``: Create plots for the fitness.
13
+ 1. ``plot_fitness() ``: Creates plots for the fitness.
14
14
15
- 2. ``plot_genes() ``: Create plots for the genes.
15
+ 2. ``plot_genes() ``: Creates plots for the genes.
16
16
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.
18
22
19
23
In the following code, the ``save_solutions `` flag is set to ``True ``
20
24
which means all solutions are saved in the ``solutions `` attribute. The
@@ -87,7 +91,7 @@ This method accepts the following parameters:
87
91
88
92
9. ``save_dir ``: Directory to save the figure.
89
93
90
- .. _ plottypeplot :
94
+ .. _ plottype=plot :
91
95
92
96
``plot_type="plot" ``
93
97
~~~~~~~~~~~~~~~~~~~~
@@ -101,10 +105,9 @@ line connecting the fitness values across all generations:
101
105
ga_instance.plot_fitness()
102
106
# ga_instance.plot_fitness(plot_type="plot")
103
107
104
- .. image :: https://user-images.githubusercontent.com/16560492/122472609-d02f5280-cf8e-11eb-88a7-f9366ff6e7c6.png
105
- :alt:
108
+ |image1 |
106
109
107
- .. _ plottypescatter :
110
+ .. _ plottype=scatter :
108
111
109
112
``plot_type="scatter" ``
110
113
~~~~~~~~~~~~~~~~~~~~~~~
@@ -117,10 +120,9 @@ these dots can be changed using the ``linewidth`` parameter.
117
120
118
121
ga_instance.plot_fitness(plot_type = " scatter" )
119
122
120
- .. image :: https://user-images.githubusercontent.com/16560492/122473159-75e2c180-cf8f-11eb-942d-31279b286dbd.png
121
- :alt:
123
+ |image2 |
122
124
123
- .. _ plottypebar :
125
+ .. _ plottype=bar :
124
126
125
127
``plot_type="bar" ``
126
128
~~~~~~~~~~~~~~~~~~~
@@ -132,8 +134,7 @@ bar graph with each individual fitness represented as a bar.
132
134
133
135
ga_instance.plot_fitness(plot_type = " bar" )
134
136
135
- .. image :: https://user-images.githubusercontent.com/16560492/122473340-b7736c80-cf8f-11eb-89c5-4f7db3b653cc.png
136
- :alt:
137
+ |image3 |
137
138
138
139
New Solution Rate
139
140
=================
@@ -174,7 +175,7 @@ in the ``plot_fitness()`` method (it also have 3 possible values for
174
175
175
176
8. ``save_dir ``: Directory to save the figure.
176
177
177
- .. _ plottypeplot -2 :
178
+ .. _ plottype=plot -2 :
178
179
179
180
``plot_type="plot" ``
180
181
~~~~~~~~~~~~~~~~~~~~
@@ -192,10 +193,9 @@ first generation is always equal to the number of solutions in the
192
193
population (i.e. the value assigned to the ``sol_per_pop `` parameter in
193
194
the constructor of the ``pygad.GA `` class) which is 10 in this example.
194
195
195
- .. image :: https://user-images.githubusercontent.com/16560492/122475815-3322e880-cf93-11eb-9648-bf66f823234b.png
196
- :alt:
196
+ |image4 |
197
197
198
- .. _ plottypescatter -2 :
198
+ .. _ plottype=scatter -2 :
199
199
200
200
``plot_type="scatter" ``
201
201
~~~~~~~~~~~~~~~~~~~~~~~
@@ -207,10 +207,9 @@ The previous graph can be represented as scattered points by setting
207
207
208
208
ga_instance.plot_new_solution_rate(plot_type = " scatter" )
209
209
210
- .. image :: https://user-images.githubusercontent.com/16560492/122476108-adec0380-cf93-11eb-80ac-7588bf90492f.png
211
- :alt:
210
+ |image5 |
212
211
213
- .. _ plottypebar -2 :
212
+ .. _ plottype=bar -2 :
214
213
215
214
``plot_type="bar" ``
216
215
~~~~~~~~~~~~~~~~~~~
@@ -222,8 +221,7 @@ vertical bar.
222
221
223
222
ga_instance.plot_new_solution_rate(plot_type = " bar" )
224
223
225
- .. image :: https://user-images.githubusercontent.com/16560492/122476173-c2c89700-cf93-11eb-9e77-d39737cd3a96.png
226
- :alt:
224
+ |image6 |
227
225
228
226
Genes
229
227
=====
@@ -307,13 +305,13 @@ solutions in the population or from just the best solutions.
307
305
308
306
An exception is raised if:
309
307
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. .
312
310
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. .
315
313
316
- .. _ graphtypeplot :
314
+ .. _ graphtype=plot :
317
315
318
316
``graph_type="plot" ``
319
317
~~~~~~~~~~~~~~~~~~~~~
@@ -322,7 +320,7 @@ When ``graph_type="plot"``, then the figure creates a normal graph where
322
320
the relationship between the gene values and the generation numbers is
323
321
represented as a continuous plot, scattered points, or bars.
324
322
325
- .. _ plottypeplot -3 :
323
+ .. _ plottype=plot -3 :
326
324
327
325
``plot_type="plot" ``
328
326
^^^^^^^^^^^^^^^^^^^^
@@ -345,8 +343,7 @@ of the next graph) lasted for 83 generations.
345
343
ga_instance.plot_genes(graph_type = " plot" ,
346
344
plot_type = " plot" )
347
345
348
- .. image :: https://user-images.githubusercontent.com/16560492/122477158-4a62d580-cf95-11eb-8c93-9b6e74cb814c.png
349
- :alt:
346
+ |image7 |
350
347
351
348
As the default value for the ``solutions `` parameter is ``"all" ``, then
352
349
the following method calls generate the same plot.
@@ -365,7 +362,7 @@ the following method calls generate the same plot.
365
362
plot_type = " plot" ,
366
363
solutions = " all" )
367
364
368
- .. _ plottypescatter -3 :
365
+ .. _ plottype=scatter -3 :
369
366
370
367
``plot_type="scatter" ``
371
368
^^^^^^^^^^^^^^^^^^^^^^^
@@ -381,10 +378,9 @@ scatter plot.
381
378
plot_type = " scatter" ,
382
379
solutions = ' all' )
383
380
384
- .. image :: https://user-images.githubusercontent.com/16560492/122477273-73836600-cf95-11eb-828f-f357c7b0f815.png
385
- :alt:
381
+ |image8 |
386
382
387
- .. _ plottypebar -3 :
383
+ .. _ plottype=bar -3 :
388
384
389
385
``plot_type="bar" ``
390
386
^^^^^^^^^^^^^^^^^^^
@@ -397,10 +393,9 @@ scatter plot.
397
393
plot_type = " bar" ,
398
394
solutions = ' all' )
399
395
400
- .. image :: https://user-images.githubusercontent.com/16560492/122477370-99106f80-cf95-11eb-8643-865b55e6b844.png
401
- :alt:
396
+ |image9 |
402
397
403
- .. _ graphtypeboxplot :
398
+ .. _ graphtype=boxplot :
404
399
405
400
``graph_type="boxplot" ``
406
401
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -419,10 +414,9 @@ figure as the default value for the ``solutions`` parameter is
419
414
ga_instance.plot_genes(graph_type = " boxplot" ,
420
415
solutions = ' all' )
421
416
422
- .. image :: https://user-images.githubusercontent.com/16560492/122479260-beeb4380-cf98-11eb-8f08-23707929b12c.png
423
- :alt:
417
+ |image10 |
424
418
425
- .. _ graphtypehistogram :
419
+ .. _ graphtype=histogram :
426
420
427
421
``graph_type="histogram" ``
428
422
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -442,8 +436,74 @@ figure as the default value for the ``solutions`` parameter is
442
436
ga_instance.plot_genes(graph_type = " histogram" ,
443
437
solutions = ' all' )
444
438
445
- .. image :: https://user-images.githubusercontent.com/16560492/122477314-8007be80-cf95-11eb-9c95-da3f49204151.png
446
- :alt:
439
+ |image11 |
447
440
448
441
All the previous figures can be created for only the best solutions by
449
442
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