You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: pygad/visualize/plot.py
+101
Original file line number
Diff line number
Diff line change
@@ -384,3 +384,104 @@ def plot_genes(self,
384
384
matplotlib.pyplot.show()
385
385
386
386
returnfig
387
+
388
+
defplot_pareto_front_curve(self,
389
+
title="Pareto Front Curve",
390
+
xlabel="Objective 1",
391
+
ylabel="Objective 2",
392
+
linewidth=3,
393
+
font_size=14,
394
+
label="Pareto Front",
395
+
color="#FF6347",
396
+
color_fitness="#4169E1",
397
+
grid=True,
398
+
alpha=0.7,
399
+
marker="o",
400
+
save_dir=None):
401
+
"""
402
+
Creates, shows, and returns the pareto front curve. Can only be used with multi-objective problems.
403
+
It only works with 2 objectives.
404
+
It also works only after completing at least 1 generation. If no generation is completed, an exception is raised.
405
+
406
+
Accepts the following:
407
+
title: Figure title.
408
+
xlabel: Label on the X-axis.
409
+
ylabel: Label on the Y-axis.
410
+
linewidth: Line width of the plot. Defaults to 3.
411
+
font_size: Font size for the labels and title. Defaults to 14.
412
+
label: The label used for the legend.
413
+
color: Color of the plot.
414
+
color_fitness: Color of the fitness points.
415
+
grid: Either True or False to control the visibility of the grid.
416
+
alpha: The transparency of the pareto front curve.
417
+
marker: The marker of the fitness points.
418
+
save_dir: Directory to save the figure.
419
+
420
+
Returns the figure.
421
+
"""
422
+
423
+
ifself.generations_completed<1:
424
+
self.logger.error("The plot_pareto_front_curve() method can only be called after completing at least 1 generation but ({self.generations_completed}) is completed.")
425
+
raiseRuntimeError("The plot_pareto_front_curve() method can only be called after completing at least 1 generation but ({self.generations_completed}) is completed.")
426
+
427
+
iftype(self.best_solutions_fitness[0]) in [list, tuple, numpy.ndarray] andlen(self.best_solutions_fitness[0]) >1:
428
+
# Multi-objective optimization problem.
429
+
iflen(self.best_solutions_fitness[0]) ==2:
430
+
# Only 2 objectives. Proceed.
431
+
pass
432
+
else:
433
+
# More than 2 objectives.
434
+
self.logger.error(f"The plot_pareto_front_curve() method only supports 2 objectives but there are {self.best_solutions_fitness[0]} objectives.")
435
+
raiseRuntimeError(f"The plot_pareto_front_curve() method only supports 2 objectives but there are {self.best_solutions_fitness[0]} objectives.")
436
+
else:
437
+
# Single-objective optimization problem.
438
+
self.logger.error("The plot_pareto_front_curve() method only works with multi-objective optimization problems.")
439
+
raiseRuntimeError("The plot_pareto_front_curve() method only works with multi-objective optimization problems.")
0 commit comments