Beispiel #1
0
    * GPy.kern.Matern52(input_dim=dims_S, active_dims=list(range(dims_Z, dims_X)))
# Defining the method to model the objective function
model = GPyModel(kernel, optimize=True, noise_variance=1e-2, num_restarts=10)

# The acquisition function that we optimize in order to pick a new x
acquisition_func = UCB(model, X_lower=X_lower, X_upper=X_upper, par=1.0)

# Context function acquires random values
def context_fkt():
    return np.random.uniform(size=(1,1))

bo = ContextualBayesianOptimization(acquisition_fkt=acquisition_func,
                                    model=model,
                                    maximize_fkt=maximizer,
                                    S_lower=S_lower,
                                    S_upper=S_upper,
                                    dims_Z=dims_Z,
                                    dims_S=dims_S,
                                    objective_fkt=objective0,
                                    context_fkt=context_fkt)

print "Result:", bo.run(num_iterations=32)

print "Finding optima"
xactions = np.linspace(0, 1, num=64)
yactions = np.array([bo.predict(np.array(xeval, ndmin=2)).flatten()[1] for xeval in xactions])
yactions_exact = np.array([objective0_min_action(Z=np.reshape(xeval, (1, 1))).flatten() for xeval in xactions])

# Create grid for contours
x = np.linspace(0, 1, num=200)
y = np.linspace(0, 1, num=200)
Beispiel #2
0
model = GPyModel(kernel, optimize=True, noise_variance=1e-2, num_restarts=10)

# The acquisition function that we optimize in order to pick a new x
acquisition_func = LCB(model, X_lower=X_lower, X_upper=X_upper, par=1.0)


# Context function acquires random values
def context_fkt():
    return np.random.uniform(size=(1, 1))


bo = ContextualBayesianOptimization(acquisition_fkt=acquisition_func,
                                    model=model,
                                    maximize_fkt=maximizer,
                                    S_lower=S_lower,
                                    S_upper=S_upper,
                                    dims_Z=dims_Z,
                                    dims_S=dims_S,
                                    objective_fkt=objective0,
                                    context_fkt=context_fkt)

print "Result:", bo.run(num_iterations=32)

print "Finding optima"
xactions = np.linspace(0, 1, num=64)
yactions = np.array(
    [bo.predict(np.array(xeval, ndmin=2)).flatten()[1] for xeval in xactions])
yactions_exact = np.array([
    objective0_min_action(Z=np.reshape(xeval, (1, 1))).flatten()
    for xeval in xactions
])
Beispiel #3
0
# Defining the method to model the objective function
kernel = GPy.kern.Matern52(input_dim=dims_Z + dims_S)
model = GPyModel(kernel, optimize=True, noise_variance=1e-2, num_restarts=10)

# The acquisition function that we optimize in order to pick a new x
acquisition_func = UCB(model, X_upper=S_upper, X_lower=S_lower, compute_incumbent=compute_incumbent, par=1.0)

def context_fkt():
    return np.random.uniform(size=(1,1))

bo = ContextualBayesianOptimization(acquisition_fkt=acquisition_func,
                                    model=model,
                                    maximize_fkt=maximizer,
                                    S_lower=S_lower,
                                    S_upper=S_upper,
                                    dims_Z=dims_Z,
                                    dims_S=dims_S,
                                    objective_fkt=objective0,
                                    context_fkt=context_fkt)

print "Result:", bo.run(num_iterations=25)

xactions = np.linspace(0, 1, num=25)
yactions = np.array([bo.predict_next(Z=np.reshape(xeval, (1, 1))).flatten()[1] for xeval in xactions])
#yactions = xactions

x = np.linspace(0, 1, num=200)
y = np.linspace(0, 1, num=200)
X, Y = np.meshgrid(x, y)
Z = objective0vis(X, Y)