48 """Bayesian Optimization with Interactive Illumination (Kent and Branke, 2023).
50 Reuse the measured design and descriptor posteriors across all three
51 phases. Use a fixed one- or two-dimensional rectangular reporting grid.
52 Model building multiplies expected joint improvement by one plus the
53 normalized entropy of posterior region membership. Focused
54 illumination considers only selected cells. Target search uses common
55 Monte Carlo draws to estimate the expected improvement in target utility.
57 :param container: Best-only Grid with one objective and one or two descriptors.
58 :param budget: Total measurement attempts across repeated optimise calls and manual batches.
59 :param dimension: Length of a real-valued genome.
60 :param ind_domain: Common lower and upper decision bounds.
61 :param quality_floor: Empty-cell threshold in weighted fitness units.
62 :param entropy_weight: Nonnegative multiplier on normalized descriptor entropy.
63 :param target_samples: Power-of-two count of fixed, scrambled Sobol posterior draws.
64 :param kwargs: Native optimizer arguments and BOP-Elites initialization and search settings.
67 def __init__(self, container, budget, dimension, ind_domain, quality_floor, *,
68 entropy_weight=1., target_samples=64, **kwargs):
69 if not 0 <= entropy_weight < np.inf:
70 raise ValueError(
"entropy_weight must be finite and nonnegative.")
73 self.
target_samples = _positive_int(target_samples,
"target_samples")
75 raise ValueError(
"target_samples must be a power of two.")
76 unsupported = (
"model_feasibility",
"descriptor_transform",
"latent_size")
77 if any(name
in kwargs
for name
in unsupported):
78 raise TypeError(
"BOIL takes direct descriptor observations.")
79 super().__init__(container, budget, dimension, ind_domain, quality_floor, **kwargs)
82 raise ValueError(
"Use finite search widths and a nonzero fitness weight.")
85 """Reset measurements, the phase, and the lifetime attempt count."""
91 stream = qmc.Sobol(len(self.
container.shape) + 1, scramble=
True, seed=0
if self.
seed is None else self.
seed)
92 self.
_draws = ndtri(np.clip(stream.random_base2(self.
target_samples.bit_length() - 1), 1e-12, 1 - 1e-12))
95 def remaining_evaluations(self):
96 """Return the number of attempts still available, including future phases."""
99 def _expect_idle(self):
101 raise RuntimeError(
"Finish the outstanding BOIL batch before changing phases.")
105 """Select a nonempty sequence of grid indices, or pass None to use the full map."""
108 if cells
is not None:
109 selected = {tuple(index(axis)
for axis
in cell)
for cell
in cells}
110 if not selected
or not selected.issubset(self.
container.solutions):
111 raise ValueError(
"Select at least one valid grid cell.")
112 ranks = np.array([cell
in selected
for cell
in self.
_cells])
117 """Maximize weighted fitness minus distance_weight times Euclidean descriptor error."""
119 target = np.asarray(descriptor, dtype=float)
120 if (target.shape != (len(self.
container.shape),)
or not np.isfinite(target).all()
122 raise ValueError(
"The target must be finite and within the descriptor domain.")
123 if not 0 <= distance_weight < np.inf:
124 raise ValueError(
"distance_weight must be finite and nonnegative.")
129 def _utility(self, values):
131 return values[..., 0]
132 distances = np.linalg.norm(values[..., 1:] - self.
_target, axis=-1)
137 """Return a BOILTargetResult for the active target, or None before any observations."""
139 raise RuntimeError(
"Call set_target() before requesting target results.")
144 row = int(np.argmax(scores))
147 tuple(map(float, values[row, 1:])), float(scores[row]))
149 def _probabilities(self, means, deviations):
150 return _region_probabilities(means[:,
None, 1:], deviations[:,
None, 1:],
153 def _modelled_point(self):
156 return super()._modelled_point()
158 def _acquisition(self, models, points, thresholds, cutoff):
159 means, deviations = self.
_posterior(models, points)
161 samples = means[:,
None, :] + deviations[:,
None, :] * self.
_draws
164 contributions = np.zeros((len(points), len(self.
_cells)))
166 contributions[:, slot] = gains
169 if self.
_focus is not None:
170 probabilities[:, ~self.
_focus] = 0.
171 improvement = _expected_improvement(means[:, :1], deviations[:, :1], thresholds)
172 entropy = -xlogy(probabilities, probabilities).sum(axis=1) / log(max(2, len(self.
_cells)))
173 contributions = probabilities * improvement * (1 + self.
entropy_weight * entropy[:,
None])
174 return contributions, means[:, 1:]
178 """Return up to one provisional solution per cell, ranked by predicted weighted fitness."""
180 samples = _positive_int(samples,
"samples")
181 if not 0 < min_probability <= 1:
182 raise ValueError(
"min_probability must be in (0, 1].")
184 raise RuntimeError(
"Evaluate at least two valid solutions before building a preview.")
185 points = qmc.Sobol(self.
dimension, scramble=
True, seed=seed).random_base2((samples - 1).bit_length())
186 points = np.vstack((points[:samples], [point
for point, _
in self.
_observations]))
190 for slot, cell
in enumerate(self.
_cells):
191 rows = np.flatnonzero(probabilities[:, slot] >= min_probability)
193 row = rows[np.argmax(means[rows, 0])]
196 tuple(map(float, means[row, 1:])),
197 float(probabilities[row, slot])))
198 return tuple(predictions)
202 raise RuntimeError(
"The BOIL evaluation budget is exhausted.")
206 def optimise(self, evaluate, budget=None, **kwargs):
207 """Run an additional phase, using the remaining budget if none is given."""
210 raise ValueError(
"The phase budget exceeds remaining_evaluations.")
211 return super().
optimise(evaluate, budget=count, **kwargs)
prediction_map(self, *, samples=512, min_probability=.5, seed=0)
Build a model-only prediction map without spending evaluations or advancing the search.