Skip to content

Commit fa3f2cd

Browse files
committed
Explain difference between permanent and dynamic exclusion
1 parent 87c4683 commit fa3f2cd

File tree

1 file changed

+75
-14
lines changed

1 file changed

+75
-14
lines changed

docs/userguide/getting_recommendations.md

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,81 @@ BayBE offers two entry points for requesting recommendations:
5353

5454

5555
## Excluding Configurations
56+
When asking for recommendation, you often don't want to consider all possible
57+
combinations of parameter values (a.k.a. the full Cartesian product space) but you may
58+
want to exclude certain configurations that are known to be infeasible or undesirable.
59+
There are several ways to do this, including using BayBE's sophisticated [constraint
60+
machinery](userguide/constraints). Which approach is the right choice for you depends on
61+
whether you want to exclude configurations *permanently* or (in-)activate them
62+
*dynamically* during your experimentation cycle.
63+
64+
### Permanent Exclusion
65+
66+
Permanently excluding certain parameter configurations from the recommendation is
67+
generally done by adjusting the {class}`~baybe.searchspace.core.SearchSpace` object
68+
accordingly, which defines the set of candidate configurations that will be considered.
69+
70+
BayBE provides several ways to achieve this, which we'll illustrate by comparing against
71+
the following "full" search space:
72+
```python
73+
searchspace_full = TaskParameter("p", ["A", "B", "C"]).to_searchspace()
74+
```
75+
Depending on the specific needs and complexity of the filtering operation, one approach
76+
may be preferred over the other, but generally these mechanisms exist:
77+
78+
* Restricting individual parameter objects:
79+
```python
80+
searchspace_reduced = TaskParameter(
81+
"p", ["A", "B", "C"], active_values=["A", "B"]
82+
).to_searchspace()
83+
```
84+
85+
```{admonition} Reduced
86+
:class: caution
87+
88+
Note that this is *not* the same as defining the parameter with a reduced set of
89+
values `["A", "B"]` since in this case the value "C" would be undefined. This
90+
makes adding measurements containing that value impossible.
91+
```
92+
93+
* Specifying only a subset of configurations (discrete spaces only):
94+
```python
95+
searchspace_reduced = SearchSpace.from_dataframe(
96+
pd.DataFrame({"p": ["A", "B"]}),
97+
parameters=[TaskParameter("p", ["A", "B", "C"])],
98+
)
99+
```
100+
101+
* Filtering the search space using constraints:
102+
```python
103+
searchspace_reduced = SearchSpace.from_product(
104+
parameters=[CategoricalParameter("p", ["A", "B", "C"])],
105+
constraints=[DiscreteExcludeConstraint(["p"], [SubSelectionCondition(["C"])])],
106+
)
107+
```
108+
109+
* Using specialized constructors like
110+
{meth}`~baybe.searchspace.discrete.SubspaceDiscrete.from_simplex`.
111+
112+
### Dynamic Exclusion
113+
114+
Dynamic exclusion of candidates means to in-/exclude certain parameter configurations
115+
while you are already in the middle of your experimentation process. Here,
116+
we need to consider two different cases:
56117

57-
Excluding certain parameter configurations from recommendation is generally done by
58-
adjusting the {class}`~baybe.searchspace.core.SearchSpace` object accordingly, which
59-
defines the set of candidate configurations that will be considered.
60118
* **Recommenders**\
61-
The above means that, for [stateless queries](#stateless), you can simply pass a
62-
different search space object to each call according to your needs:
119+
Since recommender queries are [stateless](#stateless) with respect to the
120+
experimental context, you can easily adjust your search space object for each query
121+
as needed using any of the *permanent* exclusion methods. For example:
63122
```python
64123
# Recommendation with full search space
65124
searchspace_full = CategoricalParameter("p", ["A", "B", "C"]).to_searchspace()
66125
recommender.recommend(batch_size, searchspace_full, objective, measurements)
67126

68127
# Recommendation with reduced search space
69-
searchspace_reduced = CategoricalParameter("p", ["A", "B"]).to_searchspace()
128+
searchspace_reduced = TaskParameter(
129+
"p", ["A", "B", "C"], active_values=["A", "B"]
130+
).to_searchspace()
70131
recommender.recommend(batch_size, searchspace_reduced, objective, measurements)
71132
```
72133

@@ -93,6 +154,14 @@ defines the set of candidate configurations that will be considered.
93154
{class}`~baybe.constraints.base.DiscreteConstraint` objects.
94155
For more details, see {meth}`baybe.campaign.Campaign.toggle_discrete_candidates`.
95156

157+
```{admonition} Candidate Toggling vs. Applying Constraints
158+
:class: attention
159+
160+
Currently, dynamic exclusion via toggling is only possible for discrete candidates.
161+
To restrict the set of continuous candidates, use
162+
{class}`~baybe.constraints.base.ContinuousConstraint`s when creating the space.
163+
```
164+
96165
```{admonition} Trajectory-Based Control
97166
:class: seealso
98167
@@ -101,14 +170,6 @@ defines the set of candidate configurations that will be considered.
101170
{ref}`flags <userguide/campaigns:Candidate Control in Discrete Spaces>`.
102171
```
103172

104-
```{admonition} Continuous Constraints
105-
:class: attention
106-
107-
Currently, candidate exclusion at the {class}`~baybe.campaign.Campaign` level is
108-
only possible for the discrete part of the underlying search space. To restrict
109-
the continuous part of the search, use
110-
{class}`~baybe.constraints.base.ContinuousConstraint`s when creating the space.
111-
```
112173

113174

114175

0 commit comments

Comments
 (0)