forked from anyoptimization/pymoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_decomposition.py
55 lines (37 loc) · 1.42 KB
/
test_decomposition.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
import numpy as np
from pymoo.util.remote import Remote
from pymoo.decomposition.perp_dist import PerpendicularDistance
from pymoo.decomposition.weighted_sum import WeightedSum
def test_one_to_one():
F = np.random.random((2, 2))
weights = np.array([[0.5, 0.5], [0.25, 0.25]])
val = WeightedSum().do(F, weights=weights)
assert val.ndim == 1
assert val.shape[0] == 2
def test_one_to_many():
F = np.random.random((1, 2))
weights = np.array([[0.5, 0.5], [0.25, 0.25]])
val = WeightedSum().do(F, weights=weights)
assert val.ndim == 1
assert val.shape[0] == 2
def test_many_to_one():
F = np.random.random((10, 2))
weights = np.array([[0.5, 0.5]])
val = WeightedSum().do(F, weights=weights)
assert val.ndim == 1
assert val.shape[0] == 10
def test_many_to_many():
F = np.random.random((10, 2))
weights = np.array([[0.5, 0.5], [0.25, 0.25]])
val = WeightedSum().do(F, weights=weights)
assert val.shape[0] == 10
assert val.shape[1] == 2
def test_perp_dist():
np.random.seed(1)
F = np.random.random((100, 3))
weights = np.random.random((10, 3))
correct = Remote.get_instance().load("tests", "perp_dist")
D = PerpendicularDistance(_type="python").do(F, weights, _type="many_to_many")
np.testing.assert_allclose(D, correct)
D = PerpendicularDistance(_type="cython").do(F, weights, _type="many_to_many")
np.testing.assert_allclose(D, correct)