Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Krebs committed Sep 8, 2023
1 parent 35eea9b commit aded257
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
4 changes: 3 additions & 1 deletion deepcave/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def PLUGINS(self) -> Dict[str, List["Plugin"]]:
from deepcave.plugins.budget.budget_correlation import BudgetCorrelation
from deepcave.plugins.hyperparameter.importances import Importances
from deepcave.plugins.hyperparameter.pdp import PartialDependencies
from deepcave.plugins.hyperparameter.symbolic_explanations import SymbolicExplanations
from deepcave.plugins.hyperparameter.symbolic_explanations import (
SymbolicExplanations,
)
from deepcave.plugins.objective.configuration_cube import ConfigurationCube
from deepcave.plugins.objective.cost_over_time import CostOverTime
from deepcave.plugins.objective.parallel_coordinates import ParallelCoordinates
Expand Down
18 changes: 7 additions & 11 deletions deepcave/plugins/hyperparameter/symbolic_explanations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import numpy as np
import plotly.graph_objs as go
from dash import dcc, html
from pyPDP.algorithms.pdp import PDP
from gplearn.genetic import SymbolicRegressor
from pyPDP.algorithms.pdp import PDP

from deepcave import config
from deepcave.evaluators.epm.random_forest_surrogate import RandomForestSurrogate
from deepcave.plugins.static import StaticPlugin
from deepcave.runs import Status
from deepcave.utils.layout import get_checklist_options, get_select_options, help_button
from deepcave.utils.styled_plotty import get_color, get_hyperparameter_ticks, save_image
from deepcave.utils.symbolic_regression import get_function_set, convert_symb
from deepcave.utils.symbolic_regression import convert_symb, get_function_set

GRID_POINTS_PER_AXIS = 20
SAMPLES_PER_HP = 10
Expand All @@ -24,7 +24,7 @@ class SymbolicExplanations(StaticPlugin):
id = "symbolic_explanations"
name = "Symbolic Explanations"
icon = "fas fa-subscript"
help = "docs/plugins/partial_dependencies.rst" # TODO
help = "docs/plugins/partial_dependencies.rst" # TODO
activate_run_selection = True

@staticmethod
Expand Down Expand Up @@ -129,8 +129,8 @@ def get_filter_layout(register):

def load_inputs(self):
return {
#"show_confidence": {"options": get_select_options(binary=True), "value": "true"},
#"show_ice": {"options": get_select_options(binary=True), "value": "true"},
# "show_confidence": {"options": get_select_options(binary=True), "value": "true"},
# "show_ice": {"options": get_select_options(binary=True), "value": "true"},
}

def load_dependency_inputs(self, run, previous_inputs, inputs):
Expand Down Expand Up @@ -234,11 +234,7 @@ def process(run, inputs):

y_symbolic = symb_model.predict(x).tolist()

return {
"x": x,
"y": y_symbolic,
"expr": str(conv_expr)
}
return {"x": x, "y": y_symbolic, "expr": str(conv_expr)}

@staticmethod
def get_output_layout(register):
Expand Down Expand Up @@ -313,7 +309,7 @@ def load_outputs(run, inputs, outputs):
xaxis=dict(tickvals=x_tickvals, ticktext=x_ticktext, title=hp1_name),
yaxis=dict(tickvals=y_tickvals, ticktext=y_ticktext, title=hp2_name),
margin=config.FIGURE_MARGIN,
title=expr
title=expr,
)
)

Expand Down
21 changes: 5 additions & 16 deletions deepcave/utils/symbolic_regression.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sympy
import numpy as np
import sympy
from gplearn import functions
from gplearn.functions import make_function

Expand All @@ -14,21 +14,11 @@ def exp(x):
def get_function_set():
exp_func = make_function(function=exp, arity=1, name="exp")

function_set = [
"add",
"sub",
"mul",
"div",
"sqrt",
"log",
"sin",
"cos",
"abs",
exp_func
]
function_set = ["add", "sub", "mul", "div", "sqrt", "log", "sin", "cos", "abs", exp_func]

return function_set


def convert_symb(symb, n_dim: int = None, n_decimals: int = None) -> sympy.core.expr:
"""
Convert a fitted symbolic regression to a simplified and potentially rounded mathematical expression.
Expand Down Expand Up @@ -68,14 +58,13 @@ def convert_symb(symb, n_dim: int = None, n_decimals: int = None) -> sympy.core.

symb_str = str(symb._program)


converter = {
"sub": lambda x, y: x - y,
"div": lambda x, y: x / y,
"mul": lambda x, y: x * y,
"add": lambda x, y: x + y,
"neg": lambda x: -x,
"pow": lambda x, y: x**y
"pow": lambda x, y: x**y,
}

if symb._program.length_ > 300:
Expand All @@ -99,4 +88,4 @@ def convert_symb(symb, n_dim: int = None, n_decimals: int = None) -> sympy.core.
if isinstance(a, sympy.core.numbers.Float):
symb_simpl = symb_simpl.subs(a, round(a, n_decimals))

return symb_simpl
return symb_simpl

0 comments on commit aded257

Please sign in to comment.