Пример #1
0
        x, y = input_data[:, -2], input_data[:, -1]
        z = tf.cos(x) * tf.cos(y) - tf.sin(x) * tf.sin(y)
        return z[:, None]


search_space = Box([0, 0], [6, 6])

# %% [markdown]
# The objective and constraint functions are accessible as methods on the `Sim` class. Let's visualise these functions, as well as the constrained objective.  We get the constrained objective by masking out regions where the constraint function is above the threshold.

# %%
import trieste
import matplotlib.pyplot as plt
from util.inequality_constraints_utils import plot_objective_and_constraints

plot_objective_and_constraints(search_space, Sim)
plt.show()

# %% [markdown]
# We'll make an observer that outputs both the objective and constraint data. Since the observer is outputting multiple datasets, we have to label them so that the optimization process knows which is which.

# %%
from trieste.data import Dataset

OBJECTIVE = "OBJECTIVE"
CONSTRAINT = "CONSTRAINT"

def observer(query_points):
    return {
        OBJECTIVE: Dataset(query_points, Sim.objective(query_points)),
        CONSTRAINT: Dataset(query_points, Sim.constraint(query_points)),
Пример #2
0
# constraint, defined over a two-dimensional input domain. We'll start by defining the problem
# parameters.

# %%
lower_bound = tf.cast([0.0, 0.0], default_float())
upper_bound = tf.cast([6.0, 6.0], default_float())
sim = util.Simulation(lower_bound, upper_bound, threshold=0.5)
search_space = trieste.space.Box(lower_bound, upper_bound)

# %% [markdown]
# The objective and constraint functions are accessible as methods on the `Simulation`
# class. Let's visualise these functions, as well as the constrained objective formed by applying a
# mask to the objective over regions where the constraint function crosses the threshold.

# %%
util.plot_objective_and_constraints(sim)
plt.show()

# %% [markdown]
# We'll make an observer that outputs the objective and constraint data, labelling each as shown.

# %%
OBJECTIVE = "OBJECTIVE"
CONSTRAINT = "CONSTRAINT"


def observer(query_points):
    return {
        OBJECTIVE:
        trieste.datasets.Dataset(query_points, sim.objective(query_points)),
        CONSTRAINT: