Skip to content

Commit

Permalink
Merge pull request #107 from smanist/master
Browse files Browse the repository at this point in the history
Bug fix in pareto.py, Pareto::divide_conquer_nd
  • Loading branch information
icouckuy committed Sep 12, 2018
2 parents 8c03e23 + 79cffab commit f1c268e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gpflowopt/pareto.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

np_int_type = np_float_type = np.int32 if settings.dtypes.int_type is tf.int32 else np.int64
float_type = settings.dtypes.float_type
stability = settings.numerics.jitter_level


class BoundedVolumes(Parameterized):
Expand Down Expand Up @@ -193,20 +194,25 @@ def divide_conquer_nd(self):
# Start with one cell covering the whole front
dc = [(np.zeros(outdim, dtype=np_int_type),
(int(pf_ext_idx.shape[0]) - 1) * np.ones(outdim, dtype=np_int_type))]

total_size = np.prod(max_pf - min_pf)

# Start divide and conquer until we processed all cells
while dc:
# Process test cell
cell = dc.pop()

arr = np.arange(outdim)
lb = pf_ext[pf_ext_idx[cell[0], arr], arr]
ub = pf_ext[pf_ext_idx[cell[1], arr], arr]

# Acceptance test:
if self._is_test_required((cell[1] - 0.5) < pseudo_pf):
if self._is_test_required((ub - stability) < self.front.value):
# Cell is a valid integral bound: store
self.bounds.append(pf_ext_idx[cell[0], np.arange(outdim)],
pf_ext_idx[cell[1], np.arange(outdim)])
# Reject test:
elif self._is_test_required((cell[0] + 0.5) < pseudo_pf):
elif self._is_test_required((lb + stability) < self.front.value):
# Cell can not be discarded: calculate the size of the cell
dc_dist = cell[1] - cell[0]
hc = BoundedVolumes(pf_ext[pf_ext_idx[cell[0], np.arange(outdim)], np.arange(outdim)],
Expand Down
14 changes: 14 additions & 0 deletions testing/unit/test_pareto.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def setUp(self):
self.p_generic = gpflowopt.pareto.Pareto(np.zeros((1, 2)))
self.p_generic.update(objective_scores, generic_strategy=True)

scores_3d_set1 = np.array([[2.0, 2.0, 0.0],
[2.0, 0.0, 1.0],
[3.0, 1.0, 0.0]])
scores_3d_set2 = np.array([[2.0, 0.0, 1.0],
[2.0, 2.0, 0.0],
[3.0, 1.0, 0.0]])
self.p_3d_set1 = gpflowopt.pareto.Pareto(np.zeros((1, 3)))
self.p_3d_set1.update(scores_3d_set1)
self.p_3d_set2 = gpflowopt.pareto.Pareto(np.zeros((1, 3)))
self.p_3d_set2.update(scores_3d_set2)

def test_update(self):
np.testing.assert_almost_equal(self.p_2d.bounds.lb.value, np.array([[0, 0], [1, 0], [2, 0], [3, 0]]),
err_msg='LBIDX incorrect.')
Expand All @@ -54,3 +65,6 @@ def test_hypervolume(self):

np.testing.assert_almost_equal(self.p_2d.hypervolume([1, 1]), self.p_generic.hypervolume([1, 1]), decimal=20,
err_msg='hypervolume of different strategies incorrect.')

np.testing.assert_equal(self.p_3d_set1.hypervolume([4, 4, 4]), 29.0, err_msg='3D hypervolume incorrect.')
np.testing.assert_equal(self.p_3d_set2.hypervolume([4, 4, 4]), 29.0, err_msg='3D hypervolume incorrect.')

0 comments on commit f1c268e

Please sign in to comment.