-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Mixed-integer differential evolution for next point suggestion #549
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d12fd04
Update acquisition.py
udicaprio 57e1a4d
Update acquisition.py
udicaprio bfb98ca
Merge branch 'bayesian-optimization:master' into master
udicaprio 0cd9176
Update acquisition.py
udicaprio 380fe64
Update acquisition.py
udicaprio 95f1251
Update acquisition.py
udicaprio fb101a6
Rename minimization methods for clarity and update tests accordingly
udicaprio 0e859df
Refactor differential evolution import and optimize acquisition function
udicaprio 0b6148f
Merge branch 'bayesian-optimization:master' into master
udicaprio fb9d6a2
Modification to differential evolution solver integration and refine …
udicaprio 07f75b2
Refactor DifferentialEvolutionSolver initialization to support scipy …
udicaprio a241f62
Removes fixed algorithm for acquisition function minimization and app…
udicaprio 79b8e03
Fixing formatting issue
udicaprio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
|
|
||
| import numpy as np | ||
| from numpy.random import RandomState | ||
| from scipy.optimize import minimize | ||
| from scipy.optimize._differentialevolution import DifferentialEvolutionSolver, minimize | ||
| from scipy.special import softmax | ||
| from scipy.stats import norm | ||
| from sklearn.gaussian_process import GaussianProcessRegressor | ||
|
|
@@ -219,7 +219,7 @@ def _acq_min( | |
| acq, space, n_random=max(n_random, n_l_bfgs_b), n_x_seeds=n_l_bfgs_b | ||
| ) | ||
| if n_l_bfgs_b: | ||
| x_min_l, min_acq_l = self._l_bfgs_b_minimize(acq, space, x_seeds=x_seeds) | ||
| x_min_l, min_acq_l = self._smart_minimize(acq, space, x_seeds=x_seeds) | ||
| # Either n_random or n_l_bfgs_b is not 0 => at least one of x_min_r and x_min_l is not None | ||
| if min_acq_r > min_acq_l: | ||
| return x_min_l | ||
|
|
@@ -268,7 +268,7 @@ def _random_sample_minimize( | |
| x_seeds = [] | ||
| return x_min, min_acq, x_seeds | ||
|
|
||
| def _l_bfgs_b_minimize( | ||
| def _smart_minimize( | ||
| self, | ||
| acq: Callable[[NDArray[Float]], NDArray[Float]], | ||
| space: TargetSpace, | ||
|
|
@@ -298,33 +298,41 @@ def _l_bfgs_b_minimize( | |
| continuous_dimensions = space.continuous_dimensions | ||
| continuous_bounds = space.bounds[continuous_dimensions] | ||
|
|
||
| if not continuous_dimensions.any(): | ||
| min_acq = np.inf | ||
| x_min = np.array([np.nan] * space.bounds.shape[0]) | ||
| return x_min, min_acq | ||
|
|
||
| min_acq: float | None = None | ||
| x_try: NDArray[Float] | ||
| x_min: NDArray[Float] | ||
| for x_try in x_seeds: | ||
|
|
||
| def continuous_acq(x: NDArray[Float], x_try=x_try) -> NDArray[Float]: | ||
| x_try[continuous_dimensions] = x | ||
| return acq(x_try) | ||
| # Case of continous optimization | ||
| if all(continuous_dimensions): | ||
| for x_try in x_seeds: | ||
| res: OptimizeResult = minimize(acq, x_try, bounds=continuous_bounds, method="L-BFGS-B") | ||
| if not res.success: | ||
| continue | ||
|
|
||
| # Find the minimum of minus the acquisition function | ||
| res: OptimizeResult = minimize( | ||
| continuous_acq, x_try[continuous_dimensions], bounds=continuous_bounds, method="L-BFGS-B" | ||
| ) | ||
| # See if success | ||
| if not res.success: | ||
| continue | ||
|
|
||
| # Store it if better than previous minimum(maximum). | ||
| if min_acq is None or np.squeeze(res.fun) >= min_acq: | ||
| x_try[continuous_dimensions] = res.x | ||
| x_min = x_try | ||
| min_acq = np.squeeze(res.fun) | ||
| # Store it if better than previous minimum(maximum). | ||
| if min_acq is None or np.squeeze(res.fun) >= min_acq: | ||
| x_try = res.x | ||
| x_min = x_try | ||
| min_acq = np.squeeze(res.fun) | ||
|
|
||
| # Case of mixed-integer optimization | ||
| else: | ||
| ntrials = max(1, len(x_seeds) // 100) | ||
udicaprio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for _ in range(ntrials): | ||
| xinit = space.random_sample(15 * len(space.bounds), random_state=self.random_state) | ||
| de = DifferentialEvolutionSolver(acq, bounds=space.bounds, init=xinit, rng=self.random_state) | ||
|
||
| res: OptimizeResult = de.solve() | ||
|
|
||
| # See if success | ||
| if not res.success: | ||
| continue | ||
|
|
||
| # Store it if better than previous minimum(maximum). | ||
| if min_acq is None or np.squeeze(res.fun) >= min_acq: | ||
| x_try_sc = de._unscale_parameters(res.x) | ||
till-m marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| x_try = space.kernel_transform(x_try_sc).flatten() | ||
| x_min = x_try | ||
| min_acq = np.squeeze(res.fun) | ||
|
|
||
till-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if min_acq is None: | ||
| min_acq = np.inf | ||
till-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.