Skip to content

Commit 0cd9176

Browse files
committed
Update acquisition.py
Computational-efficiency of the MIP identification increased
1 parent bfb98ca commit 0cd9176

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

bayes_opt/acquisition.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -308,28 +308,38 @@ def _l_bfgs_b_minimize(
308308
min_acq: float | None = None
309309
x_try: NDArray[Float]
310310
x_min: NDArray[Float]
311-
for x_try in x_seeds:
312311

313-
# def continuous_acq(x: NDArray[Float], x_try=x_try) -> NDArray[Float]:
314-
# x_try[continuous_dimensions] = x
315-
# return acq(x_try)
316-
if all(continuous_dimensions):
317-
# Find the minimum of minus the acquisition function
312+
#Case of continous optimization
313+
if all(continuous_dimensions):
314+
for x_try in x_seeds:
318315
res: OptimizeResult = minimize(acq, x_try, bounds=continuous_bounds, method="L-BFGS-B")
319-
else:
320-
res: OptimizeResult = differential_evolution(acq, bounds=bounds,
316+
if not res.success:
317+
continue
318+
319+
# Store it if better than previous minimum(maximum).
320+
if min_acq is None or np.squeeze(res.fun) >= min_acq:
321+
x_try = res.x
322+
x_min = x_try
323+
min_acq = np.squeeze(res.fun)
324+
325+
#Case of mixed-integer optimization
326+
else:
327+
ntrials = max(1, len(x_seeds)//100)
328+
for i in range(ntrials):
329+
xinit = space.random_sample(15*len(space.bounds), random_state=i)
330+
res: OptimizeResult = differential_evolution(acq, bounds=bounds, init=xinit,
321331
integrality=discrete_dimensions,
322332
seed=self.random_state)
323-
# See if success
324-
if not res.success:
325-
continue
326-
327-
# Store it if better than previous minimum(maximum).
328-
if min_acq is None or np.squeeze(res.fun) >= min_acq:
329-
x_try = res.x
330-
x_min = x_try
331-
min_acq = np.squeeze(res.fun)
332-
333+
# See if success
334+
if not res.success:
335+
continue
336+
337+
# Store it if better than previous minimum(maximum).
338+
if min_acq is None or np.squeeze(res.fun) >= min_acq:
339+
x_try = res.x
340+
x_min = x_try
341+
min_acq = np.squeeze(res.fun)
342+
333343
if min_acq is None:
334344
min_acq = np.inf
335345
x_min = np.array([np.nan] * space.bounds.shape[0])

0 commit comments

Comments
 (0)