Skip to content

Commit

Permalink
Remove restriction on subspaces without cardinality constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSosic committed Oct 29, 2024
1 parent 788a5ba commit 046a8e2
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions baybe/recommenders/pure/bayesian/botorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,23 @@ def _recommend_continuous(
f"acquisition functions for batch sizes > 1."
)

points, _ = self._recommend_continuous_torch(subspace_continuous, batch_size)

return pd.DataFrame(points, columns=subspace_continuous.parameter_names)

def _recommend_continuous_torch(
self, subspace_continuous: SubspaceContinuous, batch_size: int
) -> tuple[Tensor, Tensor]:
"""Dispatcher selecting continuous optimization routine."""
if subspace_continuous.constraints_cardinality:
points, _ = self._recommend_continuous_with_cardinality_constraints(
return self._recommend_continuous_with_cardinality_constraints(
subspace_continuous, batch_size
)
else:
points, _ = self._recommend_continuous_without_cardinality_constraints(
return self._recommend_continuous_without_cardinality_constraints(
subspace_continuous, batch_size
)

return pd.DataFrame(points, columns=subspace_continuous.parameter_names)

def _recommend_continuous_with_cardinality_constraints(
self,
subspace_continuous: SubspaceContinuous,
Expand Down Expand Up @@ -254,9 +260,7 @@ def _recommend_continuous_with_cardinality_constraints(
for inactive_parameters in iterator
)

return self._optimize_subspaces_without_cardinality_constraints(
subspaces, batch_size
)
return self._optimize_continuous_subspaces(subspaces, batch_size)

def _recommend_continuous_without_cardinality_constraints(
self,
Expand Down Expand Up @@ -447,10 +451,10 @@ def __str__(self) -> str:
]
return to_string(self.__class__.__name__, *fields)

def _optimize_subspaces_without_cardinality_constraints(
def _optimize_continuous_subspaces(
self, subspaces: Iterable[SubspaceContinuous], batch_size: int
) -> tuple[Tensor, Tensor]:
"""Find the optimum candidates from multiple subspaces.
"""Find the optimum candidates from multiple continuous subspaces.
Args:
subspaces: The subspaces to consider for the optimization.
Expand All @@ -465,12 +469,11 @@ def _optimize_subspaces_without_cardinality_constraints(
for subspace in subspaces:
try:
# Optimize the acquisition function
f = self._recommend_continuous_without_cardinality_constraints
points_i, acqf_values_i = f(subspace, batch_size)
p, acqf = self._recommend_continuous_torch(subspace, batch_size)

# Append optimization results
points_all.append(points_i)
acqf_values_all.append(acqf_values_i)
points_all.append(p)
acqf_values_all.append(acqf)

# The optimization problem may be infeasible in certain subspaces
except ValueError:
Expand Down

0 comments on commit 046a8e2

Please sign in to comment.