Exemple #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)
X, Y = np.meshgrid(x, y)
Z = objective0_plot(X, Y)
Exemple #2
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)
X, Y = np.meshgrid(x, y)
Z = objective0_plot(X, Y)

# Create figure with subplots
fig = plt.figure(figsize=(15, 10))
plt.hold(True)