Skip to content

Commit 0cc19cd

Browse files
committed
Fix test_hvc_monte_carlo test
1 parent 393c979 commit 0cc19cd

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pymoo/indicators/hv/monte_carlo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ def hvc_monte_carlo(dom, V, n_dom=None, k=1):
3434

3535
class ApproximateMonteCarloHypervolume(DynamicHypervolume):
3636

37-
def __init__(self, ref_point, n_samples=10000, n_exclusive=1, **kwargs) -> None:
37+
def __init__(self, ref_point, n_samples=10000, n_exclusive=1, random_state=None, **kwargs) -> None:
3838
self.n_samples = n_samples
3939
self.n_exclusive = n_exclusive
40+
self.random_state = random_state if random_state is not None else np.random.RandomState(1)
4041

4142
self.V = None
4243
self.dom = None
@@ -49,7 +50,7 @@ def _calc(self, ref_point, F):
4950
ideal = F.min(axis=0)
5051
V = np.prod(ref_point - ideal)
5152

52-
S = np.random.uniform(low=ideal, high=ref_point, size=(self.n_samples, M))
53+
S = self.random_state.uniform(low=ideal, high=ref_point, size=(self.n_samples, M))
5354

5455
dom = np.array([np.all(F[i] <= S, axis=1) for i in range(N)])
5556

tests/indicators/test_hv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def test_hvc_2d():
5959

6060

6161
@pytest.mark.parametrize('case', [case_2d(), case_3d()])
62-
@pytest.mark.skip(reason='fails since HV moocore updated. need to be checked.')
6362
def test_hvc_monte_carlo(case):
63+
random_state = np.random.RandomState(1)
6464
ref_point, F = case
6565

6666
exact = ExactHypervolume(ref_point).add(F)
@@ -70,7 +70,7 @@ def test_hvc_monte_carlo(case):
7070
np.testing.assert_allclose(exact.hvc, mc.hvc, rtol=0, atol=1e-1)
7171

7272
for i in range(len(F)):
73-
k = np.random.randint(low=0, high=len(F) - i)
73+
k = random_state.randint(low=0, high=len(F) - i)
7474

7575
exact.delete(k)
7676
mc.delete(k)

0 commit comments

Comments
 (0)