Exemple #1
0
def masked_branin(x):
    x0 = np.abs(x[:, 0] - 0.5) < 0.25
    x1 = np.abs(x[:, 1] - 0.5) < 0.40
    mask_nan = np.logical_and(x0, x1)
    y = np.array(objectives.branin(x))
    y[mask_nan] = np.nan
    return tf.convert_to_tensor(y.reshape(-1, 1), x.dtype)
Exemple #2
0
def _dim_two_gp(mean_shift: Tuple[float, float] = (0.0, 0.0)) -> GaussianProcess:
    matern52 = tfp.math.psd_kernels.MaternFiveHalves(
        amplitude=tf.cast(2.3, tf.float64), length_scale=tf.cast(0.5, tf.float64)
    )
    return GaussianProcess(
        [lambda x: mean_shift[0] + branin(x), lambda x: mean_shift[1] + quadratic(x)],
        [matern52, rbf()],
    )
    def __call__(self, x):
        if random.random() < 0.05:
            self._is_broken = True

        if self._is_broken:
            raise Exception("Observer is broken")

        return {OBJECTIVE: trieste.data.Dataset(x, branin(x))}
Exemple #4
0
def test_batch_monte_carlo_expected_improvement_raises_for_model_with_wrong_event_shape() -> None:
    builder = BatchMonteCarloExpectedImprovement(100)
    data = mk_dataset([(0.0, 0.0)], [(0.0, 0.0)])
    matern52 = tfp.math.psd_kernels.MaternFiveHalves(
        amplitude=tf.cast(2.3, tf.float64), length_scale=tf.cast(0.5, tf.float64)
    )
    model = GaussianProcess([lambda x: branin(x), lambda x: quadratic(x)], [matern52, rbf()])
    with pytest.raises(TF_DEBUGGING_ERROR_TYPES):
        builder.prepare_acquisition_function(data, model)
Exemple #5
0
def masked_branin(x):
    mask_nan = np.sqrt((x[:, 0] - 0.5) ** 2 + (x[:, 1] - .4) ** 2) < 0.3
    y = np.array(objectives.branin(x))
    y[mask_nan] = np.nan
    return tf.convert_to_tensor(y.reshape(-1, 1), x.dtype)
Exemple #6
0
def test_branin_maps_argmin_values_to_global_minima() -> None:
    expected = tf.broadcast_to(BRANIN_GLOBAL_MINIMUM, [3, 1])
    npt.assert_allclose(branin(BRANIN_GLOBAL_ARGMIN), expected, atol=1e-6)
Exemple #7
0
def test_branin_no_points_are_less_than_global_minimum() -> None:
    search_values_1d = tf.range(1001.0) / 1000
    x0, x1 = (tf.reshape(t, [-1, 1])
              for t in tf.meshgrid(search_values_1d, search_values_1d))
    x = tf.squeeze(tf.stack([x0, x1], axis=-1))
    assert tf.reduce_all(branin(x) > BRANIN_GLOBAL_MINIMUM)
Exemple #8
0
def test_branin_no_function_values_are_less_than_global_minimum() -> None:
    samples = Box([0.0, 0.0], [1.0, 1.0]).sample(1000)
    npt.assert_array_less(tf.squeeze(BRANIN_MINIMUM) - 1e-6, branin(samples))
Exemple #9
0
 def predict(self, query_points: TensorType) -> Tuple[TensorType, TensorType]:
     return branin(query_points), self.kernel(query_points, query_points)[:, None]
def test_branin_no_function_values_are_less_than_global_minimum() -> None:
    npt.assert_array_less(
        tf.squeeze(BRANIN_MINIMUM) - 1e-6, branin(_unit_grid_2d()))