Evaluate the target function on a point and register the result. Notes ----- If `params` has been previously seen and duplicate points are not allowed, returns a cached value of `result`. Parameters ---------- params : np.ndarray
(self, params: ParamsType)
| 518 | self._cache = cache_copy |
| 519 | |
| 520 | def probe(self, params: ParamsType) -> float | tuple[float, float | NDArray[Float]]: |
| 521 | """Evaluate the target function on a point and register the result. |
| 522 | |
| 523 | Notes |
| 524 | ----- |
| 525 | If `params` has been previously seen and duplicate points are not allowed, |
| 526 | returns a cached value of `result`. |
| 527 | |
| 528 | Parameters |
| 529 | ---------- |
| 530 | params : np.ndarray |
| 531 | a single point, with len(x) == self.dim |
| 532 | |
| 533 | Returns |
| 534 | ------- |
| 535 | result : float | Tuple(float, float) |
| 536 | target function value, or Tuple(target function value, constraint value) |
| 537 | |
| 538 | Example |
| 539 | ------- |
| 540 | >>> target_func = lambda p1, p2: p1 + p2 |
| 541 | >>> pbounds = {"p1": (0, 1), "p2": (1, 100)} |
| 542 | >>> space = TargetSpace(target_func, pbounds) |
| 543 | >>> space.probe([1, 5]) |
| 544 | >>> assert self.max()["target"] == 6 |
| 545 | >>> assert self.max()["params"] == {"p1": 1.0, "p2": 5.0} |
| 546 | """ |
| 547 | x = self._as_array(params) |
| 548 | if x in self and not self._allow_duplicate_points: |
| 549 | return self._cache[_hashable(x.ravel())] |
| 550 | |
| 551 | dict_params = self.array_to_params(x) |
| 552 | if self.target_func is None: |
| 553 | error_msg = "No target function has been provided." |
| 554 | raise ValueError(error_msg) |
| 555 | target = self.target_func(**dict_params) |
| 556 | |
| 557 | if self._constraint is None: |
| 558 | self.register(x, target) |
| 559 | return target |
| 560 | |
| 561 | constraint_value = self._constraint.eval(**dict_params) |
| 562 | self.register(x, target, constraint_value) |
| 563 | return target, constraint_value |
| 564 | |
| 565 | def random_sample( |
| 566 | self, n_samples: int = 0, random_state: np.random.RandomState | int | None = None |