Skip to content

Commit

Permalink
Sarah Segel: Merge pull request #109 from automl/bugfix/fanova-consta…
Browse files Browse the repository at this point in the history
…nt-hp
  • Loading branch information
Github Actions committed Feb 9, 2024
1 parent ab807a5 commit da5e6da
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion development/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: e27100b7398878a478b65fca541e6eab
config: 38f3e521f95d9c6f8103061512f8fea3
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified development/.doctrees/environment.pickle
Binary file not shown.
Binary file modified development/.doctrees/plugins/importances.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ <h1>Source code for deepcave.plugins.hyperparameter.importances</h1><div class="
<span class="kn">import</span> <span class="nn">plotly.graph_objs</span> <span class="k">as</span> <span class="nn">go</span>
<span class="kn">from</span> <span class="nn">dash</span> <span class="kn">import</span> <span class="n">dcc</span><span class="p">,</span> <span class="n">html</span>
<span class="kn">from</span> <span class="nn">dash.exceptions</span> <span class="kn">import</span> <span class="n">PreventUpdate</span>
<span class="kn">from</span> <span class="nn">ConfigSpace</span> <span class="kn">import</span> <span class="n">ConfigurationSpace</span><span class="p">,</span> <span class="n">Constant</span>

<span class="kn">from</span> <span class="nn">deepcave.config</span> <span class="kn">import</span> <span class="n">Config</span>
<span class="kn">from</span> <span class="nn">deepcave.evaluators.fanova</span> <span class="kn">import</span> <span class="n">fANOVA</span> <span class="k">as</span> <span class="n">GlobalEvaluator</span>
Expand Down Expand Up @@ -882,6 +883,26 @@ <h1>Source code for deepcave.plugins.hyperparameter.importances</h1><div class="
<span class="k">if</span> <span class="n">n_trees</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Please specify the number of trees.&quot;</span><span class="p">)</span>

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

<span class="n">configs_wo_const</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">run</span><span class="o">.</span><span class="n">configs</span><span class="p">)):</span>
<span class="n">configs_wo_const</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">run</span><span class="o">.</span><span class="n">configs</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">hp_dict_wo_const</span><span class="o">.</span><span class="n">keys</span><span class="p">()})</span>
<span class="n">run</span><span class="o">.</span><span class="n">configs</span> <span class="o">=</span> <span class="n">configs_wo_const</span>

<span class="n">hp_names</span> <span class="o">=</span> <span class="n">run</span><span class="o">.</span><span class="n">configspace</span><span class="o">.</span><span class="n">get_hyperparameter_names</span><span class="p">()</span>
<span class="n">budgets</span> <span class="o">=</span> <span class="n">run</span><span class="o">.</span><span class="n">get_budgets</span><span class="p">(</span><span class="n">include_combined</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

Expand Down
7 changes: 6 additions & 1 deletion development/_sources/plugins/importances.rst.txt
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.
6 changes: 6 additions & 0 deletions development/plugins/importances.html
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,12 @@ <h1>Importances<a class="headerlink" href="#importances" title="Link to this hea
<p>This page is under construction.</p>
</div>
<img alt="../_images/importances.png" src="../_images/importances.png" />
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>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.</p>
</div>
</section>


Expand Down
2 changes: 1 addition & 1 deletion development/searchindex.js

Large diffs are not rendered by default.

0 comments on commit da5e6da

Please sign in to comment.