Skip to content

Commit

Permalink
[MCBO]: fix missing update_best.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntGro committed Feb 26, 2024
1 parent 55d29f9 commit e706eb9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion MCBO/mcbo/optimizers/optimizer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def method_suggest(self, n_suggestions: int = 1) -> pd.DataFrame:
Returns:
a DataFrame of suggestions
"""

pass

def suggest(self, n_suggestions: int = 1) -> pd.DataFrame:
Expand All @@ -149,7 +150,7 @@ def suggest(self, n_suggestions: int = 1) -> pd.DataFrame:
Args:
n_suggestions: number of points to suggest
Returns:
dataframe of suggested points.
"""
Expand Down Expand Up @@ -230,6 +231,20 @@ def best_x(self) -> Optional[pd.DataFrame]:
return self.search_space.inverse_transform(self._best_x)
return None

def update_best(self, x_transf: torch.Tensor, y: torch.Tensor) -> None:
""" Update `best_y` and `_best_x` given new suggestions
Args:
x_transf: tensor of inputs (in transformed space)
y: tensor of black-box values
"""
best_idx = self.get_best_y_ind(y=y)
best_y = y[best_idx]

if self.best_y is None or self.is_better_than_current(current_y=self.best_y, new_y=best_y):
self.best_y = best_y
self._best_x = x_transf[best_idx: best_idx + 1]

def _restart(self):
self._best_x = None
self.best_y = None
Expand Down

0 comments on commit e706eb9

Please sign in to comment.