Version: 0.6.0

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.

Types of Output

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.4525139169 |  0.2845368465
3 |      300 |  0.4123143496 |  0.2826460505
4 |      400 |  0.3624091800 |  0.2680576859
5 |      500 |  0.3237124952 |  0.2590762910
6 |      600 |  0.2743448091 |  0.2384785285
7 |      700 |  0.2565909842 |  0.2368465686
8 |      800 |  0.2294679740 |  0.2210448785
9 |      900 |  0.1929644605 |  0.1955969395
10 |     1000 |  0.1785042488 |  0.1927740079


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.