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

Cost bo loop #195

Merged
merged 7 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions emukit/core/loop/loop_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def create_loop_state(x_init: np.ndarray, y_init: np.ndarray, cost: np.ndarray =

:param x_init: x values for initial function evaluations.
:param y_init: y values for initial function evaluations
:param cost: observed costs for initial function evaluations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

"""
if x_init.shape[0] != y_init.shape[0]:
error_message = "X and Y should have the same length. Actual length x_init {}, y_init {}".format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

def create_bayesian_optimization_loop(x_init: np.ndarray, y_init: np.ndarray, parameter_space: ParameterSpace,
acquisition_type: AcquisitionType, model_type: ModelType,
cost_init: np.ndarray = None,
model_kwargs: dict=None,
acquisition_optimizer: AcquisitionOptimizerBase = None) -> OuterLoop:
"""
Creates Bayesian optimization loop for Bayesian neural network or random forest models.

:param x_init: 2d numpy array of shape (no. points x no. input features) of initial X data
:param y_init: 2d numpy array of shape (no. points x no. targets) of initial Y data
:param cost_init: 2d numpy array of shape (no. points x no. targets) of initial cost of each function evaluation
:param parameter_space: parameter space describing input domain
:param acquisition_type: an AcquisitionType enumeration object describing which acquisition function to use
:param model_type: A ModelType enumeration object describing which model to use.
Expand Down Expand Up @@ -54,6 +56,6 @@ def create_bayesian_optimization_loop(x_init: np.ndarray, y_init: np.ndarray, pa
if acquisition_optimizer is None:
acquisition_optimizer = GradientAcquisitionOptimizer(parameter_space)
candidate_point_calculator = SequentialPointCalculator(acquisition, acquisition_optimizer)
loop_state = create_loop_state(x_init, y_init)
loop_state = create_loop_state(x_init, y_init, cost_init)
model_updater = FixedIntervalUpdater(model, 1)
return OuterLoop(candidate_point_calculator, model_updater, loop_state)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np

from emukit.test_functions.forrester import forrester_function
from emukit.examples.gp_bayesian_optimization.optimization_loops import create_bayesian_optimization_loop
from emukit.examples.gp_bayesian_optimization.enums import AcquisitionType, ModelType


def test_loop_state():

fcn, cs = forrester_function()
n_init = 5

x_init = np.random.rand(n_init, 1)
y_init = np.random.rand(n_init, 1)
c_init = np.random.rand(n_init, 1)
bo = create_bayesian_optimization_loop(x_init=x_init, y_init=y_init,
parameter_space=cs, acquisition_type=AcquisitionType.EI,
model_type=ModelType.RandomForest, cost_init=c_init)

assert bo.loop_state.X.shape[0] == n_init
assert bo.loop_state.Y.shape[0] == n_init
assert bo.loop_state.cost.shape[0] == n_init