Skip to content

Commit

Permalink
fix: allow null target_func
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Sep 8, 2024
1 parent 84e2831 commit 3ce5298
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bayes_opt/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ def _copy_target_space(self, target_space: TargetSpace) -> TargetSpace:
keys = target_space.keys
pbounds = {key: bound for key, bound in zip(keys, target_space.bounds)}
target_space_copy = TargetSpace(
None, # FIXME
None,
pbounds=pbounds,
constraint=target_space.constraint,
allow_duplicate_points=target_space._allow_duplicate_points,
Expand Down
4 changes: 2 additions & 2 deletions bayes_opt/bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BayesianOptimization(Observable):
Parameters
----------
f: function
f: function or None.
Function to be maximized.
pbounds: dict
Expand Down Expand Up @@ -110,7 +110,7 @@ class BayesianOptimization(Observable):

def __init__(
self,
f: Callable[..., float],
f: Callable[..., float] | None,
pbounds: Mapping[str, tuple[float, float]],
acquisition_function: AcquisitionFunction | None = None,
constraint: Constraint | None = None,
Expand Down
7 changes: 5 additions & 2 deletions bayes_opt/target_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TargetSpace:
Parameters
----------
target_func : function
target_func : function or None.
Function to be maximized.
pbounds : dict
Expand Down Expand Up @@ -64,7 +64,7 @@ class TargetSpace:

def __init__(
self,
target_func: Callable[..., float],
target_func: Callable[..., float] | None,
pbounds: Mapping[str, tuple[float, float]],
constraint: ConstraintModel | None = None,
random_state: int | np.random.RandomState | None = None,
Expand Down Expand Up @@ -406,6 +406,9 @@ def probe(self, params: Any) -> float | tuple[float, float | NDArray[Float]]:
return self._cache[_hashable(x.ravel())]

dict_params = self.array_to_params(x)
if self.target_func is None:
error_msg = "No target function has been provided."
raise ValueError(error_msg)
target = self.target_func(**dict_params)

if self._constraint is None:
Expand Down

0 comments on commit 3ce5298

Please sign in to comment.