Display¶
When running the code, you might have seen some printouts (when using verbose=True
), which might or might not have made a lot of sense to you. Below, a quick summary of possible printouts you might encounter is provided.
Name |
Description |
---|---|
n_gen |
The current number of generations or iterations until this point. |
n_eval |
The number of function evaluations so far. |
n_nds |
For multi-objective problems, the number of non-dominated solutions of the optima found. |
cv (min) |
The minimum constraint violation (CV) in the current population |
cv (avg) |
The average constraint violation (CV) of the current population |
f_opt |
For single-objective problems, the best function value found so far. |
f_gap |
For single-objective problems, the best gap to the optimum (only printed if the optimum is known). |
eps/indicator |
For multi-objective problems, the change of the indicator (ideal, nadir, f) over the last few generations (only printed if the Pareto-front is unknown). For more information we encourage you to have a look at the corresponding publication ([27], pdf). |
igd/gd/hv |
For multi-objective problems, the performance indicator (only printed if the Pareto-front is known). |
The default printouts can vary from algorithm to algorithm and from problem to problem. The type of printout is based on an implementation of the Display
object. If you like to customize the output, you can also write your own, as shown below:
[1]:
import numpy as np
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.util.display.column import Column
from pymoo.util.display.output import Output
class MyOutput(Output):
def __init__(self):
super().__init__()
self.x_mean = Column("x_mean", width=13)
self.x_std = Column("x_std", width=13)
self.columns += [self.x_mean, self.x_std]
def update(self, algorithm):
super().update(algorithm)
self.x_mean.set(np.mean(algorithm.pop.get("X")))
self.x_std.set(np.std(algorithm.pop.get("X")))
problem = get_problem("zdt2")
algorithm = NSGA2(pop_size=100)
res = minimize(problem,
algorithm,
('n_gen', 10),
seed=1,
output=MyOutput(),
verbose=True)
=================================================
n_gen | n_eval | x_mean | x_std
=================================================
1 | 100 | 0.5001227728 | 0.2877408633
2 | 200 | 0.4593269465 | 0.2861729745
3 | 300 | 0.4262522159 | 0.2852100808
4 | 400 | 0.4026633289 | 0.2773791496
5 | 500 | 0.3850326611 | 0.2719518939
6 | 600 | 0.3716348041 | 0.2694989517
7 | 700 | 0.3456207925 | 0.2608847090
8 | 800 | 0.3268969233 | 0.2555223578
9 | 900 | 0.3109206006 | 0.2486476627
10 | 1000 | 0.2970182918 | 0.2430209280
You have to inherit your custom display MyDisplay
from the Display
class for your own printout logic. The _do
function will be called in each iteration, and the Problem
, Evaluator
and Algorithm
are provided to you. For each column, you can add an entry to self.output
, which will be formatted and then printed.