@@ -79,6 +79,46 @@ ContinuousLinearConstraint(
79
79
A more detailed example can be found
80
80
[ here] ( ../../examples/Constraints_Continuous/linear_constraints ) .
81
81
82
+ ### ContinuousCardinalityConstraint
83
+ The {class}` ~baybe.constraints.continuous.ContinuousCardinalityConstraint ` gives you a
84
+ tool to control the number of active factors (i.e. parameters that take a non-zero
85
+ value) in your designs. This comes handy, for example, when designing mixtures with a
86
+ limited number of components.
87
+
88
+ To create a constraint of this kind, simply specify the set of parameters on which the
89
+ constraint is to be imposed, together with the corresponding upper and lower cardinality
90
+ limits. For instance, the following constraint would ensure that there is always a
91
+ minimum of one and a maximum of two components in each parameter configuration:
92
+
93
+ ``` python
94
+ from baybe.constraints import ContinuousCardinalityConstraint
95
+
96
+ ContinuousCardinalityConstraint(
97
+ parameters = [" x_1" , " x_2" , " x_3" ],
98
+ min_cardinality = 1 , # defaults to 0
99
+ max_cardinality = 2 , # defaults to the number of affected parameters (here: 3)
100
+ relative_threshold = 0.001 , # optional, defines the range of values considered active
101
+ )
102
+ ```
103
+
104
+ ``` {admonition} Computational Challenges
105
+ :class: warning
106
+
107
+ Note that, compared to optimization with [discrete cardinality
108
+ constraints](#DiscreteCardinalityConstraint), finding optimal cardinality-constrained
109
+ solutions in continuous spaces is significantly more challenging due to the
110
+ fractured nature of the resulting space. For larger parameter sets or complex constraint
111
+ settings, searching an optimal parameter configuration can quickly become infeasible,
112
+ creating the need for approximation schemes:
113
+
114
+ * The
115
+ {paramref}`BotorchRecommender.max_n_subspaces <baybe.recommenders.pure.bayesian.botorch.BotorchRecommender.max_n_subspaces>`
116
+ attribute can be used to limit the number of subspaces considered during optimization.
117
+ * When the ranges of cardinality-constrained parameters cover both positive and negative
118
+ values, minimal cardinality requirements cannot always be guaranteed, potentially
119
+ resulting in a {class}`~baybe.exceptions.MinimumCardinalityViolatedWarning`.
120
+ ```
121
+
82
122
## Conditions
83
123
Conditions are elements used within discrete constraints.
84
124
While discrete constraints can operate on one or multiple parameters, a condition
@@ -369,6 +409,20 @@ DiscretePermutationInvarianceConstraint(
369
409
The usage of ` DiscretePermutationInvarianceConstraint ` is also part of the
370
410
[ example on slot-based mixtures] ( ../../examples/Mixtures/slot_based ) .
371
411
412
+ ### DiscreteCardinalityConstraint
413
+ Like its [ continuous cousin] ( #ContinuousCardinalityConstraint ) , the
414
+ {class}` ~baybe.constraints.discrete.DiscreteCardinalityConstraint ` lets you control the
415
+ number of active parameters in your design. The construction works analogously:
416
+ ``` python
417
+ from baybe.constraints import DiscreteCardinalityConstraint
418
+
419
+ DiscreteCardinalityConstraint(
420
+ parameters = [" Fraction_1" , " Fraction_2" , " Fraction_3" ],
421
+ min_cardinality = 1 , # defaults to 0
422
+ max_cardinality = 2 , # defaults to the number of affected parameters (here: 3)
423
+ )
424
+ ```
425
+
372
426
### DiscreteCustomConstraint
373
427
With a [ ` DiscreteCustomConstraint ` ] ( baybe.constraints.discrete.DiscreteCustomConstraint )
374
428
constraint, you can specify a completely custom filter:
0 commit comments