Skip to content

Commit

Permalink
For fANOVA, remove constant hyperparameters from configspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Krebs committed Jan 8, 2024
1 parent 411f0ed commit 8ea1554
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## Bug-Fixes
- Don't convert BOHB runs with status 'running' (consistent with SMAC).
- For fANOVA, remove constant hyperparameters from configspace (#9).

# Version 1.1.3

Expand Down
20 changes: 20 additions & 0 deletions deepcave/plugins/hyperparameter/importances.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import plotly.graph_objs as go
from dash import dcc, html
from dash.exceptions import PreventUpdate
from ConfigSpace import ConfigurationSpace, Constant

from deepcave import config
from deepcave.evaluators.fanova import fANOVA as GlobalEvaluator
Expand Down Expand Up @@ -178,6 +179,25 @@ def process(run, inputs):
if n_trees is None:
raise RuntimeError("Please specify the number of trees.")

# Handle constant values in fANOVA: As the fANOVA implementation relies on pyrfr and pyrfr cannot be applied
# to constant hyperparameters (see https://github.com/automl/fanova/issues/81), as a workaround we remove
# constant hyperparameters before calculation.
# Note: This will break if there are conditions including constant hyperparameters.
hp_dict = run.configspace.get_hyperparameters_dict()
if method == "global" and any([type(v) == Constant for v in hp_dict.values()]):
hp_dict_wo_const = {
k: v for k, v in hp_dict.items() if type(v) != Constant}
configspace_wo_const = ConfigurationSpace()
for k in hp_dict_wo_const.keys():
configspace_wo_const.add_hyperparameter(hp_dict_wo_const[k])
configspace_wo_const.add_conditions(run.configspace.get_conditions())
run.configspace = configspace_wo_const

configs_wo_const = []
for n in range(len(run.configs)):
configs_wo_const.append({k: v for k,v in run.configs[n].items() if k in hp_dict_wo_const.keys()})
run.configs = configs_wo_const

hp_names = run.configspace.get_hyperparameter_names()
budgets = run.get_budgets(include_combined=True)

Expand Down

0 comments on commit 8ea1554

Please sign in to comment.