-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
60 lines (48 loc) · 1.53 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Example of a benchmark factory. The function `make_benchmark` returns an
`nmoo.Benchmark` object (following the same specifications as in the example
notebook). In a terminal, execute
nmoo run foobar:make_benchmark
to run it.
"""
import numpy as np
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.factory import get_termination
from pymoo.problems.multi import ZDT1
import nmoo
def make_benchmark() -> nmoo.Benchmark:
"""Benchmark factory"""
zdt1 = ZDT1()
wrapped_zdt1 = nmoo.WrappedProblem(zdt1)
mean = np.array([0, 0])
covariance = np.array([[1.0, -0.5], [-0.5, 1]])
noisy_zdt1 = nmoo.GaussianNoise(wrapped_zdt1, mean, covariance)
avg_zdt1 = nmoo.ResampleAverage(noisy_zdt1, n_evaluations=10)
knnavg_zdt1 = nmoo.KNNAvg(noisy_zdt1, max_distance=1.0)
nsga2 = NSGA2()
pareto_front = zdt1.pareto_front(100)
return nmoo.Benchmark(
output_dir_path="./out",
problems={
"knnavg": {
"problem": knnavg_zdt1,
"pareto_front": pareto_front,
},
"avg": {
"problem": avg_zdt1,
"pareto_front": pareto_front,
"evaluator": nmoo.PenalizedEvaluator(10),
},
},
algorithms={
"nsga2": {
"algorithm": nsga2,
},
"nsga2_100": {
"algorithm": nsga2,
"termination": get_termination("n_gen", 100),
},
},
n_runs=3,
seeds=[123, 456, 789],
)