Skip to content

Commit

Permalink
Bugfix: Exploration stops too early with single init run
Browse files Browse the repository at this point in the history
  • Loading branch information
farquet authored and apaleyes committed Apr 4, 2018
1 parent 0386772 commit 8551641
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions GPyOpt/core/bo.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ def _distance_last_evaluations(self):
"""
Computes the distance between the last two evaluations.
"""
if self.X.shape[0] < 2:
# less than 2 evaluations
return np.inf
return np.sqrt(np.sum((self.X[-1, :] - self.X[-2, :]) ** 2))

def _compute_next_evaluations(self, pending_zipped_X=None, ignored_zipped_X=None):
Expand Down
22 changes: 22 additions & 0 deletions GPyOpt/testing/methods_tests/test_bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ def test_one_initial_data_point(self):
opt.run_optimization(max_iter=1)
assert len(opt.Y) > 1

def test_infinite_distance_last_evaluations(self):
# Optimization with a single data point will have the distance between last evaluations go to infinity
# This will not be interpreted as a converged state and continue as expected
domain = [{'name': 'x', 'type': 'continuous', 'domain': (-10,10)}]

# one initial data point found randomly
bo = GPyOpt.methods.BayesianOptimization(lambda x: x*x, domain=domain,
X=None, Y=None,
initial_design_numdata=1,
initial_design_type='random')
bo.run_optimization(max_iter=3)
assert len(bo.X) == 4
assert len(bo.Y) == 4

# one initial data point given by the user
bo2 = GPyOpt.methods.BayesianOptimization(lambda x: x*x, domain=domain,
X=np.array([[1]]), Y=np.array([[1]]),
initial_design_numdata=0)
bo2.run_optimization(max_iter=2)
assert len(bo2.X) == 3
assert len(bo2.Y) == 3

def test_normalization(self):
"""Make sure normalization works with wrong model."""
np.random.seed(1)
Expand Down

0 comments on commit 8551641

Please sign in to comment.