Skip to content

Commit

Permalink
Harmonize allow_* flags
Browse files Browse the repository at this point in the history
The original name allow_repeated_recommendations is not accurate since
it also suggests that repeated configurations within a batch would be
excluded, which is not the case.
  • Loading branch information
AdrianSosic committed Nov 14, 2024
1 parent c95fc18 commit f79b557
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
15 changes: 7 additions & 8 deletions baybe/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,17 @@ class Campaign(SerialMixin):
)
"""The employed recommender"""

allow_repeated_recommendations: bool = field(default=False, kw_only=True)
"""Allow to make recommendations that were already recommended earlier.
allow_recommending_already_measured: bool = field(default=True, kw_only=True)
"""Allow to recommend experiments that were already measured earlier.
This only has an influence in discrete search spaces."""

allow_recommending_already_measured: bool = field(default=True, kw_only=True)
"""Allow to make recommendations that were measured previously.
allow_recommending_already_recommended: bool = field(default=False, kw_only=True)
"""Allow to recommend experiments that were already recommended earlier.
This only has an influence in discrete search spaces."""

allow_recommending_pending_experiments: bool = field(default=False, kw_only=True)
"""Allow `pending_experiments` to be part of the recommendations. If set to `False`,
the corresponding points will be removed from the candidates. This only has an
influence in discrete search spaces."""
"""Allow pending experiments to be part of the recommendations.
This only has an influence in discrete search spaces."""

# Metadata
_searchspace_metadata: pd.DataFrame = field(init=False, eq=eq_dataframe)
Expand Down Expand Up @@ -384,7 +383,7 @@ def recommend(

# Prepare the search space according to the current campaign state
mask_todrop = self._searchspace_metadata[_EXCLUDED].copy()
if not self.allow_repeated_recommendations:
if not self.allow_recommending_already_recommended:
mask_todrop |= self._searchspace_metadata[_RECOMMENDED]
if not self.allow_recommending_already_measured:
mask_todrop |= self._searchspace_metadata[_MEASURED]
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/campaigns.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ set of recommendable points is built based on the trajectory the campaign has ta
far. This is done by setting the following Boolean flags:
- `allow_recommending_already_measured`: Controls whether points that have already been
measured points can be recommended.
- `allow_repeated_recommendations`: Controls whether previously recommended points can
- `allow_recommending_already_recommended`: Controls whether previously recommended points can
be recommended again.
- `allow_recommending_pending_experiments`: Controls whether points marked as
`pending_experiments` can be recommended (see [asynchronous
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def simulate(acqf: AcquisitionFunction) -> SimulationResult:
objective,
recommender,
# The same arm can be pulled several times:
allow_repeated_recommendations=True,
allow_recommending_already_recommended=True,
allow_recommending_already_measured=True,
)

Expand Down
2 changes: 1 addition & 1 deletion examples/Serialization/create_from_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
},
"switch_after": 1
},
"allow_repeated_recommendations": false,
"allow_recommending_already_recommended": false,
"allow_recommending_already_measured": false
}
"""
Expand Down
4 changes: 2 additions & 2 deletions examples/Serialization/validate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"switch_after": 1
},
"allow_repeated_recommendations": false,
"allow_recommending_already_recommended": false,
"allow_recommending_already_measured": false
}
"""
Expand Down Expand Up @@ -147,7 +147,7 @@
"type": "GaussianProcessSurrogate"
},
"acquisition_function": "qEI",
"allow_repeated_recommendations": false,
"allow_recommending_already_recommended": false,
"allow_recommending_already_measured": false
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def fixture_campaign(
constraints,
recommender,
objective,
allow_repeated_recommendations,
allow_recommending_already_recommended,
allow_recommending_already_measured,
):
"""Returns a campaign."""
Expand All @@ -595,7 +595,7 @@ def fixture_campaign(
),
recommender=recommender,
objective=objective,
allow_repeated_recommendations=allow_repeated_recommendations,
allow_recommending_already_recommended=allow_recommending_already_recommended,
allow_recommending_already_measured=allow_recommending_already_measured,
)

Expand Down Expand Up @@ -657,8 +657,8 @@ def fixture_default_surrogate_model(request, kernel):
return GaussianProcessSurrogate(kernel_or_factory=kernel)


@pytest.fixture(name="allow_repeated_recommendations")
def fixture_allow_repeated_recommendations():
@pytest.fixture(name="allow_recommending_already_recommended")
def fixture_allow_recommending_already_recommended():
return False


Expand Down
2 changes: 1 addition & 1 deletion tests/test_pending_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# Repeated recommendations explicitly need to be allowed or the potential overlap will
# be avoided trivially
@pytest.mark.parametrize("allow_repeated_recommendations", [True])
@pytest.mark.parametrize("allow_recommending_already_recommended", [True])
@pytest.mark.parametrize("allow_recommending_already_measured", [True])
@pytest.mark.parametrize(
"parameter_names, recommender",
Expand Down

0 comments on commit f79b557

Please sign in to comment.