Skip to content

Commit

Permalink
Fix for the case when only one initial date point is used (SheffieldM…
Browse files Browse the repository at this point in the history
  • Loading branch information
befelix authored and apaleyes committed Mar 1, 2018
1 parent 693f8fb commit e72a64f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 4 additions & 5 deletions GPyOpt/core/bo.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def run_optimization(self, max_iter = 0, max_time = np.inf, eps = 1e-8, context
except np.linalg.linalg.LinAlgError:
break

if not ((self.num_acquisitions < self.max_iter) and (self._distance_last_evaluations() > self.eps)):
if (self.num_acquisitions >= self.max_iter
or (len(self.X) > 1 and self._distance_last_evaluations() <= self.eps)):
break

self.suggested_sample = self._compute_next_evaluations()
Expand Down Expand Up @@ -199,15 +200,13 @@ def _compute_results(self):
"""
self.Y_best = best_value(self.Y)
self.x_opt = self.X[np.argmin(self.Y),:]
self.fx_opt = min(self.Y)

self.fx_opt = np.min(self.Y)

def _distance_last_evaluations(self):
"""
Computes the distance between the last two evaluations.
"""
return np.sqrt(sum((self.X[self.X.shape[0]-1,:]-self.X[self.X.shape[0]-2,:])**2))

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
11 changes: 10 additions & 1 deletion GPyOpt/testing/methods_tests/test_bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ def test_next_locations_ignored(self):
bo_ignored = BayesianOptimization(f = None, domain = domain, X = X_init, Y = Y_init, de_duplication = True)
x_ignored = bo_ignored.suggest_next_locations(ignored_X = x_no_ignored)

self.assertFalse(np.isclose(x_ignored, x_no_ignored))
self.assertFalse(np.isclose(x_ignored, x_no_ignored))

def test_one_initial_data_point(self):
"""Make sure BO still works with only one initial data point."""
bounds = [{'name': 'var_1', 'type': 'continuous', 'domain': (-1, 1)}]
opt = BayesianOptimization(lambda x: x, bounds, initial_design_numdata=1)

# Make sure run_optimization works
opt.run_optimization(max_iter=1)
assert len(opt.Y) > 1

0 comments on commit e72a64f

Please sign in to comment.