# EGO with a failure region#

```
[1]:
```

```
from __future__ import annotations
import numpy as np
import tensorflow as tf
np.random.seed(1234)
tf.random.set_seed(1234)
```

## The problem#

This notebook is similar to the EI notebook, where we look to find the minimum value of the two-dimensional Branin function over the hypercube \([0, 1]^2\). But here, we constrain the problem, by adding an area to the search space in which the objective fails to evaluate.

We represent this setup with a function `masked_branin`

that produces null values when evaluated in the disk with center \((0.5, 0.4)\) and radius \(0.3\). It’s important to remember that while *we* know where this *failure region* is, this function is a black box from the optimizer’s point of view: the optimizer must learn it.

```
[2]:
```

```
import trieste
def masked_branin(x):
mask_nan = np.sqrt((x[:, 0] - 0.5) ** 2 + (x[:, 1] - 0.4) ** 2) < 0.3
y = np.array(trieste.objectives.Branin.objective(x))
y[mask_nan] = np.nan
return tf.convert_to_tensor(y.reshape(-1, 1), x.dtype)
```

As mentioned, we’ll search over the hypercube \([0, 1]^2\) …

```
[3]:
```

```
from trieste.space import Box
search_space = Box([0, 0], [1, 1])
```

… where the `masked_branin`

now looks as follows. The white area in the centre shows the failure region.

```
[4]:
```

```
from trieste.experimental.plotting import plot_function_plotly
fig = plot_function_plotly(
masked_branin, search_space.lower, search_space.upper
)
fig.show()
```