anyoptimization / pymoo

NSGA2, NSGA3, R-NSGA3, MOEAD, Genetic Algorithms (GA), Differential Evolution (DE), CMAES, PSO
https://pymoo.org
Apache License 2.0
2.28k stars 392 forks source link

How to produce IGD and Hypervolume performance statistics base on your current code? #494

Closed jikuizhao closed 11 months ago

jikuizhao commented 1 year ago

Dear,

I am a new learner, a simple question. How to produce IGD and Hypervolume performance statistics base on your current code?

from pymoo.algorithms.moo.nsga2 import NSGA2 from pymoo.problems import get_problem from pymoo.optimize import minimize from pymoo.visualization.scatter import Scatter

problem = get_problem("zdt1")

algorithm = NSGA2(pop_size=100)

res = minimize(problem, algorithm, ('n_gen', 200), seed=1, verbose=True)

plot = Scatter() plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7) plot.add(res.F, color="red") plot.show()

blankjul commented 1 year ago

You can store the entire history and do something like this:

from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.indicators.igd import IGD
from pymoo.optimize import minimize
from pymoo.problems import get_problem

problem = get_problem("zdt1")

algorithm = NSGA2(pop_size=100)

res = minimize(problem,
               algorithm,
               ('n_gen', 10),
               seed=1,
               save_history=True,
               verbose=True)

igd = IGD(problem.pareto_front())
for gen, snapshot in enumerate(res.history):

print(gen, igd.do(snapshot.pop.get("F")))