Skip to content

Commit cfbf43e

Browse files
committed
added ablation
1 parent 34d9b00 commit cfbf43e

9 files changed

Lines changed: 597 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Version 1.4.3
22

3+
## HyperSHAP
4+
- Added HyperSHAP evaluator
5+
- Added Tunability plugin
6+
- Added Ablation plugin
7+
38
## Requirements
49
- Updated ConfigSpace to 1.2.2
510
- Updated matplotlib to 3.10.8

deepcave/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ class Config:
6161

6262
# General config
6363
TITLE: str = "DeepCAVE"
64-
# TODO: Turn it oooooooff before PR i swear to god
65-
DEBUG: bool = True
64+
DEBUG: bool = False
6665
# How often to refresh background activities (such as update the sidebar or process button for
6766
# static plugins). Value in milliseconds.
6867
REFRESH_RATE: int = 500
@@ -118,6 +117,7 @@ def PLUGINS(self) -> Dict[str, List[Any]]:
118117
from deepcave.plugins.hyperparameter.symbolic_explanations import (
119118
SymbolicExplanations,
120119
)
120+
from deepcave.plugins.hypershap.hype_ablation import HypeAblation
121121
from deepcave.plugins.hypershap.tunability import Tunability
122122
from deepcave.plugins.objective.cost_over_time import CostOverTime
123123
from deepcave.plugins.objective.pareto_front import ParetoFront
@@ -147,7 +147,7 @@ def PLUGINS(self) -> Dict[str, List[Any]]:
147147
PartialDependencies(),
148148
SymbolicExplanations(),
149149
],
150-
"HyperSHAP": [Tunability()],
150+
"HyperSHAP": [Tunability(), HypeAblation()],
151151
}
152152
return plugins
153153

deepcave/evaluators/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626
This module provides utilities to calculate the local parameter importance (LPI).
2727
ablation
2828
This module evaluates the ablation paths.
29+
hypershap
30+
This module uses HyperSHAP for explaining Hyperparameter Optimization (HPO).
2931
"""

deepcave/evaluators/hypershap.py

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
HyperSHAP is a game-theoretic Python library that uses Shapley values and
2222
interaction indices to provide local and global insights into how
2323
individual hyper-parameters affect a model's performance.
24-
This module includes the evaluation of tunabilty, mistuneability.
24+
This module includes the evaluation of tunabilty, mistuneability, and ablation.
2525
2626
## Classes:
2727
- HyperSHAP_Eval: Provide an evaluator used for HyperSHAP evaluation.
@@ -53,7 +53,9 @@ class HyperSHAP_Eval:
5353
iv : InteractionValues
5454
An object containing evaluation results.
5555
tune : Dict[str: Any]
56-
The iv parameters converted as python dictionary.
56+
The iv tuneability parameters converted as python dictionary.
57+
abl : Dict[str: Any]
58+
The iv ablation parameters converted as python dictionary.
5759
"""
5860

5961
def __init__(self, run: AbstractRun):
@@ -62,7 +64,7 @@ def __init__(self, run: AbstractRun):
6264
self.hp_names = list(self.cs.keys())
6365
self.logger = get_logger(self.__class__.__name__)
6466

65-
def hype_tune(self, tunability: str, objective_id: int, budget_id: int) -> Dict:
67+
def hype_tune(self, tunability: str, objective_id: int, budget_id: int, seed: int = 42) -> Dict:
6668
"""
6769
Calculate the tunability or mistunability.
6870
@@ -96,9 +98,7 @@ def hype_tune(self, tunability: str, objective_id: int, budget_id: int) -> Dict:
9698
configuration_list = self.cs.sample_configuration(size=1_000)
9799
data = list(zip(configuration_list, df[objective.name].to_numpy())) # type: ignore
98100

99-
self.cs.seed(42)
100-
101-
explanation_task = ExplanationTask.from_data(config_space=self.cs, data=data)
101+
explanation_task = ExplanationTask.from_data(config_space=self.cs, data=data, seed=seed)
102102
self.hypershap = HyperSHAP(explanation_task=explanation_task)
103103

104104
baseline_config = self.cs.sample_configuration()
@@ -122,6 +122,73 @@ def hype_tune(self, tunability: str, objective_id: int, budget_id: int) -> Dict:
122122

123123
return self.tune
124124

125+
def hype_ablation(self, objective_id: int, budget_id: int, seed: int = 42) -> Dict:
126+
"""
127+
Calculate the ablation.
128+
129+
Parameters
130+
----------
131+
objective_id : int
132+
The id of the objective to evaluate on.
133+
budget_id : int
134+
The id of the budget to evaluate on.
135+
136+
Returns
137+
-------
138+
Dict
139+
The dictionary with the evaluation results.
140+
141+
Raises
142+
------
143+
ValueError
144+
If the Objective is None.
145+
"""
146+
if budget_id is None:
147+
budget_id = self.run.get_highest_budget()
148+
149+
objective = self.run.get_objective(objective_id)
150+
budget = self.run.get_budget(budget_id)
151+
152+
if objective is None:
153+
raise ValueError(
154+
"No Objective has been chosen. Please select an "
155+
"Objective or try to select the Objective again."
156+
)
157+
158+
df = self.run.get_encoded_data(
159+
objective,
160+
budget,
161+
statuses=Status.SUCCESS,
162+
)
163+
164+
# Match the configuration data with the resulting performance
165+
configuration_list = self.cs.sample_configuration(size=1_000)
166+
data = list(zip(configuration_list, df[objective.name].to_numpy())) # type: ignore
167+
168+
explanation_task = ExplanationTask.from_data(config_space=self.cs, data=data, seed=seed)
169+
self.hypershap = HyperSHAP(explanation_task=explanation_task)
170+
171+
baseline_config = self.cs.get_default_configuration()
172+
config_of_interest, _ = self.run.get_incumbent(budget=budget, objectives=objective)
173+
174+
self.iv = self.hypershap.ablation(
175+
config_of_interest=config_of_interest, baseline_config=baseline_config
176+
)
177+
178+
# Convert to python dictionary to avoid JSON serializability problems
179+
self.abl = {
180+
"index": str(self.iv.index),
181+
"max_order": self.iv.max_order,
182+
"min_order": self.iv.min_order,
183+
"estimated": self.iv.estimated,
184+
"estimation_budget": self.iv.estimation_budget,
185+
"n_players": self.iv.n_players,
186+
"baseline_value": self.iv.baseline_value,
187+
"interactions": {str(key): value for key, value in self.iv.interactions.items()},
188+
}
189+
190+
return self.abl
191+
125192
def get_tunability(self) -> Dict:
126193
"""
127194
Get the tunability or mistunability evaluation values.
@@ -132,3 +199,14 @@ def get_tunability(self) -> Dict:
132199
A dictionary containing the evaluation values.
133200
"""
134201
return self.tune
202+
203+
def get_ablation(self) -> Dict:
204+
"""
205+
Get the tunability or mistunability evaluation values.
206+
207+
Returns
208+
-------
209+
Dict
210+
A dictionary containing the evaluation values.
211+
"""
212+
return self.abl

0 commit comments

Comments
 (0)