forked from anyoptimization/pymoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_indicators.py
190 lines (128 loc) · 6.61 KB
/
test_indicators.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import numpy as np
from pymoo.indicators.gd import GD
from pymoo.indicators.gd_plus import GDPlus
from pymoo.indicators.igd import IGD
from pymoo.indicators.igd_plus import IGDPlus
from tests.test_util import load_to_test_resource
def test_values_of_indicators():
l = [
(GD, "gd"),
(IGD, "igd")
]
pf = load_to_test_resource("performance_indicator", f"performance_indicators.pf", to="numpy")
for indicator, ext in l:
for i in range(1, 5):
F = load_to_test_resource("performance_indicator", f"performance_indicators_{i}.f", to="numpy")
val = indicator(pf).do(F)
correct = load_to_test_resource("performance_indicator", f"performance_indicators_{i}.{ext}", to="numpy")
assert float(correct) == val
def test_performance_indicator_1():
A = np.array([2, 5])
B = np.array([3, 9])
D = np.array([2, 1])
pf = np.array([[1, 0], [0, 10]])
gd, igd, gd_plus, igd_plus = get_indicators(pf)
np.testing.assert_almost_equal(gd.do(A), 5.099, decimal=2)
np.testing.assert_almost_equal(gd.do(B), 3.162, decimal=2)
np.testing.assert_almost_equal(igd.do(A), 5.242, decimal=2)
np.testing.assert_almost_equal(igd.do(B), 6.191, decimal=2)
np.testing.assert_almost_equal(igd.do(D), 5.32, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(A), 3.550, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(B), 6.110, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(A), 2.0, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(B), 3.0, decimal=2)
def test_performance_indicator_2():
A = np.array([5, 2])
B = np.array([11, 3])
pf = np.array([[0, 1], [10, 0]])
gd, igd, gd_plus, igd_plus = get_indicators(pf)
np.testing.assert_almost_equal(gd.do(A), 5.099, decimal=2)
np.testing.assert_almost_equal(gd.do(B), 3.162, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(A), 2.0, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(B), 3.162, decimal=2)
np.testing.assert_almost_equal(igd.do(A), 5.242, decimal=2)
np.testing.assert_almost_equal(igd.do(B), 7.171, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(A), 3.550, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(B), 7.171, decimal=2)
def test_performance_indicator_3():
A = np.array([2, 5])
B = np.array([3, 9])
C = np.array([10, 10])
D = np.array([2, 1])
pf = np.array([[1, 0], [0, 10]])
gd, igd, gd_plus, igd_plus = get_indicators(pf)
np.testing.assert_almost_equal(gd.do(D), 1.414, decimal=2)
np.testing.assert_almost_equal(gd.do(A), 5.099, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(D), 1.414, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(A), 2.00, decimal=2)
np.testing.assert_almost_equal(igd.do(D), 5.317, decimal=2)
np.testing.assert_almost_equal(igd.do(A), 5.242, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(D), 1.707, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(A), 3.550, decimal=2)
def test_performance_indicator_4():
A = np.array([[2, 4], [3, 3], [4, 2]])
B = np.array([[2, 8], [4, 4], [8, 2]])
pf = np.array([[0, 10], [1, 6], [2, 2], [6, 1], [10, 0]])
gd, igd, gd_plus, igd_plus = get_indicators(pf)
np.testing.assert_almost_equal(gd.do(A), 1.805, decimal=2)
np.testing.assert_almost_equal(gd.do(B), 2.434, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(A), 1.138, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(B), 2.276, decimal=2)
np.testing.assert_almost_equal(igd.do(A), 3.707, decimal=2)
np.testing.assert_almost_equal(igd.do(B), 2.591, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(A), 1.483, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(B), 2.260, decimal=2)
def test_performance_indicator_5():
A = np.array([[5, 2]])
B = np.array([[6, 4], [10, 3]])
pf = np.array([[0, 1], [10, 0]])
gd, igd, gd_plus, igd_plus = get_indicators(pf)
np.testing.assert_almost_equal(gd.do(A), 5.099, decimal=2)
np.testing.assert_almost_equal(gd.do(B), 4.328, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(A), 2.0, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(B), 3.5, decimal=2)
np.testing.assert_almost_equal(igd.do(A), 5.242, decimal=2)
np.testing.assert_almost_equal(igd.do(B), 4.854, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(A), 3.550, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(B), 4.854, decimal=2)
def test_performance_indicator_6():
A = np.array([[1, 5]])
B = np.array([[5, 6]])
pf = np.array([[4, 4]])
gd, igd, gd_plus, igd_plus = get_indicators(pf)
np.testing.assert_almost_equal(gd.do(A), 3.162, decimal=2)
np.testing.assert_almost_equal(gd.do(B), 2.236, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(A), 1.0, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(B), 2.236, decimal=2)
np.testing.assert_almost_equal(igd.do(A), 3.162, decimal=2)
np.testing.assert_almost_equal(igd.do(B), 2.236, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(A), 1.0, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(B), 2.236, decimal=2)
def test_performance_indicator_8():
A = np.array([[1, 8], [2, 2], [8, 1]])
B = np.array([[4, 3]])
pf = np.array([[0, 0]])
gd, igd, gd_plus, igd_plus = get_indicators(pf)
np.testing.assert_almost_equal(gd.do(A), 6.318, decimal=2)
np.testing.assert_almost_equal(gd.do(B), 5.0, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(A), 6.318, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(B), 5.0, decimal=2)
np.testing.assert_almost_equal(igd.do(A), 2.828, decimal=2)
np.testing.assert_almost_equal(igd.do(B), 5.0, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(A), 2.828, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(B), 5.0, decimal=2)
def test_performance_indicator_9():
A = np.array([[1, 8], [2, 2], [8, 1]])
B = np.array([[2, 2]])
pf = np.array([[0, 0]])
gd, igd, gd_plus, igd_plus = get_indicators(pf)
np.testing.assert_almost_equal(gd.do(A), 6.318, decimal=2)
np.testing.assert_almost_equal(gd.do(B), 2.828, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(A), 6.318, decimal=2)
np.testing.assert_almost_equal(gd_plus.do(B), 2.828, decimal=2)
np.testing.assert_almost_equal(igd.do(A), 2.828, decimal=2)
np.testing.assert_almost_equal(igd.do(B), 2.828, decimal=2)
np.testing.assert_almost_equal(igd_plus.do(A), 2.828, decimal=3)
np.testing.assert_almost_equal(igd_plus.do(B), 2.828, decimal=3)
def get_indicators(pf):
return tuple([clazz(pf) for clazz in [GD, IGD, GDPlus, IGDPlus]])