Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bowsr minimize() IndexError #465

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions maml/apps/bowsr/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,10 @@ def min_obj(x):
# Minimize objective is the negative acquisition function
return -acquisition(x.reshape(-1, dim), gpr=gpr, y_max=y_max, noise=noise)

x0 = x_max.reshape(-1, dim)
# make sure that the initial conditions fall into the bounds
x0 = np.clip(x0, bounds[:, 0] + 3 * EPS, bounds[:, 1] - 3 * EPS)

try:
res = minimize(min_obj, x0=x0, bounds=bounds, method="L-BFGS-B")
except IndexError:
# For some reason, scipy sometimes result in a shape error for x0.
# Here, we just simply initialize based on x_max without clipping.
res = minimize(min_obj, x0=x_max.reshape(-1, dim), bounds=bounds, method="L-BFGS-B")
x0 = np.clip(x_max, bounds[:, 0] + 3 * EPS, bounds[:, 1] - 3 * EPS)

res = minimize(min_obj, x0=x0, bounds=bounds, method="L-BFGS-B")
if -float(res.fun) >= acq_max:
x_max = res.x
return _trunc(scaler.inverse_transform(x_max), decimals=3)
Expand Down