Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/fANOVA constant hyperparameters #109

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fix api examples (#68).
- Reset inputs to fix error when subsequently selecting runs with different configspaces, objectives or budgets (#106).
- Fix errors due to changing inputs before runselection (#64).
- For fANOVA, remove constant hyperparameters from configspace (#9).

# Version 1.1.3

Expand Down
21 changes: 21 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.config import Config
from deepcave.evaluators.fanova import fANOVA as GlobalEvaluator
Expand Down Expand Up @@ -177,6 +178,26 @@ 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 or forbiddens including constant hyperparameters.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have that documented in the documentation? If not, please add that there as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the docs.

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())
configspace_wo_const.add_forbidden_clauses(run.configspace.get_forbiddens())
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
7 changes: 6 additions & 1 deletion docs/plugins/importances.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ This plugin is capable of answering following questions:
* How much differs the importance between the budgets?


.. warning::
.. warning::
This page is under construction.


.. image:: ../images/plugins/importances.png

.. warning::
As the fANOVA implementation relies on pyrfr and pyrfr cannot be applied to constant hyperparameters,
as a workaround we remove constant hyperparameters before calculation.
This will break if there are conditions or forbiddens including constant hyperparameters.
Loading