NSGA-II¶
The standard method for problems with two or three objectives.
NSGAII ¶
NSGAII(*, crossover=None, mutation=None, space='encoded', operators=None, max_archive=None, **kwargs)
Non-dominated Sorting Genetic Algorithm II for several objectives.
Each iteration makes pop_size children: parents are chosen by binary tournaments
on the crowded comparison (the lower front wins, then the larger crowding distance),
each pair is crossed, and every child is mutated. Parents and children are merged and
sorted into non-dominated fronts. The best fronts fill the next population, and the
last front that does not fit whole is cut by crowding distance, the largest first.
Constraints use constrained domination (Deb et al. 2002, Section VI): a feasible solution dominates an infeasible one, and of two infeasible ones the smaller violation dominates (with exactly equal violations, Pareto dominance decides). The sort and the tournaments both use it.
Parameters
pop_size: population size N (default 100). Each iteration makes N children.crossover(ypea.operators.Crossover or None): A crossover on the [0, 1] codes, called asop(x1, x2, rng), or a native one withspace="native". None (the default) is simulated binary crossover with the paper's settings,SBX(eta=20, prob=0.9).mutation(ypea.operators.Mutation or None): A mutation on the [0, 1] codes, called asop(x, rng), or a native one withspace="native". None (the default) is polynomial mutation with the paper's settings,PolynomialMutation(eta=20), which changes each of the n codes with probability 1/n.space: "encoded" (the default) appliescrossoverandmutationto the [0, 1] codes. "native" applies the native operators of each variable type (see the guide Native operators). Real variables keep SBX and polynomial mutation, so a problem with only Real variables runs exactly as with "encoded".operators(dict or None): Native operators per variable name, as in GA (needsspace="native").max_archive: largest size ofResult.front. None (default) keeps every non-dominated solution. When there are more, the most crowded ones are dropped.
Reference: K. Deb, A. Pratap, S. Agarwal and T. Meyarivan, "A fast and elitist multiobjective genetic algorithm: NSGA-II", IEEE Transactions on Evolutionary Computation 6(2), 182 to 197, 2002.
Example¶
Solve ZDT1 (30 variables, two objectives) and measure the distance of the front to the true Pareto front:
import ypea
from ypea.benchmarks import pareto_front, zdt1
from ypea.indicators import igd
problem = ypea.Problem(
ypea.Real("x", shape=30),
lambda sol: zdt1(sol.x),
n_obj=2,
vectorized=True,
name="zdt1",
)
alg = ypea.NSGAII(max_nfe=5_000)
result = alg.solve(problem, seed=1)
true_front = pareto_front("zdt1", 1000)
score = igd(result.front.obj_values, true_front)
print(len(result.front), score)
63 0.11675501113771417
Differs from Python: MATLAB draws its own random numbers, so the front size and IGD differ from Python's.
problem = ypea.Problem( ...
vars=ypea.Real("x", shape=30, lb=0, ub=1), ...
objective=@(sol) ypea.benchmarks.zdt1(sol.x), ...
vectorized=true, ...
n_obj=2, ...
name="zdt1");
alg = ypea.NSGAII(max_nfe=5000);
result = alg.solve(problem, seed=1);
true_front = ypea.benchmarks.pareto_front("zdt1", 1000);
score = ypea.indicators.igd(result.front.obj_values, true_front);
fprintf("%d %.17g\n", length(result.front), score)
56 0.13736276606717709
Other operators from ypea.operators replace the defaults, for example ypea.NSGAII(crossover=ypea.operators.SBX(eta=15)).
Front on ZDT1¶
result.front, and the dashed line is the true front.