Skip to content

Commit ff91440

Browse files
committed
fix
1 parent 0be486f commit ff91440

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

bayes_opt/acquisition.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,15 @@ def suggest(
13161316
]
13171317
self.previous_candidates = np.array(x_max)
13181318
idx = self._sample_idx_from_softmax_gains(random_state=random_state)
1319+
if not target_space._allow_duplicate_points and x_max[idx] in target_space:
1320+
# If every candidate is a duplicate, keep the original choice.
1321+
# Avoiding duplicates then requires generating new candidates, which
1322+
# is outside GPHedge's candidate-selection responsibility.
1323+
non_duplicate_idx = [idx for idx, x in enumerate(x_max) if x not in target_space]
1324+
if len(non_duplicate_idx) > 0:
1325+
cumsum_softmax_g = np.cumsum(softmax(self.gains[non_duplicate_idx]))
1326+
r = random_state.rand()
1327+
idx = non_duplicate_idx[np.argmax(r <= cumsum_softmax_g)]
13191328
return x_max[idx]
13201329

13211330
def get_acquisition_params(self) -> dict[str, Any]:

0 commit comments

Comments
 (0)