|
12 | 12 | from hypershap import ExplanationTask |
13 | 13 | from tests.fixtures.simple_setup import SimpleBlackboxFunction |
14 | 14 |
|
| 15 | +from ConfigSpace import Configuration |
| 16 | + |
15 | 17 | from hypershap.task import BaselineExplanationTask |
16 | 18 | from hypershap.utils import Aggregation, RandomConfigSpaceSearcher, evaluate_aggregation |
17 | 19 |
|
@@ -144,3 +146,31 @@ def test_evaluate_aggregation() -> None: |
144 | 146 | assert evaluate_aggregation(Aggregation.MAX, vals) == AGG_LIST[2] |
145 | 147 | assert evaluate_aggregation(Aggregation.AVG, vals) == np.array(AGG_LIST).mean() |
146 | 148 | assert abs(evaluate_aggregation(Aggregation.VAR, vals) - np.array(AGG_LIST).var()) < EPSILON |
| 149 | + |
| 150 | + |
| 151 | +def test_fallback_unfulfilled_conditions(simple_act_base_et: ExplanationTask) -> None: |
| 152 | + """Test the fallback strategy when no configurations are left in random sample after filtering for conditions.""" |
| 153 | + bet = BaselineExplanationTask( |
| 154 | + simple_act_base_et.config_space, |
| 155 | + simple_act_base_et.surrogate_model, |
| 156 | + simple_act_base_et.config_space.get_default_configuration(), |
| 157 | + ) |
| 158 | + rcss = RandomConfigSpaceSearcher(bet) |
| 159 | + rcss.random_sample = np.array([ |
| 160 | + Configuration( |
| 161 | + configuration_space=simple_act_base_et.config_space, |
| 162 | + values={ |
| 163 | + "a": 0.4, |
| 164 | + "b": 0.1, |
| 165 | + }, |
| 166 | + ).get_array(), |
| 167 | + Configuration( |
| 168 | + configuration_space=simple_act_base_et.config_space, |
| 169 | + values={ |
| 170 | + "a": 0.5, |
| 171 | + "b": 0.1, |
| 172 | + }, |
| 173 | + ).get_array(), |
| 174 | + ]) |
| 175 | + value = rcss.search(np.array([False, True])) |
| 176 | + assert value is not None |
0 commit comments